diff options
author | stevel@tonic-gate <none@none> | 2005-06-14 00:00:00 -0700 |
---|---|---|
committer | stevel@tonic-gate <none@none> | 2005-06-14 00:00:00 -0700 |
commit | 7c478bd95313f5f23a4c958a745db2134aa03244 (patch) | |
tree | c871e58545497667cbb4b0a4f2daf204743e1fe7 /usr/src/lib/libbc/libc/gen/common/getusershell.c | |
download | illumos-joyent-7c478bd95313f5f23a4c958a745db2134aa03244.tar.gz |
OpenSolaris Launch
Diffstat (limited to 'usr/src/lib/libbc/libc/gen/common/getusershell.c')
-rw-r--r-- | usr/src/lib/libbc/libc/gen/common/getusershell.c | 107 |
1 files changed, 107 insertions, 0 deletions
diff --git a/usr/src/lib/libbc/libc/gen/common/getusershell.c b/usr/src/lib/libbc/libc/gen/common/getusershell.c new file mode 100644 index 0000000000..f03c328a8d --- /dev/null +++ b/usr/src/lib/libbc/libc/gen/common/getusershell.c @@ -0,0 +1,107 @@ +#pragma ident "%Z%%M% %I% %E% SMI" + /* from UCB 5.4 7/25/86 */ +/* + * Copyright (c) 1985 Regents of the University of California. + * All rights reserved. The Berkeley software License Agreement + * specifies the terms and conditions for redistribution. + */ + +#include <sys/param.h> +#include <sys/file.h> +#include <sys/stat.h> +#include <ctype.h> +#include <stdio.h> + +#define SHELLS "/etc/shells" + +/* + * Do not add local shells here. They should be added in /etc/shells + */ +static char *okshells[] = + { "/bin/sh", "/bin/csh", "/usr/bin/sh", "/usr/bin/csh", 0 }; + +static char **shells, *strings; +static char **curshell; +extern char **initshells(); + +/* + * Get a list of shells from SHELLS, if it exists. + */ +char * +getusershell() +{ + char *ret; + + if (curshell == NULL) + curshell = initshells(); + ret = *curshell; + if (ret != NULL) + curshell++; + return (ret); +} + +endusershell() +{ + + if (shells != NULL) + free((char *)shells); + shells = NULL; + if (strings != NULL) + free(strings); + strings = NULL; + curshell = NULL; +} + +setusershell() +{ + + curshell = initshells(); +} + +static char ** +initshells() +{ + register char **sp, *cp; + register FILE *fp; + struct stat statb; + extern char *malloc(), *calloc(); + + if (shells != NULL) + free((char *)shells); + shells = NULL; + if (strings != NULL) + free(strings); + strings = NULL; + if ((fp = fopen(SHELLS, "r")) == (FILE *)0) + return(okshells); + if (fstat(fileno(fp), &statb) == -1) { + (void)fclose(fp); + return(okshells); + } + if ((strings = malloc((unsigned)statb.st_size + 1)) == NULL) { + (void)fclose(fp); + return(okshells); + } + shells = (char **)calloc((unsigned)statb.st_size / 3, sizeof (char *)); + if (shells == NULL) { + (void)fclose(fp); + free(strings); + strings = NULL; + return(okshells); + } + sp = shells; + cp = strings; + while (fgets(cp, MAXPATHLEN + 1, fp) != NULL) { + while (*cp != '#' && *cp != '/' && *cp != '\0') + cp++; + if (*cp == '#' || *cp == '\0') + continue; + *sp++ = cp; + while (!isspace(*cp) && *cp != '#' && *cp != '\0') + cp++; + *cp++ = '\0'; + } + *sp = (char *)0; + (void)fclose(fp); + return (shells); +} |