2 * $Id: getusershell.c,v 1.3 2001-06-29 14:14:46 rufustfirefly 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 static int _getusershell_dummy;
32 #if defined(ultrix) || defined(_IBMR2) || defined(NEED_GETUSERSHELL)
34 #include <sys/param.h>
40 #define SHELLS "/etc/shells"
43 * Do not add local shells here. They should be added in /etc/shells
45 static char *okshells[] = {
46 "/bin/sh", "/bin/csh",
53 static char **shells, *strings;
54 static char **curshell = NULL;
55 extern char **initshells();
58 * Get a list of shells from SHELLS, if it exists.
66 curshell = initshells();
88 curshell = initshells();
94 register char **sp, *cp;
97 extern char *malloc(), *calloc();
100 free((char *)shells);
105 if ((fp = fopen(SHELLS, "r")) == (FILE *)0)
107 if (fstat(fileno(fp), &statb) == -1) {
111 if ((strings = malloc((unsigned)statb.st_size)) == NULL) {
115 shells = (char **)calloc((unsigned)statb.st_size / 3, sizeof (char *));
116 if (shells == NULL) {
124 while (fgets(cp, MAXPATHLEN + 1, fp) != NULL) {
125 while (*cp != '#' && *cp != '/' && *cp != '\0')
127 if (*cp == '#' || *cp == '\0')
130 while (!isspace(*cp) && *cp != '#' && *cp != '\0')