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 (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")
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")
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 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);
231 sprintf(message, "%s%s", RADIUS_SECRET, ea_secret);
232 mvwaddstr(main_sub, 3, 0, message);
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);
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);
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);
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);
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);
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);
269 sprintf(message, "%s%s", DOT1X_SECRET, ea_secret);
270 mvwaddstr(main_sub, 4, 0, message);
273 sprintf(message, "%s%s", MAC_AUTH, AuthModes_OO[auth_mode - 1]);
274 mvwaddstr(main_sub, 0, 0, message);
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);
282 print_help("Trying to retrieve auth. MAC address list from AP. Please wait.");
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);
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;
298 i = snmp(varbinds, 1, SET);
300 print_helperr(ERR_SET);
306 if (varbinds[0].len_val == 12) {
310 (struct AuthorizedMacTableString *) malloc(varbinds[0].
312 memcpy(AuthMac, varbinds[0].value, varbinds[0].len_val);
314 (struct AuthorizedMacTableString *) varbinds[0].value;*/
316 print_helperr(PACKET_ERROR);
320 rshort(AuthMac->NumOfAllTableAddresses);
322 (AuthMac->NumOfAllTableAddresses ==
323 65535) ? 0 : AuthMac->NumOfAllTableAddresses;
327 first = (struct MacListStat *)
328 malloc(sizeof(struct MacListStat));
331 curr->next = (struct MacListStat *)
332 malloc(sizeof(struct MacListStat));
335 memcpy(curr->addr, AuthMac->MacAddress, 6);
341 begin = (mac_num > MAX_LINES) ? mac_num + 1 - (MAX_LINES) : 1;
345 mvwaddstr(main_sub, 9, 0, _("(insufficient community used)"));
348 scroll_rows(first, begin, end, 9, 0);
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);
358 print_help(MAC_HELP);
367 auth_mode = menu_choose(0, strlen(MAC_AUTH),
368 ap_type == ATMEL410 && ap_vendorext == SBRIDGES ?
370 ap_type == ATMEL12350 &&
371 (ap_vendorext == GEMTEK || ap_vendorext == EZYNET) ?
374 ap_vendorext == NONE ?
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]
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);
396 /* no MACs available for deletion */
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);
405 clear_main_new(6, 7);
421 curr->next = pmac->next;
427 /* Rather do not ask how this works. */
431 } else if (i > (end - 1)) {
433 } else { /* begin <= i <= (end - 1) */
434 if ((begin == 1) && ((end - 1) == mac_num)) {
436 } else if ((begin > 1) && ((end - 1) < mac_num)) {
437 /* Uncomment for top side scrolling first. */
442 } else if (begin > 1) {
448 sprintf(message, "MAX_LINES: %i mac_num: %i begin: %i end: %i",
449 MAX_LINES, mac_num, begin, end);
451 mvwaddstr(main_sub, 0, 0, message);
455 scroll_rows(first, begin, end, 9, 0);
456 clear_main_new(6, 7);
465 mvwaddstr(main_sub, 6, 0, MAC_ADD);
466 get_mac(message, 6, strlen(MAC_ADD));
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);
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);
481 print_help(MAC_HELP);
489 while (curr && curr->next)
492 first = (struct MacListStat *)
493 malloc(sizeof(struct MacListStat));
496 curr->next = (struct MacListStat *)
497 malloc(sizeof(struct MacListStat));
501 memcpy(curr->addr, message, 6);
503 /* get_value(message, 1, strlen(MAC_ADD), 13, ANY_STRING, 0, 0,
506 for (i = 0; i < 6; i++) {
507 mess[0] = message[2 * i];
508 mess[1] = message[2 * i + 1];
510 curr->addr[i] = strtol(mess, NULL, 16);
512 clear_main_new(1, 2);
514 begin = (mac_num > MAX_LINES) ? mac_num + 1 - (MAX_LINES) : 1;
516 scroll_rows(first, begin, end, 9, 0);
517 clear_main_new(6, 7);
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);
530 if (ap_type == ATMEL410 && ap_vendorext == SBRIDGES && auth_mode == 3) {
531 get_ip(&ea_ip, 1, strlen(RADIUS_IP), RADIUS_HELP);
534 if (ap_type == ATMEL12350 && ap_vendorext == EZYNET) {
535 get_ip(&ea_ip, 3, strlen(DOT1X_IP), DOT1X_HELP);
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]);
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);
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);
565 if (ap_type == ATMEL12350 && ap_vendorext == EZYNET) {
566 get_value(ea_secret, 4, strlen(DOT1X_SECRET), -17,
567 ANY_STRING, 0, 0, NULL);
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);
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);
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);
605 if (varbinds[0].len_val != 12) {
606 print_helperr(PACKET_ERROR);
616 int c = swap4(auth_mode);
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;
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;
637 if (ap_type == ATMEL410 && ap_vendorext == SBRIDGES) {
638 varbinds[i].oid = AuthRadiusIP;
639 varbinds[i].len_oid = sizeof(AuthRadiusIP);
642 if (ap_type == ATMEL12350 && ap_vendorext == EZYNET) {
643 varbinds[i].oid = ServerIP;
644 varbinds[i].len_oid = sizeof(ServerIP);
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;
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;
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;
676 int c = strlen(ea_secret);
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;
686 varbinds[i].oid = AuthRadiusSecret;
687 varbinds[i].len_oid = sizeof(AuthRadiusSecret);
690 if (ap_type == ATMEL12350 && ap_vendorext == EZYNET) {
691 varbinds[i].oid = ServerSecret;
692 varbinds[i].len_oid = sizeof(ServerSecret);
695 varbinds[i].value = ea_secret;
696 varbinds[i].len_val = c;
697 varbinds[i].type = STRING_VALUE;
702 if (ap_type == ATMEL410 && ap_vendorext == SBRIDGES) {
703 varbinds[i].oid = AuthRadiusReauthorizationTime;
704 varbinds[i].len_oid = sizeof(AuthRadiusReauthorizationTime);
707 if (ap_type == ATMEL12350 && ap_vendorext == EZYNET) {
708 varbinds[i].oid = BroadcastKeyPeriod;
709 varbinds[i].len_oid = sizeof(BroadcastKeyPeriod);
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;
719 print_help(WAIT_SET);
720 if (snmp(varbinds, i, SET) <= 0) {
721 print_helperr(ERR_SET);
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);
729 print_help(DONE_SET);
736 scroll_rows(first, begin, end, 9, 0);
744 scroll_rows(first, begin, end, 9, 0);
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);
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);
767 begin = (mac_num > MAX_LINES) ? mac_num + 1 - (MAX_LINES) : 1;
769 scroll_rows(first, begin, end, 9, 0);
775 end = (mac_num > MAX_LINES) ? MAX_LINES : mac_num;
776 scroll_rows(first, begin, end, 9, 0);
787 while ((curr = first)) {
793 print_top(NULL, NULL);
799 struct MacListStat *pmac, *first = NULL, *curr = NULL;
801 { 0x2b, 0x06, 0x01, 0x04, 0x01, 0x87, 0x29, 0x03, 0x01, 0x03, 0x02,
802 0x02, 0x01, 0x02, 0x00
805 { 0x2b, 0x06, 0x01, 0x04, 0x01, 0x87, 0x29, 0x03, 0x01, 0x03, 0x02,
806 0x02, 0x01, 0x03, 0x00
808 char MacRowStatus[] =
809 { 0x2b, 0x06, 0x01, 0x04, 0x01, 0x87, 0x29, 0x03, 0x01, 0x03, 0x02,
810 0x02, 0x01, 0x04, 0x00
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;
817 print_top(NULL, AUTH_TITLE);
819 mvwaddstr(main_sub, 2, 0, MAC_HEADER);
821 print_help(WAIT_RET);
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);
834 while (memcmp(varbinds[0].oid, Mac, sizeof(Mac) - 1) == 0) {
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];
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);
860 if (memcmp(auth_enable, varbinds[0].value, 6)) {
862 first = (struct MacListStat *)
863 malloc(sizeof(struct MacListStat));
866 curr->next = (struct MacListStat *)
867 malloc(sizeof(struct MacListStat));
870 memcpy(curr->addr, varbinds[0].value, 6);
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);
889 end = (mac_num > MAX_LINES) ? MAX_LINES : mac_num;
891 sprintf(message, "%s%s", MAC_AUTH, (auth_mac) ? OFF : ON);
892 mvwaddstr(main_sub, 0, 0, message);
894 scroll_rows(first, begin, end, 3, 0);
898 print_help(MAC_HELP);
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);
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);
923 curr->next = pmac->next;
928 end = (mac_num > MAX_LINES) ? MAX_LINES : mac_num;
929 scroll_rows(first, begin, end, 3, 0);
930 clear_main_new(1, 2);
934 mvwaddstr(main_sub, 1, 0, MAC_ADD);
936 while (curr && curr->next)
939 first = (struct MacListStat *)
940 malloc(sizeof(struct MacListStat));
943 curr->next = (struct MacListStat *)
944 malloc(sizeof(struct MacListStat));
949 get_mac(curr->addr, 1, strlen(MAC_ADD));
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);
955 clear_main_new(1, 2);
958 end = (mac_num > MAX_LINES) ? MAX_LINES : mac_num;
959 scroll_rows(first, begin, end, 3, 0);
963 print_help(WAIT_SET);
965 Mac[sizeof(Mac) - 1] = 0;
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);
976 while (memcmp(varbinds[0].oid, Mac, sizeof(Mac) - 1) == 0) {
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);
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);
1005 Mac[sizeof(Mac) - 1] = i;
1006 MacAllow[sizeof(MacAllow) - 1] = i;
1007 MacRowStatus[sizeof(MacRowStatus) - 1] = i;
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);
1035 while (curr != NULL) {
1036 Mac[sizeof(Mac) - 1] = i;
1037 MacAllow[sizeof(MacAllow) - 1] = i;
1038 MacRowStatus[sizeof(MacRowStatus) - 1] = i;
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);
1063 wbkgd(main_sub, A_NORMAL);
1065 print_help(DONE_SET);
1069 if (end < mac_num) {
1072 scroll_rows(first, begin, end, 3, 0);
1081 scroll_rows(first, begin, end, 3, 0);
1088 print_help(ANY_KEY);
1092 while ((curr = first)) {
1096 print_top(NULL, NULL);