% Remember to use the lgrind style

\Head{}
\File{finduidgidcheck.sh}{2003}{Apr}{16}{18:46}{3010}
\L{\LB{\C{}\#!_\1bin\1sh}}
\CE{}\L{\LB{}}
\L{\LB{\C{}\#_Question_6,_shell_programming_assignment,_2003.}}
\CE{}\L{\LB{}}
\L{\LB{\V{prog}=\N{\$}(\V{basename}_\N{\$0})}}
\L{\LB{\V{usage}()_\{}}
\L{\LB{___\V{echo}_\S{}\3Usage:_\$prog_[\-v]_[\-d_directory]\3\SE{}}}
\L{\LB{___\V{echo}_\-\-_\S{}\3\-v_verbose_mode_(show_all_SUID,_SGID_files)\3\SE{}}}
\L{\LB{___\V{echo}_\S{}\3Default:_only_show_SUID,_SGID_files_where_permission_or_ownership\3\SE{}}}
\L{\LB{___\V{echo}_\S{}\3does_not_match_original_installed_state.\3\SE{}}}
\L{\LB{___\V{echo}_\-\-_\S{}\3\-d_directory:_examine_files_below_directory_instead_of_current_dir.\3\SE{}}}
\L{\LB{___\K{exit}_\N{1}}}
\L{\LB{\}}}
\L{\LB{}}
\L{\LB{\V{unset}_\V{START\_DIRECTORY}}}
\L{\LB{\V{VERBOSE}=\N{0}}}
\L{\LB{\K{while}_\V{getopts}_\S{}\3:vd:\3\SE{}_\V{opt}}}
\L{\LB{\K{do}}}
\L{\LB{____\K{case}_\N{\$opt}_\K{in}}}
\L{\LB{________\V{v})_\V{VERBOSE}=\N{1}___;;}}
\L{\LB{________\V{d})_\V{START\_DIRECTORY}=\N{\$OPTARG}_;;}}
\L{\LB{________\*)_\V{usage}_______;;}}
\L{\LB{____\K{esac}}}
\L{\LB{\K{done}}}
\L{\LB{}}
\L{\LB{\V{UG\_TMPFILE}=\N{\$}(\V{mktemp}_\1\V{tmp}\1\N{\$}\{\V{prog}\}.\V{XXXXXX})___\|\,\|_\K{exit}_\N{1}}}
\L{\LB{\V{U\_TMPFILE}=\N{\$}(\V{mktemp}_\1\V{tmp}\1\N{\$}\{\V{prog}\}.\V{XXXXXX})____\|\,\|_\K{exit}_\N{1}}}
\L{\LB{\V{G\_TMPFILE}=\N{\$}(\V{mktemp}_\1\V{tmp}\1\N{\$}\{\V{prog}\}.\V{XXXXXX})____\|\,\|_\K{exit}_\N{1}}}
\L{\LB{\V{RPM\_TMPFILE}=\N{\$}(\V{mktemp}_\1\V{tmp}\1\N{\$}\{\V{prog}\}.\V{XXXXXX})__\|\,\|_\K{exit}_\N{1}}}
\L{\LB{\K{trap}_\S{}\3rm_\$UG\_TMPFILE_\$U\_TMPFILE_\$G\_TMPFILE_\$RPM\_TMPFILE\3\SE{}_\2}}
\L{\LB{____\V{HUP}_\V{INT}_\V{QUIT}_\V{PIPE}_\V{ALRM}_\V{TERM}_\V{EXIT}}}
\L{\LB{}}
\L{\LB{\K{if}_[_\S{}\3\$START\_DIRECTORY\3\SE{}_];_\K{then}}}
\L{\LB{____\K{cd}_\S{}\3\$START\_DIRECTORY\3\SE{}_\>_\1\V{dev}\1\V{null}_\N{2}\>\&\N{1}_\2}}
\L{\LB{____\|\,\|_\{_\V{echo}_\S{}\3Cannot_cd_to_\$START\_DIRECTORY\3\SE{};_\K{exit}_\N{1};_\}}}
\L{\LB{\K{fi}}}
\L{\LB{}}
\L{\LB{\V{find}_\N{\$PWD}_\-\V{path}_\S{}\4\1proc\4\SE{}_\-\V{prune}_\-\V{o}_\2}}
\L{\LB{__________\-\V{type}_\V{f}_\2(_\-\V{perm}_\-\N{6000}_\-\V{fprintf}_\N{\$}\{\V{UG\_TMPFILE}\}_\S{}\3\%m\2t\%u\2t\%g\2t\%p\2n\3\SE{}_\-\V{o}_\2}}
\L{\LB{_____________________\-\V{perm}_\-\N{4000}_\-\V{fprintf}_\N{\$}\{\V{U\_TMPFILE}\}__\S{}\3\%m\2t\%u\2t\%g\2t\%p\2n\3\SE{}_\-\V{o}_\2}}
\L{\LB{_____________________\-\V{perm}_\-\N{2000}_\-\V{fprintf}_\N{\$}\{\V{G\_TMPFILE}\}__\S{}\3\%m\2t\%u\2t\%g\2t\%p\2n\3\SE{}_\2)}}
\L{\LB{}}
\L{\LB{\K{for}_\V{file}_\K{in}_\N{\$}(\V{cat}_\N{\$UG}\V{\_TMPFILE}_\N{\$U}\V{\_TMPFILE}_\N{\$G}\V{\_TMPFILE}_\|_\V{cut}_\-\V{f}_\N{4}\-)}}
\L{\LB{\K{do}}}
\L{\LB{____\K{if}_!_\V{ORIG\_STATE}=\N{\$}(\V{fgrep}_\N{\$fi$\ell$e}_\N{\$}\{\V{RPM\_TMPFILE}\})}}
\L{\LB{____\K{then}}}
\L{\LB{________\V{rpm}_\-\V{q}_\-\-\V{qf}_\2}}
\L{\LB{________\S{}\4[\%6o\{FILEMODES\}\2t\%\{FILEUSERNAME\}\2t\%\{FILEGROUPNAME\}\2t\%\{FILENAMES\}\2n]\4\SE{}_\2}}
\L{\LB{____________\-\V{f}_\N{\$fi$\ell$e}_\2}}
\L{\LB{____________\|_\V{cut}_\-\V{c}_\N{3}\-\N{6},\N{8}\-_\>\!\!\>_\N{\$}\{\V{RPM\_TMPFILE}\}}}
\L{\LB{________\K{if}_!_\V{ORIG\_STATE}=\N{\$}(\V{fgrep}_\N{\$fi$\ell$e}_\N{\$}\{\V{RPM\_TMPFILE}\})}}
\L{\LB{________\K{then}}}
\L{\LB{____________\C{}\#_This_file_is_not_owned_by_any_RPM_package.}}
\CE{}\L{\LB{____________\C{}\#_More_important_to_show_it!!!!!!}}
\CE{}\L{\LB{____________\V{NOT\_RPM}=\N{1}}}
\L{\LB{________\K{else}}}
\L{\LB{____________\V{NOT\_RPM}=\N{0}}}
\L{\LB{________\K{fi}}}
\L{\LB{____\K{fi}}}
\L{\LB{____\V{CURRENT\_STATE}=\N{\$}(\V{cat}_\N{\$UG}\V{\_TMPFILE}_\N{\$U}\V{\_TMPFILE}_\N{\$G}\V{\_TMPFILE}_\|_\V{grep}_\S{}\3\$\{file\}\$\3\SE{})}}
\L{\LB{____\K{set}_\-\-_\N{\$CURRENT}\V{\_STATE}}}
\L{\LB{____\V{mode}=\N{\$1}_\V{user}=\N{\$2}_\V{group}=\N{\$3}}}
\L{\LB{____\K{if}_[_\S{}\3\$NOT\_RPM\3\SE{}_=_\S{}\31\3\SE{}_];_\K{then}}}
\L{\LB{________\V{printf}_\S{}\3NOT_RPM:_\%\-10s__\%\-10s__\%\-14s__\%s\2n\3\SE{}_\2}}
\L{\LB{____________\N{\$mode}_\N{\$user}_\N{\$group}_\N{\$fi$\ell$e}}}
\L{\LB{________\K{continue}}}
\L{\LB{____\K{fi}}}
\L{\LB{____\K{set}_\-\-_\N{\$ORIG}\V{\_STATE}}}
\L{\LB{____\V{orig\_mode}=\N{\$1}_\V{orig\_user}=\N{\$2}_\V{orig\_group}=\N{\$3}}}
\L{\LB{____\K{if}_[_\S{}\3\$mode\3\SE{}__!=_\S{}\3\$orig\_mode\3\SE{}_\-\V{o}_\2}}
\L{\LB{_________\S{}\3\$user\3\SE{}__!=_\S{}\3\$orig\_user\3\SE{}_\-\V{o}_\2}}
\L{\LB{_________\S{}\3\$group\3\SE{}_!=_\S{}\3\$orig\_group\3\SE{}_]}}
\L{\LB{____\K{then}}}
\L{\LB{________\K{if}_[_\S{}\3\$mode\3\SE{}_!=_\S{}\3\$orig\_mode\3\SE{}_];_\K{then}}}
\L{\LB{____________\V{modeinfo}=\S{}\3\$orig\_mode=\>\$mode\3\SE{}}}
\L{\LB{________\K{else}}}
\L{\LB{____________\V{modeinfo}=\S{}\3\$mode\3\SE{}}}
\L{\LB{________\K{fi}}}
\L{\LB{________\K{if}_[_\S{}\3\$user\3\SE{}__!=_\S{}\3\$orig\_user\3\SE{}_];_\K{then}}}
\L{\LB{____________\V{userinfo}=\S{}\3\$orig\_user=\>\$user\3\SE{}}}
\L{\LB{________\K{else}}}
\L{\LB{____________\V{userinfo}=\S{}\3\$user\3\SE{}}}
\L{\LB{________\K{fi}}}
\L{\LB{________\K{if}_[_\S{}\3\$group\3\SE{}__!=_\S{}\3\$orig\_group\3\SE{}_];_\K{then}}}
\L{\LB{____________\V{groupinfo}=\S{}\3\$orig\_group=\>\$group\3\SE{}}}
\L{\LB{________\K{else}}}
\L{\LB{____________\V{groupinfo}=\S{}\3\$group\3\SE{}}}
\L{\LB{________\K{fi}}}
\L{\LB{________}}
\L{\LB{________\V{printf}_\S{}\3WARNING:_\%\-10s__\%\-10s__\%\-14s__\%s\2n\3\SE{}_\2}}
\L{\LB{____________\N{\$modeinfo}_\N{\$userinfo}_\N{\$groupinfo}_\N{\$fi$\ell$e}}}
\L{\LB{____\K{elif}_[_\S{}\3\$VERBOSE\3\SE{}_=_\S{}\31\3\SE{}_];_\K{then}}}
\L{\LB{________\V{printf}_\S{}\3okay:____\%\-10s__\%\-10s__\%\-14s__\%s\2n\3\SE{}_\2}}
\L{\LB{____________\N{\$mode}_\N{\$user}_\N{\$group}_\N{\$fi$\ell$e}}}
\L{\LB{____\K{fi}}}
\L{\LB{\K{done}}}
