From fc2957b4a7c60a74c7d35b4d54f580761d44b99b Mon Sep 17 00:00:00 2001 From: Johan Danielsson Date: Mon, 22 May 2000 07:22:03 +0000 Subject: [PATCH] initshells for aix git-svn-id: svn://svn.h5l.se/heimdal/trunk/heimdal@8279 ec53bebd-3082-4978-b11e-865c3cabbd6b --- lib/roken/getusershell.c | 139 +++++++++++++++++++++++---------------- 1 file changed, 83 insertions(+), 56 deletions(-) diff --git a/lib/roken/getusershell.c b/lib/roken/getusershell.c index 9d4892309..6c0908144 100644 --- a/lib/roken/getusershell.c +++ b/lib/roken/getusershell.c @@ -54,6 +54,13 @@ RCSID("$Id$"); #include #endif +#ifdef HAVE_USERSEC_H +#include +#endif +#ifdef HAVE_USERCONF_H +#include +#endif + #ifndef _PATH_SHELLS #define _PATH_SHELLS "/etc/shells" #endif @@ -81,80 +88,100 @@ static char **initshells (void); char * getusershell() { - char *ret; + char *ret; - if (curshell == NULL) - curshell = initshells(); - ret = *curshell; - if (ret != NULL) - curshell++; - return (ret); + if (curshell == NULL) + curshell = initshells(); + ret = *curshell; + if (ret != NULL) + curshell++; + return (ret); } void endusershell() { - - if (shells != NULL) - free(shells); - shells = NULL; - if (strings != NULL) - free(strings); - strings = NULL; - curshell = NULL; + if (shells != NULL) + free(shells); + shells = NULL; + if (strings != NULL) + free(strings); + strings = NULL; + curshell = NULL; } void setusershell() { - - curshell = initshells(); + curshell = initshells(); } static char ** initshells() { - char **sp, *cp; - FILE *fp; - struct stat statb; + char **sp, *cp; +#ifndef HAVE_GETCONFATTR + FILE *fp; +#endif + struct stat statb; - if (shells != NULL) - free(shells); + if (shells != NULL) + free(shells); + shells = NULL; + if (strings != NULL) + free(strings); + strings = NULL; +#ifdef HAVE_GETCONFATTR + shells = calloc(47, sizeof(*shells)); + if(shells == NULL) + return okshells; + if(getconfattr(SC_SYS_LOGIN, SC_SHELLS, &cp, SEC_LIST) != 0) { + free(shells); shells = NULL; - if (strings != NULL) - free(strings); - strings = NULL; - if ((fp = fopen(_PATH_SHELLS, "r")) == NULL) - return (okshells); - if (fstat(fileno(fp), &statb) == -1) { - fclose(fp); - return (okshells); - } - if ((strings = malloc((u_int)statb.st_size)) == NULL) { - fclose(fp); - return (okshells); - } - shells = calloc((unsigned)statb.st_size / 3, sizeof (char *)); - if (shells == NULL) { - 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 = NULL; + return okshells; + } + strings = strdup(cp); + if(strings == NULL) { + free(shells); + shells = NULL; + return okshells; + } + for(sp = shells, cp = strings; cp; cp += strlen(cp) + 1, sp++) { + *sp = cp; + } +#else + if ((fp = fopen(_PATH_SHELLS, "r")) == NULL) + return (okshells); + if (fstat(fileno(fp), &statb) == -1) { fclose(fp); - return (shells); + return (okshells); + } + if ((strings = malloc((u_int)statb.st_size)) == NULL) { + fclose(fp); + return (okshells); + } + shells = calloc((unsigned)statb.st_size / 3, sizeof (char *)); + if (shells == NULL) { + 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'; + } + fclose(fp); +#endif + *sp = NULL; + return (shells); } #endif /* HAVE_GETUSERSHELL */