summaryrefslogtreecommitdiffstats
path: root/usr.sbin/rpc.yppasswdd/yppasswdd_server.c
diff options
context:
space:
mode:
authordes <des@FreeBSD.org>2002-05-08 15:42:37 +0000
committerdes <des@FreeBSD.org>2002-05-08 15:42:37 +0000
commit3ad511fc27fa6689b6c4002569c77387593df263 (patch)
tree4f377e5fb5fd80a085429535107277db4d769673 /usr.sbin/rpc.yppasswdd/yppasswdd_server.c
parentb1c4fde84af2a34481392012f99682efde811482 (diff)
downloadFreeBSD-src-3ad511fc27fa6689b6c4002569c77387593df263.zip
FreeBSD-src-3ad511fc27fa6689b6c4002569c77387593df263.tar.gz
Use libutil instead of pw_{copy,util}.c. Clean up a little. Warnsify.
Sponsored by: DARPA, NAI Labs
Diffstat (limited to 'usr.sbin/rpc.yppasswdd/yppasswdd_server.c')
-rw-r--r--usr.sbin/rpc.yppasswdd/yppasswdd_server.c239
1 files changed, 104 insertions, 135 deletions
diff --git a/usr.sbin/rpc.yppasswdd/yppasswdd_server.c b/usr.sbin/rpc.yppasswdd/yppasswdd_server.c
index 2ba3bac..9841397 100644
--- a/usr.sbin/rpc.yppasswdd/yppasswdd_server.c
+++ b/usr.sbin/rpc.yppasswdd/yppasswdd_server.c
@@ -35,78 +35,51 @@ static const char rcsid[] =
"$FreeBSD$";
#endif /* not lint */
-#include <stdio.h>
-#include <string.h>
-#include <ctype.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <dirent.h>
-#include <sys/stat.h>
+#include <sys/param.h>
+#include <sys/fcntl.h>
#include <sys/socket.h>
-#include <netinet/in.h>
+#include <sys/stat.h>
+#include <sys/wait.h>
+
#include <arpa/inet.h>
-#include <limits.h>
+#include <netinet/in.h>
+
+#include <ctype.h>
#include <db.h>
-#include <pwd.h>
+#include <dirent.h>
#include <errno.h>
+#include <limits.h>
+#include <pwd.h>
#include <signal.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+
+#include <libgen.h>
+#include <libutil.h>
+
#include <rpc/rpc.h>
#include <rpcsvc/yp.h>
-#include <sys/types.h>
-#include <sys/wait.h>
-#include <sys/param.h>
-#include <sys/fcntl.h>
-struct dom_binding {};
+struct dom_binding;
#include <rpcsvc/ypclnt.h>
#include "yppasswdd_extern.h"
#include "yppasswd.h"
#include "yppasswd_private.h"
-
-char *tempname;
-
-void
-reaper(int sig)
-{
- extern pid_t pid;
- extern int pstat;
- int st;
- int saved_errno;
-
- saved_errno = errno;
-
- if (sig > 0) {
- if (sig == SIGCHLD)
- while (wait3(&st, WNOHANG, NULL) > 0) ;
- } else {
- pid = waitpid(pid, &pstat, 0);
- }
-
- errno = saved_errno;
- return;
-}
-
-void
-install_reaper(int on)
-{
- if (on) {
- signal(SIGCHLD, reaper);
- } else {
- signal(SIGCHLD, SIG_DFL);
- }
- return;
-}
+#include "ypxfr_extern.h"
+#include "yp_extern.h"
static struct passwd yp_password;
static void
copy_yp_pass(char *p, int x, int m)
{
- register char *t, *s = p;
+ char *t, *s = p;
static char *buf;
yp_password.pw_fields = 0;
- buf = (char *)realloc(buf, m + 10);
+ buf = realloc(buf, m + 10);
bzero(buf, m + 10);
/* Turn all colons into NULLs */
@@ -150,7 +123,7 @@ copy_yp_pass(char *p, int x, int m)
static int
validchars(char *arg)
{
- int i;
+ size_t i;
for (i = 0; i < strlen(arg); i++) {
if (iscntrl(arg[i])) {
@@ -171,7 +144,7 @@ validchars(char *arg)
}
static int
-validate_master(struct passwd *opw, struct x_master_passwd *npw)
+validate_master(struct passwd *opw __unused, struct x_master_passwd *npw)
{
if (npw->pw_name[0] == '+' || npw->pw_name[0] == '-') {
@@ -205,7 +178,7 @@ validate(struct passwd *opw, struct x_passwd *npw)
return(1);
}
- if (npw->pw_uid != opw->pw_uid) {
+ if ((uid_t)npw->pw_uid != opw->pw_uid) {
yp_error("UID mismatch: client says user %s has UID %d",
npw->pw_name, npw->pw_uid);
yp_error("database says user %s has UID %d", opw->pw_name,
@@ -213,7 +186,7 @@ validate(struct passwd *opw, struct x_passwd *npw)
return(1);
}
- if (npw->pw_gid != opw->pw_gid) {
+ if ((gid_t)npw->pw_gid != opw->pw_gid) {
yp_error("GID mismatch: client says user %s has GID %d",
npw->pw_name, npw->pw_gid);
yp_error("database says user %s has GID %d", opw->pw_name,
@@ -276,7 +249,7 @@ find_domain(struct x_passwd *pw)
}
while ((dirp = readdir(dird)) != NULL) {
- snprintf(yp_mapdir, sizeof(yp_mapdir), "%s/%s",
+ snprintf(yp_mapdir, sizeof yp_mapdir, "%s/%s",
yp_dir, dirp->d_name);
if (stat(yp_mapdir, &statbuf) < 0) {
yp_error("stat(%s) failed: %s", yp_mapdir,
@@ -293,10 +266,10 @@ find_domain(struct x_passwd *pw)
&key, &data, 0) != YP_TRUE) {
continue;
}
- *(char *)(data.data + data.size) = '\0';
+ *((char *)data.data + data.size) = '\0';
copy_yp_pass(data.data, 1, data.size);
- if (yp_password.pw_uid == pw->pw_uid &&
- yp_password.pw_gid == pw->pw_gid) {
+ if (yp_password.pw_uid == (uid_t)pw->pw_uid &&
+ yp_password.pw_gid == (gid_t)pw->pw_gid) {
hit++;
snprintf(domain, YPMAXDOMAIN, "%s", tmp);
}
@@ -311,6 +284,20 @@ find_domain(struct x_passwd *pw)
return((char *)&domain);
}
+static const char *maps[] = {
+ "master.passwd.byname",
+ "master.passwd.byuid",
+ "passwd.byname",
+ "passwd.byuid"
+};
+
+static const char *formats[] = {
+ "%s:%s:%d:%d:%s:%ld:%ld:%s:%s:%s",
+ "%s:%s:%d:%d:%s:%ld:%ld:%s:%s:%s",
+ "%s:%s:%d:%d:%s:%s:%s",
+ "%s:%s:%d:%d:%s:%s:%s"
+};
+
static int
update_inplace(struct passwd *pw, char *domain)
{
@@ -320,23 +307,19 @@ update_inplace(struct passwd *pw, char *domain)
char pwbuf[YPMAXRECORD];
char keybuf[20];
int i;
- char *maps[] = { "master.passwd.byname", "master.passwd.byuid",
- "passwd.byname", "passwd.byuid" };
-
- char *formats[] = { "%s:%s:%d:%d:%s:%ld:%ld:%s:%s:%s",
- "%s:%s:%d:%d:%s:%ld:%ld:%s:%s:%s",
- "%s:%s:%d:%d:%s:%s:%s", "%s:%s:%d:%d:%s:%s:%s" };
char *ptr = NULL;
- char *yp_last = "YP_LAST_MODIFIED";
+ static char yp_last[] = "YP_LAST_MODIFIED";
char yplastbuf[YPMAXRECORD];
- snprintf(yplastbuf, sizeof(yplastbuf), "%lu", time(NULL));
+ snprintf(yplastbuf, sizeof yplastbuf, "%llu",
+ (unsigned long long)time(NULL));
for (i = 0; i < 4; i++) {
if (i % 2) {
- snprintf(keybuf, sizeof(keybuf), "%ld", pw->pw_uid);
- key.data = (char *)&keybuf;
+ snprintf(keybuf, sizeof keybuf,
+ "%llu", (unsigned long long)pw->pw_uid);
+ key.data = &keybuf;
key.size = strlen(keybuf);
} else {
key.data = pw->pw_name;
@@ -380,7 +363,7 @@ update_inplace(struct passwd *pw, char *domain)
strlen(pw->pw_name))) {
yp_error("warning: found entry for UID %d \
in map %s@%s with wrong name (%.*s)", pw->pw_uid, maps[i], domain,
- ptr - (char *)data.data, data.data);
+ ptr - (char *)data.data, (char *)data.data);
yp_error("there may be more than one user \
with the same UID - continuing");
continue;
@@ -390,7 +373,7 @@ with the same UID - continuing");
* We're really being ultra-paranoid here.
* This is generally a 'can't happen' condition.
*/
- snprintf(pwbuf, sizeof(pwbuf), ":%d:%d:", pw->pw_uid,
+ snprintf(pwbuf, sizeof pwbuf, ":%d:%d:", pw->pw_uid,
pw->pw_gid);
if (!strstr(data.data, pwbuf)) {
yp_error("warning: found entry for user %s \
@@ -402,13 +385,13 @@ with the same name - continuing");
}
if (i < 2) {
- snprintf(pwbuf, sizeof(pwbuf), formats[i],
+ snprintf(pwbuf, sizeof pwbuf, formats[i],
pw->pw_name, pw->pw_passwd, pw->pw_uid,
pw->pw_gid, pw->pw_class, pw->pw_change,
pw->pw_expire, pw->pw_gecos, pw->pw_dir,
pw->pw_shell);
} else {
- snprintf(pwbuf, sizeof(pwbuf), formats[i],
+ snprintf(pwbuf, sizeof pwbuf, formats[i],
pw->pw_name, *(ptr+1) == '*' ? "*" : pw->pw_passwd,
pw->pw_uid, pw->pw_gid, pw->pw_gecos, pw->pw_dir,
pw->pw_shell);
@@ -450,21 +433,6 @@ with the same name - continuing");
return(0);
}
-static char *
-yp_mktmpnam(void)
-{
- static char path[MAXPATHLEN];
- char *p;
-
- sprintf(path,"%s",passfile);
- if ((p = strrchr(path, '/')))
- ++p;
- else
- p = path;
- strcpy(p, "yppwtmp.XXXXXX");
- return(mktemp(path));
-}
-
int *
yppasswdproc_update_1_svc(yppasswd *argp, struct svc_req *rqstp)
{
@@ -495,17 +463,16 @@ yppasswdproc_update_1_svc(yppasswd *argp, struct svc_req *rqstp)
rqhost = svc_getcaller(rqstp->rq_xprt);
gettimeofday(&t_test, NULL);
- if (!bcmp((char *)rqhost, (char *)&clntaddr,
- sizeof(struct sockaddr_in)) &&
+ if (!bcmp(rqhost, &clntaddr, sizeof *rqhost) &&
t_test.tv_sec > t_saved.tv_sec &&
t_test.tv_sec - t_saved.tv_sec < 300) {
- bzero((char *)&clntaddr, sizeof(struct sockaddr_in));
- bzero((char *)&t_saved, sizeof(struct timeval));
+ bzero(&clntaddr, sizeof clntaddr);
+ bzero(&t_saved, sizeof t_saved);
return(NULL);
}
- bcopy((char *)rqhost, (char *)&clntaddr, sizeof(struct sockaddr_in));
+ bcopy(rqhost, &clntaddr, sizeof clntaddr);
gettimeofday(&t_saved, NULL);
if (yp_access(resvport ? "master.passwd.byname" : NULL, rqstp)) {
@@ -548,7 +515,7 @@ yppasswdproc_update_1_svc(yppasswd *argp, struct svc_req *rqstp)
}
/* Nul terminate, please. */
- *(char *)(data.data + data.size) = '\0';
+ *((char *)data.data + data.size) = '\0';
copy_yp_pass(data.data, 1, data.size);
@@ -608,30 +575,31 @@ yppasswdproc_update_1_svc(yppasswd *argp, struct svc_req *rqstp)
/* Step 5: make a new password file with the updated info. */
- if ((pfd = pw_lock()) < 0) {
- return (&result);
+ if (pw_init(dirname(passfile), passfile)) {
+ yp_error("pw_init() failed");
+ return &result;
}
- if ((tfd = pw_tmp()) < 0) {
- return (&result);
+ if ((pfd = pw_lock()) == -1) {
+ pw_fini();
+ yp_error("pw_lock() failed");
+ return &result;
}
-
- if (pw_copy(pfd, tfd, &yp_password)) {
- yp_error("failed to created updated password file -- \
-cleaning up and bailing out");
- unlink(tempname);
- return(&result);
+ if ((tfd = pw_tmp(-1)) == -1) {
+ pw_fini();
+ yp_error("pw_tmp() failed");
+ return &result;
}
-
- passfile_hold = yp_mktmpnam();
- rename(passfile, passfile_hold);
- if (strcmp(passfile, _PATH_MASTERPASSWD)) {
- rename(tempname, passfile);
- } else {
- if (pw_mkdb(argp->newpw.pw_name) < 0) {
- yp_error("pwd_mkdb failed");
- return(&result);
- }
+ if (pw_copy(pfd, tfd, &yp_password, NULL) == -1) {
+ pw_fini();
+ yp_error("pw_copy() failed");
+ return &result;
}
+ if (pw_mkdb(yp_password.pw_name) == -1) {
+ pw_fini();
+ yp_error("pw_mkdb() failed");
+ return &result;
+ }
+ pw_fini();
if (inplace) {
if ((rval = update_inplace(&yp_password, domain))) {
@@ -769,7 +737,7 @@ allow additions to be made to the password database");
} else {
/* Nul terminate, please. */
- *(char *)(data.data + data.size) = '\0';
+ *((char *)data.data + data.size) = '\0';
copy_yp_pass(data.data, 1, data.size);
}
@@ -794,30 +762,31 @@ allow additions to be made to the password database");
passfile = (char *)&passfile_buf;
}
- if ((pfd = pw_lock()) < 0) {
- return (&result);
+ if (pw_init(dirname(passfile), passfile)) {
+ yp_error("pw_init() failed");
+ return &result;
}
- if ((tfd = pw_tmp()) < 0) {
- return (&result);
+ if ((pfd = pw_lock()) == -1) {
+ pw_fini();
+ yp_error("pw_lock() failed");
+ return &result;
}
-
- if (pw_copy(pfd, tfd, (struct passwd *)&argp->newpw)) {
- yp_error("failed to created updated password file -- \
-cleaning up and bailing out");
- unlink(tempname);
- return(&result);
+ if ((tfd = pw_tmp(-1)) == -1) {
+ pw_fini();
+ yp_error("pw_tmp() failed");
+ return &result;
}
-
- passfile_hold = yp_mktmpnam();
- rename(passfile, passfile_hold);
- if (strcmp(passfile, _PATH_MASTERPASSWD)) {
- rename(tempname, passfile);
- } else {
- if (pw_mkdb(argp->newpw.pw_name) < 0) {
- yp_error("pwd_mkdb failed");
- return(&result);
- }
+ if (pw_copy(pfd, tfd, (struct passwd *)&argp->newpw, NULL) == -1) {
+ pw_fini();
+ yp_error("pw_copy() failed");
+ return &result;
+ }
+ if (pw_mkdb(argp->newpw.pw_name) == -1) {
+ pw_fini();
+ yp_error("pw_mkdb() failed");
+ return &result;
}
+ pw_fini();
if (inplace) {
if ((rval = update_inplace((struct passwd *)&argp->newpw,
OpenPOWER on IntegriCloud