SHA256
3
0
forked from pool/bash
Dr. Werner Fink 2011-11-21 13:32:56 +00:00 committed by Git OBS Bridge
parent 32aa646d84
commit d9608bd972
2 changed files with 143 additions and 65 deletions

View File

@ -1,48 +1,58 @@
--- bashline.c --- bashline.c
+++ bashline.c 2011-11-11 13:22:00.119146416 +0000 +++ bashline.c 2011-11-21 12:41:19.831646479 +0000
@@ -2148,10 +2148,10 @@ bash_groupname_completion_function (text @@ -2149,6 +2149,7 @@ bash_groupname_completion_function (text
if (gnamelen == 0 || (STREQN (gname, grent->gr_name, gnamelen)))
break;
} }
value = savestring (grent->gr_name);
+ endgrent (); + endgrent ();
return (value);
if (grent == 0) #endif
{
- endgrent ();
return ((char *)NULL);
} }
--- examples/loadables/finfo.c --- examples/loadables/finfo.c
+++ examples/loadables/finfo.c 2011-11-11 13:21:12.319218165 +0000 +++ examples/loadables/finfo.c 2011-11-21 12:23:17.331147246 +0000
@@ -269,9 +269,11 @@ struct stat *st; @@ -269,6 +269,7 @@ struct stat *st;
printmode((int) st->st_mode);
printf("Link count: %d\n", (int) st->st_nlink);
pw = getpwuid(st->st_uid); pw = getpwuid(st->st_uid);
+ endpwent();
owner = pw ? pw->pw_name : "unknown"; owner = pw ? pw->pw_name : "unknown";
printf("Uid of owner: %d (%s)\n", (int) st->st_uid, owner); printf("Uid of owner: %d (%s)\n", (int) st->st_uid, owner);
+ endpwent();
gr = getgrgid(st->st_gid); gr = getgrgid(st->st_gid);
+ endgrent();
owner = gr ? gr->gr_name : "unknown"; owner = gr ? gr->gr_name : "unknown";
printf("Gid of owner: %d (%s)\n", (int) st->st_gid, owner); printf("Gid of owner: %d (%s)\n", (int) st->st_gid, owner);
printf("Device type: %d\n", (int) st->st_rdev); @@ -277,6 +278,7 @@ struct stat *st;
@@ -348,12 +350,14 @@ int flags; printf("File last access time: %s", ctime (&st->st_atime));
printf("File last modify time: %s", ctime (&st->st_mtime));
printf("File last status change time: %s", ctime (&st->st_ctime));
+ endgrent();
fflush(stdout);
return(0);
}
@@ -345,16 +347,18 @@ int flags;
else if (flags & OPT_PMASK)
printf("%o\n", getperm(st->st_mode) & pmask); printf("%o\n", getperm(st->st_mode) & pmask);
else if (flags & OPT_UID) { else if (flags & OPT_UID) {
pw = getpwuid(st->st_uid); - pw = getpwuid(st->st_uid);
+ endpwent(); - if (flags & OPT_ASCII)
if (flags & OPT_ASCII) + if (flags & OPT_ASCII) {
+ pw = getpwuid(st->st_uid);
printf("%s\n", pw ? pw->pw_name : "unknown"); printf("%s\n", pw ? pw->pw_name : "unknown");
else - else
+ endpwent();
+ } else
printf("%d\n", st->st_uid); printf("%d\n", st->st_uid);
} else if (flags & OPT_GID) { } else if (flags & OPT_GID) {
gr = getgrgid(st->st_gid); - gr = getgrgid(st->st_gid);
+ endgrent(); - if (flags & OPT_ASCII)
if (flags & OPT_ASCII) + if (flags & OPT_ASCII) {
+ gr = getgrgid(st->st_gid);
printf("%s\n", gr ? gr->gr_name : "unknown"); printf("%s\n", gr ? gr->gr_name : "unknown");
else - else
+ endgrent();
+ } else
printf("%d\n", st->st_gid);
} else if (flags & OPT_SIZE)
printf("%ld\n", (long) st->st_size);
--- examples/loadables/id.c --- examples/loadables/id.c
+++ examples/loadables/id.c 2011-11-11 13:19:36.515148229 +0000 +++ examples/loadables/id.c 2011-11-21 12:39:06.895646231 +0000
@@ -42,6 +42,7 @@ @@ -42,6 +42,7 @@
#if !defined (HAVE_GETPW_DECLS) #if !defined (HAVE_GETPW_DECLS)
@ -51,31 +61,72 @@
#endif #endif
extern struct group *getgrgid (); extern struct group *getgrgid ();
@@ -146,6 +147,7 @@ inituser (uname) @@ -136,18 +137,26 @@ static int
inituser (uname)
char *uname;
{
- struct passwd *pwd;
-
if (uname)
{
+ struct passwd *pwd;
+ int r;
+
+ r = 0;
pwd = getpwnam (uname);
if (pwd == 0)
{
builtin_error ("%s: no such user", uname); builtin_error ("%s: no such user", uname);
return -1; - return -1;
+ r = -1;
} }
- ruid = euid = pwd->pw_uid;
- rgid = egid = pwd->pw_gid;
+ else
+ {
+ ruid = euid = pwd->pw_uid;
+ rgid = egid = pwd->pw_gid;
+ }
+ endpwent (); + endpwent ();
ruid = euid = pwd->pw_uid; + if (r < 0)
rgid = egid = pwd->pw_gid; + return r;
} }
@@ -173,6 +175,7 @@ id_pruser (uid) else
{
@@ -172,11 +181,12 @@ id_pruser (uid)
{
pwd = getpwuid (uid); pwd = getpwuid (uid);
if (pwd == NULL) if (pwd == NULL)
r = 1; - r = 1;
+ r = 1;
+ else
+ printf ("%s", pwd->pw_name);
+ endpwent (); + endpwent ();
} }
if (pwd) - if (pwd)
printf ("%s", pwd->pw_name); - printf ("%s", pwd->pw_name);
@@ -197,6 +200,7 @@ id_prgrp (gid) - else
+ if (pwd == NULL)
printf ("%u", (unsigned) uid);
return r;
@@ -197,11 +207,12 @@ id_prgrp (gid)
grp = getgrgid (gid); grp = getgrgid (gid);
if (grp == NULL) if (grp == NULL)
r = 1; r = 1;
+ else
+ printf ("%s", grp->gr_name);
+ endgrent (); + endgrent ();
} }
if (grp) - if (grp)
@@ -307,6 +311,8 @@ id_prall (uname) - printf ("%s", grp->gr_name);
- else
+ if (grp == NULL)
printf ("%u", (unsigned) gid);
return r;
@@ -307,6 +318,8 @@ id_prall (uname)
else else
printf ("(%s)", grp->gr_name); printf ("(%s)", grp->gr_name);
} }
@ -85,8 +136,8 @@
return r; return r;
} }
--- lib/tilde/shell.c --- lib/tilde/shell.c
+++ lib/tilde/shell.c 2011-11-11 13:12:35.932960442 +0000 +++ lib/tilde/shell.c 2011-11-21 13:07:02.099146925 +0000
@@ -45,7 +45,12 @@ @@ -45,9 +45,18 @@
#include <pwd.h> #include <pwd.h>
#if !defined (HAVE_GETPW_DECLS) #if !defined (HAVE_GETPW_DECLS)
@ -98,23 +149,38 @@
+# endif +# endif
#endif /* !HAVE_GETPW_DECLS */ #endif /* !HAVE_GETPW_DECLS */
+#if !defined (savestring)
+# define savestring(x) strcpy ((char *)xmalloc (1 + strlen (x)), (x))
+#endif /* !savestring */
+
char * char *
@@ -62,8 +67,13 @@ get_home_dir () get_env_value (varname)
char *varname;
@@ -58,12 +67,19 @@ get_env_value (varname)
char *
get_home_dir ()
{
- char *home_dir;
+ static char *home_dir;
struct passwd *entry; struct passwd *entry;
home_dir = (char *)NULL; - home_dir = (char *)NULL;
+ if (home_dir)
+ goto out;
+#if defined (HAVE_GETPWUID) +#if defined (HAVE_GETPWUID)
entry = getpwuid (getuid ()); entry = getpwuid (getuid ());
if (entry) if (entry)
home_dir = entry->pw_dir; - home_dir = entry->pw_dir;
+ home_dir = savestring(entry->pw_dir);
+#endif +#endif
+#if defined (HAVE_GETPWENT) +#if defined (HAVE_GETPWENT)
+ endpwent (); + endpwent ();
+#endif +#endif
+out:
return (home_dir); return (home_dir);
} }
--- lib/tilde/tilde.c --- lib/tilde/tilde.c
+++ lib/tilde/tilde.c 2011-11-11 13:10:07.375646928 +0000 +++ lib/tilde/tilde.c 2011-11-11 13:10:07.000000000 +0000
@@ -61,6 +61,7 @@ extern struct passwd *getpwuid PARAMS((u @@ -61,6 +61,7 @@ extern struct passwd *getpwuid PARAMS((u
# endif # endif
# if defined (HAVE_GETPWNAM) # if defined (HAVE_GETPWNAM)

View File

@ -1,5 +1,5 @@
--- lib/readline/complete.c --- lib/readline/complete.c
+++ lib/readline/complete.c 2011-11-11 13:16:05.635147670 +0000 +++ lib/readline/complete.c 2011-11-21 12:51:35.695646715 +0000
@@ -83,6 +83,7 @@ typedef int QSFUNC (); @@ -83,6 +83,7 @@ typedef int QSFUNC ();
defined. */ defined. */
#if defined (HAVE_GETPWENT) && (!defined (HAVE_GETPW_DECLS) || defined (_POSIX_SOURCE)) #if defined (HAVE_GETPWENT) && (!defined (HAVE_GETPW_DECLS) || defined (_POSIX_SOURCE))
@ -8,25 +8,19 @@
#endif /* HAVE_GETPWENT && (!HAVE_GETPW_DECLS || _POSIX_SOURCE) */ #endif /* HAVE_GETPWENT && (!HAVE_GETPW_DECLS || _POSIX_SOURCE) */
/* If non-zero, then this is the address of a function to call when /* If non-zero, then this is the address of a function to call when
@@ -2049,12 +2050,12 @@ rl_username_completion_function (text, s @@ -2068,6 +2069,9 @@ rl_username_completion_function (text, s
break; if (first_char == '~')
} rl_filename_completion_desired = 1;
#endif
+#if defined (HAVE_GETPWENT) +#if defined (HAVE_GETPWENT)
+ endpwent (); + endpwent ();
+#endif +#endif
return (value);
if (entry == 0)
{
-#if defined (HAVE_GETPWENT)
- endpwent ();
-#endif
return ((char *)NULL);
} }
else #endif /* !__WIN32__ && !__OPENNT */
--- lib/readline/shell.c --- lib/readline/shell.c
+++ lib/readline/shell.c 2011-11-11 13:14:02.683147026 +0000 +++ lib/readline/shell.c 2011-11-21 13:08:46.343647023 +0000
@@ -61,9 +61,14 @@ @@ -61,9 +61,18 @@
#include "rlshell.h" #include "rlshell.h"
#include "xmalloc.h" #include "xmalloc.h"
@ -40,21 +34,39 @@
+extern void endpwent (); +extern void endpwent ();
+# endif +# endif
+#endif /* !HAVE_GETPW_DECLS */ +#endif /* !HAVE_GETPW_DECLS */
+
+#if !defined (savestring)
+# define savestring(x) strcpy ((char *)xmalloc (1 + strlen (x)), (x))
+#endif /* !savestring */
#ifndef NULL #ifndef NULL
# define NULL 0 # define NULL 0
@@ -168,6 +173,9 @@ sh_get_home_dir () @@ -159,15 +168,20 @@ sh_get_env_value (varname)
char *
sh_get_home_dir ()
{
- char *home_dir;
+ static char *home_dir;
struct passwd *entry;
- home_dir = (char *)NULL;
+ if (home_dir)
+ goto out;
#if defined (HAVE_GETPWUID)
entry = getpwuid (getuid ());
if (entry) if (entry)
home_dir = entry->pw_dir; - home_dir = entry->pw_dir;
+ home_dir = savestring(entry->pw_dir);
#endif #endif
+#if defined (HAVE_GETPWENT) +#if defined (HAVE_GETPWENT)
+ endpwent (); + endpwent ();
+#endif +#endif
+out:
return (home_dir); return (home_dir);
} }
--- lib/readline/tilde.c --- lib/readline/tilde.c
+++ lib/readline/tilde.c 2011-11-11 13:09:48.843646721 +0000 +++ lib/readline/tilde.c 2011-11-11 13:09:49.000000000 +0000
@@ -61,6 +61,7 @@ extern struct passwd *getpwuid PARAMS((u @@ -61,6 +61,7 @@ extern struct passwd *getpwuid PARAMS((u
# endif # endif
# if defined (HAVE_GETPWNAM) # if defined (HAVE_GETPWNAM)