2 * auth.c from Access Point SNMP Utils for Linux
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>
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.
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.
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
27 #define MAX_LINES LINES-12
28 #define PACKET_ERROR _("AuthorizedMacTableString packet error")
30 #define AUTH_TITLE _("APClient authorization credentials")
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")
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")
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")
51 extern WINDOW *main_sub;
53 extern short ap_type, ap_vendorext;
57 char AuthorizationMacEnable[] = {
58 0x2B, 0x06, 0x01, 0x04, 0x01, 0x83, 0x1A, 0x01, 0x02, 0x06, 0x01, 0x00
60 char AutorizedMac[] = {
61 0x2B, 0x06, 0x01, 0x04, 0x01, 0x83, 0x1A, 0x01, 0x02, 0x06, 0x02, 0x00
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
68 char AuthRadiusSecret[] = {
69 0x2B, 0x06, 0x01, 0x04, 0x01, 0x83, 0x1A, 0x01, 0x02, 0x06, 0x04, 0x00
71 char AuthRadiusSecretLength[] = {
72 0x2B, 0x06, 0x01, 0x04, 0x01, 0x83, 0x1A, 0x01, 0x02, 0x06, 0x05, 0x00
74 char AuthRadiusPort[] = {
75 0x2B, 0x06, 0x01, 0x04, 0x01, 0x83, 0x1A, 0x01, 0x02, 0x06, 0x06, 0x00
77 char AuthRadiusReauthorizationTime[] = {
78 0x2B, 0x06, 0x01, 0x04, 0x01, 0x83, 0x1A, 0x01, 0x02, 0x06, 0x07, 0x00
80 char AuthRadiusDestinPort[] = {
81 0x2B, 0x06, 0x01, 0x04, 0x01, 0x83, 0x1A, 0x01, 0x02, 0x06, 0x08, 0x00
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
89 char BroadcastKeyPeriod[] = {
90 0x2B, 0x06, 0x01, 0x04, 0x01, 0xE0, 0x3E, 0x01, 0x02, 0x08, 0x02, 0x00
93 0x2B, 0x06, 0x01, 0x04, 0x01, 0xE0, 0x3E, 0x01, 0x02, 0x08, 0x03, 0x00
95 char ServerSecret[] = {
96 0x2B, 0x06, 0x01, 0x04, 0x01, 0xE0, 0x3E, 0x01, 0x02, 0x08, 0x04, 0x00
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;
106 /* for ATMEL* MIBs with NONE extensions */
107 char *AuthModes_OO[] = {
112 /* for ATMEL410 MIB with SBRIDGES extensions */
113 char *AuthModes_IOR[] = {
119 /* for ATMEL12350 MIBs with GEMTEK or EZYNET extensions */
120 char *AuthModes_AOD[] = {
121 _("Allow listed MACs only"),
123 _("Deny listed MACs only")
126 char *Dot1xModes[] = {
129 _("Mixed environment")
132 /* These will be used for both Radius-related and 802.1x-related stuff. */
133 struct in_addr ea_ip;
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;
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;
145 if (ap_type == ATMEL12350) {
146 AuthorizationMacEnable[5] = 0xE0;
147 AuthorizationMacEnable[6] = 0x3E;
148 AutorizedMac[5] = 0xE0;
149 AutorizedMac[6] = 0x3E;
152 varbinds[i].oid = AuthorizationMacEnable;
153 varbinds[i].len_oid = sizeof(AuthorizationMacEnable);
154 varbinds[i].type = NULL_VALUE;
155 varbinds[i].len_val = 0;
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;
165 varbinds[i].oid = AuthRadiusPort;
166 varbinds[i].len_oid = sizeof(AuthRadiusPort);
167 varbinds[i].type = NULL_VALUE;
168 varbinds[i].len_val = 0;
171 varbinds[i].oid = AuthRadiusReauthorizationTime;
172 varbinds[i].len_oid = sizeof(AuthRadiusReauthorizationTime);
173 varbinds[i].type = NULL_VALUE;
174 varbinds[i].len_val = 0;
177 varbinds[i].oid = AuthRadiusDestinPort;
178 varbinds[i].len_oid = sizeof(AuthRadiusDestinPort);
179 varbinds[i].type = NULL_VALUE;
180 varbinds[i].len_val = 0;
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;
191 varbinds[i].oid = BroadcastKeyPeriod;
192 varbinds[i].len_oid = sizeof(BroadcastKeyPeriod);
193 varbinds[i].type = NULL_VALUE;
194 varbinds[i].len_val = 0;
197 varbinds[i].oid = ServerIP;
198 varbinds[i].len_oid = sizeof(ServerIP);
199 varbinds[i].type = NULL_VALUE;
200 varbinds[i].len_val = 0;
204 print_help(WAIT_RET);
205 if (snmp(varbinds, i, GET) < i) {
206 print_helperr(ERR_RET);
209 print_top(NULL, AUTH_TITLE);
211 auth_mode = *(varbinds[0].value);
213 strcpy(ea_secret, _("(not shown)"));
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);
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);
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);
229 sprintf(message, "%s%s", RADIUS_SECRET, ea_secret);
230 mvwaddstr(main_sub, 3, 0, message);
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);
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);
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);
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);
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);
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);
263 sprintf(message, "%s%s", DOT1X_SECRET, ea_secret);
264 mvwaddstr(main_sub, 4, 0, message);
267 sprintf(message, "%s%s", MAC_AUTH, AuthModes_OO[auth_mode - 1]);
268 mvwaddstr(main_sub, 0, 0, message);
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);
276 print_help("Trying to retrieve auth. MAC address list from AP. Please wait.");
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);
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;
292 i = snmp(varbinds, 1, SET);
294 print_helperr(ERR_SET);
300 if (varbinds[0].len_val == 12) {
304 (struct AuthorizedMacTableString *) malloc(varbinds[0].
306 memcpy(AuthMac, varbinds[0].value, varbinds[0].len_val);
308 (struct AuthorizedMacTableString *) varbinds[0].value;*/
310 print_helperr(PACKET_ERROR);
314 rshort(AuthMac->NumOfAllTableAddresses);
316 (AuthMac->NumOfAllTableAddresses ==
317 65535) ? 0 : AuthMac->NumOfAllTableAddresses;
321 first = (struct MacListStat *)
322 malloc(sizeof(struct MacListStat));
325 curr->next = (struct MacListStat *)
326 malloc(sizeof(struct MacListStat));
329 memcpy(curr->addr, AuthMac->MacAddress, 6);
335 begin = (mac_num > MAX_LINES) ? mac_num + 1 - (MAX_LINES) : 1;
339 mvwaddstr(main_sub, 9, 0, _("(insufficient community used)"));
342 scroll_rows(first, begin, end, 9, 0);
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);
352 print_help(MAC_HELP);
361 auth_mode = menu_choose(0, strlen(MAC_AUTH),
362 ap_type == ATMEL410 && ap_vendorext == SBRIDGES ?
364 ap_type == ATMEL12350 &&
365 (ap_vendorext == GEMTEK || ap_vendorext == EZYNET) ?
368 ap_vendorext == NONE ?
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]
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);
390 /* no MACs available for deletion */
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);
399 clear_main_new(6, 7);
415 curr->next = pmac->next;
421 /* Rather do not ask how this works. */
425 } else if (i > (end - 1)) {
427 } else { /* begin <= i <= (end - 1) */
428 if ((begin == 1) && ((end - 1) == mac_num)) {
430 } else if ((begin > 1) && ((end - 1) < mac_num)) {
431 /* Uncomment for top side scrolling first. */
436 } else if (begin > 1) {
442 sprintf(message, "MAX_LINES: %i mac_num: %i begin: %i end: %i",
443 MAX_LINES, mac_num, begin, end);
445 mvwaddstr(main_sub, 0, 0, message);
449 scroll_rows(first, begin, end, 9, 0);
450 clear_main_new(6, 7);
459 mvwaddstr(main_sub, 6, 0, MAC_ADD);
460 get_mac(message, 6, strlen(MAC_ADD));
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);
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);
475 print_help(MAC_HELP);
483 while (curr && curr->next)
486 first = (struct MacListStat *)
487 malloc(sizeof(struct MacListStat));
490 curr->next = (struct MacListStat *)
491 malloc(sizeof(struct MacListStat));
495 memcpy(curr->addr, message, 6);
497 /* get_value(message, 1, strlen(MAC_ADD), 13, ANY_STRING, 0, 0,
500 for (i = 0; i < 6; i++) {
501 mess[0] = message[2 * i];
502 mess[1] = message[2 * i + 1];
504 curr->addr[i] = strtol(mess, NULL, 16);
506 clear_main_new(1, 2);
508 begin = (mac_num > MAX_LINES) ? mac_num + 1 - (MAX_LINES) : 1;
510 scroll_rows(first, begin, end, 9, 0);
511 clear_main_new(6, 7);
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);
524 if (ap_type == ATMEL410 && ap_vendorext == SBRIDGES && auth_mode == 3) {
525 get_ip(&ea_ip, 1, strlen(RADIUS_IP), RADIUS_HELP);
528 if (ap_type == ATMEL12350 && ap_vendorext == EZYNET) {
529 get_ip(&ea_ip, 3, strlen(DOT1X_IP), DOT1X_HELP);
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]);
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);
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);
559 if (ap_type == ATMEL12350 && ap_vendorext == EZYNET) {
560 get_value(ea_secret, 4, strlen(DOT1X_SECRET), -17,
561 ANY_STRING, 0, 0, NULL);
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);
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);
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);
599 if (varbinds[0].len_val != 12) {
600 print_helperr(PACKET_ERROR);
610 int c = swap4(auth_mode);
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;
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;
631 if (ap_type == ATMEL410 && ap_vendorext == SBRIDGES) {
632 varbinds[i].oid = AuthRadiusIP;
633 varbinds[i].len_oid = sizeof(AuthRadiusIP);
636 if (ap_type == ATMEL12350 && ap_vendorext == EZYNET) {
637 varbinds[i].oid = ServerIP;
638 varbinds[i].len_oid = sizeof(ServerIP);
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;
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;
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;
670 int c = strlen(ea_secret);
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;
680 varbinds[i].oid = AuthRadiusSecret;
681 varbinds[i].len_oid = sizeof(AuthRadiusSecret);
684 if (ap_type == ATMEL12350 && ap_vendorext == EZYNET) {
685 varbinds[i].oid = ServerSecret;
686 varbinds[i].len_oid = sizeof(ServerSecret);
689 varbinds[i].value = ea_secret;
690 varbinds[i].len_val = c;
691 varbinds[i].type = STRING_VALUE;
696 if (ap_type == ATMEL410 && ap_vendorext == SBRIDGES) {
697 varbinds[i].oid = AuthRadiusReauthorizationTime;
698 varbinds[i].len_oid = sizeof(AuthRadiusReauthorizationTime);
701 if (ap_type == ATMEL12350 && ap_vendorext == EZYNET) {
702 varbinds[i].oid = BroadcastKeyPeriod;
703 varbinds[i].len_oid = sizeof(BroadcastKeyPeriod);
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;
713 print_help(WAIT_SET);
714 if (snmp(varbinds, i, SET) <= 0) {
715 print_helperr(ERR_SET);
718 print_help(DONE_SET);
725 scroll_rows(first, begin, end, 9, 0);
733 scroll_rows(first, begin, end, 9, 0);
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);
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);
756 begin = (mac_num > MAX_LINES) ? mac_num + 1 - (MAX_LINES) : 1;
758 scroll_rows(first, begin, end, 9, 0);
764 end = (mac_num > MAX_LINES) ? MAX_LINES : mac_num;
765 scroll_rows(first, begin, end, 9, 0);
776 while ((curr = first)) {
782 print_top(NULL, NULL);
788 struct MacListStat *pmac, *first = NULL, *curr = NULL;
790 { 0x2b, 0x06, 0x01, 0x04, 0x01, 0x87, 0x29, 0x03, 0x01, 0x03, 0x02,
791 0x02, 0x01, 0x02, 0x00
794 { 0x2b, 0x06, 0x01, 0x04, 0x01, 0x87, 0x29, 0x03, 0x01, 0x03, 0x02,
795 0x02, 0x01, 0x03, 0x00
797 char MacRowStatus[] =
798 { 0x2b, 0x06, 0x01, 0x04, 0x01, 0x87, 0x29, 0x03, 0x01, 0x03, 0x02,
799 0x02, 0x01, 0x04, 0x00
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;
806 print_top(NULL, AUTH_TITLE);
808 mvwaddstr(main_sub, 2, 5, MAC_HEADER);
810 print_help(WAIT_RET);
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);
823 while (memcmp(varbinds[0].oid, Mac, sizeof(Mac) - 1) == 0) {
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];
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);
849 if (memcmp(auth_enable, varbinds[0].value, 6)) {
851 first = (struct MacListStat *)
852 malloc(sizeof(struct MacListStat));
855 curr->next = (struct MacListStat *)
856 malloc(sizeof(struct MacListStat));
859 memcpy(curr->addr, varbinds[0].value, 6);
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);
878 end = (mac_num > MAX_LINES) ? MAX_LINES : mac_num;
880 sprintf(message, "%s%s", MAC_AUTH, (auth_mac) ? OFF : ON);
881 mvwaddstr(main_sub, 0, 0, message);
883 scroll_rows(first, begin, end, 3, 0);
887 print_help(MAC_HELP);
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);
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);
912 curr->next = pmac->next;
917 end = (mac_num > MAX_LINES) ? MAX_LINES : mac_num;
918 scroll_rows(first, begin, end, 3, 0);
919 clear_main_new(1, 2);
923 mvwaddstr(main_sub, 1, 0, MAC_ADD);
925 while (curr && curr->next)
928 first = (struct MacListStat *)
929 malloc(sizeof(struct MacListStat));
932 curr->next = (struct MacListStat *)
933 malloc(sizeof(struct MacListStat));
938 get_mac(curr->addr, 1, strlen(MAC_ADD));
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);
944 clear_main_new(1, 2);
947 end = (mac_num > MAX_LINES) ? MAX_LINES : mac_num;
948 scroll_rows(first, begin, end, 3, 0);
952 print_help(WAIT_SET);
954 Mac[sizeof(Mac) - 1] = 0;
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);
965 while (memcmp(varbinds[0].oid, Mac, sizeof(Mac) - 1) == 0) {
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);
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);
994 Mac[sizeof(Mac) - 1] = i;
995 MacAllow[sizeof(MacAllow) - 1] = i;
996 MacRowStatus[sizeof(MacRowStatus) - 1] = i;
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);
1024 while (curr != NULL) {
1025 Mac[sizeof(Mac) - 1] = i;
1026 MacAllow[sizeof(MacAllow) - 1] = i;
1027 MacRowStatus[sizeof(MacRowStatus) - 1] = i;
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);
1052 print_help(DONE_SET);
1056 if (end < mac_num) {
1059 scroll_rows(first, begin, end, 3, 0);
1068 scroll_rows(first, begin, end, 3, 0);
1075 print_help(ANY_KEY);
1079 while ((curr = first)) {
1083 print_top(NULL, NULL);