Skip to content

Commit

Permalink
Move all special attribute checks into the loop which iterates over t…
Browse files Browse the repository at this point in the history
…he contents of the request list
  • Loading branch information
arr2036 committed Jun 2, 2014
1 parent 5273f97 commit ce44980
Showing 1 changed file with 47 additions and 61 deletions.
108 changes: 47 additions & 61 deletions src/main/radclient.c
Original file line number Diff line number Diff line change
Expand Up @@ -321,16 +321,6 @@ static int radclient_init(TALLOC_CTX *ctx, rc_file_pair_t *files)
continue;
}

fr_cursor_init(&cursor, &request->filter);
vp = fr_cursor_next_by_num(&cursor, PW_PACKET_TYPE, 0, TAG_ANY);
if (vp) {
fr_cursor_remove(&cursor);
request->packet_code = vp->vp_integer;
talloc_free(vp);
} else {
request->packet_code = packet_code; /* Use the default set on the command line */
}

/*
* Read in filter VP's.
*/
Expand Down Expand Up @@ -380,54 +370,9 @@ static int radclient_init(TALLOC_CTX *ctx, rc_file_pair_t *files)
pairsort(&request->filter, attrtagcmp);
}

request->password[0] = '\0';
/*
* Determine the response code from the request (if not already set)
*/
if (!request->filter_code) {
switch (request->packet_code) {
case PW_CODE_AUTHENTICATION_REQUEST:
request->filter_code = PW_CODE_AUTHENTICATION_ACK;
break;

case PW_CODE_ACCOUNTING_REQUEST:
request->filter_code = PW_CODE_ACCOUNTING_RESPONSE;
break;

case PW_CODE_COA_REQUEST:
request->filter_code = PW_CODE_COA_ACK;
break;

case PW_CODE_DISCONNECT_REQUEST:
request->filter_code = PW_CODE_DISCONNECT_ACK;
break;

default:
break;
}
}

/*
* Keep a copy of the the User-Password attribute.
*/
if ((vp = pairfind(request->packet->vps, PW_USER_PASSWORD, 0, TAG_ANY)) != NULL) {
strlcpy(request->password, vp->vp_strvalue,
sizeof(request->password));
/*
* Otherwise keep a copy of the CHAP-Password attribute.
*/
} else if ((vp = pairfind(request->packet->vps, PW_CHAP_PASSWORD, 0, TAG_ANY)) != NULL) {
strlcpy(request->password, vp->vp_strvalue,
sizeof(request->password));

} else if ((vp = pairfind(request->packet->vps, PW_MS_CHAP_PASSWORD, 0, TAG_ANY)) != NULL) {
strlcpy(request->password, vp->vp_strvalue,
sizeof(request->password));
} else {
request->password[0] = '\0';
}

/*
* Fix up Digest-Attributes issues
* Process special attributes
*/
for (vp = fr_cursor_init(&cursor, &request->packet->vps);
vp;
Expand All @@ -446,10 +391,10 @@ static int radclient_init(TALLOC_CTX *ctx, rc_file_pair_t *files)
default:
break;

/*
* Allow it to set the packet type in
* the attributes read from the file.
*/
/*
* Allow it to set the packet type in
* the attributes read from the file.
*/
case PW_PACKET_TYPE:
request->packet->code = vp->vp_integer;
break;
Expand Down Expand Up @@ -530,10 +475,51 @@ static int radclient_init(TALLOC_CTX *ctx, rc_file_pair_t *files)
}
break;

/*
* Keep a copy of the the password attribute.
*/
case PW_USER_PASSWORD:
case PW_CHAP_PASSWORD:
case PW_MS_CHAP_PASSWORD:
strlcpy(request->password, vp->vp_strvalue, sizeof(request->password));
break;
}
} /* loop over the VP's we read in */

/*
* Use the default set on the command line
*/
if (request->packet_code == 0) {
request->packet_code = packet_code;
}

/*
* Automatically set the response code from the request code
* (if one wasn't already set).
*/
if (!request->filter_code) {
switch (request->packet_code) {
case PW_CODE_AUTHENTICATION_REQUEST:
request->filter_code = PW_CODE_AUTHENTICATION_ACK;
break;

case PW_CODE_ACCOUNTING_REQUEST:
request->filter_code = PW_CODE_ACCOUNTING_RESPONSE;
break;

case PW_CODE_COA_REQUEST:
request->filter_code = PW_CODE_COA_ACK;
break;

case PW_CODE_DISCONNECT_REQUEST:
request->filter_code = PW_CODE_DISCONNECT_ACK;
break;

default:
break;
}
}

/*
* Automatically set the dst port if one wasn't already set.
*/
Expand Down

0 comments on commit ce44980

Please sign in to comment.