diff --git a/login-utils/su-common.c b/login-utils/su-common.c index bfcd49405..98774051c 100644 --- a/login-utils/su-common.c +++ b/login-utils/su-common.c @@ -1,48 +1,26 @@ -/* su for Linux. Run a shell with substitute user and group IDs. - Copyright (C) 1992-2006 Free Software Foundation, Inc. - Copyright (C) 2012 SUSE Linux Products GmbH, Nuernberg - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2, or (at your option) - any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software Foundation, - Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ - -/* Run a shell with the real and effective UID and GID and groups - of USER, default `root'. - - The shell run is taken from USER's password entry, /bin/sh if - none is specified there. If the account has a password, su - prompts for a password unless run by a user with real UID 0. - - Does not change the current directory. - Sets `HOME' and `SHELL' from the password entry for USER, and if - USER is not root, sets `USER' and `LOGNAME' to USER. - The subshell is not a login shell. - - If one or more ARGs are given, they are passed as additional - arguments to the subshell. - - Does not handle /bin/sh or other shells specially - (setting argv[0] to "-su", passing -c only to certain shells, etc.). - I don't see the point in doing that, and it's ugly. - - Based on an implementation by David MacKenzie . */ - -enum { - EXIT_CANNOT_INVOKE = 126, - EXIT_ENOENT = 127 -}; - -#include +/* + * su(1) for Linux. Run a shell with substitute user and group IDs. + * + * Copyright (C) 1992-2006 Free Software Foundation, Inc. + * Copyright (C) 2012 SUSE Linux Products GmbH, Nuernberg + * Copyright (C) 2016 Karel Zak + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the Free + * Software Foundation; either version 2, or (at your option) any later + * version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. You should have received a copy of the GNU General Public + * License along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + * USA. + * + * + * Based on an implementation by David MacKenzie . + */ #include #include #include @@ -50,9 +28,9 @@ enum { #include #include #ifdef HAVE_SECURITY_PAM_MISC_H -#include +# include #elif defined(HAVE_SECURITY_OPENPAM_H) -#include +# include #endif #include #include @@ -62,6 +40,7 @@ enum { #include "err.h" #include + #include "c.h" #include "xalloc.h" #include "nls.h" @@ -71,6 +50,9 @@ enum { #include "strutils.h" #include "ttyutils.h" +#include "logindefs.h" +#include "su-common.h" + /* name of the pam configuration files. separate configs for su and su - */ #define PAM_SRVNAME_SU "su" #define PAM_SRVNAME_SU_L "su-l" @@ -83,9 +65,6 @@ enum { #define is_pam_failure(_rc) ((_rc) != PAM_SUCCESS) -#include "logindefs.h" -#include "su-common.h" - /* The shell to run if none is given in the user's passwd entry. */ #define DEFAULT_SHELL "/bin/sh" @@ -96,6 +75,11 @@ enum { extern char **environ; #endif +enum { + EXIT_CANNOT_INVOKE = 126, + EXIT_ENOENT = 127 +}; + static void run_shell(char const *, char const *, char **, size_t) __attribute__ ((__noreturn__));