3 * Copyright (c) 1985 Regents of the University of California.
6 * Redistribution and use in source and binary forms are permitted
7 * provided that: (1) source distributions retain this entire copyright
8 * notice and comment, and (2) distributions including binaries display
9 * the following acknowledgement: ``This product includes software
10 * developed by the University of California, Berkeley and its contributors''
11 * in the documentation or other materials provided with the distribution
12 * and in all advertising materials mentioning features or use of this
13 * software. Neither the name of the University nor the names of its
14 * contributors may be used to endorse or promote products derived
15 * from this software without specific prior written permission.
16 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
17 * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
18 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
23 #endif /* HAVE_CONFIG_H */
25 #if defined(LIBC_SCCS) && !defined(lint)
26 static char sccsid[] = "@(#)getusershell.c 5.6 (Berkeley) 6/1/90";
27 #endif /* LIBC_SCCS and not lint */
29 #if defined(ultrix) || defined(_IBMR2) || defined(NEED_GETUSERSHELL)
31 #include <sys/param.h>
37 #define SHELLS "/etc/shells"
40 * Do not add local shells here. They should be added in /etc/shells
42 static char *okshells[] = {
43 "/bin/sh", "/bin/csh",
50 static char **shells, *strings;
51 static char **curshell = NULL;
52 extern char **initshells();
55 * Get a list of shells from SHELLS, if it exists.
63 curshell = initshells();
85 curshell = initshells();
91 register char **sp, *cp;
94 extern char *malloc(), *calloc();
102 if ((fp = fopen(SHELLS, "r")) == (FILE *)0)
104 if (fstat(fileno(fp), &statb) == -1) {
108 if ((strings = malloc((unsigned)statb.st_size)) == NULL) {
112 shells = (char **)calloc((unsigned)statb.st_size / 3, sizeof (char *));
113 if (shells == NULL) {
121 while (fgets(cp, MAXPATHLEN + 1, fp) != NULL) {
122 while (*cp != '#' && *cp != '/' && *cp != '\0')
124 if (*cp == '#' || *cp == '\0')
127 while (!isspace(*cp) && *cp != '#' && *cp != '\0')