Move server-specific code to tls_listen.c
[freeradius.git] / src / modules / rlm_eap / radeapclient.c
index 6b5b2df..0806f89 100644 (file)
@@ -51,10 +51,13 @@ static int filedone = 0;
 static int totalapp = 0;
 static int totaldeny = 0;
 static char filesecret[256];
-const char *radius_dir = RADDBDIR;
+char *radius_dir = NULL;
 const char *progname = "radeapclient";
 /* fr_randctx randctx; */
 
+#ifdef WITH_TLS
+#include <freeradius-devel/tls.h>
+#endif
 
 radlog_dest_t radlog_dest = RADLOG_STDERR;
 const char *radlog_dir = NULL;
@@ -83,6 +86,7 @@ static void NEVER_RETURNS usage(void)
        fprintf(stderr, "  -f file     Read packets from file, not stdin.\n");
        fprintf(stderr, "  -r retries  If timeout, retry sending the packet 'retries' times.\n");
        fprintf(stderr, "  -t timeout  Wait 'timeout' seconds before retrying (may be a floating point number).\n");
+       fprintf(stderr, "  -h          Print usage help information.\n");
        fprintf(stderr, "  -i id       Set request id to 'id'.  Values may be 0..255\n");
        fprintf(stderr, "  -S file     read secret from file, not command line.\n");
        fprintf(stderr, "  -q          Do not print anything out.\n");
@@ -179,13 +183,13 @@ static void debug_packet(RADIUS_PACKET *packet, int direction)
                printf("%s %s packet %s host %s port %d, id=%d, length=%d\n",
                       received, fr_packet_codes[packet->code], from,
                       inet_ntop(ip->af, &ip->ipaddr, buffer, sizeof(buffer)),
-                      port, packet->id, packet->data_len);
+                      port, packet->id, (int) packet->data_len);
        } else {
                printf("%s packet %s host %s port %d code=%d, id=%d, length=%d\n",
                       received, from,
                       inet_ntop(ip->af, &ip->ipaddr, buffer, sizeof(buffer)),
                       port,
-                      packet->code, packet->id, packet->data_len);
+                      packet->code, packet->id, (int) packet->data_len);
        }
 
        for (vp = packet->vps; vp != NULL; vp = vp->next) {
@@ -204,6 +208,8 @@ static int send_packet(RADIUS_PACKET *req, RADIUS_PACKET **rep)
        for (i = 0; i < retries; i++) {
                fd_set          rdfdesc;
 
+               debug_packet(req, R_SENT);
+
                rad_send(req, NULL, secret);
 
                /* And wait for reply, timing out as necessary */
@@ -693,8 +699,6 @@ static int respond_eap_sim(RADIUS_PACKET *req,
         */
        unmap_eapsim_types(req);
 
-       debug_packet(req, R_SENT);
-
        if((vp = pairfind(req->vps, ATTRIBUTE_EAP_SIM_SUBTYPE, 0)) == NULL)
        {
                return 0;
@@ -862,8 +866,6 @@ static int sendrecv_eap(RADIUS_PACKET *rep)
  again:
        rep->id++;
 
-       debug_packet(rep, R_SENT);
-
        /*
         * if there are EAP types, encode them into an EAP-Message
         *
@@ -991,7 +993,7 @@ int main(int argc, char **argv)
                        count = atoi(optarg);
                        break;
                case 'd':
-                       radius_dir = optarg;
+                       radius_dir = strdup(optarg);
                        break;
                case 'f':
                        filename = optarg;
@@ -1079,6 +1081,8 @@ int main(int argc, char **argv)
                usage();
        }
 
+       if (!radius_dir) radius_dir = strdup(RADDBDIR);
+
        if (dict_init(radius_dir, RADIUS_DICTIONARY) < 0) {
                fr_perror("radclient");
                return 1;
@@ -1194,6 +1198,7 @@ int main(int argc, char **argv)
                sendrecv_eap(req);
        }
 
+       free(radius_dir);
        if(do_summary) {
                printf("\n\t   Total approved auths:  %d\n", totalapp);
                printf("\t     Total denied auths:  %d\n", totaldeny);
@@ -1469,9 +1474,9 @@ main(int argc, char *argv[])
                }
 
                vp = pairfind(req2->vps,
-                             ATTRIBUTE_EAP_SIM_BASE+PW_EAP_SIM_MAC);
-               vpkey   = pairfind(req->vps, ATTRIBUTE_EAP_SIM_KEY);
-               vpextra = pairfind(req->vps, ATTRIBUTE_EAP_SIM_EXTRA);
+                             ATTRIBUTE_EAP_SIM_BASE+PW_EAP_SIM_MAC, 0);
+               vpkey   = pairfind(req->vps, ATTRIBUTE_EAP_SIM_KEY, 0);
+               vpextra = pairfind(req->vps, ATTRIBUTE_EAP_SIM_EXTRA, 0);
 
                if(vp != NULL && vpkey != NULL && vpextra!=NULL) {
                        uint8_t calcmac[16];