2 * $Id: getusershell.c,v 1.4 2003-02-17 01:51:08 srittau Exp $
4 * Copyright (c) 1985 Regents of the University of California.
7 * Redistribution and use in source and binary forms are permitted
8 * provided that: (1) source distributions retain this entire copyright
9 * notice and comment, and (2) distributions including binaries display
10 * the following acknowledgement: ``This product includes software
11 * developed by the University of California, Berkeley and its contributors''
12 * in the documentation or other materials provided with the distribution
13 * and in all advertising materials mentioning features or use of this
14 * software. Neither the name of the University nor the names of its
15 * contributors may be used to endorse or promote products derived
16 * from this software without specific prior written permission.
17 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
18 * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
19 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
24 #endif /* HAVE_CONFIG_H */
26 #if defined(LIBC_SCCS) && !defined(lint)
27 static char sccsid[] = "@(#)getusershell.c 5.6 (Berkeley) 6/1/90";
28 #endif /* LIBC_SCCS and not lint */
30 #if defined(ultrix) || defined(_IBMR2) || defined(NEED_GETUSERSHELL)
32 #include <sys/param.h>
38 #define SHELLS "/etc/shells"
41 * Do not add local shells here. They should be added in /etc/shells
43 static char *okshells[] = {
44 "/bin/sh", "/bin/csh",
51 static char **shells, *strings;
52 static char **curshell = NULL;
53 extern char **initshells();
56 * Get a list of shells from SHELLS, if it exists.
64 curshell = initshells();
86 curshell = initshells();
92 register char **sp, *cp;
95 extern char *malloc(), *calloc();
103 if ((fp = fopen(SHELLS, "r")) == (FILE *)0)
105 if (fstat(fileno(fp), &statb) == -1) {
109 if ((strings = malloc((unsigned)statb.st_size)) == NULL) {
113 shells = (char **)calloc((unsigned)statb.st_size / 3, sizeof (char *));
114 if (shells == NULL) {
122 while (fgets(cp, MAXPATHLEN + 1, fp) != NULL) {
123 while (*cp != '#' && *cp != '/' && *cp != '\0')
125 if (*cp == '#' || *cp == '\0')
128 while (!isspace(*cp) && *cp != '#' && *cp != '\0')