aboutsummaryrefslogtreecommitdiff
path: root/usr.sbin
diff options
context:
space:
mode:
authorKonstantin Belousov <kib@FreeBSD.org>2019-09-02 10:20:57 +0000
committerKonstantin Belousov <kib@FreeBSD.org>2019-09-02 10:20:57 +0000
commitfe890b204c8ab91b56af2bd35e17f4b91182d18f (patch)
tree1d3971db51a4ef81ac6ddfe8dc48ac3ffb7fdd48 /usr.sbin
parent6e8750cd9a1f512f4d36ad7a8f894dff02251a29 (diff)
downloadsrc-fe890b204c8ab91b56af2bd35e17f4b91182d18f.tar.gz
src-fe890b204c8ab91b56af2bd35e17f4b91182d18f.zip
MFC r350957:
Increase YPMAXRECORD to 16M to be compatible with Linux. Sponsored by: Mellanox Technologies
Notes
Notes: svn path=/stable/11/; revision=351694
Diffstat (limited to 'usr.sbin')
-rw-r--r--usr.sbin/rpc.yppasswdd/yppasswdd_server.c39
-rw-r--r--usr.sbin/rpc.ypupdated/yp_dbupdate.c2
-rw-r--r--usr.sbin/ypldap/yp.c58
-rw-r--r--usr.sbin/yppush/yppush_main.c22
-rw-r--r--usr.sbin/ypserv/yp_server.c3
5 files changed, 86 insertions, 38 deletions
diff --git a/usr.sbin/rpc.yppasswdd/yppasswdd_server.c b/usr.sbin/rpc.yppasswdd/yppasswdd_server.c
index ae5ca5964053..b18bb3cd87a1 100644
--- a/usr.sbin/rpc.yppasswdd/yppasswdd_server.c
+++ b/usr.sbin/rpc.yppasswdd/yppasswdd_server.c
@@ -321,15 +321,16 @@ update_inplace(struct passwd *pw, char *domain)
DB *dbp = NULL;
DBT key = { NULL, 0 };
DBT data = { NULL, 0 };
- char pwbuf[YPMAXRECORD];
+ char *pwbuf;
char keybuf[20];
int i;
char *ptr = NULL;
static char yp_last[] = "YP_LAST_MODIFIED";
- char yplastbuf[YPMAXRECORD];
+ char yplastbuf[64];
snprintf(yplastbuf, sizeof yplastbuf, "%llu",
(unsigned long long)time(NULL));
+ pwbuf = NULL;
for (i = 0; i < 4; i++) {
@@ -362,12 +363,12 @@ update_inplace(struct passwd *pw, char *domain)
if (yp_get_record(domain,maps[i],&key,&data,1) != YP_TRUE) {
yp_error("couldn't read %s/%s: %s", domain,
maps[i], strerror(errno));
- return(1);
+ goto ret1;
}
if ((ptr = strchr(data.data, ':')) == NULL) {
yp_error("no colon in passwd record?!");
- return(1);
+ goto ret1;
}
/*
@@ -391,8 +392,12 @@ 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,
- pw->pw_gid);
+ free(pwbuf);
+ asprintf(&pwbuf, ":%d:%d:", pw->pw_uid, pw->pw_gid);
+ if (pwbuf == NULL) {
+ yp_error("no memory");
+ goto ret1;
+ }
if (!strstr(data.data, pwbuf)) {
yp_error("warning: found entry for user %s \
in map %s@%s with wrong UID", pw->pw_name, maps[i], domain);
@@ -403,24 +408,30 @@ with the same name - continuing");
}
if (i < 2) {
- snprintf(pwbuf, sizeof pwbuf, formats[i],
+ free(pwbuf);
+ asprintf(&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],
+ free(pwbuf);
+ asprintf(&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);
}
+ if (pwbuf == NULL) {
+ yp_error("no memory");
+ goto ret1;
+ }
#define FLAGS O_RDWR|O_CREAT
if ((dbp = yp_open_db_rw(domain, maps[i], FLAGS)) == NULL) {
yp_error("couldn't open %s/%s r/w: %s",domain,
maps[i],strerror(errno));
- return(1);
+ goto ret1;
}
data.data = pwbuf;
@@ -430,7 +441,7 @@ with the same name - continuing");
yp_error("failed to update record in %s/%s", domain,
maps[i]);
(void)(dbp->close)(dbp);
- return(1);
+ goto ret1;
}
key.data = yp_last;
@@ -442,13 +453,17 @@ with the same name - continuing");
yp_error("failed to update timestamp in %s/%s", domain,
maps[i]);
(void)(dbp->close)(dbp);
- return(1);
+ goto ret1;
}
(void)(dbp->close)(dbp);
}
- return(0);
+ free(pwbuf);
+ return (0);
+ret1:
+ free(pwbuf);
+ return (1);
}
int *
diff --git a/usr.sbin/rpc.ypupdated/yp_dbupdate.c b/usr.sbin/rpc.ypupdated/yp_dbupdate.c
index 3481a6b2b3c4..15c06c297bf4 100644
--- a/usr.sbin/rpc.ypupdated/yp_dbupdate.c
+++ b/usr.sbin/rpc.ypupdated/yp_dbupdate.c
@@ -79,7 +79,7 @@ ypmap_update(char *netname, char *map, unsigned int op, unsigned int keylen,
DB *dbp;
DBT key = { NULL, 0 }, data = { NULL, 0 };
char *yp_last = "YP_LAST_MODIFIED";
- char yplastbuf[YPMAXRECORD];
+ char yplastbuf[32];
char *domptr;
int rval = 0;
diff --git a/usr.sbin/ypldap/yp.c b/usr.sbin/ypldap/yp.c
index fc7e03b2c0a1..0cbadc371c5e 100644
--- a/usr.sbin/ypldap/yp.c
+++ b/usr.sbin/ypldap/yp.c
@@ -323,7 +323,7 @@ ypproc_match_2_svc(ypreq_key *arg, struct svc_req *req)
static struct ypresp_val res;
const char *estr;
char *bp, *cp;
- char key[YPMAXRECORD+1];
+ char *key;
log_debug("matching '%.*s' in map %s", arg->key.keydat_len,
arg->key.keydat_val, arg->map);
@@ -342,7 +342,9 @@ ypproc_match_2_svc(ypreq_key *arg, struct svc_req *req)
log_debug("argument too long");
return (NULL);
}
- memset(key, 0, sizeof(key));
+ key = calloc(arg->key.keydat_len + 1, 1);
+ if (key == NULL)
+ return (NULL);
(void)strncpy(key, arg->key.keydat_val, arg->key.keydat_len);
if (strcmp(arg->map, "passwd.byname") == 0 ||
@@ -351,23 +353,23 @@ ypproc_match_2_svc(ypreq_key *arg, struct svc_req *req)
if ((ue = RB_FIND(user_name_tree, env->sc_user_names,
&ukey)) == NULL) {
res.stat = YP_NOKEY;
- return (&res);
+ goto out;
}
yp_make_val(&res, ue->ue_line, 1);
- return (&res);
+ goto out;
} else if (strcmp(arg->map, "passwd.byuid") == 0 ||
strcmp(arg->map, "master.passwd.byuid") == 0) {
ukey.ue_uid = strtonum(key, 0, UID_MAX, &estr);
if (estr) {
res.stat = YP_BADARGS;
- return (&res);
+ goto out;
}
if ((ue = RB_FIND(user_uid_tree, &env->sc_user_uids,
&ukey)) == NULL) {
res.stat = YP_NOKEY;
- return (&res);
+ goto out;
}
yp_make_val(&res, ue->ue_line, 1);
@@ -376,12 +378,12 @@ ypproc_match_2_svc(ypreq_key *arg, struct svc_req *req)
gkey.ge_gid = strtonum(key, 0, GID_MAX, &estr);
if (estr) {
res.stat = YP_BADARGS;
- return (&res);
+ goto out;
}
if ((ge = RB_FIND(group_gid_tree, &env->sc_group_gids,
&gkey)) == NULL) {
res.stat = YP_NOKEY;
- return (&res);
+ goto out;
}
yp_make_val(&res, ge->ge_line, 1);
@@ -391,7 +393,7 @@ ypproc_match_2_svc(ypreq_key *arg, struct svc_req *req)
if ((ge = RB_FIND(group_name_tree, env->sc_group_names,
&gkey)) == NULL) {
res.stat = YP_NOKEY;
- return (&res);
+ goto out;
}
yp_make_val(&res, ge->ge_line, 1);
@@ -401,46 +403,49 @@ ypproc_match_2_svc(ypreq_key *arg, struct svc_req *req)
if (strncmp(bp, "unix.", strlen("unix.")) != 0) {
res.stat = YP_BADARGS;
- return (&res);
+ goto out;
}
bp += strlen("unix.");
if (*bp == '\0') {
res.stat = YP_BADARGS;
- return (&res);
+ goto out;
}
if (!(cp = strsep(&bp, "@"))) {
res.stat = YP_BADARGS;
- return (&res);
+ goto out;
}
if (strcmp(bp, arg->domain) != 0) {
res.stat = YP_BADARGS;
- return (&res);
+ goto out;
}
ukey.ue_uid = strtonum(cp, 0, UID_MAX, &estr);
if (estr) {
res.stat = YP_BADARGS;
- return (&res);
+ goto out;
}
if ((ue = RB_FIND(user_uid_tree, &env->sc_user_uids,
&ukey)) == NULL) {
res.stat = YP_NOKEY;
- return (&res);
+ goto out;
}
yp_make_val(&res, ue->ue_netid_line, 0);
- return (&res);
+ goto out;
} else {
log_debug("unknown map %s", arg->map);
res.stat = YP_NOMAP;
- return (&res);
+ goto out;
}
+out:
+ free(key);
+ return (&res);
}
ypresp_key_val *
@@ -479,14 +484,19 @@ ypproc_next_2_svc(ypreq_key *arg, struct svc_req *req)
struct groupent *ge;
char *line;
static struct ypresp_key_val res;
- char key[YPMAXRECORD+1];
+ char *key;
if (yp_valid_domain(arg->domain, (struct ypresp_val *)&res) == -1)
return (&res);
+ key = NULL;
if (strcmp(arg->map, "passwd.byname") == 0 ||
strcmp(arg->map, "master.passwd.byname") == 0) {
- memset(key, 0, sizeof(key));
+ key = calloc(arg->key.keydat_len + 1, 1);
+ if (key == NULL) {
+ res.stat = YP_YPERR;
+ return (&res);
+ }
(void)strncpy(key, arg->key.keydat_val,
arg->key.keydat_len);
ukey.ue_line = key;
@@ -506,6 +516,7 @@ ypproc_next_2_svc(ypreq_key *arg, struct svc_req *req)
RB_REMOVE(user_name_tree, env->sc_user_names,
&ukey);
res.stat = YP_NOKEY;
+ free(key);
return (&res);
}
RB_REMOVE(user_name_tree, env->sc_user_names, &ukey);
@@ -513,11 +524,16 @@ ypproc_next_2_svc(ypreq_key *arg, struct svc_req *req)
line = ue->ue_line + (strlen(ue->ue_line) + 1);
line = line + (strlen(line) + 1);
yp_make_keyval(&res, line, line);
+ free(key);
return (&res);
} else if (strcmp(arg->map, "group.byname") == 0) {
- memset(key, 0, sizeof(key));
+ key = calloc(arg->key.keydat_len + 1, 1);
+ if (key == NULL) {
+ res.stat = YP_YPERR;
+ return (&res);
+ }
(void)strncpy(key, arg->key.keydat_val,
arg->key.keydat_len);
@@ -533,6 +549,7 @@ ypproc_next_2_svc(ypreq_key *arg, struct svc_req *req)
RB_REMOVE(group_name_tree, env->sc_group_names,
&gkey);
res.stat = YP_NOKEY;
+ free(key);
return (&res);
}
RB_REMOVE(group_name_tree, env->sc_group_names, &gkey);
@@ -541,6 +558,7 @@ ypproc_next_2_svc(ypreq_key *arg, struct svc_req *req)
line = ge->ge_line + (strlen(ge->ge_line) + 1);
line = line + (strlen(line) + 1);
yp_make_keyval(&res, line, line);
+ free(key);
return (&res);
} else {
log_debug("unknown map %s", arg->map);
diff --git a/usr.sbin/yppush/yppush_main.c b/usr.sbin/yppush/yppush_main.c
index 5a712e5a41b0..6196810de272 100644
--- a/usr.sbin/yppush/yppush_main.c
+++ b/usr.sbin/yppush/yppush_main.c
@@ -436,14 +436,25 @@ static int
yppush_foreach(int status, char *key, int keylen, char *val, int vallen,
char *data)
{
- char server[YPMAXRECORD + 2];
+ char *server;
if (status != YP_TRUE)
return (status);
- snprintf(server, sizeof(server), "%.*s", vallen, val);
- if (skip_master && strcasecmp(server, yppush_master) == 0)
+ asprintf(&server, "%.*s", vallen, val);
+
+ /*
+ * Do not stop the iteration on the allocation failure. We
+ * cannot usefully react on low memory condition anyway, and
+ * the failure is more likely due to insane val.
+ */
+ if (server == NULL)
+ return (0);
+
+ if (skip_master && strcasecmp(server, yppush_master) == 0) {
+ free(server);
return (0);
+ }
/*
* Restrict the number of concurrent jobs: if yppush_jobs number
@@ -454,12 +465,15 @@ yppush_foreach(int status, char *key, int keylen, char *val, int vallen,
;
/* Cleared for takeoff: set everything in motion. */
- if (yp_push(server, yppush_mapname, yppush_transid))
+ if (yp_push(server, yppush_mapname, yppush_transid)) {
+ free(server);
return(yp_errno);
+ }
/* Bump the job counter and transaction ID. */
yppush_running_jobs++;
yppush_transid++;
+ free(server);
return (0);
}
diff --git a/usr.sbin/ypserv/yp_server.c b/usr.sbin/ypserv/yp_server.c
index 304fd50efe34..6ef96f697ed6 100644
--- a/usr.sbin/ypserv/yp_server.c
+++ b/usr.sbin/ypserv/yp_server.c
@@ -171,8 +171,9 @@ ypproc_match_2_svc(ypreq_key *argp, struct svc_req *rqstp)
if (do_dns && result.stat != YP_TRUE &&
(strstr(argp->map, "hosts") || strstr(argp->map, "ipnodes"))) {
#endif
- char nbuf[YPMAXRECORD];
+ char *nbuf;
+ nbuf = alloca(argp->key.keydat_len + 1);
/* NUL terminate! NUL terminate!! NUL TERMINATE!!! */
bcopy(argp->key.keydat_val, nbuf, argp->key.keydat_len);
nbuf[argp->key.keydat_len] = '\0';