More radclient formatting and minor fixes
authorArran Cudbard-Bell <a.cudbardb@freeradius.org>
Tue, 17 Jun 2014 09:05:15 +0000 (10:05 +0100)
committerArran Cudbard-Bell <a.cudbardb@freeradius.org>
Tue, 17 Jun 2014 09:05:15 +0000 (10:05 +0100)
src/main/radclient.c

index 86a0be4..45b3943 100644 (file)
@@ -48,7 +48,7 @@ static bool do_output = true;
 static rc_stats_t stats;
 
 static uint16_t server_port = 0;
-static int packet_code = 0;
+static int packet_code = PW_CODE_UNDEFINED;
 static fr_ipaddr_t server_ipaddr;
 static int resend_count = 1;
 static bool done = true;
@@ -85,7 +85,7 @@ static void NEVER_RETURNS usage(void)
 {
        fprintf(stderr, "Usage: radclient [options] server[:port] <command> [<secret>]\n");
 
-       fprintf(stderr, "  <command>              One of auth, acct, status, coa, or disconnect.\n");
+       fprintf(stderr, "  <command>              One of auth, acct, status, coa, disconnect or auto.\n");
        fprintf(stderr, "  -4                     Use IPv4 address of server\n");
        fprintf(stderr, "  -6                     Use IPv6 address of server.\n");
        fprintf(stderr, "  -c <count>             Send each packet 'count' times.\n");
@@ -229,6 +229,7 @@ static void radclient_get_port(PW_CODE type, uint16_t *port)
 
        case PW_CODE_DISCONNECT_REQUEST:
                if (*port == 0) *port = PW_POD_UDP_PORT;
+               return;
 
        case PW_CODE_COA_REQUEST:
                if (*port == 0) *port = PW_COA_UDP_PORT;
@@ -236,6 +237,7 @@ static void radclient_get_port(PW_CODE type, uint16_t *port)
 
        case PW_CODE_UNDEFINED:
                if (*port == 0) *port = 0;
+               return;
        }
 }
 
@@ -521,16 +523,12 @@ static int radclient_init(TALLOC_CTX *ctx, rc_file_pair_t *files)
                /*
                 *      Use the default set on the command line
                 */
-               if (request->packet->code == PW_CODE_UNDEFINED) {
-                       request->packet->code = packet_code;
-               }
+               if (request->packet->code == PW_CODE_UNDEFINED) request->packet->code = packet_code;
 
                /*
                 *      Default to the filename
                 */
-               if (!request->name) {
-                       request->name = request->files->packets;
-               }
+               if (!request->name) request->name = request->files->packets;
 
                /*
                 *      Automatically set the response code from the request code
@@ -720,9 +718,7 @@ static int filename_walk(UNUSED void *context, void *data)
        /*
         *      Read request(s) from the file.
         */
-       if (!radclient_init(files, files)) {
-               return -1;      /* stop walking */
-       }
+       if (!radclient_init(files, files)) return -1;   /* stop walking */
 
        return 0;
 }
@@ -748,10 +744,7 @@ static void deallocate_id(rc_request_t *request)
         *      and ensure that the next packet has a unique
         *      authentication vector.
         */
-       if (request->packet->data) {
-               TALLOC_FREE(request->packet->data);
-       }
-
+       if (request->packet->data) TALLOC_FREE(request->packet->data);
        if (request->reply) rad_free(&request->reply);
 }
 
@@ -766,9 +759,7 @@ static int send_one_packet(rc_request_t *request)
         *      Remember when we have to wake up, to re-send the
         *      request, of we didn't receive a reply.
         */
-       if ((sleep_time == -1) || (sleep_time > (int) timeout)) {
-               sleep_time = (int) timeout;
-       }
+       if ((sleep_time == -1) || (sleep_time > (int) timeout)) sleep_time = (int) timeout;
 
        /*
         *      Haven't sent the packet yet.  Initialize it.
@@ -786,8 +777,7 @@ static int send_one_packet(rc_request_t *request)
                 */
        retry:
                request->packet->src_ipaddr.af = server_ipaddr.af;
-               rcode = fr_packet_list_id_alloc(pl, ipproto,
-                                               &request->packet, NULL);
+               rcode = fr_packet_list_id_alloc(pl, ipproto, &request->packet, NULL);
                if (!rcode) {
                        int mysockfd;
 
@@ -828,7 +818,6 @@ static int send_one_packet(rc_request_t *request)
 
                        if ((vp = pairfind(request->packet->vps, PW_USER_PASSWORD, 0, TAG_ANY)) != NULL) {
                                pairstrcpy(vp, request->password);
-
                        } else if ((vp = pairfind(request->packet->vps, PW_CHAP_PASSWORD, 0, TAG_ANY)) != NULL) {
                                bool already_hex = false;
 
@@ -869,9 +858,7 @@ static int send_one_packet(rc_request_t *request)
                                        vp->length = 17;
                                }
                        } else if (pairfind(request->packet->vps, PW_MS_CHAP_PASSWORD, 0, TAG_ANY) != NULL) {
-                               mschapv1_encode(request->packet,
-                                               &request->packet->vps,
-                                               request->password);
+                               mschapv1_encode(request->packet, &request->packet->vps, request->password);
                        } else {
                                DEBUG("WARNING: No password in the request");
                        }
@@ -978,19 +965,13 @@ static int recv_one_packet(int wait_time)
        max_fd = fr_packet_list_fd_set(pl, &set);
        if (max_fd < 0) exit(1); /* no sockets to listen on! */
 
-       if (wait_time <= 0) {
-               tv.tv_sec = 0;
-       } else {
-               tv.tv_sec = wait_time;
-       }
+       tv.tv_sec = (wait_time <= 0) ? 0 : wait_time;
        tv.tv_usec = 0;
 
        /*
         *      No packet was received.
         */
-       if (select(max_fd, &set, NULL, NULL, &tv) <= 0) {
-               return 0;
-       }
+       if (select(max_fd, &set, NULL, NULL, &tv) <= 0) return 0;
 
        /*
         *      Look for the packet.
@@ -1169,20 +1150,25 @@ int main(int argc, char **argv)
                case '4':
                        force_af = AF_INET;
                        break;
+
                case '6':
                        force_af = AF_INET6;
                        break;
+
                case 'c':
                        if (!isdigit((int) *optarg))
                                usage();
                        resend_count = atoi(optarg);
                        break;
+
                case 'D':
                        dict_dir = optarg;
                        break;
+
                case 'd':
                        radius_dir = optarg;
                        break;
+
                case 'f':
                {
                        char const *p;
@@ -1203,9 +1189,11 @@ int main(int argc, char **argv)
                        rbtree_insert(filename_tree, (void *) files);
                }
                        break;
+
                case 'F':
                        print_filename = true;
                        break;
+
                case 'i':       /* currently broken */
                        if (!isdigit((int) *optarg))
                                usage();
@@ -1254,14 +1242,15 @@ int main(int argc, char **argv)
                        break;
 
                case 'r':
-                       if (!isdigit((int) *optarg))
-                               usage();
+                       if (!isdigit((int) *optarg)) usage();
                        retries = atoi(optarg);
                        if ((retries == 0) || (retries > 1000)) usage();
                        break;
+
                case 's':
                        do_summary = true;
                        break;
+
                case 'S':
                {
                        char *p;
@@ -1291,19 +1280,23 @@ int main(int argc, char **argv)
                        secret = filesecret;
                }
                       break;
+
                case 't':
                        if (!isdigit((int) *optarg))
                                usage();
                        timeout = atof(optarg);
                        break;
+
                case 'v':
                        DEBUG("%s", radclient_version);
                        exit(0);
                        break;
+
                case 'x':
                        fr_debug_flag++;
                        rc_debug_flag++;
                        break;
+
                case 'h':
                default:
                        usage();
@@ -1335,7 +1328,6 @@ int main(int argc, char **argv)
        }
        fr_strerror();  /* Clear the error buffer */
 
-
        /*
         *      Get the request type
         */