static const char rcsid[] = "$Id$";
#include "autoconf.h"
-#include "libradius.h"
#include <stdio.h>
#include <stdlib.h>
#include "conf.h"
#include "radpaths.h"
#include "missing.h"
+#include "libradius.h"
static int retries = 10;
static float timeout = 3;
static int server_port = 0;
static int packet_code = 0;
-static uint32_t server_ipaddr = INADDR_NONE;
+static uint32_t server_ipaddr = 0;
static int resend_count = 1;
static int done = 1;
static radclient_t *radclient_tail = NULL;
-static void usage(void)
+static void NEVER_RETURNS usage(void)
{
fprintf(stderr, "Usage: radclient [options] server[:port] <command> [<secret>]\n");
* Keep a copy of the the User-Password attribute.
*/
if ((vp = pairfind(radclient->request->vps, PW_PASSWORD)) != NULL) {
- strNcpy(radclient->password, (char *)vp->strvalue, sizeof(vp->strvalue));
+ strNcpy(radclient->password, (char *)vp->strvalue, sizeof(radclient->password));
/*
* Otherwise keep a copy of the CHAP-Password attribute.
*/
} else if ((vp = pairfind(radclient->request->vps, PW_CHAP_PASSWORD)) != NULL) {
- strNcpy(radclient->password, (char *)vp->strvalue, sizeof(vp->strvalue));
+ strNcpy(radclient->password, (char *)vp->strvalue, sizeof(radclient->password));
} else {
radclient->password[0] = '\0';
}
radclient->request->dst_port = (vp->lvalue & 0xffff);
break;
- case PW_PACKET_DST_IP_ADDRESS:
- radclient->request->dst_ipaddr = vp->lvalue;
- break;
-
case PW_DIGEST_REALM:
case PW_DIGEST_NONCE:
case PW_DIGEST_METHOD:
if (radclient->request->dst_port == 0) {
radclient->request->dst_port = server_port;
}
- if (radclient->request->dst_ipaddr == 0) {
- if (server_ipaddr == INADDR_NONE) {
- fprintf(stderr, "radclient: No server was given, but request %d in file %s did not contain Packet-Dst-IP-Address\n",
- radclient->packet_number, radclient->filename);
- return -1;
- }
- radclient->request->dst_ipaddr = server_ipaddr;
- }
+ radclient->request->dst_ipaddr = server_ipaddr;
if (radclient->request->code == 0) {
if (packet_code == -1) {
VALUE_PAIR *vp;
if ((vp = pairfind(radclient->request->vps, PW_PASSWORD)) != NULL) {
- strNcpy((char *)vp->strvalue, radclient->password, strlen(radclient->password) + 1);
- vp->length = strlen(radclient->password);
+ strNcpy((char *)vp->strvalue, radclient->password, sizeof(vp->strvalue));
+ vp->length = strlen(vp->strvalue);
} else if ((vp = pairfind(radclient->request->vps, PW_CHAP_PASSWORD)) != NULL) {
- strNcpy((char *)vp->strvalue, radclient->password, strlen(radclient->password) + 1);
- vp->length = strlen(radclient->password);
+ strNcpy((char *)vp->strvalue, radclient->password, sizeof(vp->strvalue));
+ vp->length = strlen(vp->strvalue);
rad_chap_encode(radclient->request, (char *) vp->strvalue, radclient->request->id, vp);
vp->length = 17;
/*
* Send the packet.
*/
- rad_send(radclient->request, NULL, secret);
+ if (rad_send(radclient->request, NULL, secret) < 0) {
+ fprintf(stderr, "radclient: Failed to send packet for ID %d: %s\n",
+ radclient->request->id, librad_errstr);
+ }
return 0;
}
node = rbtree_find(request_tree, &myclient);
if (!node) {
fprintf(stderr, "radclient: received response to request we did not send.\n");
+ rad_free(&reply);
return -1; /* got reply to packet we didn't send */
}
if (rad_decode(reply, radclient->request, secret) != 0) {
librad_perror("rad_decode");
totallost++;
- return -1;
+ goto packet_done; /* shared secret is incorrect */
}
/* libradius debug already prints out the value pairs for us */
totaldeny++;
}
- if (radclient->reply) rad_free(&radclient->reply);
+packet_done:
+ rad_free(&radclient->reply);
/*
* Once we've sent the packet as many times as requested,
/*
* Resolve hostname.
*/
- if (strcmp(argv[1], "-") != 0) {
- server_ipaddr = ip_getaddr(argv[1]);
- if (server_ipaddr == INADDR_NONE) {
- fprintf(stderr, "radclient: Failed to find IP address for host %s\n", argv[1]);
- exit(1);
- }
+ server_ipaddr = ip_getaddr(argv[1]);
+ if (server_ipaddr == INADDR_NONE) {
+ fprintf(stderr, "radclient: Failed to find IP address for host %s\n", argv[1]);
+ exit(1);
}
/*