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