VALUE_PAIR *vp;
char *p, *s;
- if ((da = dict_attrbyname(attribute)) == NULL)
+ if ((da = dict_attrbyname(attribute)) == NULL) {
+ librad_log("unknown attribute %s", attribute);
return NULL;
+ }
- if ((vp = (VALUE_PAIR *)malloc(sizeof(VALUE_PAIR))) == NULL)
+ if ((vp = (VALUE_PAIR *)malloc(sizeof(VALUE_PAIR))) == NULL) {
+ librad_log("out of memory");
return NULL;
+ }
memset(vp, 0, sizeof(VALUE_PAIR));
vp->attribute = da->attr;
case PW_TYPE_DATE:
if ((vp->lvalue = gettime(value)) == (time_t)-1) {
free(vp);
+ librad_log("failed to get time");
return NULL;
}
vp->length = 4;
break;
default:
free(vp);
+ librad_log("unknown attribute type");
return NULL;
}
return vp;
/* Get attribute. */
gettoken(ptr, attr, sizeof(attr));
- if (attr[0] == 0)
+ if (attr[0] == 0) {
+ librad_log("No token read");
return NULL;
+ }
/* Now we should have an '=' here. */
token = gettoken(ptr, buf, sizeof(buf));
- if (token < T_EQSTART || token > T_EQEND)
+ if (token < T_EQSTART || token > T_EQEND) {
+ librad_log("expecting '='");
return NULL;
+ }
/* Read value. */
gettoken(ptr, value, sizeof(value));
- if (value[0] == 0)
+ if (value[0] == 0) {
+ librad_log("failed to get value");
return NULL;
+ }
/*
* Peek at the next token. Must be T_EOL or T_COMMA.
*/
p = *ptr;
t = gettoken(&p, buf, sizeof(buf));
- if (t != T_EOL && t != T_COMMA)
+ if (t != T_EOL && t != T_COMMA) {
+ librad_log("Expected end of line or comma");
return NULL;
+ }
if (t == T_COMMA) {
*ptr = p;
*/
if (*p == 0)
*eol = 1;
- } else
+ } else {
*eol = 1;
+ }
return pairmake(attr, value, token);
}
p = buf;
do {
if ((vp = pairread(&p, &eol)) == NULL) {
- librad_perror("radclient");
+ librad_perror("radclient:");
error = 1;
break;
}
void usage(void)
{
- fprintf(stderr, "Usage: radclient [-dn] server acct|auth <secret>\n");
+ fprintf(stderr, "Usage: radclient [-d raddb ] [-nx] server acct|auth <secret>\n");
exit(1);
}
int c;
int port = 0;
int s;
+ char *radius_dir = RADDBDIR;
- if (dict_init(RADDBDIR, RADIUS_DICTIONARY) < 0) {
- librad_perror("radclient");
- return 1;
- }
-
- while ((c = getopt(argc, argv, "dn")) != EOF) switch(c) {
+ while ((c = getopt(argc, argv, "d:nx")) != EOF) switch(c) {
case 'd':
- librad_debug = 1;
+ radius_dir = optarg;
break;
case 'n':
do_output = 0;
break;
+ case 'x':
+ librad_debug = 1;
+ break;
default:
usage();
break;
argc -= (optind - 1);
argv += (optind - 1);
- if (argc < 4)
+ if (argc < 4) {
usage();
+ }
+
+ if (dict_init(radius_dir, RADIUS_DICTIONARY) < 0) {
+ librad_perror("radclient");
+ return 1;
+ }
if ((req = rad_alloc(1)) == NULL) {
librad_perror("radclient");
} else if (isdigit(argv[2][0])) {
if (port == 0) port = 1645;
port = atoi(argv[2]);
- } else
+ } else {
usage();
+ }
/*
* Resolve hostname.
/*
* Read valuepairs.
*/
- if ((req->vps = readvp()) == NULL)
+ if ((req->vps = readvp()) == NULL) {
exit(1);
+ }
/*
* Find the password pair and encode it.