[ale] Correct Signal Handling

Vaidhy Mayilrangam vaidhy at loonys.net
Thu Dec 6 09:00:22 EST 2001


you might also want to catch SIGINT .. 

Vaidhy

On Thu, Dec 06, 2001 at 09:39:34AM -0500, Chris Fowler wrote:
> Hello,
> 
> I'm writing a simple program to change the uid of a user to that of root.  Like su.  I need 
> corectly set the signals in theis program so that when any termination signals are sent 
> to the SHELL that the porgram contiunes and termintes normally.  Should I place the
> child in its own process group?  Below is code:
> 
> 
> 
> #define SHELL "/bin/sh"
> 
> void become_root(void);
> 
> static struct config cfg;
> 
> /* NOTE!!:
>  *
>  * This program must be suid as root to operate correctly!
>  *
>  */
> 
> int
> become_admin(int argc, char *argv[])
> {
>         char *password;
> 
>         if(readcfg(&cfg, sizeof(struct config)) == -1)
>                 err_quit("read config");
> 
>         openlog("admin", LOG_PID, LOG_AUTHPRIV);
> 
>         password = getpass("password: ");
> 
>         log_info("user->admin attempt by: %s", getenv("LOGNAME"));
> 
>         if(strcmp(cfg.user[0].password, (char *)crypt(password, cfg.user[0].password)) == 0)
>                 become_root();
> 
> 
>         log_info("user->admin failed for %s\n", getenv("LOGNAME"));
> 
>         fprintf(stderr, "access denied");
>         return 0;
> }
> 
> void
> become_root(void)
> {
>         int pid;
> 
>         log_info("user->admin succeeded by %s", getenv("LOGNAME"));
> 
>         signal(SIGQUIT, SIG_IGN);
>         signal(SIGHUP, SIG_IGN);
> 
>         pid = fork();
> 
>         if(pid < 0)
>                 err_quit("fork");
> 
>         if(pid == 0)
>         {
>                 extern char **environ;
>                 setgid(0);
>                 setuid(0);
> 
>                 execle(SHELL, SHELL,0, environ);
>                 err_quit("exec");
>         }
> 
>         wait(NULL);
> 
>         log_info("user->admin exited by: %s", getenv("LOGNAME"));
> 
>         exit(0);
> }
> 
> 
> Thanks,
> Chris Fowler
> 
> 
> 
> ---
> This message has been sent through the ALE general discussion list.
> See http://www.ale.org/mailing-lists.shtml for more info. Problems should be 
> sent to listmaster at ale dot org.
> 
> 

---
This message has been sent through the ALE general discussion list.
See http://www.ale.org/mailing-lists.shtml for more info. Problems should be 
sent to listmaster at ale dot org.






More information about the Ale mailing list