1 Index: bash-3.2/libcnisint.c
2 ===================================================================
3 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
4 +++ bash-3.2/libcnisint.c 2008-08-01 17:52:42.000000000 -0300
6 +#include "libcnisint.h"
18 + struct ENTDATA entdata;
19 +# define ENTDATA_DECL(data) struct ENTDATA *const entdata = &data->entdata;
21 +# define ENTDATA_DECL(data)
27 +static FILE *stream = NULL;
28 +static struct passwd passwd;
29 +static char buffer[NSS_BUFLEN_PASSWD];
31 +# define STRING_FIELD(variable, terminator_p, swallow) \
34 + while (*line != '\0' && !terminator_p (*line)) \
36 + if (*line != '\0') \
41 + while (swallow && terminator_p (*line)); \
45 +# define STRUCTURE passwd
46 +# define TRAILING_LIST_PARSER
48 +# define LINE_PARSER(EOLSET, BODY) \
49 +int parse_line (char *line, struct STRUCTURE *result, \
50 + struct parser_data *data, size_t datalen) \
52 + ENTDATA_DECL (data) \
53 + char *p = strpbrk (line, EOLSET "\n"); \
57 + TRAILING_LIST_PARSER; \
61 +# define INT_FIELD_MAYBE_NULL(variable, terminator_p, swallow, base, convert, default) \
64 + if (*line == '\0') \
65 + /* We expect some more input, so don't allow the string to end here. */ \
67 + variable = convert (strtoul (line, &endp, base)); \
69 + variable = default; \
70 + if (terminator_p (*endp)) \
73 + while (swallow && terminator_p (*endp)); \
74 + else if (*endp != '\0') \
79 +# define INT_FIELD(variable, terminator_p, swallow, base, convert) \
82 + variable = convert (strtoul (line, &endp, base)); \
85 + else if (terminator_p (*endp)) \
88 + while (swallow && terminator_p (*endp)); \
89 + else if (*endp != '\0') \
94 +# define ISCOLON(c) ((c) == ':')
97 + STRING_FIELD (result->pw_name, ISCOLON, 0)
99 + && (result->pw_name[0] == '+' || result->pw_name[0] == '-'))
101 + /* This a special case. We allow lines containing only a `+' sign
102 + since this is used for nss_compat. All other services will
103 + reject this entry later. Initialize all other fields now. */
104 + result->pw_passwd = NULL;
105 + result->pw_uid = 0;
106 + result->pw_gid = 0;
107 + result->pw_gecos = NULL;
108 + result->pw_dir = NULL;
109 + result->pw_shell = NULL;
113 + STRING_FIELD (result->pw_passwd, ISCOLON, 0)
114 + if (result->pw_name[0] == '+' || result->pw_name[0] == '-')
116 + INT_FIELD_MAYBE_NULL (result->pw_uid, ISCOLON, 0, 10, , 0)
117 + INT_FIELD_MAYBE_NULL (result->pw_gid, ISCOLON, 0, 10, , 0)
121 + INT_FIELD (result->pw_uid, ISCOLON, 0, 10,)
122 + INT_FIELD (result->pw_gid, ISCOLON, 0, 10,)
124 + STRING_FIELD (result->pw_gecos, ISCOLON, 0)
125 + STRING_FIELD (result->pw_dir, ISCOLON, 0)
126 + result->pw_shell = line;
131 +void internal_setpwent (void)
133 + if (stream == NULL)
135 + stream = fopen ("/etc/passwd", "rme");
137 + if (stream == NULL)
138 + fprintf (stderr, "ERROR: Cannot fopen \"/etc/passwd\". Errno: %d", errno);
145 +void internal_endpwent (void)
147 + if (stream != NULL)
154 +struct passwd *internal_getpwent (void)
156 + struct parser_data *data = (void *) &buffer;
157 + struct passwd *result = &passwd;
158 + int buflen = NSS_BUFLEN_PASSWD;
168 + /* We need at least 3 characters for one line. */
172 + fprintf (stderr, "ERROR: Range error");
176 + fgetpos (stream, &pos);
177 + buffer[buflen - 1] = '\xff';
178 + p = fgets (buffer, buflen, stream);
179 + if (p == NULL && feof (stream))
182 + if (p == NULL || buffer[buflen - 1] != '\xff')
185 + fsetpos (stream, &pos);
189 + /* Terminate the line for any case. */
190 + buffer[buflen - 1] = '\0';
192 + /* Skip leading blanks. */
193 + while (isspace (*p))
196 + while (*p == '\0' || *p == '#' || /* Ignore empty and comment lines. */
197 + /* Parse the line. If it is invalid, loop to
198 + get the next line of the file to parse. */
199 + !(parse_res = parse_line (p, result, data, buflen)));
201 + if (parse_res == -1)
202 + /* The parser ran out of space. */
205 + if (result->pw_name[0] != '+' && result->pw_name[0] != '-')
206 + /* This is a real entry. */
217 + * as we don't suppose to use them */
225 +/* Searches in /etc/passwd and the NSS subsystem for a special user id */
226 +struct passwd *internal_getpwuid (uid_t uid)
228 + struct parser_data *data = (void *) buffer;
229 + struct passwd *result = &passwd;
230 + int buflen = NSS_BUFLEN_PASSWD;
232 + internal_setpwent ();
242 + /* We need at least 3 characters for one line. */
246 + fprintf (stderr, "ERROR: Range error");
250 + fgetpos (stream, &pos);
251 + buffer[buflen - 1] = '\xff';
252 + p = fgets (buffer, buflen, stream);
253 + if (p == NULL && feof (stream))
256 + if (p == NULL || buffer[buflen - 1] != '\xff')
259 + fsetpos (stream, &pos);
263 + /* Terminate the line for any case. */
264 + buffer[buflen - 1] = '\0';
266 + /* Skip leading blanks. */
267 + while (isspace (*p))
270 + while (*p == '\0' || *p == '#' || /* Ignore empty and comment lines. */
271 + /* Parse the line. If it is invalid, loop to
272 + get the next line of the file to parse. */
273 + !(parse_res = parse_line (p, result, data, buflen)));
275 + if (parse_res == -1)
276 + /* The parser ran out of space. */
279 + /* This is a real entry. */
280 + if (result->pw_name[0] != '+' && result->pw_name[0] != '-')
282 + if (result->pw_uid == uid)
296 + * as we don't suppose to use them */
299 + internal_endpwent ();
302 Index: bash-3.2/libcnisint.h
303 ===================================================================
304 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
305 +++ bash-3.2/libcnisint.h 2008-08-01 17:18:20.000000000 -0300
309 +void internal_setpwent (void);
310 +void internal_endpwent (void);
311 +struct passwd *internal_getpwent (void);
312 +struct passwd *internal_getpwuid (uid_t uid);
314 Index: bash-3.2/examples/loadables/finfo.c
315 ===================================================================
316 --- bash-3.2.orig/examples/loadables/finfo.c 2008-08-01 14:29:55.000000000 -0300
317 +++ bash-3.2/examples/loadables/finfo.c 2008-08-01 15:32:37.000000000 -0300
319 #include <sys/types.h>
320 #include "posixstat.h"
327 #include "builtins.h"
330 +#include "libcnisint.h"
336 printf("Mode: (%o) ", (int) st->st_mode);
337 printmode((int) st->st_mode);
338 printf("Link count: %d\n", (int) st->st_nlink);
339 - pw = getpwuid(st->st_uid);
340 + pw = internal_getpwuid(st->st_uid);
341 owner = pw ? pw->pw_name : "unknown";
342 printf("Uid of owner: %d (%s)\n", (int) st->st_uid, owner);
343 gr = getgrgid(st->st_gid);
345 else if (flags & OPT_PMASK)
346 printf("%o\n", getperm(st->st_mode) & pmask);
347 else if (flags & OPT_UID) {
348 - pw = getpwuid(st->st_uid);
349 + pw = internal_getpwuid(st->st_uid);
350 if (flags & OPT_ASCII)
351 printf("%s\n", pw ? pw->pw_name : "unknown");
353 Index: bash-3.2/examples/loadables/id.c
354 ===================================================================
355 --- bash-3.2.orig/examples/loadables/id.c 2008-08-01 14:17:24.000000000 -0300
356 +++ bash-3.2/examples/loadables/id.c 2008-08-01 14:51:23.000000000 -0300
360 #include "bashtypes.h"
363 #include "bashansi.h"
366 # include <sys/param.h>
369 -#if !defined (HAVE_GETPW_DECLS)
370 -extern struct passwd *getpwuid ();
372 +#include "libcnisint.h"
374 extern struct group *getgrgid ();
379 if (id_flags & ID_USENAME)
381 - pwd = getpwuid (uid);
382 + pwd = internal_getpwuid (uid);
389 printf ("uid=%u", (unsigned) ruid);
390 - pwd = getpwuid (ruid);
391 + pwd = internal_getpwuid (ruid);
398 printf (" euid=%u", (unsigned) euid);
399 - pwd = getpwuid (euid);
400 + pwd = internal_getpwuid (euid);
404 Index: bash-3.2/lib/readline/complete.c
405 ===================================================================
406 --- bash-3.2.orig/lib/readline/complete.c 2008-07-31 19:06:06.000000000 -0300
407 +++ bash-3.2/lib/readline/complete.c 2008-08-01 15:52:25.000000000 -0300
412 -#if defined (HAVE_PWD_H)
415 +#include "libcnisint.h"
417 #include "posixdir.h"
418 #include "posixstat.h"
420 /* Unix version of a hidden file. Could be different on other systems. */
421 #define HIDDEN_FILE(fname) ((fname)[0] == '.')
423 -/* Most systems don't declare getpwent in <pwd.h> if _POSIX_SOURCE is
425 -#if defined (HAVE_GETPWENT) && (!defined (HAVE_GETPW_DECLS) || defined (_POSIX_SOURCE))
426 -extern struct passwd *getpwent PARAMS((void));
427 -#endif /* HAVE_GETPWENT && (!HAVE_GETPW_DECLS || _POSIX_SOURCE) */
429 /* If non-zero, then this is the address of a function to call when
430 completing a word would normally display the list of possible matches.
431 This function is called instead of actually doing the display.
432 @@ -1849,24 +1841,19 @@
434 username = savestring (&text[first_char_loc]);
435 namelen = strlen (username);
437 + internal_setpwent ();
440 -#if defined (HAVE_GETPWENT)
441 - while (entry = getpwent ())
442 + while (entry = internal_getpwent ())
444 /* Null usernames should result in all users as possible completions. */
445 if (namelen == 0 || (STREQN (username, entry->pw_name, namelen)))
452 -#if defined (HAVE_GETPWENT)
455 - return ((char *)NULL);
456 + internal_endpwent ();
460 Index: bash-3.2/lib/readline/shell.c
461 ===================================================================
462 --- bash-3.2.orig/lib/readline/shell.c 2008-08-01 14:44:38.000000000 -0300
463 +++ bash-3.2/lib/readline/shell.c 2008-08-01 15:36:03.000000000 -0300
465 #if defined (HAVE_FCNTL_H)
468 -#if defined (HAVE_PWD_H)
472 +#include "libcnisint.h"
480 -#if defined (HAVE_GETPWUID) && !defined (HAVE_GETPW_DECLS)
481 -extern struct passwd *getpwuid PARAMS((uid_t));
482 -#endif /* HAVE_GETPWUID && !HAVE_GETPW_DECLS */
488 struct passwd *entry;
490 home_dir = (char *)NULL;
491 -#if defined (HAVE_GETPWUID)
492 - entry = getpwuid (getuid ());
493 + entry = internal_getpwuid (getuid ());
495 home_dir = entry->pw_dir;
500 Index: bash-3.2/lib/readline/tilde.c
501 ===================================================================
502 --- bash-3.2.orig/lib/readline/tilde.c 2008-07-31 19:09:19.000000000 -0300
503 +++ bash-3.2/lib/readline/tilde.c 2008-08-01 15:51:52.000000000 -0300
505 # include "ansi_stdlib.h"
506 #endif /* HAVE_STDLIB_H */
508 -#include <sys/types.h>
509 -#if defined (HAVE_PWD_H)
512 +#include "libcnisint.h"
517 #endif /* TEST || STATIC_MALLOC */
519 #if !defined (HAVE_GETPW_DECLS)
520 -# if defined (HAVE_GETPWUID)
521 -extern struct passwd *getpwuid PARAMS((uid_t));
523 # if defined (HAVE_GETPWNAM)
524 extern struct passwd *getpwnam PARAMS((const char *));
526 @@ -409,15 +403,11 @@
528 dirname = savestring (filename);
530 -#if defined (HAVE_GETPWENT)
532 dirname = glue_prefix_and_suffix (user_entry->pw_dir, filename, user_len);
536 -#if defined (HAVE_GETPWENT)
539 + internal_endpwent ();
543 Index: bash-3.2/lib/tilde/shell.c
544 ===================================================================
545 --- bash-3.2.orig/lib/tilde/shell.c 2008-08-01 14:41:32.000000000 -0300
546 +++ bash-3.2/lib/tilde/shell.c 2008-08-01 15:32:49.000000000 -0300
548 # include <strings.h>
549 #endif /* !HAVE_STRING_H */
553 -#if !defined (HAVE_GETPW_DECLS)
554 -extern struct passwd *getpwuid ();
555 -#endif /* !HAVE_GETPW_DECLS */
556 +#include "libcnisint.h"
559 get_env_value (varname)
561 struct passwd *entry;
563 home_dir = (char *)NULL;
564 - entry = getpwuid (getuid ());
565 + entry = internal_getpwuid (getuid ());
567 home_dir = entry->pw_dir;
569 Index: bash-3.2/lib/tilde/tilde.c
570 ===================================================================
571 --- bash-3.2.orig/lib/tilde/tilde.c 2008-08-01 15:41:27.000000000 -0300
572 +++ bash-3.2/lib/tilde/tilde.c 2008-08-01 15:51:13.000000000 -0300
574 #endif /* HAVE_STDLIB_H */
576 #include <sys/types.h>
577 -#if defined (HAVE_PWD_H)
581 +#include "libcnisint.h"
586 #endif /* TEST || STATIC_MALLOC */
588 #if !defined (HAVE_GETPW_DECLS)
589 -# if defined (HAVE_GETPWUID)
590 -extern struct passwd *getpwuid PARAMS((uid_t));
592 # if defined (HAVE_GETPWNAM)
593 extern struct passwd *getpwnam PARAMS((const char *));
595 @@ -409,15 +405,11 @@
597 dirname = savestring (filename);
599 -#if defined (HAVE_GETPWENT)
601 dirname = glue_prefix_and_suffix (user_entry->pw_dir, filename, user_len);
605 -#if defined (HAVE_GETPWENT)
608 + internal_endpwent ();
612 Index: bash-3.2/shell.c
613 ===================================================================
614 --- bash-3.2.orig/shell.c 2008-07-31 19:10:00.000000000 -0300
615 +++ bash-3.2/shell.c 2008-08-01 15:46:10.000000000 -0300
619 #include "filecntl.h"
622 +#include "libcnisint.h"
624 #if defined (HAVE_UNISTD_H)
627 # include <opennt/opennt.h>
630 -#if !defined (HAVE_GETPW_DECLS)
631 -extern struct passwd *getpwuid ();
632 -#endif /* !HAVE_GETPW_DECLS */
637 @@ -1586,7 +1583,7 @@
638 /* Don't fetch this more than once. */
639 if (current_user.user_name == 0)
641 - entry = getpwuid (current_user.uid);
642 + entry = internal_getpwuid (current_user.uid);
645 current_user.user_name = savestring (entry->pw_name);
646 @@ -1602,7 +1599,7 @@
647 current_user.shell = savestring ("/bin/sh");
648 current_user.home_dir = savestring ("/");
651 + internal_endpwent ();
655 Index: bash-3.2/config.h.in
656 ===================================================================
657 --- bash-3.2.orig/config.h.in 2008-08-01 15:54:05.000000000 -0300
658 +++ bash-3.2/config.h.in 2008-08-01 15:54:34.000000000 -0300
660 /* Define if you have the getpeername function. */
661 #undef HAVE_GETPEERNAME
663 -/* Define if you have the getpwent function. */
664 -#undef HAVE_GETPWENT
666 /* Define if you have the getpwnam function. */
669 -/* Define if you have the getpwuid function. */
670 -#undef HAVE_GETPWUID
672 /* Define if you have the getrlimit function. */
673 #undef HAVE_GETRLIMIT
675 Index: bash-3.2/configure.in
676 ===================================================================
677 --- bash-3.2.orig/configure.in 2008-08-01 15:55:19.000000000 -0300
678 +++ bash-3.2/configure.in 2008-08-01 15:56:12.000000000 -0300
681 AC_CHECK_FUNCS(vsnprintf snprintf vasprintf asprintf)
682 AC_CHECK_FUNCS(isascii isblank isgraph isprint isspace isxdigit)
683 -AC_CHECK_FUNCS(getpwent getpwnam getpwuid)
684 +AC_CHECK_FUNCS(getpwnam)
685 AC_REPLACE_FUNCS(getcwd memset strcasecmp strerror strftime strnlen strpbrk strstr)
686 AC_REPLACE_FUNCS(strtod strtol strtoul strtoll strtoull strtoimax strtoumax)
693 -dnl this is reportedly no longer necessary for irix[56].?
695 -irix4*) AC_CHECK_LIB(sun, getpwent) ;;
698 dnl check for getpeername in the socket library only if it's not in libc
699 if test "$ac_cv_func_getpeername" = no; then
700 BASH_CHECK_LIB_SOCKET
701 Index: bash-3.2/patchlevel.h
702 ===================================================================
703 --- bash-3.2.orig/patchlevel.h 2008-08-01 16:24:52.000000000 -0300
704 +++ bash-3.2/patchlevel.h 2008-08-01 16:25:03.000000000 -0300
706 regexp `^#define[ ]*PATCHLEVEL', since that's what support/mkversion.sh
707 looks for to find the patch level (for the sccs version string). */
709 -#define PATCHLEVEL 5
710 +#define PATCHLEVEL 6
712 #endif /* _PATCHLEVEL_H_ */
713 Index: bash-3.2/Makefile.in
714 ===================================================================
715 --- bash-3.2.orig/Makefile.in 2008-08-01 16:32:13.000000000 -0300
716 +++ bash-3.2/Makefile.in 2008-08-01 17:12:17.000000000 -0300
718 input.c bashhist.c array.c arrayfunc.c sig.c pathexp.c \
719 unwind_prot.c siglist.c bashline.c bracecomp.c error.c \
720 list.c stringlib.c locale.c findcmd.c redir.c \
721 - pcomplete.c pcomplib.c syntax.c xmalloc.c
722 + pcomplete.c pcomplib.c syntax.c xmalloc.c libcnisint.c
724 HSOURCES = shell.h flags.h trap.h hashcmd.h hashlib.h jobs.h builtins.h \
725 general.h variables.h config.h $(ALLOC_HEADERS) alias.h \
727 command.h input.h error.h bashansi.h dispose_cmd.h make_cmd.h \
728 subst.h externs.h siglist.h bashhist.h bashline.h bashtypes.h \
729 array.h arrayfunc.h sig.h mailcheck.h bashintl.h bashjmp.h \
730 - execute_cmd.h parser.h pathexp.h pathnames.h pcomplete.h \
731 + execute_cmd.h parser.h pathexp.h pathnames.h pcomplete.h libcnisint.h \
734 SOURCES = $(CSOURCES) $(HSOURCES) $(BUILTIN_DEFS)
736 trap.o input.o unwind_prot.o pathexp.o sig.o test.o version.o \
737 alias.o array.o arrayfunc.o braces.o bracecomp.o bashhist.o \
738 bashline.o $(SIGLIST_O) list.o stringlib.o locale.o findcmd.o redir.o \
739 - pcomplete.o pcomplib.o syntax.o xmalloc.o $(SIGNAMES_O)
740 + pcomplete.o pcomplib.o syntax.o xmalloc.o libcnisint.o $(SIGNAMES_O)
742 # Where the source code of the shell builtins resides.
743 BUILTIN_SRCDIR=$(srcdir)/builtins
745 shell.o: make_cmd.h subst.h sig.h pathnames.h externs.h
746 shell.o: flags.h trap.h mailcheck.h builtins.h $(DEFSRC)/common.h
747 shell.o: jobs.h siglist.h input.h execute_cmd.h findcmd.h bashhist.h
748 -shell.o: ${GLOB_LIBSRC}/strmatch.h ${BASHINCDIR}/posixtime.h
749 +shell.o: ${GLOB_LIBSRC}/strmatch.h ${BASHINCDIR}/posixtime.h libcnisint.h
750 sig.o: config.h bashtypes.h
751 sig.o: shell.h syntax.h config.h bashjmp.h ${BASHINCDIR}/posixjmp.h command.h ${BASHINCDIR}/stdc.h error.h
752 sig.o: general.h xmalloc.h bashtypes.h variables.h arrayfunc.h conftypes.h array.h hashlib.h