瀏覽代碼

make sure <prefix>/etc/rc does not complain in cronjobs of non-privileged setups

Ralf S. Engelschall 21 年之前
父節點
當前提交
ac744f0a1f
共有 3 個文件被更改,包括 17 次插入2 次删除
  1. 1 0
      openpkg/HISTORY
  2. 2 0
      openpkg/openpkg.spec
  3. 14 2
      openpkg/rc

+ 1 - 0
openpkg/HISTORY

@@ -2,6 +2,7 @@
 2004
 ====
 
+20040429 make sure <prefix>/etc/rc does not complain in cronjobs of non-privileged setups
 20040429 port to NetBSD 1.6.2
 20040428 fix "openpkg man" command now that OPENPKG_TOOLS_CMDPATH is not provided
 20040428 let rc point out that it searches subdirectories for unresolved file conflicts

+ 2 - 0
openpkg/openpkg.spec

@@ -1008,6 +1008,8 @@ Provides:     openpkg = 2.0.2-2.0.2
 
     #   install Run-Command files
     sed -e "s:@l_prefix@:%{l_prefix}:g" \
+        -e "s:@l_susr@:%{l_susr}:g" \
+        -e "s:@l_musr@:%{l_musr}:g" \
         <`SOURCE rc` \
         >$RPM_BUILD_ROOT%{l_prefix}/etc/rc
     chmod 755 $RPM_BUILD_ROOT%{l_prefix}/etc/rc

+ 14 - 2
openpkg/rc

@@ -534,8 +534,20 @@ for cmd in $cmds; do
             #   execute the generated script with GNU Bash
             if [ ".$user" != ".$s_user" ]; then
                 #   execute as different user
-                su - $s_user -c "PATH=\"$PATH\"; $bash $tmpfile" >$outfile 2>$errfile
-                rc=$?
+                if [ ".$user" = ".@l_susr@" -a ".@l_susr@" = ".root" ]; then
+                    su - $s_user -c "PATH=\"$PATH\"; $bash $tmpfile" >$outfile 2>$errfile
+                    rc=$?
+                elif [ ".@l_susr@" != ".root" ]; then
+                    #   do not complain if we would not have any chance
+                    #   at all to switch the user because we are running
+                    #   in a non-privileged instance. Else we would just
+                    #   trash the mailbox of the user receiving the
+                    #   output of periodic run-commands.
+                    rc=0
+                else
+                    echo "openpkg:rc:WARNING: $prefix:$s_name:%$cmd: require root privileges to run as user \"$s_user\"" 1>&2
+                    rc=1
+                fi
             else
                 #   execute as current user
                 $bash $tmpfile >$outfile 2>$errfile