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>
|
#include <sys/param.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifdef HAVE_USERSEC_H
|
||||||
|
#include <usersec.h>
|
||||||
|
#endif
|
||||||
|
#ifdef HAVE_USERCONF_H
|
||||||
|
#include <userconf.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifndef _PATH_SHELLS
|
#ifndef _PATH_SHELLS
|
||||||
#define _PATH_SHELLS "/etc/shells"
|
#define _PATH_SHELLS "/etc/shells"
|
||||||
#endif
|
#endif
|
||||||
@@ -81,80 +88,100 @@ static char **initshells (void);
|
|||||||
char *
|
char *
|
||||||
getusershell()
|
getusershell()
|
||||||
{
|
{
|
||||||
char *ret;
|
char *ret;
|
||||||
|
|
||||||
if (curshell == NULL)
|
if (curshell == NULL)
|
||||||
curshell = initshells();
|
curshell = initshells();
|
||||||
ret = *curshell;
|
ret = *curshell;
|
||||||
if (ret != NULL)
|
if (ret != NULL)
|
||||||
curshell++;
|
curshell++;
|
||||||
return (ret);
|
return (ret);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
endusershell()
|
endusershell()
|
||||||
{
|
{
|
||||||
|
if (shells != NULL)
|
||||||
if (shells != NULL)
|
free(shells);
|
||||||
free(shells);
|
shells = NULL;
|
||||||
shells = NULL;
|
if (strings != NULL)
|
||||||
if (strings != NULL)
|
free(strings);
|
||||||
free(strings);
|
strings = NULL;
|
||||||
strings = NULL;
|
curshell = NULL;
|
||||||
curshell = NULL;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
setusershell()
|
setusershell()
|
||||||
{
|
{
|
||||||
|
curshell = initshells();
|
||||||
curshell = initshells();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static char **
|
static char **
|
||||||
initshells()
|
initshells()
|
||||||
{
|
{
|
||||||
char **sp, *cp;
|
char **sp, *cp;
|
||||||
FILE *fp;
|
#ifndef HAVE_GETCONFATTR
|
||||||
struct stat statb;
|
FILE *fp;
|
||||||
|
#endif
|
||||||
|
struct stat statb;
|
||||||
|
|
||||||
if (shells != NULL)
|
if (shells != NULL)
|
||||||
free(shells);
|
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;
|
shells = NULL;
|
||||||
if (strings != NULL)
|
return okshells;
|
||||||
free(strings);
|
}
|
||||||
strings = NULL;
|
strings = strdup(cp);
|
||||||
if ((fp = fopen(_PATH_SHELLS, "r")) == NULL)
|
if(strings == NULL) {
|
||||||
return (okshells);
|
free(shells);
|
||||||
if (fstat(fileno(fp), &statb) == -1) {
|
shells = NULL;
|
||||||
fclose(fp);
|
return okshells;
|
||||||
return (okshells);
|
}
|
||||||
}
|
for(sp = shells, cp = strings; cp; cp += strlen(cp) + 1, sp++) {
|
||||||
if ((strings = malloc((u_int)statb.st_size)) == NULL) {
|
*sp = cp;
|
||||||
fclose(fp);
|
}
|
||||||
return (okshells);
|
#else
|
||||||
}
|
if ((fp = fopen(_PATH_SHELLS, "r")) == NULL)
|
||||||
shells = calloc((unsigned)statb.st_size / 3, sizeof (char *));
|
return (okshells);
|
||||||
if (shells == NULL) {
|
if (fstat(fileno(fp), &statb) == -1) {
|
||||||
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;
|
|
||||||
fclose(fp);
|
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 */
|
#endif /* HAVE_GETUSERSHELL */
|
||||||
|
Reference in New Issue
Block a user