]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
let's use the v4 APIs instead of just copying code from v3
authorAlan T. DeKok <aland@freeradius.org>
Tue, 8 Jun 2021 13:49:35 +0000 (09:49 -0400)
committerAlan T. DeKok <aland@freeradius.org>
Tue, 8 Jun 2021 13:49:35 +0000 (09:49 -0400)
src/modules/rlm_mschap/rlm_mschap.c

index 26827a2757232a92eba56ef2ede07582ec551c52..db4ddc6e62f19de49f7acef1f7cc0eea45b6395f 100644 (file)
@@ -496,14 +496,13 @@ static xlat_action_t mschap_xlat(TALLOC_CTX *ctx, fr_dcursor_t *out, request_t *
         *
         *      This is the full domain name, not just the name after host/
         */
-       } else if (strncasecmp(fmt, "Domain-Name", 11) == 0) {
+       } else if (strncasecmp(arg->vb_strvalue, "Domain-Name", 11) == 0) {
                char *p;
 
-               user_name = fr_pair_find_by_num(request->packet->vps, PW_USER_NAME, 0, TAG_ANY);
-               if (!user_name) {
-                       REDEBUG("No User-Name was found in the request");
-                       return -1;
-               }
+               vb = fr_value_box_alloc_null(ctx);
+
+               user_name = mschap_identity_find(request);
+               if (!user_name) return XLAT_ACTION_FAIL;
 
                /*
                 *      First check to see if this is a host/ style User-Name
@@ -519,27 +518,30 @@ static xlat_action_t mschap_xlat(TALLOC_CTX *ctx, fr_dcursor_t *out, request_t *
                        p = strchr(user_name->vp_strvalue, '.');
                        if (!p) {
                                RDEBUG2("setting NT-Domain to same as machine name");
-                               strlcpy(out, user_name->vp_strvalue + 5, outlen);
+                               fr_value_box_strdup(ctx, vb, NULL, user_name->vp_strvalue + 5, user_name->vp_tainted);
                        } else {
                                p++;    /* skip the period */
-                               strlcpy(out, p, outlen);
+
+                               fr_value_box_strdup(ctx, vb, NULL, p, user_name->vp_tainted);
                        }
                } else {
                        p = strchr(user_name->vp_strvalue, '\\');
                        if (!p) {
                                REDEBUG("No NT-Domain was found in the User-Name");
-                               return -1;
+                               talloc_free(vb);
+                               return XLAT_ACTION_FAIL;
                        }
 
                        /*
                         *      Hack.  This is simpler than the alternatives.
                         */
                        *p = '\0';
-                       strlcpy(out, user_name->vp_strvalue, outlen);
+                       fr_value_box_strdup(ctx, vb, NULL, user_name->vp_strvalue, user_name->vp_tainted);
                        *p = '\\';
                }
 
-               return strlen(out);
+               fr_dcursor_append(out, vb);
+               return XLAT_ACTION_DONE;
 
        /*
         *      Pull the NT-Domain out of the User-Name, if it exists.