initshells for aix
git-svn-id: svn://svn.h5l.se/heimdal/trunk/heimdal@8279 ec53bebd-3082-4978-b11e-865c3cabbd6b
This commit is contained in:
@@ -54,6 +54,13 @@ RCSID("$Id$");
|
||||
#include <sys/param.h>
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_USERSEC_H
|
||||
#include <usersec.h>
|
||||
#endif
|
||||
#ifdef HAVE_USERCONF_H
|
||||
#include <userconf.h>
|
||||
#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 */
|
||||
|
Reference in New Issue
Block a user