#endif /* HAVE_STRINGS_H */
#include <fcntl.h>
#include <limits.h>
-#include <pwd.h>
-#include <grp.h>
+#include "tsgetgrpw.h"
#include "sudo.h"
#ifndef LINE_MAX
static const char *grfile = "/etc/group";
static int gr_stayopen;
-void setgrfile __P((const char *));
-void setgrent __P((void));
-void endgrent __P((void));
-struct group *getgrent __P((void));
-struct group *getgrnam __P((const char *));
-struct group *getgrgid __P((gid_t));
-
-void setpwfile __P((const char *));
-void setpwent __P((void));
-void endpwent __P((void));
-struct passwd *getpwent __P((void));
-struct passwd *getpwnam __P((const char *));
-struct passwd *getpwuid __P((uid_t));
-
void
setpwfile(file)
const char *file;
char *cp, *colon;
if ((colon = fgets(pwbuf, sizeof(pwbuf), pwf)) == NULL)
- return(NULL);
+ return NULL;
zero_bytes(&pw, sizeof(pw));
if ((colon = strchr(cp = colon, ':')) == NULL)
- return(NULL);
+ return NULL;
*colon++ = '\0';
pw.pw_name = cp;
if ((colon = strchr(cp = colon, ':')) == NULL)
- return(NULL);
+ return NULL;
*colon++ = '\0';
pw.pw_passwd = cp;
if ((colon = strchr(cp = colon, ':')) == NULL)
- return(NULL);
+ return NULL;
*colon++ = '\0';
pw.pw_uid = atoi(cp);
if ((colon = strchr(cp = colon, ':')) == NULL)
- return(NULL);
+ return NULL;
*colon++ = '\0';
pw.pw_gid = atoi(cp);
if ((colon = strchr(cp = colon, ':')) == NULL)
- return(NULL);
+ return NULL;
*colon++ = '\0';
pw.pw_gecos = cp;
if ((colon = strchr(cp = colon, ':')) == NULL)
- return(NULL);
+ return NULL;
*colon++ = '\0';
pw.pw_dir = cp;
pw.pw_shell = colon;
len = strlen(colon);
if (len > 0 && colon[len - 1] == '\n')
colon[len - 1] = '\0';
- return(&pw);
+ return &pw;
}
struct passwd *
if (pwf == NULL) {
if ((pwf = fopen(pwfile, "r")) == NULL)
- return(NULL);
+ return NULL;
fcntl(fileno(pwf), F_SETFD, FD_CLOEXEC);
} else {
rewind(pwf);
fclose(pwf);
pwf = NULL;
}
- return(pw);
+ return pw;
}
struct passwd *
if (pwf == NULL) {
if ((pwf = fopen(pwfile, "r")) == NULL)
- return(NULL);
+ return NULL;
fcntl(fileno(pwf), F_SETFD, FD_CLOEXEC);
} else {
rewind(pwf);
fclose(pwf);
pwf = NULL;
}
- return(pw);
+ return pw;
}
void
int n;
if ((colon = fgets(grbuf, sizeof(grbuf), grf)) == NULL)
- return(NULL);
+ return NULL;
zero_bytes(&gr, sizeof(gr));
if ((colon = strchr(cp = colon, ':')) == NULL)
- return(NULL);
+ return NULL;
*colon++ = '\0';
gr.gr_name = cp;
if ((colon = strchr(cp = colon, ':')) == NULL)
- return(NULL);
+ return NULL;
*colon++ = '\0';
gr.gr_passwd = cp;
if ((colon = strchr(cp = colon, ':')) == NULL)
- return(NULL);
+ return NULL;
*colon++ = '\0';
gr.gr_gid = atoi(cp);
len = strlen(colon);
gr.gr_mem[n++] = NULL;
} else
gr.gr_mem = NULL;
- return(&gr);
+ return &gr;
}
struct group *
if (grf == NULL) {
if ((grf = fopen(grfile, "r")) == NULL)
- return(NULL);
+ return NULL;
fcntl(fileno(grf), F_SETFD, FD_CLOEXEC);
} else {
rewind(grf);
fclose(grf);
grf = NULL;
}
- return(gr);
+ return gr;
}
struct group *
if (grf == NULL) {
if ((grf = fopen(grfile, "r")) == NULL)
- return(NULL);
+ return NULL;
fcntl(fileno(grf), F_SETFD, FD_CLOEXEC);
} else {
rewind(grf);
fclose(grf);
grf = NULL;
}
- return(gr);
+ return gr;
}