]> arthur.barton.de Git - netatalk.git/blob - libatalk/compat/getusershell.c
Active Directory LDAP queries for ACL support
[netatalk.git] / libatalk / compat / getusershell.c
1 /*
2  *
3  * Copyright (c) 1985 Regents of the University of California.
4  * All rights reserved.
5  *
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.
19  */
20
21 #ifdef HAVE_CONFIG_H
22 #include "config.h"
23 #endif /* HAVE_CONFIG_H */
24
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 */
28
29 #if defined(ultrix) || defined(_IBMR2) || defined(NEED_GETUSERSHELL)
30
31 #include <sys/param.h>
32 #include <sys/file.h>
33 #include <sys/stat.h>
34 #include <ctype.h>
35 #include <stdio.h>
36
37 #define SHELLS "/etc/shells"
38
39 /*
40  * Do not add local shells here.  They should be added in /etc/shells
41  */
42 static char *okshells[] = {
43     "/bin/sh", "/bin/csh",
44 #ifdef _IBMR2
45     "/bin/ksh",
46 #endif /* _IBMR2 */
47     0
48 };
49
50 static char **shells, *strings;
51 static char **curshell = NULL;
52 extern char **initshells();
53
54 /*
55  * Get a list of shells from SHELLS, if it exists.
56  */
57 char *
58 getusershell()
59 {
60         char *ret;
61
62         if (curshell == NULL)
63                 curshell = initshells();
64         ret = *curshell;
65         if (ret != NULL)
66                 curshell++;
67         return (ret);
68 }
69
70 endusershell()
71 {
72         
73         if (shells != NULL)
74                 free((char *)shells);
75         shells = NULL;
76         if (strings != NULL)
77                 free(strings);
78         strings = NULL;
79         curshell = NULL;
80 }
81
82 setusershell()
83 {
84
85         curshell = initshells();
86 }
87
88 static char **
89 initshells()
90 {
91         register char **sp, *cp;
92         register FILE *fp;
93         struct stat statb;
94         extern char *malloc(), *calloc();
95
96         if (shells != NULL)
97                 free((char *)shells);
98         shells = NULL;
99         if (strings != NULL)
100                 free(strings);
101         strings = NULL;
102         if ((fp = fopen(SHELLS, "r")) == (FILE *)0)
103                 return(okshells);
104         if (fstat(fileno(fp), &statb) == -1) {
105                 (void)fclose(fp);
106                 return(okshells);
107         }
108         if ((strings = malloc((unsigned)statb.st_size)) == NULL) {
109                 (void)fclose(fp);
110                 return(okshells);
111         }
112         shells = (char **)calloc((unsigned)statb.st_size / 3, sizeof (char *));
113         if (shells == NULL) {
114                 (void)fclose(fp);
115                 free(strings);
116                 strings = NULL;
117                 return(okshells);
118         }
119         sp = shells;
120         cp = strings;
121         while (fgets(cp, MAXPATHLEN + 1, fp) != NULL) {
122                 while (*cp != '#' && *cp != '/' && *cp != '\0')
123                         cp++;
124                 if (*cp == '#' || *cp == '\0')
125                         continue;
126                 *sp++ = cp;
127                 while (!isspace(*cp) && *cp != '#' && *cp != '\0')
128                         cp++;
129                 *cp++ = '\0';
130         }
131         *sp = (char *)0;
132         (void)fclose(fp);
133         return (shells);
134 }
135
136 # endif /* ultrix */