]> git.decadent.org.uk Git - ap-utils.git/blob - src/auth.c
Pass correct platform options to configure
[ap-utils.git] / src / auth.c
1 /*
2  *      auth.c from Access Point SNMP Utils for Linux
3  *
4  * Copyright (c) 2002 Roman Festchook <roma at polesye dot net>
5  * Copyright (c) 2005 Jan Rafaj <jr-aputils at cedric dot unob dot cz>
6  *
7  * This program is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License Version 2 from
9  * June 1991 as published by the Free Software Foundation.
10  *
11  * This program is distributed in the hope that it will be useful, but
12  * WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License along
17  * with this program; if not, write to the Free Software Foundation, Inc.,
18  * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19  *
20  */
21
22 #include <stdlib.h>
23 #include <unistd.h>
24 #include <string.h>
25 #include "ap-utils.h"
26
27 #define MAX_LINES LINES-12
28 #define PACKET_ERROR _("AuthorizedMacTableString packet error")
29
30 #define AUTH_TITLE _("APClient authorization credentials")
31
32 #define MAC_AUTH _("[A] MAC authorization: ")
33 #define MAC_ADD  _("Enter MAC: ")
34 #define MAC_DEL  _("Delete Num: ")
35 #define MAC_HEADER _(" NUM     MAC address     ")
36 #define MAC_HELP _("A: auth; N: new; D: del; arrows: scroll; W: write conf; Q: quit")
37
38 #define RADIUS_IP _("[I] Radius server IP: ")
39 #define RADIUS_DEST_PORT _("[P] Radius server port: ")
40 #define RADIUS_SECRET _("[S] Radius server secret: ")
41 #define RADIUS_TIME _("[T] Reauthorization time (minutes): ")
42 #define RADIUS_PORT _("[F] Radius source port: ")
43 #define RADIUS_HELP _("A: auth; N: new; D: del; IPSTF: set; arrows: scroll; W: write conf; Q: quit")
44
45 #define DOT1X_MODE _("[M] 802.1x authorization: ")
46 #define DOT1X_TIME _("[T] key broadcasting time period (seconds): ")
47 #define DOT1X_IP _("[I] 802.1x auth. server IP: ")
48 #define DOT1X_SECRET _("[S] 802.1x auth. server secret: ")
49 #define DOT1X_HELP _("A: auth; N: new; D: del; MTIS: set; arrows: scroll; W: write conf; Q: quit")
50
51 extern WINDOW *main_sub;
52 extern int LINES;
53 extern short ap_type, ap_vendorext;
54
55 void atmel_auth()
56 {
57     char AuthorizationMacEnable[] = {
58         0x2B, 0x06, 0x01, 0x04, 0x01, 0x83, 0x1A, 0x01, 0x02, 0x06, 0x01, 0x00
59     };
60     char AutorizedMac[] = {
61         0x2B, 0x06, 0x01, 0x04, 0x01, 0x83, 0x1A, 0x01, 0x02, 0x06, 0x02, 0x00
62     };
63
64     /* These 6 are ATMEL410 MIB with SBRIDGES extensions -specific */
65     char AuthRadiusIP[] = {
66         0x2B, 0x06, 0x01, 0x04, 0x01, 0x83, 0x1A, 0x01, 0x02, 0x06, 0x03, 0x00
67     };
68     char AuthRadiusSecret[] = {
69         0x2B, 0x06, 0x01, 0x04, 0x01, 0x83, 0x1A, 0x01, 0x02, 0x06, 0x04, 0x00
70     };
71     char AuthRadiusSecretLength[] = {
72         0x2B, 0x06, 0x01, 0x04, 0x01, 0x83, 0x1A, 0x01, 0x02, 0x06, 0x05, 0x00
73     };
74     char AuthRadiusPort[] = {
75         0x2B, 0x06, 0x01, 0x04, 0x01, 0x83, 0x1A, 0x01, 0x02, 0x06, 0x06, 0x00
76     };
77     char AuthRadiusReauthorizationTime[] = {
78         0x2B, 0x06, 0x01, 0x04, 0x01, 0x83, 0x1A, 0x01, 0x02, 0x06, 0x07, 0x00
79     };
80     char AuthRadiusDestinPort[] = {
81         0x2B, 0x06, 0x01, 0x04, 0x01, 0x83, 0x1A, 0x01, 0x02, 0x06, 0x08, 0x00
82     };
83
84     /* These 4 are ATMEL12350 MIB with EZYNET extensions -specific */
85     /* Note: GEMTEK MIB falsely claims it has these, but it is not true. :( */
86     char Dot1xEnable[] = {
87         0x2B, 0x06, 0x01, 0x04, 0x01, 0xE0, 0x3E, 0x01, 0x02, 0x08, 0x01, 0x00
88     };
89     char BroadcastKeyPeriod[] = {
90         0x2B, 0x06, 0x01, 0x04, 0x01, 0xE0, 0x3E, 0x01, 0x02, 0x08, 0x02, 0x00
91     };
92     char ServerIP[] = {
93         0x2B, 0x06, 0x01, 0x04, 0x01, 0xE0, 0x3E, 0x01, 0x02, 0x08, 0x03, 0x00
94     };
95     char ServerSecret[] = {
96         0x2B, 0x06, 0x01, 0x04, 0x01, 0xE0, 0x3E, 0x01, 0x02, 0x08, 0x04, 0x00
97     };
98
99     struct AuthorizedMacTableString {
100         unsigned int short Action;
101         unsigned int short NumOfAllTableAddresses;
102         unsigned int short NumOfCurrentAddress;
103         unsigned char MacAddress[6];
104     } *AuthMac = NULL, get;
105
106     /* for ATMEL* MIBs with NONE extensions */
107     char *AuthModes_OO[] = {
108         ON,
109         OFF
110     };
111         
112     /* for ATMEL410 MIB with SBRIDGES extensions */
113     char *AuthModes_IOR[] = {
114         _("Internal"),
115         OFF,
116         _("Radius")
117     };
118
119     /* for ATMEL12350 MIBs with GEMTEK or EZYNET extensions */
120     char *AuthModes_AOD[] = {
121         _("Allow listed MACs only"),
122         OFF,
123         _("Deny listed MACs only")
124     };
125
126     char *Dot1xModes[] = {
127         ON,
128         OFF,
129         _("Mixed environment")
130     };
131
132     /* These will be used for both Radius-related and 802.1x-related stuff. */
133     struct in_addr ea_ip;
134     char ea_secret[33];
135     int ea_mode, ea_port, ea_time, ea_dest_port,
136         m_ea_mode = 0, m_ea_port = 0, m_ea_ip = 0, m_ea_secret = 0,
137         m_ea_time = 0, m_ea_dest_port = 0;
138
139     struct MacListStat *pmac, *first = NULL, *curr = NULL;
140     char message[1024], m_authmac = 0;
141     int i = 0, total_mac, auth_mode = 0, mac_num = 0, begin, end;
142     varbind varbinds[7];
143
144
145     if (ap_type == ATMEL12350) {
146         AuthorizationMacEnable[5] = 0xE0;
147         AuthorizationMacEnable[6] = 0x3E;
148         AutorizedMac[5] = 0xE0;
149         AutorizedMac[6] = 0x3E;
150     }
151
152     varbinds[i].oid = AuthorizationMacEnable;
153     varbinds[i].len_oid = sizeof(AuthorizationMacEnable);
154     varbinds[i].type = NULL_VALUE;
155     varbinds[i].len_val = 0;
156     i++;
157
158     if (ap_type == ATMEL410 && ap_vendorext == SBRIDGES) {
159         varbinds[i].oid = AuthRadiusIP;
160         varbinds[i].len_oid = sizeof(AuthRadiusIP);
161         varbinds[i].type = NULL_VALUE;
162         varbinds[i].len_val = 0;
163         i++;
164
165         varbinds[i].oid = AuthRadiusPort;
166         varbinds[i].len_oid = sizeof(AuthRadiusPort);
167         varbinds[i].type = NULL_VALUE;
168         varbinds[i].len_val = 0;
169         i++;
170
171         varbinds[i].oid = AuthRadiusReauthorizationTime;
172         varbinds[i].len_oid = sizeof(AuthRadiusReauthorizationTime);
173         varbinds[i].type = NULL_VALUE;
174         varbinds[i].len_val = 0;
175         i++;
176
177         varbinds[i].oid = AuthRadiusDestinPort;
178         varbinds[i].len_oid = sizeof(AuthRadiusDestinPort);
179         varbinds[i].type = NULL_VALUE;
180         varbinds[i].len_val = 0;
181         i++;
182     }
183
184     if (ap_type == ATMEL12350 && ap_vendorext == EZYNET) {
185         varbinds[i].oid = Dot1xEnable;
186         varbinds[i].len_oid = sizeof(Dot1xEnable);
187         varbinds[i].type = NULL_VALUE;
188         varbinds[i].len_val = 0;
189         i++;
190
191         varbinds[i].oid = BroadcastKeyPeriod;
192         varbinds[i].len_oid = sizeof(BroadcastKeyPeriod);
193         varbinds[i].type = NULL_VALUE;
194         varbinds[i].len_val = 0;
195         i++;
196
197         varbinds[i].oid = ServerIP;
198         varbinds[i].len_oid = sizeof(ServerIP);
199         varbinds[i].type = NULL_VALUE;
200         varbinds[i].len_val = 0;
201         i++;
202     }
203
204     print_help(WAIT_RET);
205     if (snmp(varbinds, i, GET) < i) {
206         print_helperr(ERR_RET);
207         goto exit;
208     }
209     print_top(NULL, AUTH_TITLE);
210
211     auth_mode = *(varbinds[0].value);
212
213     strcpy(ea_secret, _("(not shown)"));
214
215     if (ap_type == ATMEL410 && ap_vendorext == SBRIDGES) {
216         sprintf(message, "%s%s", MAC_AUTH, AuthModes_IOR[auth_mode - 1]);
217         mvwaddstr(main_sub, 0, 0, message);
218
219         if (auth_mode == 3) { /* Radius */
220             memcpy(&ea_ip.s_addr, varbinds[1].value, 4);
221             sprintf(message, "%s%s", RADIUS_IP, inet_ntoa(ea_ip));
222             mvwaddstr(main_sub, 1, 0, message);
223
224             ea_dest_port = varbinds[4].len_val == 2 ?
225                 (varbinds[4].value[0] << 8) | varbinds[4].value[1] :
226                 varbinds[4].value[0] < 0x80 ?
227                 varbinds[4].value[0] : 0xff00 | varbinds[4].value[0];
228             sprintf(message, "%s%d", RADIUS_DEST_PORT, ea_dest_port);
229             mvwaddstr(main_sub, 2, 0, message);
230
231             sprintf(message, "%s%s", RADIUS_SECRET, ea_secret);
232             mvwaddstr(main_sub, 3, 0, message);
233
234             ea_time = varbinds[3].len_val == 2 ?
235                 (varbinds[3].value[0] << 8) | varbinds[3].value[1] :
236                 varbinds[3].value[0] < 0x80 ?
237                 varbinds[3].value[0] : 0xff00 | varbinds[3].value[0];
238             sprintf(message, "%s%d", RADIUS_TIME, ea_time);
239             mvwaddstr(main_sub, 4, 0, message);
240
241             ea_port = varbinds[2].len_val == 2 ?
242                 (varbinds[2].value[0] << 8) | varbinds[2].value[1] :
243                 varbinds[2].value[0] < 0x80 ?
244                 varbinds[2].value[0] : 0xff00 | varbinds[2].value[0];
245             sprintf(message, "%s%d", RADIUS_PORT, ea_port);
246             mvwaddstr(main_sub, 5, 0, message);
247         }
248     } else if (ap_type == ATMEL12350 &&
249         (ap_vendorext == GEMTEK || ap_vendorext == EZYNET)) {
250         sprintf(message, "%s%s", MAC_AUTH, AuthModes_AOD[auth_mode - 1]);
251         mvwaddstr(main_sub, 0, 0, message);
252
253         if (ap_vendorext == EZYNET) {
254             ea_mode = *(varbinds[1].value);
255             sprintf(message, "%s%s", DOT1X_MODE, Dot1xModes[ea_mode - 1]);
256             mvwaddstr(main_sub, 1, 0, message);
257
258             ea_time = varbinds[2].len_val == 2 ?
259                 (varbinds[2].value[0] << 8) | varbinds[2].value[1] :
260                 varbinds[2].value[0] < 0x80 ?
261                 varbinds[2].value[0] : 0xff00 | varbinds[2].value[0];
262             sprintf(message, "%s%d", DOT1X_TIME, ea_time);
263             mvwaddstr(main_sub, 2, 0, message);
264
265             memcpy(&ea_ip.s_addr, varbinds[3].value, 4);
266             sprintf(message, "%s%s", DOT1X_IP, inet_ntoa(ea_ip));
267             mvwaddstr(main_sub, 3, 0, message);
268
269             sprintf(message, "%s%s", DOT1X_SECRET, ea_secret);
270             mvwaddstr(main_sub, 4, 0, message);
271         }
272     } else {
273         sprintf(message, "%s%s", MAC_AUTH, AuthModes_OO[auth_mode - 1]);
274         mvwaddstr(main_sub, 0, 0, message);
275     }
276     mvwaddstr(main_sub, 7, 0, _("Authorized MAC addresses:"));
277     wattrset(main_sub, COLOR_PAIR(13));
278     mvwaddstr(main_sub, 8, 0, MAC_HEADER);
279     wattrset(main_sub, A_NORMAL);
280     wrefresh(main_sub);
281
282     print_help("Trying to retrieve auth. MAC address list from AP. Please wait.");
283
284     total_mac = 0;
285     mac_num = 0;
286
287     while (mac_num <= total_mac) {
288         get.Action = 0x02; rshort(get.Action);
289         get.NumOfAllTableAddresses = total_mac; rshort(get.NumOfAllTableAddresses);
290         get.NumOfCurrentAddress = mac_num; rshort(get.NumOfCurrentAddress);
291
292         varbinds[0].oid = AutorizedMac;
293         varbinds[0].len_oid = sizeof(AutorizedMac);
294         varbinds[0].value = (char *) &get;
295         varbinds[0].len_val = 12;
296         varbinds[0].type = STRING_VALUE;
297
298         i = snmp(varbinds, 1, SET);
299         if (i == 0) {
300             print_helperr(ERR_SET);
301             goto exit;
302         }
303         if (i < 0)
304             break;
305
306         if (varbinds[0].len_val == 12) {
307             if (AuthMac)
308                 free(AuthMac);
309             AuthMac =
310                 (struct AuthorizedMacTableString *) malloc(varbinds[0].
311                                                            len_val);
312             memcpy(AuthMac, varbinds[0].value, varbinds[0].len_val);
313 /*          AuthMac =
314                 (struct AuthorizedMacTableString *) varbinds[0].value;*/
315         } else {
316             print_helperr(PACKET_ERROR);
317             goto exit;
318         }
319
320         rshort(AuthMac->NumOfAllTableAddresses);
321         total_mac =
322             (AuthMac->NumOfAllTableAddresses ==
323              65535) ? 0 : AuthMac->NumOfAllTableAddresses;
324
325         if (mac_num) {
326             if (first == NULL) {
327                 first = (struct MacListStat *)
328                     malloc(sizeof(struct MacListStat));
329                 curr = first;
330             } else {
331                 curr->next = (struct MacListStat *)
332                     malloc(sizeof(struct MacListStat));
333                 curr = curr->next;
334             }
335             memcpy(curr->addr, AuthMac->MacAddress, 6);
336             curr->next = NULL;
337         }
338         mac_num++;
339     }
340
341     begin = (mac_num > MAX_LINES) ? mac_num + 1 - (MAX_LINES) : 1;
342     end = mac_num;
343
344     if (i < 0) {
345         mvwaddstr(main_sub, 9, 0, _("(insufficient community used)"));
346         wrefresh(main_sub);
347     } else {
348         scroll_rows(first, begin, end, 9, 0);
349     }
350
351     noecho();
352
353     if (ap_type == ATMEL410 && ap_vendorext == SBRIDGES)
354         print_help(RADIUS_HELP);
355     else if (ap_type == ATMEL12350 && ap_vendorext == EZYNET)
356         print_help(DOT1X_HELP);
357     else
358         print_help(MAC_HELP);
359
360     while (1) {
361         switch (getch()) {
362         case 'q':
363         case 'Q':
364             goto quit;
365         case 'a':
366         case 'A':
367             auth_mode = menu_choose(0, strlen(MAC_AUTH),
368                 ap_type == ATMEL410 && ap_vendorext == SBRIDGES ?
369                     AuthModes_IOR :
370                 ap_type == ATMEL12350 &&
371                     (ap_vendorext == GEMTEK || ap_vendorext == EZYNET) ?
372                     AuthModes_AOD :
373                     AuthModes_OO,
374                 ap_vendorext == NONE ?
375                     2 : 3
376             );
377             clear_main_new(0, 1);
378             print_menusel(0, 0, MAC_AUTH,
379                 ap_type == ATMEL410 && ap_vendorext == SBRIDGES ?
380                     AuthModes_IOR[auth_mode] :
381                 ap_type == ATMEL12350 &&
382                     (ap_vendorext == GEMTEK || ap_vendorext == EZYNET) ?
383                     AuthModes_AOD[auth_mode] :
384                     AuthModes_OO[auth_mode]
385             );
386             auth_mode++;
387 /*
388             auth_mode = on_off(0, strlen(MAC_AUTH));
389             clear_main_new(0, 1);
390             print_menusel(0, 0, MAC_AUTH, (auth_mode == 1) ? ON : OFF);
391 */
392             m_authmac = 1;
393             continue;
394         case 'd':
395         case 'D':
396             /* no MACs available for deletion */
397             if (mac_num == 1)
398                 continue;
399
400             mvwaddstr(main_sub, 6, 0, MAC_DEL);
401             get_value(message, 6, strlen(MAC_DEL), 5, INT_STRING,
402                 0, mac_num - 1, NULL);
403             i = atoi(message);
404             if (i == 0) {
405                 clear_main_new(6, 7);
406                 continue;
407             }
408             curr = first;
409             if (i == 1) {
410                 if (curr->next) {
411                     pmac = curr->next;
412                     free(first);
413                     first = pmac;
414                 }
415             } else {
416                 int j = i;
417
418                 while (--j > 1)
419                     curr = curr->next;
420                 pmac = curr->next;
421                 curr->next = pmac->next;
422                 free(pmac);
423             }
424
425             mac_num--;
426
427             /* Rather do not ask how this works. */
428             if (i < begin) {
429                 begin--;
430                 end--;
431             } else if (i > (end - 1)) {
432                 /* Nothing to do! */
433             } else { /* begin <= i <= (end - 1) */
434                 if ((begin == 1) && ((end - 1) == mac_num)) {
435                     end--;
436                 } else if ((begin > 1) && ((end - 1) < mac_num)) {
437                     /* Uncomment for top side scrolling first. */
438 /*
439                     begin--;
440                     end--;
441 */
442                 } else if (begin > 1) {
443                     begin--;
444                     end--;
445                 }
446             }
447 #if 0 /* DEBUG */
448             sprintf(message, "MAX_LINES: %i mac_num: %i begin: %i end: %i",
449                 MAX_LINES, mac_num, begin, end);
450             clear_main(0);
451             mvwaddstr(main_sub, 0, 0, message);
452             wrefresh(main_sub);
453             exit(0);
454 #endif /* DEBUG */
455             scroll_rows(first, begin, end, 9, 0);
456             clear_main_new(6, 7);
457             continue;
458         case 'n':
459         case 'N':
460             if (mac_num == 1) {
461                 free(first);
462                 first = NULL;
463             }
464 again:
465             mvwaddstr(main_sub, 6, 0, MAC_ADD);
466             get_mac(message, 6, strlen(MAC_ADD));
467
468             curr = first;
469             i = 1;
470             while (curr) {
471                 if (memcmp(curr->addr, message, 6) == 0) {
472                     sprintf(message, _("Given MAC already exists in MAC list "
473                         "at position %d. Press any key."), i);
474                     print_helperr(message);
475                     getch();
476                     if (ap_type == ATMEL410 && ap_vendorext == SBRIDGES)
477                         print_help(RADIUS_HELP);
478                     else if (ap_type == ATMEL12350 && ap_vendorext == EZYNET)
479                         print_help(DOT1X_HELP);
480                     else
481                         print_help(MAC_HELP);
482                     goto again;
483                 }
484                 curr = curr->next;
485                 i++;
486             }
487
488             curr = first;
489             while (curr && curr->next)
490                 curr = curr->next;
491             if (first == NULL) {
492                 first = (struct MacListStat *)
493                     malloc(sizeof(struct MacListStat));
494                 curr = first;
495             } else {
496                 curr->next = (struct MacListStat *)
497                     malloc(sizeof(struct MacListStat));
498                 curr = curr->next;
499             }
500             curr->next = NULL;
501             memcpy(curr->addr, message, 6);
502             mac_num++;
503 /*          get_value(message, 1, strlen(MAC_ADD), 13, ANY_STRING, 0, 0,
504                 NULL);
505
506             for (i = 0; i < 6; i++) {
507                 mess[0] = message[2 * i];
508                 mess[1] = message[2 * i + 1];
509                 mess[2] = '\0';
510                 curr->addr[i] = strtol(mess, NULL, 16);
511             }
512             clear_main_new(1, 2);
513 */
514             begin = (mac_num > MAX_LINES) ? mac_num + 1 - (MAX_LINES) : 1;
515             end = mac_num;
516             scroll_rows(first, begin, end, 9, 0);
517             clear_main_new(6, 7);
518             continue;
519         case 'f':
520         case 'F':
521             if (ap_type == ATMEL410 && ap_vendorext == SBRIDGES && auth_mode == 3) {
522                 get_value(message, 5, strlen(RADIUS_PORT), 6,
523                     INT_STRING, 0, 65535, RADIUS_HELP);
524                 ea_port = atoi(message);
525                 m_ea_port = 1;
526             };
527             continue;
528         case 'i':
529         case 'I':
530             if (ap_type == ATMEL410 && ap_vendorext == SBRIDGES && auth_mode == 3) {
531                 get_ip(&ea_ip, 1, strlen(RADIUS_IP), RADIUS_HELP);
532                 m_ea_ip = 1;
533             }
534             if (ap_type == ATMEL12350 && ap_vendorext == EZYNET) {
535                 get_ip(&ea_ip, 3, strlen(DOT1X_IP), DOT1X_HELP);
536                 m_ea_ip = 1;
537             }
538             continue;
539         case 'm':
540         case 'M':
541             if (ap_type == ATMEL12350 && ap_vendorext == EZYNET) {
542                 ea_mode = menu_choose(1, strlen(DOT1X_MODE), Dot1xModes, 3);
543                 clear_main_new(1, 2);
544                 print_menusel(1, 0, DOT1X_MODE, Dot1xModes[ea_mode]);
545                 ea_mode++;
546                 m_ea_mode = 1;
547             }
548             continue;
549         case 'p':
550         case 'P':
551             if (ap_type == ATMEL410 && ap_vendorext == SBRIDGES && auth_mode == 3) {
552                 get_value(message, 2, strlen(RADIUS_DEST_PORT), 6,
553                     INT_STRING, 0, 65535, RADIUS_HELP);
554                 ea_dest_port = atoi(message);
555                 m_ea_dest_port = 1;
556             }
557             continue;
558         case 's':
559         case 'S':
560             if (ap_type == ATMEL410 && ap_vendorext == SBRIDGES && auth_mode == 3) {
561                 get_value(ea_secret, 3, strlen(RADIUS_SECRET), -33,
562                     ANY_STRING, 0, 0, NULL);
563                 m_ea_secret = 1;
564             }
565             if (ap_type == ATMEL12350 && ap_vendorext == EZYNET) {
566                 get_value(ea_secret, 4, strlen(DOT1X_SECRET), -17,
567                     ANY_STRING, 0, 0, NULL);
568                 m_ea_secret = 1;
569             }
570             continue;
571         case 't':
572         case 'T':
573             if (ap_type == ATMEL410 && ap_vendorext == SBRIDGES && auth_mode == 3) {
574                 get_value(message, 4, strlen(RADIUS_TIME), 6,
575                     INT_STRING, 0, 65535, RADIUS_HELP);
576                 ea_time = atoi(message);
577                 m_ea_time = 1;
578             }
579             if (ap_type == ATMEL12350 && ap_vendorext == EZYNET) {
580                 get_value(message, 2, strlen(DOT1X_TIME), 6,
581                     INT_STRING, 0, 65535, RADIUS_HELP);
582                 ea_time = atoi(message);
583                 m_ea_time = 1;
584             }
585             continue;
586         case 'w':
587         case 'W':
588             curr = first;
589             i = (mac_num == 1 ? 0 : 1);
590             while (curr != NULL) {
591                 get.Action = 0x01; rshort(get.Action);
592                 get.NumOfAllTableAddresses = mac_num - 1; rshort(get.NumOfAllTableAddresses);
593                 get.NumOfCurrentAddress = i; rshort(get.NumOfCurrentAddress);
594                 memcpy(get.MacAddress, curr->addr, 6);
595                 varbinds[0].oid = AutorizedMac;
596                 varbinds[0].len_oid = sizeof(AutorizedMac);
597                 varbinds[0].value = (char *) &get;
598                 varbinds[0].len_val = 12;
599                 varbinds[0].type = STRING_VALUE;
600                 print_help(WAIT_SET);
601                 if (snmp(varbinds, 1, SET) <= 0) {
602                     print_helperr(ERR_SET);
603                     goto exit;
604                 }
605                 if (varbinds[0].len_val != 12) {
606                     print_helperr(PACKET_ERROR);
607                     goto exit;
608                 }
609                 curr = curr->next;
610                 i++;
611             }
612
613             i = 0;
614
615             if (m_authmac) {
616                 int c = swap4(auth_mode);
617
618                 varbinds[i].oid = AuthorizationMacEnable;
619                 varbinds[i].len_oid = sizeof(AuthorizationMacEnable);
620                 varbinds[i].value = (char *) &c;
621                 varbinds[i].len_val = 1;
622                 varbinds[i].type = INT_VALUE;
623                 i++;
624             }
625
626             if (m_ea_port) {
627                 varbinds[i].oid = AuthRadiusPort;
628                 varbinds[i].len_oid = sizeof(AuthRadiusPort);
629                 ea_port = htons(ea_port);
630                 varbinds[i].value = (char *) &ea_port;
631                 varbinds[i].len_val = 2;
632                 varbinds[i].type = INT_VALUE;
633                 i++;
634             }
635
636             if (m_ea_ip) {
637                 if (ap_type == ATMEL410 && ap_vendorext == SBRIDGES) {
638                     varbinds[i].oid = AuthRadiusIP;
639                     varbinds[i].len_oid = sizeof(AuthRadiusIP);
640                 }
641
642                 if (ap_type == ATMEL12350 && ap_vendorext == EZYNET) {
643                     varbinds[i].oid = ServerIP;
644                     varbinds[i].len_oid = sizeof(ServerIP);
645                 }
646
647                 ea_ip.s_addr = htonl(ea_ip.s_addr);
648                 ea_ip.s_addr = swap4(ea_ip.s_addr);
649                 varbinds[i].value = (char *) &ea_ip.s_addr;
650                 varbinds[i].len_val = 4;
651                 varbinds[i].type = INT_VALUE;
652                 i++;
653             }
654
655             if (m_ea_mode) {
656                 varbinds[i].oid = Dot1xEnable;
657                 varbinds[i].len_oid = sizeof(Dot1xEnable);
658                 ea_mode = swap4(ea_mode);
659                 varbinds[i].value = (char *) &ea_mode;
660                 varbinds[i].len_val = 1;
661                 varbinds[i].type = INT_VALUE;
662                 i++;
663             }
664
665             if (m_ea_dest_port) {
666                 varbinds[i].oid = AuthRadiusDestinPort;
667                 varbinds[i].len_oid = sizeof(AuthRadiusDestinPort);
668                 ea_dest_port = htons(ea_dest_port);
669                 varbinds[i].value = (char *) &ea_dest_port;
670                 varbinds[i].len_val = 2;
671                 varbinds[i].type = INT_VALUE;
672                 i++;
673             }
674
675             if (m_ea_secret) {
676                 int c = strlen(ea_secret);
677
678                 if (ap_type == ATMEL410 && ap_vendorext == SBRIDGES) {
679                     varbinds[i].oid = AuthRadiusSecretLength;
680                     varbinds[i].len_oid = sizeof(AuthRadiusSecretLength);
681                     varbinds[i].value = (char *) &c;
682                     varbinds[i].len_val = 1;
683                     varbinds[i].type = INT_VALUE;
684                     i++;
685
686                     varbinds[i].oid = AuthRadiusSecret;
687                     varbinds[i].len_oid = sizeof(AuthRadiusSecret);
688                 }
689
690                 if (ap_type == ATMEL12350 && ap_vendorext == EZYNET) {
691                     varbinds[i].oid = ServerSecret;
692                     varbinds[i].len_oid = sizeof(ServerSecret);
693                 }
694
695                 varbinds[i].value = ea_secret;
696                 varbinds[i].len_val = c;
697                 varbinds[i].type = STRING_VALUE;
698                 i++;
699             }
700
701             if (m_ea_time) {
702                 if (ap_type == ATMEL410 && ap_vendorext == SBRIDGES) {
703                     varbinds[i].oid = AuthRadiusReauthorizationTime;
704                     varbinds[i].len_oid = sizeof(AuthRadiusReauthorizationTime);
705                 }
706
707                 if (ap_type == ATMEL12350 && ap_vendorext == EZYNET) {
708                     varbinds[i].oid = BroadcastKeyPeriod;
709                     varbinds[i].len_oid = sizeof(BroadcastKeyPeriod);
710                 }
711
712                 ea_time = htons(ea_time);
713                 varbinds[i].value = (char *) &ea_time;
714                 varbinds[i].len_val = 2;
715                 varbinds[i].type = INT_VALUE;
716                 i++;
717             }
718
719             print_help(WAIT_SET);
720             if (snmp(varbinds, i, SET) <= 0) {
721                 print_helperr(ERR_SET);
722                 goto exit;
723             }
724             wbkgd(main_sub, A_NORMAL);
725             wattrset(main_sub, COLOR_PAIR(13));
726             mvwaddstr(main_sub, 8, 0, MAC_HEADER);
727             wattrset(main_sub, A_NORMAL);
728             wrefresh(main_sub);
729             print_help(DONE_SET);
730             goto exit;
731         case KEY_DOWN:
732         case KEY_RIGHT:
733             if (end < mac_num) {
734                 begin++;
735                 end++;
736                 scroll_rows(first, begin, end, 9, 0);
737             }
738             continue;
739         case KEY_UP:
740         case KEY_LEFT:
741             if (begin > 1) {
742                 begin--;
743                 end--;
744                 scroll_rows(first, begin, end, 9, 0);
745             }
746             continue;
747         case KEY_NPAGE:
748             if (end < mac_num) {
749                 end = (end + (MAX_LINES) - 1 < mac_num) ?
750                     end + (MAX_LINES) - 1 : mac_num;
751                 begin = (end - (MAX_LINES) + 1 > 0) ?
752                     end - (MAX_LINES) + 1 : 1;
753                 scroll_rows(first, begin, end, 9, 0);
754             }
755             continue;
756         case KEY_PPAGE:
757             if (begin > 1) {
758                 begin = (begin - (MAX_LINES) + 1 > 0) ?
759                     begin - (MAX_LINES) + 1 : 1;
760                 end = (begin + (MAX_LINES) - 1 < mac_num) ?
761                     begin + (MAX_LINES) - 1 : mac_num;
762                 scroll_rows(first, begin, end, 9, 0);
763             }
764             continue;
765         case KEY_END:
766             if (end < mac_num) {
767                 begin = (mac_num > MAX_LINES) ? mac_num + 1 - (MAX_LINES) : 1;
768                 end = mac_num;
769                 scroll_rows(first, begin, end, 9, 0);
770             }
771             continue;
772         case KEY_HOME:
773             if (begin > 1) {
774                 begin = 1;
775                 end = (mac_num > MAX_LINES) ? MAX_LINES : mac_num;
776                 scroll_rows(first, begin, end, 9, 0);
777             }
778             continue;
779         }
780         continue;
781     }
782
783     print_help(ANY_KEY);
784   exit:
785     getch();
786   quit:
787     while ((curr = first)) {
788         first = curr->next;
789         free(curr);
790     }
791     if (AuthMac)
792         free(AuthMac);
793     print_top(NULL, NULL);
794     clear_main(0);
795 }
796
797 void nwn_auth_mac()
798 {
799     struct MacListStat *pmac, *first = NULL, *curr = NULL;
800     char Mac[] =
801         { 0x2b, 0x06, 0x01, 0x04, 0x01, 0x87, 0x29, 0x03, 0x01, 0x03, 0x02,
802         0x02, 0x01, 0x02, 0x00
803     };
804     char MacAllow[] =
805         { 0x2b, 0x06, 0x01, 0x04, 0x01, 0x87, 0x29, 0x03, 0x01, 0x03, 0x02,
806         0x02, 0x01, 0x03, 0x00
807     };
808     char MacRowStatus[] =
809         { 0x2b, 0x06, 0x01, 0x04, 0x01, 0x87, 0x29, 0x03, 0x01, 0x03, 0x02,
810         0x02, 0x01, 0x04, 0x00
811     };
812     char message[1024], auth_enable[] =
813         { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
814     char destroy = 6, create = 4, allow = 1;
815     int i, auth_mac = 0, mac_num = 0, begin, end;
816     varbind varbinds[3];
817     print_top(NULL, AUTH_TITLE);
818
819     mvwaddstr(main_sub, 2, 0, MAC_HEADER);
820     wrefresh(main_sub);
821     print_help(WAIT_RET);
822
823     mac_num = 1;
824     varbinds[0].oid = Mac;
825     varbinds[0].len_oid = sizeof(Mac);
826     varbinds[0].value = Mac;
827     varbinds[0].len_val = 0;
828     varbinds[0].type = NULL_VALUE;
829     if (snmp(varbinds, 1, GET_NEXT) <= 0) {
830         print_helperr(ERR_RET);
831         goto exit;
832     }
833
834     while (memcmp(varbinds[0].oid, Mac, sizeof(Mac) - 1) == 0) {
835
836         Mac[sizeof(Mac) - 1] = varbinds[0].oid[sizeof(Mac) - 1];
837         MacAllow[sizeof(MacAllow) - 1] = varbinds[0].oid[sizeof(Mac) - 1];
838         MacRowStatus[sizeof(MacRowStatus) - 1] =
839             varbinds[0].oid[sizeof(Mac) - 1];
840
841         varbinds[0].oid = Mac;
842         varbinds[0].len_oid = sizeof(Mac);
843         varbinds[0].value = Mac;
844         varbinds[0].len_val = 0;
845         varbinds[0].type = NULL_VALUE;
846         varbinds[1].oid = MacAllow;
847         varbinds[1].len_oid = sizeof(MacAllow);
848         varbinds[1].value = Mac;
849         varbinds[1].len_val = 0;
850         varbinds[1].type = NULL_VALUE;
851         varbinds[2].oid = MacRowStatus;
852         varbinds[2].len_oid = sizeof(MacRowStatus);
853         varbinds[2].value = Mac;
854         varbinds[2].len_val = 0;
855         varbinds[2].type = NULL_VALUE;
856         if (snmp(varbinds, 3, GET) < 3) {
857             print_helperr(ERR_RET);
858             goto exit;
859         }
860         if (memcmp(auth_enable, varbinds[0].value, 6)) {
861             if (first == NULL) {
862                 first = (struct MacListStat *)
863                     malloc(sizeof(struct MacListStat));
864                 curr = first;
865             } else {
866                 curr->next = (struct MacListStat *)
867                     malloc(sizeof(struct MacListStat));
868                 curr = curr->next;
869             }
870             memcpy(curr->addr, varbinds[0].value, 6);
871             curr->next = NULL;
872             mac_num++;
873         } else
874             auth_mac = 1;
875
876
877         varbinds[0].oid = Mac;
878         varbinds[0].len_oid = sizeof(Mac);
879         varbinds[0].value = Mac;
880         varbinds[0].len_val = 0;
881         varbinds[0].type = NULL_VALUE;
882         if (snmp(varbinds, 1, GET_NEXT) <= 0) {
883             print_helperr(ERR_RET);
884             goto exit;
885         }
886     }
887
888     begin = 1;
889     end = (mac_num > MAX_LINES) ? MAX_LINES : mac_num;
890
891     sprintf(message, "%s%s", MAC_AUTH, (auth_mac) ? OFF : ON);
892     mvwaddstr(main_sub, 0, 0, message);
893
894     scroll_rows(first, begin, end, 3, 0);
895
896     noecho();
897
898     print_help(MAC_HELP);
899     while (1) {
900         switch (getch()) {
901         case 'Q':
902         case 'q':
903             goto quit;
904         case 'a':
905             auth_mac = on_off(0, strlen(MAC_AUTH)) - 1;
906             clear_main_new(0, 1);
907             print_menusel(0, 0, MAC_AUTH, (auth_mac) ? OFF : ON);
908             continue;
909         case 'd':
910             mvwaddstr(main_sub, 1, 0, MAC_DEL);
911             get_value(message, 1, strlen(MAC_DEL), 5, INT_STRING,
912                 1, mac_num - 1, NULL);
913             i = atoi(message);
914             if (i == 1) {
915                 pmac = first;
916                 first = first->next;
917                 free(pmac);
918             } else {
919                 curr = first;
920                 while (--i > 1)
921                     curr = curr->next;
922                 pmac = curr->next;
923                 curr->next = pmac->next;
924                 free(pmac);
925             }
926             mac_num--;
927             begin = 1;
928             end = (mac_num > MAX_LINES) ? MAX_LINES : mac_num;
929             scroll_rows(first, begin, end, 3, 0);
930             clear_main_new(1, 2);
931             continue;
932         case 'n':
933         case 'N':
934             mvwaddstr(main_sub, 1, 0, MAC_ADD);
935             curr = first;
936             while (curr && curr->next)
937                 curr = curr->next;
938             if (first == NULL) {
939                 first = (struct MacListStat *)
940                     malloc(sizeof(struct MacListStat));
941                 curr = first;
942             } else {
943                 curr->next = (struct MacListStat *)
944                     malloc(sizeof(struct MacListStat));
945                 curr = curr->next;
946             }
947             curr->next = NULL;
948             mac_num++;
949             get_mac(curr->addr, 1, strlen(MAC_ADD));
950 /*
951             for (i = 0; i < 6; i++) {
952                 get_value(message, 1, 20 + i * 3, 3, ANY_STRING, 0, 0, NULL);
953                 curr->addr[i] = strtol(message, NULL, 16);
954             }
955             clear_main_new(1, 2);
956 */
957             begin = 1;
958             end = (mac_num > MAX_LINES) ? MAX_LINES : mac_num;
959             scroll_rows(first, begin, end, 3, 0);
960             continue;
961         case 'w':
962         case 'W':
963             print_help(WAIT_SET);
964
965             Mac[sizeof(Mac) - 1] = 0;
966
967             varbinds[0].oid = Mac;
968             varbinds[0].len_oid = sizeof(Mac);
969             varbinds[0].value = Mac;
970             varbinds[0].len_val = 0;
971             varbinds[0].type = NULL_VALUE;
972             if (snmp(varbinds, 1, GET_NEXT) <= 0) {
973                 print_helperr(ERR_RET);
974                 goto exit;
975             }
976             while (memcmp(varbinds[0].oid, Mac, sizeof(Mac) - 1) == 0) {
977
978                 MacRowStatus[sizeof(MacRowStatus) - 1] =
979                     varbinds[0].oid[sizeof(Mac) - 1];
980                 varbinds[0].oid = MacRowStatus;
981                 varbinds[0].len_oid = sizeof(MacRowStatus);
982                 varbinds[0].value = &destroy;
983                 varbinds[0].len_val = 1;
984                 varbinds[0].type = INT_VALUE;
985                 if (snmp(varbinds, 1, SET) <= 0) {
986                     print_helperr(ERR_SET);
987                     goto exit;
988                 }
989                 varbinds[0].oid = Mac;
990                 varbinds[0].len_oid = sizeof(Mac);
991                 varbinds[0].value = Mac;
992                 varbinds[0].len_val = 0;
993                 varbinds[0].type = NULL_VALUE;
994                 if (snmp(varbinds, 1, GET_NEXT) <= 0) {
995                     print_helperr(ERR_RET);
996                     goto exit;
997                 }
998             }
999
1000
1001             curr = first;
1002             i = 1;
1003
1004             if (auth_mac) {
1005                 Mac[sizeof(Mac) - 1] = i;
1006                 MacAllow[sizeof(MacAllow) - 1] = i;
1007                 MacRowStatus[sizeof(MacRowStatus) - 1] = i;
1008
1009                 varbinds[0].oid = MacRowStatus;
1010                 varbinds[0].len_oid = sizeof(MacRowStatus);
1011                 varbinds[0].value = &create;
1012                 varbinds[0].len_val = 1;
1013                 varbinds[0].type = INT_VALUE;
1014                 varbinds[1].oid = Mac;
1015                 varbinds[1].len_oid = sizeof(Mac);
1016                 varbinds[1].value = auth_enable;
1017                 varbinds[1].len_val = 6;
1018                 varbinds[1].type = STRING_VALUE;
1019                 varbinds[2].oid = MacAllow;
1020                 varbinds[2].len_oid = sizeof(MacAllow);
1021                 varbinds[2].value = &allow;
1022                 varbinds[2].len_val = 1;
1023                 varbinds[2].type = INT_VALUE;
1024                 print_help(WAIT_SET);
1025                 if (snmp(varbinds, 3, SET) <= 0) {
1026                     print_helperr(ERR_SET);
1027                     goto exit;
1028                 }
1029                 i++;
1030             }
1031
1032
1033
1034
1035             while (curr != NULL) {
1036                 Mac[sizeof(Mac) - 1] = i;
1037                 MacAllow[sizeof(MacAllow) - 1] = i;
1038                 MacRowStatus[sizeof(MacRowStatus) - 1] = i;
1039
1040                 varbinds[0].oid = MacRowStatus;
1041                 varbinds[0].len_oid = sizeof(MacRowStatus);
1042                 varbinds[0].value = &create;
1043                 varbinds[0].len_val = 1;
1044                 varbinds[0].type = INT_VALUE;
1045                 varbinds[1].oid = Mac;
1046                 varbinds[1].len_oid = sizeof(Mac);
1047                 varbinds[1].value = curr->addr;
1048                 varbinds[1].len_val = 6;
1049                 varbinds[1].type = STRING_VALUE;
1050                 varbinds[2].oid = MacAllow;
1051                 varbinds[2].len_oid = sizeof(MacAllow);
1052                 varbinds[2].value = &allow;
1053                 varbinds[2].len_val = 1;
1054                 varbinds[2].type = INT_VALUE;
1055                 print_help(WAIT_SET);
1056                 if (snmp(varbinds, 3, SET) <= 0) {
1057                     print_helperr(ERR_SET);
1058                     goto exit;
1059                 }
1060                 curr = curr->next;
1061                 i++;
1062             }
1063             wbkgd(main_sub, A_NORMAL);
1064             wrefresh(main_sub);
1065             print_help(DONE_SET);
1066             goto exit;
1067         case KEY_DOWN:
1068         case KEY_RIGHT:
1069             if (end < mac_num) {
1070                 begin++;
1071                 end++;
1072                 scroll_rows(first, begin, end, 3, 0);
1073             }
1074
1075             continue;
1076         case KEY_UP:
1077         case KEY_LEFT:
1078             if (begin > 1) {
1079                 begin--;
1080                 end--;
1081                 scroll_rows(first, begin, end, 3, 0);
1082             }
1083             continue;
1084         }
1085         continue;
1086     }
1087
1088     print_help(ANY_KEY);
1089   exit:
1090     getch();
1091   quit:
1092     while ((curr = first)) {
1093         first = curr->next;
1094         free(curr);
1095     }
1096     print_top(NULL, NULL);
1097     clear_main(0);
1098 }