]> git.decadent.org.uk Git - ap-utils.git/blob - src/auth.c
Imported Upstream version 1.5~pre2
[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 (sec): ")
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 (sec): ")
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             memcpy(&ea_dest_port, varbinds[4].value, 2);
225             ea_dest_port = ntohs(ea_dest_port);
226             sprintf(message, "%s%d", RADIUS_DEST_PORT, ea_dest_port);
227             mvwaddstr(main_sub, 2, 0, message);
228
229             sprintf(message, "%s%s", RADIUS_SECRET, ea_secret);
230             mvwaddstr(main_sub, 3, 0, message);
231
232             memcpy(&ea_time, varbinds[3].value, 2);
233             ea_time = ntohs(ea_time);
234             sprintf(message, "%s%d", RADIUS_TIME, ea_time);
235             mvwaddstr(main_sub, 4, 0, message);
236
237             memcpy(&ea_port, varbinds[2].value, 2);
238             ea_port = ntohs(ea_port);
239             sprintf(message, "%s%d", RADIUS_PORT, ea_port);
240             mvwaddstr(main_sub, 5, 0, message);
241         }
242     } else if (ap_type == ATMEL12350 &&
243         (ap_vendorext == GEMTEK || ap_vendorext == EZYNET)) {
244         sprintf(message, "%s%s", MAC_AUTH, AuthModes_AOD[auth_mode - 1]);
245         mvwaddstr(main_sub, 0, 0, message);
246
247         if (ap_vendorext == EZYNET) {
248             ea_mode = *(varbinds[1].value);
249             sprintf(message, "%s%s", DOT1X_MODE, Dot1xModes[ea_mode - 1]);
250             mvwaddstr(main_sub, 1, 0, message);
251
252             ea_time = varbinds[2].len_val == 2 ?
253                 (varbinds[2].value[0] << 8) | varbinds[2].value[1] :
254                 varbinds[2].value[0] < 0x80 ?
255                 varbinds[2].value[0] : 0xff00 | varbinds[2].value[0];
256             sprintf(message, "%s%d", DOT1X_TIME, ea_time);
257             mvwaddstr(main_sub, 2, 0, message);
258
259             memcpy(&ea_ip.s_addr, varbinds[3].value, 4);
260             sprintf(message, "%s%s", DOT1X_IP, inet_ntoa(ea_ip));
261             mvwaddstr(main_sub, 3, 0, message);
262
263             sprintf(message, "%s%s", DOT1X_SECRET, ea_secret);
264             mvwaddstr(main_sub, 4, 0, message);
265         }
266     } else {
267         sprintf(message, "%s%s", MAC_AUTH, AuthModes_OO[auth_mode - 1]);
268         mvwaddstr(main_sub, 0, 0, message);
269     }
270     mvwaddstr(main_sub, 7, 0, _("Authorized MAC addresses:"));
271     wattrset(main_sub, COLOR_PAIR(13));
272     mvwaddstr(main_sub, 8, 0, MAC_HEADER);
273     wattrset(main_sub, A_NORMAL);
274     wrefresh(main_sub);
275
276     print_help("Trying to retrieve auth. MAC address list from AP. Please wait.");
277
278     total_mac = 0;
279     mac_num = 0;
280
281     while (mac_num <= total_mac) {
282         get.Action = 0x02; rshort(get.Action);
283         get.NumOfAllTableAddresses = total_mac; rshort(get.NumOfAllTableAddresses);
284         get.NumOfCurrentAddress = mac_num; rshort(get.NumOfCurrentAddress);
285
286         varbinds[0].oid = AutorizedMac;
287         varbinds[0].len_oid = sizeof(AutorizedMac);
288         varbinds[0].value = (char *) &get;
289         varbinds[0].len_val = 12;
290         varbinds[0].type = STRING_VALUE;
291
292         i = snmp(varbinds, 1, SET);
293         if (i == 0) {
294             print_helperr(ERR_SET);
295             goto exit;
296         }
297         if (i < 0)
298             break;
299
300         if (varbinds[0].len_val == 12) {
301             if (AuthMac)
302                 free(AuthMac);
303             AuthMac =
304                 (struct AuthorizedMacTableString *) malloc(varbinds[0].
305                                                            len_val);
306             memcpy(AuthMac, varbinds[0].value, varbinds[0].len_val);
307 /*          AuthMac =
308                 (struct AuthorizedMacTableString *) varbinds[0].value;*/
309         } else {
310             print_helperr(PACKET_ERROR);
311             goto exit;
312         }
313
314         rshort(AuthMac->NumOfAllTableAddresses);
315         total_mac =
316             (AuthMac->NumOfAllTableAddresses ==
317              65535) ? 0 : AuthMac->NumOfAllTableAddresses;
318
319         if (mac_num) {
320             if (first == NULL) {
321                 first = (struct MacListStat *)
322                     malloc(sizeof(struct MacListStat));
323                 curr = first;
324             } else {
325                 curr->next = (struct MacListStat *)
326                     malloc(sizeof(struct MacListStat));
327                 curr = curr->next;
328             }
329             memcpy(curr->addr, AuthMac->MacAddress, 6);
330             curr->next = NULL;
331         }
332         mac_num++;
333     }
334
335     begin = (mac_num > MAX_LINES) ? mac_num + 1 - (MAX_LINES) : 1;
336     end = mac_num;
337
338     if (i < 0) {
339         mvwaddstr(main_sub, 9, 0, _("(insufficient community used)"));
340         wrefresh(main_sub);
341     } else {
342         scroll_rows(first, begin, end, 9, 0);
343     }
344
345     noecho();
346
347     if (ap_type == ATMEL410 && ap_vendorext == SBRIDGES)
348         print_help(RADIUS_HELP);
349     else if (ap_type == ATMEL12350 && ap_vendorext == EZYNET)
350         print_help(DOT1X_HELP);
351     else
352         print_help(MAC_HELP);
353
354     while (1) {
355         switch (getch()) {
356         case 'q':
357         case 'Q':
358             goto quit;
359         case 'a':
360         case 'A':
361             auth_mode = menu_choose(0, strlen(MAC_AUTH),
362                 ap_type == ATMEL410 && ap_vendorext == SBRIDGES ?
363                     AuthModes_IOR :
364                 ap_type == ATMEL12350 &&
365                     (ap_vendorext == GEMTEK || ap_vendorext == EZYNET) ?
366                     AuthModes_AOD :
367                     AuthModes_OO,
368                 ap_vendorext == NONE ?
369                     2 : 3
370             );
371             clear_main_new(0, 1);
372             print_menusel(0, 0, MAC_AUTH,
373                 ap_type == ATMEL410 && ap_vendorext == SBRIDGES ?
374                     AuthModes_IOR[auth_mode] :
375                 ap_type == ATMEL12350 &&
376                     (ap_vendorext == GEMTEK || ap_vendorext == EZYNET) ?
377                     AuthModes_AOD[auth_mode] :
378                     AuthModes_OO[auth_mode]
379             );
380             auth_mode++;
381 /*
382             auth_mode = on_off(0, strlen(MAC_AUTH));
383             clear_main_new(0, 1);
384             print_menusel(0, 0, MAC_AUTH, (auth_mode == 1) ? ON : OFF);
385 */
386             m_authmac = 1;
387             continue;
388         case 'd':
389         case 'D':
390             /* no MACs available for deletion */
391             if (mac_num == 1)
392                 continue;
393
394             mvwaddstr(main_sub, 6, 0, MAC_DEL);
395             get_value(message, 6, strlen(MAC_DEL), 5, INT_STRING,
396                 0, mac_num - 1, NULL);
397             i = atoi(message);
398             if (i == 0) {
399                 clear_main_new(6, 7);
400                 continue;
401             }
402             curr = first;
403             if (i == 1) {
404                 if (curr->next) {
405                     pmac = curr->next;
406                     free(first);
407                     first = pmac;
408                 }
409             } else {
410                 int j = i;
411
412                 while (--j > 1)
413                     curr = curr->next;
414                 pmac = curr->next;
415                 curr->next = pmac->next;
416                 free(pmac);
417             }
418
419             mac_num--;
420
421             /* Rather do not ask how this works. */
422             if (i < begin) {
423                 begin--;
424                 end--;
425             } else if (i > (end - 1)) {
426                 /* Nothing to do! */
427             } else { /* begin <= i <= (end - 1) */
428                 if ((begin == 1) && ((end - 1) == mac_num)) {
429                     end--;
430                 } else if ((begin > 1) && ((end - 1) < mac_num)) {
431                     /* Uncomment for top side scrolling first. */
432 /*
433                     begin--;
434                     end--;
435 */
436                 } else if (begin > 1) {
437                     begin--;
438                     end--;
439                 }
440             }
441 #if 0 /* DEBUG */
442             sprintf(message, "MAX_LINES: %i mac_num: %i begin: %i end: %i",
443                 MAX_LINES, mac_num, begin, end);
444             clear_main(0);
445             mvwaddstr(main_sub, 0, 0, message);
446             wrefresh(main_sub);
447             exit(0);
448 #endif /* DEBUG */
449             scroll_rows(first, begin, end, 9, 0);
450             clear_main_new(6, 7);
451             continue;
452         case 'n':
453         case 'N':
454             if (mac_num == 1) {
455                 free(first);
456                 first = NULL;
457             }
458 again:
459             mvwaddstr(main_sub, 6, 0, MAC_ADD);
460             get_mac(message, 6, strlen(MAC_ADD));
461
462             curr = first;
463             i = 1;
464             while (curr) {
465                 if (memcmp(curr->addr, message, 6) == 0) {
466                     sprintf(message, _("Given MAC already exists in MAC list "
467                         "at position %d. Press any key."), i);
468                     print_helperr(message);
469                     getch();
470                     if (ap_type == ATMEL410 && ap_vendorext == SBRIDGES)
471                         print_help(RADIUS_HELP);
472                     else if (ap_type == ATMEL12350 && ap_vendorext == EZYNET)
473                         print_help(DOT1X_HELP);
474                     else
475                         print_help(MAC_HELP);
476                     goto again;
477                 }
478                 curr = curr->next;
479                 i++;
480             }
481
482             curr = first;
483             while (curr && curr->next)
484                 curr = curr->next;
485             if (first == NULL) {
486                 first = (struct MacListStat *)
487                     malloc(sizeof(struct MacListStat));
488                 curr = first;
489             } else {
490                 curr->next = (struct MacListStat *)
491                     malloc(sizeof(struct MacListStat));
492                 curr = curr->next;
493             }
494             curr->next = NULL;
495             memcpy(curr->addr, message, 6);
496             mac_num++;
497 /*          get_value(message, 1, strlen(MAC_ADD), 13, ANY_STRING, 0, 0,
498                 NULL);
499
500             for (i = 0; i < 6; i++) {
501                 mess[0] = message[2 * i];
502                 mess[1] = message[2 * i + 1];
503                 mess[2] = '\0';
504                 curr->addr[i] = strtol(mess, NULL, 16);
505             }
506             clear_main_new(1, 2);
507 */
508             begin = (mac_num > MAX_LINES) ? mac_num + 1 - (MAX_LINES) : 1;
509             end = mac_num;
510             scroll_rows(first, begin, end, 9, 0);
511             clear_main_new(6, 7);
512             continue;
513         case 'f':
514         case 'F':
515             if (ap_type == ATMEL410 && ap_vendorext == SBRIDGES && auth_mode == 3) {
516                 get_value(message, 5, strlen(RADIUS_PORT), 6,
517                     INT_STRING, 0, 65535, RADIUS_HELP);
518                 ea_port = atoi(message);
519                 m_ea_port = 1;
520             };
521             continue;
522         case 'i':
523         case 'I':
524             if (ap_type == ATMEL410 && ap_vendorext == SBRIDGES && auth_mode == 3) {
525                 get_ip(&ea_ip, 1, strlen(RADIUS_IP), RADIUS_HELP);
526                 m_ea_ip = 1;
527             }
528             if (ap_type == ATMEL12350 && ap_vendorext == EZYNET) {
529                 get_ip(&ea_ip, 3, strlen(DOT1X_IP), DOT1X_HELP);
530                 m_ea_ip = 1;
531             }
532             continue;
533         case 'm':
534         case 'M':
535             if (ap_type == ATMEL12350 && ap_vendorext == EZYNET) {
536                 ea_mode = menu_choose(1, strlen(DOT1X_MODE), Dot1xModes, 3);
537                 clear_main_new(1, 2);
538                 print_menusel(1, 0, DOT1X_MODE, Dot1xModes[ea_mode]);
539                 ea_mode++;
540                 m_ea_mode = 1;
541             }
542             continue;
543         case 'p':
544         case 'P':
545             if (ap_type == ATMEL410 && ap_vendorext == SBRIDGES && auth_mode == 3) {
546                 get_value(message, 2, strlen(RADIUS_DEST_PORT), 6,
547                     INT_STRING, 0, 65535, RADIUS_HELP);
548                 ea_dest_port = atoi(message);
549                 m_ea_dest_port = 1;
550             }
551             continue;
552         case 's':
553         case 'S':
554             if (ap_type == ATMEL410 && ap_vendorext == SBRIDGES && auth_mode == 3) {
555                 get_value(ea_secret, 3, strlen(RADIUS_SECRET), -33,
556                     ANY_STRING, 0, 0, NULL);
557                 m_ea_secret = 1;
558             }
559             if (ap_type == ATMEL12350 && ap_vendorext == EZYNET) {
560                 get_value(ea_secret, 4, strlen(DOT1X_SECRET), -17,
561                     ANY_STRING, 0, 0, NULL);
562                 m_ea_secret = 1;
563             }
564             continue;
565         case 't':
566         case 'T':
567             if (ap_type == ATMEL410 && ap_vendorext == SBRIDGES && auth_mode == 3) {
568                 get_value(message, 4, strlen(RADIUS_TIME), 6,
569                     INT_STRING, 0, 65535, RADIUS_HELP);
570                 ea_time = atoi(message);
571                 m_ea_time = 1;
572             }
573             if (ap_type == ATMEL12350 && ap_vendorext == EZYNET) {
574                 get_value(message, 2, strlen(DOT1X_TIME), 6,
575                     INT_STRING, 0, 65535, RADIUS_HELP);
576                 ea_time = atoi(message);
577                 m_ea_time = 1;
578             }
579             continue;
580         case 'w':
581         case 'W':
582             curr = first;
583             i = (mac_num == 1 ? 0 : 1);
584             while (curr != NULL) {
585                 get.Action = 0x01; rshort(get.Action);
586                 get.NumOfAllTableAddresses = mac_num - 1; rshort(get.NumOfAllTableAddresses);
587                 get.NumOfCurrentAddress = i; rshort(get.NumOfCurrentAddress);
588                 memcpy(get.MacAddress, curr->addr, 6);
589                 varbinds[0].oid = AutorizedMac;
590                 varbinds[0].len_oid = sizeof(AutorizedMac);
591                 varbinds[0].value = (char *) &get;
592                 varbinds[0].len_val = 12;
593                 varbinds[0].type = STRING_VALUE;
594                 print_help(WAIT_SET);
595                 if (snmp(varbinds, 1, SET) <= 0) {
596                     print_helperr(ERR_SET);
597                     goto exit;
598                 }
599                 if (varbinds[0].len_val != 12) {
600                     print_helperr(PACKET_ERROR);
601                     goto exit;
602                 }
603                 curr = curr->next;
604                 i++;
605             }
606
607             i = 0;
608
609             if (m_authmac) {
610                 int c = swap4(auth_mode);
611
612                 varbinds[i].oid = AuthorizationMacEnable;
613                 varbinds[i].len_oid = sizeof(AuthorizationMacEnable);
614                 varbinds[i].value = (char *) &c;
615                 varbinds[i].len_val = 1;
616                 varbinds[i].type = INT_VALUE;
617                 i++;
618             }
619
620             if (m_ea_port) {
621                 varbinds[i].oid = AuthRadiusPort;
622                 varbinds[i].len_oid = sizeof(AuthRadiusPort);
623                 ea_port = htons(ea_port);
624                 varbinds[i].value = (char *) &ea_port;
625                 varbinds[i].len_val = 2;
626                 varbinds[i].type = INT_VALUE;
627                 i++;
628             }
629
630             if (m_ea_ip) {
631                 if (ap_type == ATMEL410 && ap_vendorext == SBRIDGES) {
632                     varbinds[i].oid = AuthRadiusIP;
633                     varbinds[i].len_oid = sizeof(AuthRadiusIP);
634                 }
635
636                 if (ap_type == ATMEL12350 && ap_vendorext == EZYNET) {
637                     varbinds[i].oid = ServerIP;
638                     varbinds[i].len_oid = sizeof(ServerIP);
639                 }
640
641                 ea_ip.s_addr = htonl(ea_ip.s_addr);
642                 ea_ip.s_addr = swap4(ea_ip.s_addr);
643                 varbinds[i].value = (char *) &ea_ip.s_addr;
644                 varbinds[i].len_val = 4;
645                 varbinds[i].type = INT_VALUE;
646                 i++;
647             }
648
649             if (m_ea_mode) {
650                 varbinds[i].oid = Dot1xEnable;
651                 varbinds[i].len_oid = sizeof(Dot1xEnable);
652                 ea_mode = swap4(ea_mode);
653                 varbinds[i].value = (char *) &ea_mode;
654                 varbinds[i].len_val = 1;
655                 varbinds[i].type = INT_VALUE;
656                 i++;
657             }
658
659             if (m_ea_dest_port) {
660                 varbinds[i].oid = AuthRadiusDestinPort;
661                 varbinds[i].len_oid = sizeof(AuthRadiusDestinPort);
662                 ea_dest_port = htons(ea_dest_port);
663                 varbinds[i].value = (char *) &ea_dest_port;
664                 varbinds[i].len_val = 2;
665                 varbinds[i].type = INT_VALUE;
666                 i++;
667             }
668
669             if (m_ea_secret) {
670                 int c = strlen(ea_secret);
671
672                 if (ap_type == ATMEL410 && ap_vendorext == SBRIDGES) {
673                     varbinds[i].oid = AuthRadiusSecretLength;
674                     varbinds[i].len_oid = sizeof(AuthRadiusSecretLength);
675                     varbinds[i].value = (char *) &c;
676                     varbinds[i].len_val = 1;
677                     varbinds[i].type = INT_VALUE;
678                     i++;
679
680                     varbinds[i].oid = AuthRadiusSecret;
681                     varbinds[i].len_oid = sizeof(AuthRadiusSecret);
682                 }
683
684                 if (ap_type == ATMEL12350 && ap_vendorext == EZYNET) {
685                     varbinds[i].oid = ServerSecret;
686                     varbinds[i].len_oid = sizeof(ServerSecret);
687                 }
688
689                 varbinds[i].value = ea_secret;
690                 varbinds[i].len_val = c;
691                 varbinds[i].type = STRING_VALUE;
692                 i++;
693             }
694
695             if (m_ea_time) {
696                 if (ap_type == ATMEL410 && ap_vendorext == SBRIDGES) {
697                     varbinds[i].oid = AuthRadiusReauthorizationTime;
698                     varbinds[i].len_oid = sizeof(AuthRadiusReauthorizationTime);
699                 }
700
701                 if (ap_type == ATMEL12350 && ap_vendorext == EZYNET) {
702                     varbinds[i].oid = BroadcastKeyPeriod;
703                     varbinds[i].len_oid = sizeof(BroadcastKeyPeriod);
704                 }
705
706                 ea_time = htons(ea_time);
707                 varbinds[i].value = (char *) &ea_time;
708                 varbinds[i].len_val = 2;
709                 varbinds[i].type = INT_VALUE;
710                 i++;
711             }
712
713             print_help(WAIT_SET);
714             if (snmp(varbinds, i, SET) <= 0) {
715                 print_helperr(ERR_SET);
716                 goto exit;
717             }
718             print_help(DONE_SET);
719             goto exit;
720         case KEY_DOWN:
721         case KEY_RIGHT:
722             if (end < mac_num) {
723                 begin++;
724                 end++;
725                 scroll_rows(first, begin, end, 9, 0);
726             }
727             continue;
728         case KEY_UP:
729         case KEY_LEFT:
730             if (begin > 1) {
731                 begin--;
732                 end--;
733                 scroll_rows(first, begin, end, 9, 0);
734             }
735             continue;
736         case KEY_NPAGE:
737             if (end < mac_num) {
738                 end = (end + (MAX_LINES) - 1 < mac_num) ?
739                     end + (MAX_LINES) - 1 : mac_num;
740                 begin = (end - (MAX_LINES) + 1 > 0) ?
741                     end - (MAX_LINES) + 1 : 1;
742                 scroll_rows(first, begin, end, 9, 0);
743             }
744             continue;
745         case KEY_PPAGE:
746             if (begin > 1) {
747                 begin = (begin - (MAX_LINES) + 1 > 0) ?
748                     begin - (MAX_LINES) + 1 : 1;
749                 end = (begin + (MAX_LINES) - 1 < mac_num) ?
750                     begin + (MAX_LINES) - 1 : mac_num;
751                 scroll_rows(first, begin, end, 9, 0);
752             }
753             continue;
754         case KEY_END:
755             if (end < mac_num) {
756                 begin = (mac_num > MAX_LINES) ? mac_num + 1 - (MAX_LINES) : 1;
757                 end = mac_num;
758                 scroll_rows(first, begin, end, 9, 0);
759             }
760             continue;
761         case KEY_HOME:
762             if (begin > 1) {
763                 begin = 1;
764                 end = (mac_num > MAX_LINES) ? MAX_LINES : mac_num;
765                 scroll_rows(first, begin, end, 9, 0);
766             }
767             continue;
768         }
769         continue;
770     }
771
772     print_help(ANY_KEY);
773   exit:
774     getch();
775   quit:
776     while ((curr = first)) {
777         first = curr->next;
778         free(curr);
779     }
780     if (AuthMac)
781         free(AuthMac);
782     print_top(NULL, NULL);
783     clear_main(0);
784 }
785
786 void nwn_auth_mac()
787 {
788     struct MacListStat *pmac, *first = NULL, *curr = NULL;
789     char Mac[] =
790         { 0x2b, 0x06, 0x01, 0x04, 0x01, 0x87, 0x29, 0x03, 0x01, 0x03, 0x02,
791         0x02, 0x01, 0x02, 0x00
792     };
793     char MacAllow[] =
794         { 0x2b, 0x06, 0x01, 0x04, 0x01, 0x87, 0x29, 0x03, 0x01, 0x03, 0x02,
795         0x02, 0x01, 0x03, 0x00
796     };
797     char MacRowStatus[] =
798         { 0x2b, 0x06, 0x01, 0x04, 0x01, 0x87, 0x29, 0x03, 0x01, 0x03, 0x02,
799         0x02, 0x01, 0x04, 0x00
800     };
801     char message[1024], auth_enable[] =
802         { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
803     char destroy = 6, create = 4, allow = 1;
804     int i, auth_mac = 0, mac_num = 0, begin, end;
805     varbind varbinds[3];
806     print_top(NULL, AUTH_TITLE);
807
808     mvwaddstr(main_sub, 2, 5, MAC_HEADER);
809     wrefresh(main_sub);
810     print_help(WAIT_RET);
811
812     mac_num = 1;
813     varbinds[0].oid = Mac;
814     varbinds[0].len_oid = sizeof(Mac);
815     varbinds[0].value = Mac;
816     varbinds[0].len_val = 0;
817     varbinds[0].type = NULL_VALUE;
818     if (snmp(varbinds, 1, GET_NEXT) <= 0) {
819         print_helperr(ERR_RET);
820         goto exit;
821     }
822
823     while (memcmp(varbinds[0].oid, Mac, sizeof(Mac) - 1) == 0) {
824
825         Mac[sizeof(Mac) - 1] = varbinds[0].oid[sizeof(Mac) - 1];
826         MacAllow[sizeof(MacAllow) - 1] = varbinds[0].oid[sizeof(Mac) - 1];
827         MacRowStatus[sizeof(MacRowStatus) - 1] =
828             varbinds[0].oid[sizeof(Mac) - 1];
829
830         varbinds[0].oid = Mac;
831         varbinds[0].len_oid = sizeof(Mac);
832         varbinds[0].value = Mac;
833         varbinds[0].len_val = 0;
834         varbinds[0].type = NULL_VALUE;
835         varbinds[1].oid = MacAllow;
836         varbinds[1].len_oid = sizeof(MacAllow);
837         varbinds[1].value = Mac;
838         varbinds[1].len_val = 0;
839         varbinds[1].type = NULL_VALUE;
840         varbinds[2].oid = MacRowStatus;
841         varbinds[2].len_oid = sizeof(MacRowStatus);
842         varbinds[2].value = Mac;
843         varbinds[2].len_val = 0;
844         varbinds[2].type = NULL_VALUE;
845         if (snmp(varbinds, 3, GET) < 3) {
846             print_helperr(ERR_RET);
847             goto exit;
848         }
849         if (memcmp(auth_enable, varbinds[0].value, 6)) {
850             if (first == NULL) {
851                 first = (struct MacListStat *)
852                     malloc(sizeof(struct MacListStat));
853                 curr = first;
854             } else {
855                 curr->next = (struct MacListStat *)
856                     malloc(sizeof(struct MacListStat));
857                 curr = curr->next;
858             }
859             memcpy(curr->addr, varbinds[0].value, 6);
860             curr->next = NULL;
861             mac_num++;
862         } else
863             auth_mac = 1;
864
865
866         varbinds[0].oid = Mac;
867         varbinds[0].len_oid = sizeof(Mac);
868         varbinds[0].value = Mac;
869         varbinds[0].len_val = 0;
870         varbinds[0].type = NULL_VALUE;
871         if (snmp(varbinds, 1, GET_NEXT) <= 0) {
872             print_helperr(ERR_RET);
873             goto exit;
874         }
875     }
876
877     begin = 1;
878     end = (mac_num > MAX_LINES) ? MAX_LINES : mac_num;
879
880     sprintf(message, "%s%s", MAC_AUTH, (auth_mac) ? OFF : ON);
881     mvwaddstr(main_sub, 0, 0, message);
882
883     scroll_rows(first, begin, end, 3, 0);
884
885     noecho();
886
887     print_help(MAC_HELP);
888     while (1) {
889         switch (getch()) {
890         case 'Q':
891         case 'q':
892             goto quit;
893         case 'a':
894             auth_mac = on_off(0, strlen(MAC_AUTH)) - 1;
895             clear_main_new(0, 1);
896             print_menusel(0, 0, MAC_AUTH, (auth_mac) ? OFF : ON);
897             continue;
898         case 'd':
899             mvwaddstr(main_sub, 1, 0, MAC_DEL);
900             get_value(message, 1, strlen(MAC_DEL), 5, INT_STRING,
901                 1, mac_num - 1, NULL);
902             i = atoi(message);
903             if (i == 1) {
904                 pmac = first;
905                 first = first->next;
906                 free(pmac);
907             } else {
908                 curr = first;
909                 while (--i > 1)
910                     curr = curr->next;
911                 pmac = curr->next;
912                 curr->next = pmac->next;
913                 free(pmac);
914             }
915             mac_num--;
916             begin = 1;
917             end = (mac_num > MAX_LINES) ? MAX_LINES : mac_num;
918             scroll_rows(first, begin, end, 3, 0);
919             clear_main_new(1, 2);
920             continue;
921         case 'n':
922         case 'N':
923             mvwaddstr(main_sub, 1, 0, MAC_ADD);
924             curr = first;
925             while (curr && curr->next)
926                 curr = curr->next;
927             if (first == NULL) {
928                 first = (struct MacListStat *)
929                     malloc(sizeof(struct MacListStat));
930                 curr = first;
931             } else {
932                 curr->next = (struct MacListStat *)
933                     malloc(sizeof(struct MacListStat));
934                 curr = curr->next;
935             }
936             curr->next = NULL;
937             mac_num++;
938             get_mac(curr->addr, 1, strlen(MAC_ADD));
939 /*
940             for (i = 0; i < 6; i++) {
941                 get_value(message, 1, 20 + i * 3, 3, ANY_STRING, 0, 0, NULL);
942                 curr->addr[i] = strtol(message, NULL, 16);
943             }
944             clear_main_new(1, 2);
945 */
946             begin = 1;
947             end = (mac_num > MAX_LINES) ? MAX_LINES : mac_num;
948             scroll_rows(first, begin, end, 3, 0);
949             continue;
950         case 'w':
951         case 'W':
952             print_help(WAIT_SET);
953
954             Mac[sizeof(Mac) - 1] = 0;
955
956             varbinds[0].oid = Mac;
957             varbinds[0].len_oid = sizeof(Mac);
958             varbinds[0].value = Mac;
959             varbinds[0].len_val = 0;
960             varbinds[0].type = NULL_VALUE;
961             if (snmp(varbinds, 1, GET_NEXT) <= 0) {
962                 print_helperr(ERR_RET);
963                 goto exit;
964             }
965             while (memcmp(varbinds[0].oid, Mac, sizeof(Mac) - 1) == 0) {
966
967                 MacRowStatus[sizeof(MacRowStatus) - 1] =
968                     varbinds[0].oid[sizeof(Mac) - 1];
969                 varbinds[0].oid = MacRowStatus;
970                 varbinds[0].len_oid = sizeof(MacRowStatus);
971                 varbinds[0].value = &destroy;
972                 varbinds[0].len_val = 1;
973                 varbinds[0].type = INT_VALUE;
974                 if (snmp(varbinds, 1, SET) <= 0) {
975                     print_helperr(ERR_SET);
976                     goto exit;
977                 }
978                 varbinds[0].oid = Mac;
979                 varbinds[0].len_oid = sizeof(Mac);
980                 varbinds[0].value = Mac;
981                 varbinds[0].len_val = 0;
982                 varbinds[0].type = NULL_VALUE;
983                 if (snmp(varbinds, 1, GET_NEXT) <= 0) {
984                     print_helperr(ERR_RET);
985                     goto exit;
986                 }
987             }
988
989
990             curr = first;
991             i = 1;
992
993             if (auth_mac) {
994                 Mac[sizeof(Mac) - 1] = i;
995                 MacAllow[sizeof(MacAllow) - 1] = i;
996                 MacRowStatus[sizeof(MacRowStatus) - 1] = i;
997
998                 varbinds[0].oid = MacRowStatus;
999                 varbinds[0].len_oid = sizeof(MacRowStatus);
1000                 varbinds[0].value = &create;
1001                 varbinds[0].len_val = 1;
1002                 varbinds[0].type = INT_VALUE;
1003                 varbinds[1].oid = Mac;
1004                 varbinds[1].len_oid = sizeof(Mac);
1005                 varbinds[1].value = auth_enable;
1006                 varbinds[1].len_val = 6;
1007                 varbinds[1].type = STRING_VALUE;
1008                 varbinds[2].oid = MacAllow;
1009                 varbinds[2].len_oid = sizeof(MacAllow);
1010                 varbinds[2].value = &allow;
1011                 varbinds[2].len_val = 1;
1012                 varbinds[2].type = INT_VALUE;
1013                 print_help(WAIT_SET);
1014                 if (snmp(varbinds, 3, SET) <= 0) {
1015                     print_helperr(ERR_SET);
1016                     goto exit;
1017                 }
1018                 i++;
1019             }
1020
1021
1022
1023
1024             while (curr != NULL) {
1025                 Mac[sizeof(Mac) - 1] = i;
1026                 MacAllow[sizeof(MacAllow) - 1] = i;
1027                 MacRowStatus[sizeof(MacRowStatus) - 1] = i;
1028
1029                 varbinds[0].oid = MacRowStatus;
1030                 varbinds[0].len_oid = sizeof(MacRowStatus);
1031                 varbinds[0].value = &create;
1032                 varbinds[0].len_val = 1;
1033                 varbinds[0].type = INT_VALUE;
1034                 varbinds[1].oid = Mac;
1035                 varbinds[1].len_oid = sizeof(Mac);
1036                 varbinds[1].value = curr->addr;
1037                 varbinds[1].len_val = 6;
1038                 varbinds[1].type = STRING_VALUE;
1039                 varbinds[2].oid = MacAllow;
1040                 varbinds[2].len_oid = sizeof(MacAllow);
1041                 varbinds[2].value = &allow;
1042                 varbinds[2].len_val = 1;
1043                 varbinds[2].type = INT_VALUE;
1044                 print_help(WAIT_SET);
1045                 if (snmp(varbinds, 3, SET) <= 0) {
1046                     print_helperr(ERR_SET);
1047                     goto exit;
1048                 }
1049                 curr = curr->next;
1050                 i++;
1051             }
1052             print_help(DONE_SET);
1053             goto exit;
1054         case KEY_DOWN:
1055         case KEY_RIGHT:
1056             if (end < mac_num) {
1057                 begin++;
1058                 end++;
1059                 scroll_rows(first, begin, end, 3, 0);
1060             }
1061
1062             continue;
1063         case KEY_UP:
1064         case KEY_LEFT:
1065             if (begin > 1) {
1066                 begin--;
1067                 end--;
1068                 scroll_rows(first, begin, end, 3, 0);
1069             }
1070             continue;
1071         }
1072         continue;
1073     }
1074
1075     print_help(ANY_KEY);
1076   exit:
1077     getch();
1078   quit:
1079     while ((curr = first)) {
1080         first = curr->next;
1081         free(curr);
1082     }
1083     print_top(NULL, NULL);
1084     clear_main(0);
1085 }