From: mdw Date: Thu, 7 Aug 1997 16:28:59 +0000 (+0000) Subject: Do something useful when users attempt to become themselves. X-Git-Tag: 1.3.3~124 X-Git-Url: https://git.distorted.org.uk/~mdw/become/commitdiff_plain/88e486d58fd7f8086bf6b7a9b3cf0127671edb33 Do something useful when users attempt to become themselves. --- diff --git a/src/become.c b/src/become.c index 627eda5..a690072 100644 --- a/src/become.c +++ b/src/become.c @@ -1,6 +1,6 @@ /* -*-c-*- * - * $Id: become.c,v 1.2 1997/08/04 10:24:20 mdw Exp $ + * $Id: become.c,v 1.3 1997/08/07 16:28:59 mdw Exp $ * * Main code for `become' * @@ -29,6 +29,9 @@ /*----- Revision history --------------------------------------------------* * * $Log: become.c,v $ + * Revision 1.3 1997/08/07 16:28:59 mdw + * Do something useful when users attempt to become themselves. + * * Revision 1.2 1997/08/04 10:24:20 mdw * Sources placed under CVS control. * @@ -708,9 +711,20 @@ int main(int argc, char *argv[]) } T( trace(TRACE_SETUP, "setup: canonify binary to `%s'", rq.cmd); ) - /* --- Run the check --- */ + /* --- Run the check --- * + * + * If the user is already what she wants to be, then print a warning. + * Then, if I was just going to spawn a shell, quit, to reduce user + * confusion. Otherwise, do what was wanted anyway. + */ - { + if (rq.from == rq.to) { + moan("you already are `%s'!", to_pw->pw_name); + if (!cmd && todo == shell) { + moan("(to prevent confusion, I'm not spawning a shell)"); + exit(0); + } + } else { int a = check(&rq); syslog(LOG_INFO, @@ -730,7 +744,7 @@ int main(int argc, char *argv[]) puts("permission granted"); return (0); } else { - if (setuid(rq.to) == -1 || seteuid(rq.to) == -1) + if (setuid(rq.to) == -1) die("couldn't set uid: %s", strerror(errno)); execve(rq.cmd, todo, env); die("couldn't exec `%s': %s", rq.cmd, strerror(errno));