Skip to contentSkip to conversation

spasswd

PATCH Russell Coker 2 participants 2 messages Sep 8, 2002 – Sep 21, 2002 SELinux security module

lore
Share & tools
lore
#0 lore raw

I have attached a patch for the spasswd program. This fixes a bug in my code that was included in the CVS (and is now in the release version).

To demonstrate the bug run "spasswd", "sadminpasswd" etc and then press ^C or ^\ to kill it. It'll kill the wrapper but leave the child process running in the background, then when the shell and the child process start fighting over the standard input it goes into an infinite loop (and in the case of "spasswd" the user running it may not have permission to clean it up).

The patch makes the wrapper handle the signals that can be handled and then deliver them to the child process, and it makes the wait() operation handle the interruption.

I've tested this code reasonably thoroughly and am quite confidant in it's ability to work correctly.

Signature · 3 lines
I do not get viruses because I do not use MS software.
If you use Outlook then please do not put my email address in your
address-book so that WHEN you get a virus it won't use my address in the
Quoted 1 line

From field.

utils/spasswd/spasswd.c +28 -5
@@ -9,6 +9,7 @@
 #include <syslog.h>
 #include <string.h>
 #include <fs_secure.h>
+#include <errno.h>
 
 #ifndef PASSWD
 #define PASSWD "/usr/bin/passwd"
@@ -39,6 +40,13 @@
 
 #define SZ 255
 
+pid_t child;
+
+void sig_handler(int sig, siginfo_t *siginf, void *unused)
+{
+  kill(child, siginf->si_signo);
+}
+
 
 int main(int argc, char **argv) 
 {
@@ -55,6 +63,7 @@
   int status;
   char **passwd_argv;
   int i;
+  struct sigaction sa;
 
   passwd_argv = malloc( (argc + 1) * sizeof(char *) );
   if(!passwd_argv)
@@ -136,8 +145,20 @@
 
   openlog(p, LOG_CONS, LOG_AUTH);
 
-  ret = fork();
-  switch(ret)
+  sa.sa_sigaction = &sig_handler;
+  sa.sa_flags = SA_SIGINFO;
+  if(sigaction(SIGHUP, &sa, NULL)
+    || sigaction(SIGINT, &sa, NULL)
+    || sigaction(SIGQUIT, &sa, NULL)
+    || sigaction(SIGPIPE, &sa, NULL)
+    || sigaction(SIGTERM, &sa, NULL))
+  {
+    fprintf(stderr, "Can't handle signals.");
+    return 1;
+  }
+
+  child = fork();
+  switch(child)
   {
   case 0:  /* child */
     execv(PASSWD, passwd_argv);
@@ -147,15 +168,17 @@
     perror(argv[0]);
     exit(1);
   }
-  if(wait(&status) != ret)
+  while( (ret = wait(&status)) == -1 && errno == EINTR)
+    ;
+  if(ret != child)
   {
-    fprintf(stderr, "Error waiting for child.\n");
+    fprintf(stderr, "Error %d waiting for child.\n", errno);
     ret = 1;
   }
   else
   {
     if(!WIFEXITED(status) || WEXITSTATUS(status) != 0)
-      fprintf(stderr, "Child had an error.\n");
+      fprintf(stderr, "Child returned an error.\n");
     else
       ret = 0;
   }
#1 lore raw
Quoted 2 lines · Russell Coker

I have attached a patch for the spasswd program. This fixes a bug in my code that was included in the CVS (and is now in the release version).

Thanks, merged.

--
Stephen D. Smalley, NAI Labs
[email protected]

--
This message was distributed to subscribers of the selinux mailing list. If you no longer wish to subscribe, send mail to [email protected] with the words "unsubscribe selinux" without quotes as the message.