more strlcpy() related changes

This commit is contained in:
Nikos Mavrogiannopoulos
2014-12-14 20:12:08 +01:00
parent 9fc8568107
commit 3bbee0b069
3 changed files with 17 additions and 18 deletions

View File

@@ -179,7 +179,7 @@ struct pam_ctx_st * pctx;
if (pctx->cr == NULL)
goto fail2;
snprintf(pctx->username, sizeof(pctx->username), "%s", user);
strlcpy(pctx->username, user, sizeof(pctx->username));
if (ip != NULL)
pam_set_item(pctx->ph, PAM_RHOST, ip);
@@ -219,9 +219,9 @@ int size;
if (msg != NULL) {
if (pctx->msg.length == 0)
if (pctx->changing)
snprintf(msg, msg_size, "Please enter the new password.");
strlcpy(msg, "Please enter the new password.", msg_size);
else
snprintf(msg, msg_size, "Please enter your password.");
strlcpy(msg, "Please enter your password.", msg_size);
else {
size = MIN(msg_size-1, pctx->msg.length);
memcpy(msg, pctx->msg.data, size);
@@ -291,7 +291,7 @@ unsigned found;
for (i=0;i<ngroups;i++) {
grp = getgrgid(groups[i]);
if (grp != NULL && strcmp(suggested, grp->gr_name) == 0) {
snprintf(groupname, groupname_size, "%s", grp->gr_name);
strlcpy(groupname, grp->gr_name, groupname_size);
found = 1;
break;
}
@@ -306,7 +306,7 @@ unsigned found;
} else {
struct group* grp = getgrgid(pwd->pw_gid);
if (grp != NULL)
snprintf(groupname, groupname_size, "%s", grp->gr_name);
strlcpy(groupname, grp->gr_name, groupname_size);
}
}
@@ -328,7 +328,7 @@ int pret;
}
if (user != NULL) {
snprintf(username, username_size, "%s", user);
strlcpy(username, user, username_size);
return 0;
}

View File

@@ -145,8 +145,7 @@ static int read_auth_pass(struct plain_ctx_st *pctx)
p = strtok_r(NULL, ":", &sp);
if (p != NULL) {
snprintf(pctx->cpass,
sizeof(pctx->cpass), "%s", p);
strlcpy(pctx->cpass, p, sizeof(pctx->cpass));
ret = 0;
goto exit;
}
@@ -172,7 +171,7 @@ static int plain_auth_init(void **ctx, void *pool, const char *username, const c
if (pctx == NULL)
return ERR_AUTH_FAIL;
snprintf(pctx->username, sizeof(pctx->username), "%s", username);
strlcpy(pctx->username, username, sizeof(pctx->username));
pctx->passwd = additional;
pctx->pass_msg = pass_msg_first;
@@ -197,7 +196,7 @@ static int plain_auth_group(void *ctx, const char *suggested, char *groupname, i
if (suggested != NULL) {
for (i=0;i<pctx->groupnames_size;i++) {
if (strcmp(suggested, pctx->groupnames[i]) == 0) {
snprintf(groupname, groupname_size, "%s", pctx->groupnames[i]);
strlcpy(groupname, pctx->groupnames[i], groupname_size);
found = 1;
break;
}
@@ -212,7 +211,7 @@ static int plain_auth_group(void *ctx, const char *suggested, char *groupname, i
}
if (pctx->groupnames_size > 0 && groupname[0] == 0) {
snprintf(groupname, groupname_size, "%s", pctx->groupnames[0]);
strlcpy(groupname, pctx->groupnames[0], groupname_size);
}
return 0;
}
@@ -249,7 +248,7 @@ static int plain_auth_msg(void *ctx, char *msg, size_t msg_size)
{
struct plain_ctx_st *pctx = ctx;
snprintf(msg, msg_size, "%s", pctx->pass_msg);
strlcpy(msg, pctx->pass_msg, msg_size);
return 0;
}

View File

@@ -71,8 +71,8 @@ static int radius_auth_init(void **ctx, void *pool, const char *username, const
if (pctx == NULL)
return ERR_AUTH_FAIL;
snprintf(pctx->username, sizeof(pctx->username), "%s", username);
snprintf(pctx->remote_ip, sizeof(pctx->remote_ip), "%s", ip);
strlcpy(pctx->username, username, sizeof(pctx->username));
strlcpy(pctx->remote_ip, ip, sizeof(pctx->remote_ip));
pctx->config = additional;
pctx->pass_msg = pass_msg_first;
@@ -99,7 +99,7 @@ static int radius_auth_group(void *ctx, const char *suggested, char *groupname,
if (suggested != NULL) {
if (strcmp(suggested, pctx->groupname) == 0) {
snprintf(groupname, groupname_size, "%s", pctx->groupname);
strlcpy(groupname, pctx->groupname, groupname_size);
return 0;
}
@@ -110,7 +110,7 @@ static int radius_auth_group(void *ctx, const char *suggested, char *groupname,
}
if (pctx->groupname[0] != 0 && groupname[0] == 0) {
snprintf(groupname, groupname_size, "%s", pctx->groupname);
strlcpy(groupname, pctx->groupname, groupname_size);
}
return 0;
}
@@ -176,7 +176,7 @@ static int radius_auth_pass(void *ctx, const char *pass, unsigned pass_len)
goto fail;
} else if (vp->attribute == RAD_GROUP_NAME && vp->type == PW_TYPE_STRING) {
/* Group-Name */
snprintf(pctx->groupname, sizeof(pctx->groupname), "%s", vp->strvalue);
strlcpy(pctx->groupname, vp->strvalue, sizeof(pctx->groupname));
} else if (vp->attribute == PW_FRAMED_IPV6_ADDRESS && vp->type == PW_TYPE_IPV6ADDR) {
/* Framed-IPv6-Address */
inet_ntop(AF_INET6, vp->strvalue, pctx->ipv6, sizeof(pctx->ipv6));
@@ -241,7 +241,7 @@ static int radius_auth_msg(void *ctx, char *msg, size_t msg_size)
{
struct radius_ctx_st *pctx = ctx;
snprintf(msg, msg_size, "%s", pctx->pass_msg);
strlcpy(msg, pctx->pass_msg, msg_size);
return 0;
}