VALUE_PAIR *paircopy(TALLOC_CTX *ctx, VALUE_PAIR *vp);
VALUE_PAIR *paircopy2(TALLOC_CTX *ctx, VALUE_PAIR *vp, unsigned int attr, unsigned int vendor, int8_t tag);
void pairmemcpy(VALUE_PAIR *vp, uint8_t const * src, size_t len);
+void pairstrcpy(VALUE_PAIR *vp, char const * src);
void pairmove(TALLOC_CTX *ctx, VALUE_PAIR **to, VALUE_PAIR **from);
void pairfilter(TALLOC_CTX *ctx, VALUE_PAIR **to, VALUE_PAIR **from,
unsigned int attr, unsigned int vendor, int8_t tag);
VERIFY(vp);
/*
- * Even for integers, dates and ip addresses we
- * keep the original string in vp->vp_strvalue.
+ * Even for integers, dates and ip addresses we
+ * keep the original string in vp->vp_strvalue.
+ *
+ * @todo: too many things depend on this!
*/
if (vp->da->type != PW_TYPE_TLV) {
- strlcpy(vp->vp_strvalue, value, sizeof(vp->vp_strvalue));
- vp->length = strlen(vp->vp_strvalue);
+ pairstrcpy(vp, value);
}
switch(vp->da->type) {
memcpy(vp->vp_octets, src, size);
vp->length = size;
}
+
+
+/** Copy data into an "string" data type.
+ *
+ * @param[in,out] vp to update
+ * @param[in] src data to copy
+ * @param[in] size of the data
+ */
+void pairstrcpy(VALUE_PAIR *vp, char const *src)
+{
+ size_t size = strlen(src);
+
+ if (size >= sizeof(vp->vp_strvalue)) size = sizeof(vp->vp_strvalue) - 1;
+
+ memcpy(vp->vp_strvalue, src, size);
+ vp->vp_strvalue[size] = '\0';
+ vp->length = size;
+}
VALUE_PAIR *vp;
if ((vp = pairfind(radclient->request->vps, PW_USER_PASSWORD, 0, TAG_ANY)) != NULL) {
- strlcpy(vp->vp_strvalue, radclient->password,
- sizeof(vp->vp_strvalue));
- vp->length = strlen(vp->vp_strvalue);
+ pairstrcpy(vp, radclient->password);
} else if ((vp = pairfind(radclient->request->vps, PW_CHAP_PASSWORD, 0, TAG_ANY)) != NULL) {
int already_hex = 0;
* Allow the user to specify ASCII or hex CHAP-Password
*/
if (!already_hex) {
- strlcpy(vp->vp_strvalue, radclient->password,
- sizeof(vp->vp_strvalue));
- vp->length = strlen(vp->vp_strvalue);
+ pairstrcpy(vp, radclient->password);
rad_chap_encode(radclient->request,
vp->vp_octets,
pairfree(&(stopreq->packet->vps)); \
return 0; \
} \
- strlcpy((char *)vp->vp_strvalue, v, sizeof vp->vp_strvalue); \
- vp->length = strlen(v); \
+ pairstrcpy(vp, v); \
pairadd(&(stopreq->packet->vps), vp); \
} while(0)
if (*password != '\0') {
if ((vp = pairfind(rep->vps, PW_CLEARTEXT_PASSWORD, 0, TAG_ANY)) != NULL) {
- strlcpy((char *)vp->vp_strvalue, password, sizeof(vp->vp_strvalue));
- vp->length = strlen(password);
+ pairstrcpy(vp, password);
} else if ((vp = pairfind(rep->vps, PW_USER_PASSWORD, 0, TAG_ANY)) != NULL) {
- strlcpy((char *)vp->vp_strvalue, password, sizeof(vp->vp_strvalue));
- vp->length = strlen(password);
+ pairstrcpy(vp, password);
} else if ((vp = pairfind(rep->vps, PW_CHAP_PASSWORD, 0, TAG_ANY)) != NULL) {
- strlcpy((char *)vp->vp_strvalue, password, sizeof(vp->vp_strvalue));
- vp->length = strlen(password);
+ pairstrcpy(vp, password);
rad_chap_encode(rep, vp->vp_octets, rep->id, vp);
vp->length = 17;
*/
vp = pairfind(request->reply->vps, PW_USER_NAME, 0, TAG_ANY);
if (!vp) {
- vp = pairmake_reply("User-Name", "",
- T_OP_EQ);
- strlcpy(vp->vp_strvalue, request->username->vp_strvalue,
- sizeof(vp->vp_strvalue));
- vp->length = request->username->length;
+ vp = paircopyvp(request->reply, request->username);
+ pairadd(&request->reply->vps, vp);
}
/*
req->username = vp;
}
- strlcpy((char *)vp->vp_strvalue, rest, sizeof(vp->vp_strvalue));
- vp->length = strlen(vp->vp_strvalue);
+ pairstrcpy(vp, rest);
return ret;
}
* Add Cleartext-Password attribute to the request
*/
vp = radius_paircreate(request, &request->config_items, PW_CLEARTEXT_PASSWORD, 0);
- strlcpy(vp->vp_strvalue, password, sizeof(vp->vp_strvalue));
+ pairstrcpy(vp, password);
vp->length = pass_size;
RDEBUG2("Added eDirectory password in check items as %s = %s", vp->da->name, vp->vp_strvalue);
if ((ptr = strchr(namepair->vp_strvalue, '\\')) != NULL) {
strlcpy(newname, ptr + 1, sizeof(newname));
/* Same size */
- strcpy(namepair->vp_strvalue, newname);
- namepair->length = strlen(newname);
+ pairstrcpy(namepair, newname);
}
}
vp = pairfind(request_pairs, PW_HUNTGROUP_NAME, 0, TAG_ANY);
if (!vp) {
vp = radius_paircreate(request, &request->packet->vps, PW_HUNTGROUP_NAME, 0);
- strlcpy(vp->vp_strvalue, i->name, sizeof(vp->vp_strvalue));
- vp->length = strlen(vp->vp_strvalue);
+ pairstrcpy(vp, i->name);
}
r = RLM_MODULE_OK;
}
RDEBUG2("Setting Stripped-User-Name = \"%s\"", username);
}
- strlcpy(vp->vp_strvalue, username, sizeof(vp->vp_strvalue));
- vp->length = strlen((char *)vp->vp_strvalue);
+ pairstrcpy(vp, username);
request->username = vp;
}
vp = pairalloc(request->packet, inst->sql_user);
vp->op = T_OP_SET;
- strlcpy(vp->vp_strvalue, expanded, sizeof(vp->vp_strvalue));
- talloc_free(expanded);
-
- vp->length = strlen(vp->vp_strvalue);
+ pairstrcpy(vp, expanded); /* FIXME: pairsteal */
pairadd(&request->packet->vps, vp);
+ talloc_free(expanded);
+
RDEBUG2("SQL-User-Name updated");
return 0;
* needs to verify it's associated with the user.
*
* It's left up to the user if they want to decode it or not.
+ *
+ * @todo: is this even right? Is there anything in passcode other than
+ * the public ID? Why pairmake(...NULL) instead of pairmake(..., passcode) ?
*/
if (inst->id_len) {
vp = pairmake(request, &request->packet->vps, "Yubikey-Public-ID", NULL, T_OP_SET);
return RLM_MODULE_FAIL;
}
- strlcpy(vp->vp_strvalue, passcode, inst->id_len + 1);
-
- vp->length = inst->id_len;
+ pairstrcpy(vp, passcode);
}
return RLM_MODULE_OK;