[Pkg-shadow-devel] patches for su synchronisation
Nicolas François
nicolas.francois at centraliens.net
Sat Dec 17 17:26:06 UTC 2005
Tomasz,
This second patch changes the way options are handled by getopt. Once a
non-su option is found, the getopt processing is stopped.
Whithout this patch, "su root -c ls" won't work (getopt will complain that
-c is not an su option).
The third patch fixes "su - -- root" or "su - root -- -c" (it is needed if
the second patch is applied).
--
Nekral
-------------- next part --------------
--- src/su.c.1 2005-12-17 18:15:45.000000000 +0100
+++ src/su.c 2005-12-17 18:18:23.000000000 +0100
@@ -336,9 +336,19 @@
};
while ((c =
- getopt_long (argc, argv, "hlmps:", long_options,
+ getopt_long (argc, argv, "-hlmps:", long_options,
&option_index)) != -1) {
switch (c) {
+ case 1:
+ /* this is not an su option */
+ /* The next arguments are either '-', the
+ * target name, or arguments to be passed
+ * to the shell.
+ */
+ /* rewind the (not yet handled) option */
+ optind--;
+ goto end_su_options;
+ break; /* NOT REACHED */
case 'h':
usage ();
break;
@@ -353,9 +363,10 @@
shellstr = optarg;
break;
default:
- usage ();
+ usage (); /* NOT REACHED */
}
}
+end_su_options:
if (optind < argc && !strcmp (argv[optind], "-")) {
fakelogin = 1;
optind++;
-------------- next part --------------
--- src/su.c.2 2005-12-17 18:23:02.000000000 +0100
+++ src/su.c 2005-12-17 18:23:25.000000000 +0100
@@ -370,6 +370,8 @@
if (optind < argc && !strcmp (argv[optind], "-")) {
fakelogin = 1;
optind++;
+ if (optind < argc && !strcmp(argv[optind], "--"))
+ optind++;
}
}
@@ -410,6 +412,8 @@
*/
if (optind < argc && argv[optind][0] != '-') {
STRFCPY (name, argv[optind++]); /* use this login id */
+ if (optind < argc && !strcmp(argv[optind], "--"))
+ optind++;
}
if (!name[0]) /* use default user ID */
(void) strcpy (name, "root");
More information about the Pkg-shadow-devel
mailing list