]> git.pld-linux.org Git - packages/coreutils.git/blob - coreutils-runuser.patch
- uniformized configs to use system-auth where possible
[packages/coreutils.git] / coreutils-runuser.patch
1 --- coreutils-6.7/tests/help-version.runuser    2006-12-07 09:06:04.000000000 +0000
2 +++ coreutils-6.7/tests/help-version    2007-01-09 17:31:44.000000000 +0000
3 @@ -168,6 +168,7 @@
4  seq_args=10
5  sleep_args=0
6  su_args=--version
7 +runuser_args=--version
8  
9  # I'd rather not run sync, since it spins up disks that I've
10  # deliberately caused to spin down (but not unmounted).
11 --- coreutils-6.7/README.runuser        2006-11-24 21:28:27.000000000 +0000
12 +++ coreutils-6.7/README        2007-01-09 17:32:16.000000000 +0000
13 @@ -11,7 +11,7 @@
14    dd df dir dircolors dirname du echo env expand expr factor false fmt fold
15    ginstall groups head hostid hostname id join kill link ln logname ls
16    md5sum mkdir mkfifo mknod mv nice nl nohup od paste pathchk pinky pr
17 -  printenv printf ptx pwd readlink rm rmdir seq sha1sum sha224sum sha256sum
18 +  printenv printf ptx pwd readlink rm rmdir runuser seq sha1sum sha224sum sha256sum
19    sha384sum sha512sum shred shuf sleep sort split stat stty su sum sync tac
20    tail tee test touch tr true tsort tty uname unexpand uniq unlink uptime
21    users vdir wc who whoami yes
22 --- coreutils-6.7/src/su.c.runuser      2007-01-09 17:27:56.000000000 +0000
23 +++ coreutils-6.7/src/su.c      2007-01-09 17:30:12.000000000 +0000
24 @@ -110,9 +110,15 @@
25  #include "error.h"
26  
27  /* The official name of this program (e.g., no `g' prefix).  */
28 +#ifndef RUNUSER
29  #define PROGRAM_NAME "su"
30 +#else
31 +#define PROGRAM_NAME "runuser"
32 +#endif
33  
34 +#ifndef AUTHORS
35  #define AUTHORS "David MacKenzie"
36 +#endif
37  
38  #if HAVE_PATHS_H
39  # include <paths.h>
40 @@ -150,6 +156,10 @@
41  #ifndef USE_PAM
42  char *crypt ();
43  #endif
44 +#ifndef CHECKPASSWD
45 +#define CHECKPASSWD 1
46 +#endif
47 +
48  char *getusershell ();
49  void endusershell ();
50  void setusershell ();
51 @@ -157,7 +167,11 @@
52  extern char **environ;
53  
54  static void run_shell (char const *, char const *, char **, size_t,
55 -       const struct passwd *)
56 +       const struct passwd *
57 +#ifdef RUNUSER
58 +                      , gid_t *groups, int num_groups
59 +#endif
60 +       )
61  #ifdef USE_PAM
62         ;
63  #else
64 @@ -187,6 +201,10 @@
65    {"login", no_argument, NULL, 'l'},
66    {"preserve-environment", no_argument, NULL, 'p'},
67    {"shell", required_argument, NULL, 's'},
68 +#ifdef RUNUSER
69 +  {"group", required_argument, NULL, 'g'},
70 +  {"supp-group", required_argument, NULL, 'G'},
71 +#endif
72    {GETOPT_HELP_OPTION_DECL},
73    {GETOPT_VERSION_OPTION_DECL},
74    {NULL, 0, NULL, 0}
75 @@ -288,10 +306,12 @@
76    retval = pam_start(PROGRAM_NAME, pw->pw_name, &conv, &pamh);
77    PAM_BAIL_P;
78  
79 +#ifndef RUNUSER
80    if (getuid() != 0 && !isatty(0)) {
81         fprintf(stderr, _("standard in must be a tty\n"));
82         exit(1);
83    }
84 +#endif
85  
86    caller = getpwuid(getuid());
87    if(caller != NULL && caller->pw_name != NULL) {
88 @@ -308,6 +328,11 @@
89      retval = pam_set_item(pamh, PAM_TTY, tty_name);
90      PAM_BAIL_P;
91    }
92 +#ifdef RUNUSER
93 +  if (getuid() != geteuid())
94 +    /* safety net: deny operation if we are suid by accident */
95 +    error(EXIT_FAIL, 1, "runuser may not be setuid");
96 +#else
97    retval = pam_authenticate(pamh, 0);
98    PAM_BAIL_P;
99    retval = pam_acct_mgmt(pamh, 0);
100 @@ -317,6 +342,7 @@
101      PAM_BAIL_P;
102    }
103    PAM_BAIL_P;
104 +#endif
105    /* must be authenticated if this point was reached */
106    return 1;
107  #else /* !USE_PAM */
108 @@ -398,11 +424,22 @@
109  /* Become the user and group(s) specified by PW.  */
110  
111  static void
112 -change_identity (const struct passwd *pw)
113 +change_identity (const struct passwd *pw
114 +#ifdef RUNUSER
115 +                , gid_t *groups, int num_groups
116 +#endif
117 +       )
118  {
119  #ifdef HAVE_INITGROUPS
120 +  int rc = 0;
121    errno = 0;
122 -  if (initgroups (pw->pw_name, pw->pw_gid) == -1) {
123 +#ifdef RUNUSER
124 +  if (num_groups)
125 +    rc = setgroups(num_groups, groups);
126 +  else
127 +#endif
128 +    rc = initgroups(pw->pw_name, pw->pw_gid);
129 +  if (rc == -1) {
130  #ifdef USE_PAM
131      pam_close_session(pamh, 0);
132      pam_end(pamh, PAM_ABORT);
133 @@ -449,7 +486,11 @@
134  
135  static void
136  run_shell (char const *shell, char const *command, char **additional_args,
137 -          size_t n_additional_args, const struct passwd *pw)
138 +          size_t n_additional_args, const struct passwd *pw
139 +#ifdef RUNUSER
140 +          , gid_t *groups, int num_groups
141 +#endif
142 +       )
143  {
144    size_t n_args = 1 + fast_startup + 2 * !!command + n_additional_args + 1;
145    char const **args = xnmalloc (n_args, sizeof *args);
146 @@ -480,7 +521,11 @@
147  
148    child = fork();
149    if (child == 0) {  /* child shell */
150 -  change_identity (pw);
151 +  change_identity (pw
152 +#ifdef RUNUSER
153 +                  , groups, num_groups
154 +#endif
155 +         );
156    pam_end(pamh, 0);
157    if (!same_session)
158      setsid ();
159 @@ -657,6 +702,12 @@
160    char *shell = NULL;
161    struct passwd *pw;
162    struct passwd pw_copy;
163 +#ifdef RUNUSER
164 +  struct group *gr;
165 +  gid_t groups[NGROUPS_MAX];
166 +  int num_supp_groups = 0;
167 +  int use_gid = 0;
168 +#endif
169  
170    initialize_main (&argc, &argv);
171    program_name = argv[0];
172 @@ -671,7 +722,11 @@
173    simulate_login = false;
174    change_environment = true;
175  
176 -  while ((optc = getopt_long (argc, argv, "c:flmps:", longopts, NULL)) != -1)
177 +  while ((optc = getopt_long (argc, argv, "c:flmps:"
178 +#ifdef RUNUSER
179 +                             "g:G:"
180 +#endif
181 +                             , longopts, NULL)) != -1)
182      {
183        switch (optc)
184         {
185 @@ -701,6 +756,28 @@
186           shell = optarg;
187           break;
188  
189 +#ifdef RUNUSER
190 +       case 'g':
191 +         gr = getgrnam(optarg);
192 +         if (!gr)
193 +           error (EXIT_FAIL, 0, _("group %s does not exist"), optarg);
194 +         use_gid = 1;
195 +         groups[0] = gr->gr_gid;
196 +         break;
197 +
198 +       case 'G':
199 +         num_supp_groups++;
200 +         if (num_supp_groups >= NGROUPS_MAX)
201 +           error (EXIT_FAIL, 0,
202 +                  _("Can't specify more than %d supplemental groups"),
203 +                  NGROUPS_MAX - 1);
204 +         gr = getgrnam(optarg);
205 +         if (!gr)
206 +           error (EXIT_FAIL, 0, _("group %s does not exist"), optarg);
207 +         groups[num_supp_groups] = gr->gr_gid;
208 +         break;
209 +#endif
210 +
211         case_GETOPT_HELP_CHAR;
212  
213         case_GETOPT_VERSION_CHAR (PROGRAM_NAME, AUTHORS);
214 @@ -739,7 +816,20 @@
215                           : DEFAULT_SHELL);
216    endpwent ();
217  
218 -  if (!correct_password (pw))
219 +#ifdef RUNUSER
220 +  if (num_supp_groups && !use_gid)
221 +  {
222 +    pw->pw_gid = groups[1];
223 +    memmove (groups, groups + 1, sizeof(gid_t) * num_supp_groups);
224 +  }
225 +  else if (use_gid)
226 +  {
227 +    pw->pw_gid = groups[0];
228 +    num_supp_groups++;
229 +  }
230 +#endif
231 +
232 +  if (CHECKPASSWD && !correct_password (pw))
233      {
234  #ifdef SYSLOG_FAILURE
235        log_su (pw, false);
236 @@ -771,8 +861,16 @@
237    modify_environment (pw, shell);
238  
239  #ifndef USE_PAM
240 -  change_identity (pw);
241 +  change_identity (pw
242 +#ifdef RUNUSER
243 +                  , groups, num_supp_groups
244 +#endif
245 +                  );
246  #endif
247  
248 -  run_shell (shell, command, argv + optind, MAX (0, argc - optind), pw);
249 +  run_shell (shell, command, argv + optind, MAX (0, argc - optind), pw
250 +#ifdef RUNUSER
251 +            , groups, num_supp_groups
252 +#endif
253 +            );
254  }
255 --- coreutils-6.7/src/Makefile.am.runuser       2007-01-09 17:27:56.000000000 +0000
256 +++ coreutils-6.7/src/Makefile.am       2007-01-09 17:27:56.000000000 +0000
257 @@ -17,7 +17,7 @@
258  ## along with this program; if not, write to the Free Software Foundation,
259  ## Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
260  
261 -EXTRA_PROGRAMS = chroot df hostid nice pinky stty su uname uptime users who
262 +EXTRA_PROGRAMS = chroot df hostid nice pinky stty su runuser uname uptime users who
263  
264  bin_SCRIPTS = groups
265  bin_PROGRAMS = [ chgrp chown chmod cp dd dircolors du \
266 @@ -112,6 +112,10 @@
267  mv_LDADD += $(LIB_ACL)
268  ginstall_LDADD += $(LIB_ACL)
269  
270 +runuser_SOURCES = su.c
271 +runuser_CFLAGS = -DRUNUSER -DAUTHORS="\"David MacKenzie, Dan Walsh\""
272 +runuser_LDADD = $(LDADD) $(LIB_CRYPT) @LIB_PAM@
273 +
274  $(PROGRAMS): ../lib/libcoreutils.a
275  
276  SUFFIXES = .sh
277 @@ -126,7 +130,7 @@
278         chmod +x $@-t
279         mv $@-t $@
280  
281 -all-local: su$(EXEEXT)
282 +all-local: su$(EXEEXT) runuser
283  
284  installed_su = $(DESTDIR)$(bindir)/`echo su|sed '$(transform)'`
285  
286 --- coreutils-6.7/AUTHORS.runuser       2006-10-22 17:54:15.000000000 +0100
287 +++ coreutils-6.7/AUTHORS       2007-01-09 17:27:56.000000000 +0000
288 @@ -60,6 +60,7 @@
289  readlink: Dmitry V. Levin
290  rm: Paul Rubin, David MacKenzie, Richard Stallman, Jim Meyering
291  rmdir: David MacKenzie
292 +runuser: David MacKenzie, Dan Walsh
293  seq: Ulrich Drepper
294  sha1sum: Ulrich Drepper, Scott Miller, David Madore
295  sha224sum: Ulrich Drepper, Scott Miller, David Madore
296 --- coreutils-6.7/man/Makefile.am.runuser       2006-11-16 08:49:56.000000000 +0000
297 +++ coreutils-6.7/man/Makefile.am       2007-01-09 17:32:38.000000000 +0000
298 @@ -26,7 +26,7 @@
299    link.1 ln.1 logname.1 \
300    ls.1 md5sum.1 mkdir.1 mkfifo.1 mknod.1 mv.1 nl.1 nohup.1 od.1 \
301    paste.1 pathchk.1 pr.1 printenv.1 printf.1 ptx.1 pwd.1 readlink.1 \
302 -  rm.1 rmdir.1 seq.1 sha1sum.1 sha224sum.1 sha256sum.1 sha384sum.1 sha512sum.1 \
303 +  rm.1 rmdir.1 runuser.1 seq.1 sha1sum.1 sha224sum.1 sha256sum.1 sha384sum.1 sha512sum.1 \
304    shred.1 shuf.1 sleep.1 sort.1 split.1 stat.1 \
305    su.1 sum.1 sync.1 tac.1 tail.1 tee.1 test.1 touch.1 tr.1 true.1 tsort.1 \
306    tty.1 unexpand.1 uniq.1 unlink.1 vdir.1 wc.1 \
307 @@ -105,6 +105,7 @@
308  readlink.1:    $(common_dep)   $(srcdir)/readlink.x    ../src/readlink.c
309  rm.1:          $(common_dep)   $(srcdir)/rm.x          ../src/rm.c
310  rmdir.1:       $(common_dep)   $(srcdir)/rmdir.x       ../src/rmdir.c
311 +runuser.1:     $(common_dep)   $(srcdir)/runuser.x     ../src/su.c
312  seq.1:         $(common_dep)   $(srcdir)/seq.x         ../src/seq.c
313  sha1sum.1:     $(common_dep)   $(srcdir)/sha1sum.x     ../src/md5sum.c
314  sha224sum.1:   $(common_dep)   $(srcdir)/sha224sum.x   ../src/md5sum.c
315 --- /dev/null   2007-01-09 09:38:07.860075128 +0000
316 +++ coreutils-6.7/man/runuser.x 2007-01-09 17:27:56.000000000 +0000
317 @@ -0,0 +1,4 @@
318 +[NAME]
319 +runuser \- run a shell with substitute user and group IDs
320 +[DESCRIPTION]
321 +.\" Add any additional description here
322 --- /dev/null   2007-01-09 09:38:07.860075128 +0000
323 +++ coreutils-6.7/man/runuser.1 2007-01-09 17:27:56.000000000 +0000
324 @@ -0,0 +1,68 @@
325 +.\" DO NOT MODIFY THIS FILE!  It was generated by help2man 1.33.
326 +.TH RUNUSER "1" "September 2004" "runuser (coreutils) 5.2.1" "User Commands"
327 +.SH NAME
328 +runuser \- run a shell with substitute user and group IDs, similar to su, but will not run PAM hooks
329 +.SH SYNOPSIS
330 +.B runuser
331 +[\fIOPTION\fR]... [\fI-\fR] [\fIUSER \fR[\fIARG\fR]...]
332 +.SH DESCRIPTION
333 +.\" Add any additional description here
334 +.PP
335 +Change the effective user id and group id to that of USER.  No PAM hooks
336 +are run, and there will be no password prompt.  This command is useful
337 +when run as the root user.  If run as a non-root user without privilege
338 +to set user ID, the command will fail.
339 +.TP
340 +-, \fB\-l\fR, \fB\-\-login\fR
341 +make the shell a login shell
342 +.TP
343 +\fB\-c\fR, \fB\-\-commmand\fR=\fICOMMAND\fR
344 +pass a single COMMAND to the shell with \fB\-c\fR
345 +.TP
346 +\fB\-f\fR, \fB\-\-fast\fR
347 +pass \fB\-f\fR to the shell (for csh or tcsh)
348 +.TP
349 +\fB\-g\fR, \fB\-\-group\fR=\fIGROUP\fR
350 +specify the primary group
351 +.TP
352 +\fB\-G\fR, \fB\-\-supp-group\fR=\fIGROUP\fR
353 +specify a supplemental group
354 +.TP
355 +\fB\-m\fR, \fB\-\-preserve\-environment\fR
356 +do not reset environment variables
357 +.TP
358 +\fB\-p\fR
359 +same as \fB\-m\fR
360 +.TP
361 +\fB\-s\fR, \fB\-\-shell\fR=\fISHELL\fR
362 +run SHELL if /etc/shells allows it
363 +.TP
364 +\fB\-\-help\fR
365 +display this help and exit
366 +.TP
367 +\fB\-\-version\fR
368 +output version information and exit
369 +.PP
370 +A mere - implies \fB\-l\fR.   If USER not given, assume root.
371 +.SH AUTHOR
372 +Written by David MacKenzie, Dan Walsh.
373 +.SH "REPORTING BUGS"
374 +Report bugs to <bug-coreutils@gnu.org>.
375 +.SH COPYRIGHT
376 +Copyright \(co 2004 Free Software Foundation, Inc.
377 +.br
378 +This is free software; see the source for copying conditions.  There is NO
379 +warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
380 +.SH "SEE ALSO"
381 +Since this command is trimmed down version of su use you can use the su manual.
382 +The full documentation for
383 +.B su
384 +is maintained as a Texinfo manual.  If the
385 +.B info
386 +and
387 +.B su
388 +programs are properly installed at your site, the command
389 +.IP
390 +.B info coreutils su
391 +.PP
392 +should give you access to the complete manual.
This page took 0.148538 seconds and 3 git commands to generate.