2 * auth.c from Access Point SNMP Utils for Linux
4 * Copyright (c) 2002 Roman Festchook <roma at polesye dot net>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License Version 2 from
8 * June 1991 as published by the Free Software Foundation.
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
26 #define MAX_LINES LINES-6
27 #define PACKET_ERROR _("AuthorizedMacTableString packet error")
29 #define MAC_AUTH _("[A] MAC authorization: ")
30 #define MAC_ADD _("Enter MAC: ")
31 #define MAC_DEL _("Delete Num: ")
32 #define MAC_TITLE _("Authorized MAC addresses")
33 #define MAC_HEADER _("NUM MAC address")
34 #define MAC_HELP _("A - auth; N - new; D - del; arrows - scroll; W - write conf; Q - quit")
35 #define MAC_RADIUS_HELP _("A - auth; IPSTF - set; W - write conf; Q - quit")
36 #define MAC_NONE_HELP _("A - auth; 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: ")
42 #define RADIUS_PORT _("[F] RADIUS SOURCE PORT: ")
44 extern WINDOW *main_sub;
50 struct AuthorizedMacTableString {
51 unsigned int short Action;
52 unsigned int short NumOfAllTableAddresses;
53 unsigned int short NumOfCurrentAddress;
54 unsigned char MacAddress[6];
55 } *AuthMac = NULL, get;
57 struct MacListStat *pmac, *first = NULL, *curr = NULL;
60 char EnableAuthMAC[] =
61 { 0x2B, 0x06, 0x01, 0x04, 0x01, 0x83, 0x1A, 0x01,
62 0x02, 0x06, 0x01, 0x00
64 char AutorizedMac[] = { 0x2B, 0x06, 0x01, 0x04, 0x01, 0x83, 0x1A, 0x01,
65 0x02, 0x06, 0x02, 0x00
68 char AuthRadiusIP[] = { 0x2B, 0x06, 0x01, 0x04, 0x01, 0x83, 0x1A, 0x01,
69 0x02, 0x06, 0x03, 0x00
71 char AuthRadiusSecret[] = { 0x2B, 0x06, 0x01, 0x04, 0x01, 0x83, 0x1A, 0x01,
72 0x02, 0x06, 0x04, 0x00
74 char AuthRadiusSecretLength[] = { 0x2B, 0x06, 0x01, 0x04, 0x01, 0x83, 0x1A, 0x01,
75 0x02, 0x06, 0x05, 0x00
77 char AuthRadiusPort[] = { 0x2B, 0x06, 0x01, 0x04, 0x01, 0x83, 0x1A, 0x01,
78 0x02, 0x06, 0x06, 0x00
80 char AuthRadiusReauthorizationTime[] = { 0x2B, 0x06, 0x01, 0x04, 0x01, 0x83, 0x1A, 0x01,
81 0x02, 0x06, 0x07, 0x00
83 char AuthRadiusDestinPort[] = { 0x2B, 0x06, 0x01, 0x04, 0x01, 0x83, 0x1A, 0x01,
84 0x02, 0x06, 0x08, 0x00
87 char *auth_types[] = { _("Internal"), OFF, "RADIUS" };
89 struct in_addr radius_ip;
90 char message[1024], m_authmac = 0, radius_secret[32], m_radius_secret=0, m_radius_ip=0;
91 int radius_port, radius_time, radius_dest_port, m_radius_port=0, m_radius_time=0, m_radius_dest_port=0;
92 int i, total_mac, auth_mac = 0, mac_num = 0, begin=0, end=0, c=0;
95 memcpy(radius_secret, _("<hidden>"), 32);
97 varbinds[0].oid = EnableAuthMAC;
98 varbinds[0].len_oid = sizeof(EnableAuthMAC);
99 varbinds[0].type = NULL_VALUE;
100 varbinds[0].len_val = 0;
102 varbinds[1].oid = AuthRadiusIP;
103 varbinds[1].len_oid = sizeof(AuthRadiusIP);
104 varbinds[1].type = NULL_VALUE;
105 varbinds[1].len_val = 0;
107 varbinds[3].oid = AuthRadiusPort;
108 varbinds[3].len_oid = sizeof(AuthRadiusPort);
109 varbinds[3].type = NULL_VALUE;
110 varbinds[3].len_val = 0;
112 varbinds[4].oid = AuthRadiusReauthorizationTime;
113 varbinds[4].len_oid = sizeof(AuthRadiusReauthorizationTime);
114 varbinds[4].type = NULL_VALUE;
115 varbinds[4].len_val = 0;
117 varbinds[2].oid = AuthRadiusDestinPort;
118 varbinds[2].len_oid = sizeof(AuthRadiusDestinPort);
119 varbinds[2].type = NULL_VALUE;
120 varbinds[2].len_val = 0;
122 print_help(WAIT_RET);
123 if (snmp(varbinds, 5, GET) <= 0) {
124 print_helperr(ERR_RET);
127 print_top(NULL, MAC_TITLE);
129 auth_mac = *(varbinds[0].value);
130 memcpy(&radius_ip.s_addr, varbinds[1].value, 4);
131 memcpy(&radius_dest_port, varbinds[2].value, 2);
132 radius_dest_port = ntohs(radius_dest_port);
133 memcpy(&radius_port, varbinds[3].value, 2);
134 radius_port = ntohs(radius_port);
135 memcpy(&radius_time, varbinds[4].value, 2);
136 radius_time = ntohs(radius_time);
138 sprintf(message, "%s%s", MAC_AUTH, auth_types[auth_mac-1]);
139 mvwaddstr(main_sub, 0, 0, message);
145 while (mac_num <= total_mac) {
146 get.Action = 0x02; rshort(get.Action);
147 get.NumOfAllTableAddresses = total_mac; rshort(get.NumOfAllTableAddresses);
148 get.NumOfCurrentAddress = mac_num; rshort(get.NumOfCurrentAddress);
150 varbinds[0].oid = AutorizedMac;
151 varbinds[0].len_oid = sizeof(AutorizedMac);
152 varbinds[0].value = (char *) &get;
153 varbinds[0].len_val = 12;
154 varbinds[0].type = STRING_VALUE;
156 if (snmp(varbinds, 1, SET) <= 0) {
157 print_helperr(ERR_RET);
161 if (varbinds[0].len_val == 12) {
165 (struct AuthorizedMacTableString *) malloc(varbinds[0].
167 memcpy(AuthMac, varbinds[0].value, varbinds[0].len_val);
169 (struct AuthorizedMacTableString *) varbinds[0].value;*/
171 print_helperr(PACKET_ERROR);
175 rshort(AuthMac->NumOfAllTableAddresses);
177 (AuthMac->NumOfAllTableAddresses ==
178 65535) ? 0 : AuthMac->NumOfAllTableAddresses;
182 first = (struct MacListStat *)
183 malloc(sizeof(struct MacListStat));
186 curr->next = (struct MacListStat *)
187 malloc(sizeof(struct MacListStat));
190 memcpy(curr->addr, AuthMac->MacAddress, 6);
199 mvwaddstr(main_sub, 2, 1, MAC_HEADER);
201 end = (MAX_LINES < mac_num) ? MAX_LINES : mac_num;
202 scroll_rows(first, begin, end, 3, 0);
203 print_help(MAC_HELP);
204 } else if(auth_mac == 3) {
205 sprintf(message, "%s%s", RADIUS_IP, inet_ntoa(radius_ip));
206 mvwaddstr(main_sub, 2, 0, message);
207 sprintf(message, "%s%d", RADIUS_DEST_PORT, radius_dest_port);
208 mvwaddstr(main_sub, 3, 0, message);
209 sprintf(message, "%s%s", RADIUS_SECRET, radius_secret);
210 mvwaddstr(main_sub, 4, 0, message);
211 sprintf(message, "%s%d", RADIUS_TIME, radius_time);
212 mvwaddstr(main_sub, 5, 0, message);
213 sprintf(message, "%s%d", RADIUS_PORT, radius_port);
214 mvwaddstr(main_sub, 6, 0, message);
217 print_help(MAC_RADIUS_HELP);
219 print_help(MAC_NONE_HELP);
230 auth_mac = menu_choose(0, strlen(MAC_AUTH), auth_types, 3)+1;
231 clear_main_new(0, 1);
232 print_menusel(0, 0, MAC_AUTH, auth_types[auth_mac-1]);
240 get_value(radius_secret, 4, strlen(RADIUS_SECRET), 32, ANY_STRING, 0, 0, NULL);
248 get_value(message, 3, strlen(RADIUS_DEST_PORT), 6, INT_STRING, 0, 65535, MAC_RADIUS_HELP);
249 radius_dest_port = atoi(message);
250 m_radius_dest_port = 1;
257 get_value(message, 5, strlen(RADIUS_TIME), 6, INT_STRING, 0, 65535, MAC_RADIUS_HELP);
258 radius_time = atoi(message);
266 get_value(message, 6, strlen(RADIUS_PORT), 6, INT_STRING, 0, 65535, MAC_RADIUS_HELP);
267 radius_port = atoi(message);
275 get_ip(&radius_ip, 2, strlen(RADIUS_IP), MAC_RADIUS_HELP);
283 mvwaddstr(main_sub, 1, 0, MAC_DEL);
284 get_value(message, 1, strlen(MAC_DEL), 5, INT_STRING,
285 1, mac_num - 1, NULL);
296 curr->next = pmac->next;
301 end = (MAX_LINES < mac_num) ? MAX_LINES : mac_num;
302 scroll_rows(first, begin, end, 3, 0);
303 clear_main_new(1, 2);
310 mvwaddstr(main_sub, 1, 0, MAC_ADD);
312 while (curr && curr->next)
315 first = (struct MacListStat *)
316 malloc(sizeof(struct MacListStat));
319 curr->next = (struct MacListStat *)
320 malloc(sizeof(struct MacListStat));
325 get_mac(curr->addr, 1, strlen(MAC_ADD));
327 end = (MAX_LINES < mac_num) ? MAX_LINES : mac_num;
328 scroll_rows(first, begin, end, 3, 0);
329 clear_main_new(1, 2);
335 auth_mac_hw = swap4(auth_mac);
336 varbinds[i].oid = EnableAuthMAC;
337 varbinds[i].len_oid = sizeof(EnableAuthMAC);
338 varbinds[i].type = INT_VALUE;
339 varbinds[i].value = (char *) &auth_mac_hw;
340 varbinds[i].len_val = 1;
345 radius_ip.s_addr = htonl(radius_ip.s_addr);
346 radius_ip.s_addr = swap4(radius_ip.s_addr);
347 varbinds[i].oid = AuthRadiusIP;
348 varbinds[i].len_oid = sizeof(AuthRadiusIP);
349 varbinds[i].value = (char *) &radius_ip.s_addr;
350 varbinds[i].len_val = 4;
351 varbinds[i].type = INT_VALUE;
355 if (m_radius_dest_port) {
356 varbinds[i].oid = AuthRadiusDestinPort;
357 varbinds[i].len_oid = sizeof(AuthRadiusDestinPort);
358 radius_dest_port = htons(radius_dest_port);
359 varbinds[i].value = (char *) &radius_dest_port;
360 varbinds[i].len_val = 2;
361 varbinds[i].type = 0x02;
366 varbinds[i].oid = AuthRadiusReauthorizationTime;
367 varbinds[i].len_oid = sizeof(AuthRadiusReauthorizationTime);
368 radius_time = htons(radius_time);
369 varbinds[i].value = (char *) &radius_time;
370 varbinds[i].len_val = 2;
371 varbinds[i].type = 0x02;
376 varbinds[i].oid = AuthRadiusPort;
377 varbinds[i].len_oid = sizeof(AuthRadiusPort);
378 radius_port = htons(radius_port);
379 varbinds[i].value = (char *) &radius_port;
380 varbinds[i].len_val = 2;
381 varbinds[i].type = 0x02;
384 if (m_radius_secret) {
385 c = strlen(radius_secret);
386 varbinds[i].oid = AuthRadiusSecretLength;
387 varbinds[i].len_oid = sizeof(AuthRadiusSecretLength);
388 varbinds[i].value = (char *)&c;
389 varbinds[i].len_val = 1;
390 varbinds[i].type = INT_VALUE;
392 varbinds[i].oid = AuthRadiusSecret;
393 varbinds[i].len_oid = sizeof(AuthRadiusSecret);
394 varbinds[i].value = radius_secret;
395 varbinds[i].len_val = c;
396 varbinds[i].type = STRING_VALUE;
400 print_help(WAIT_SET);
401 if (snmp(varbinds, i, SET) <= 0) {
402 print_helperr(ERR_RET);
408 while (curr != NULL) {
409 get.Action = 0x01; rshort(get.Action);
410 get.NumOfAllTableAddresses = mac_num - 1; rshort(get.NumOfAllTableAddresses);
411 get.NumOfCurrentAddress = i; rshort(get.NumOfCurrentAddress);
412 memcpy(get.MacAddress, curr->addr, 6);
413 varbinds[0].oid = AutorizedMac;
414 varbinds[0].len_oid = sizeof(AutorizedMac);
415 varbinds[0].value = (char *) &get;
416 varbinds[0].len_val = 12;
417 varbinds[0].type = STRING_VALUE;
418 print_help(WAIT_SET);
419 if (snmp(varbinds, 1, SET) <= 0) {
420 print_helperr(ERR_RET);
423 if (varbinds[0].len_val != 12) {
424 print_helperr(PACKET_ERROR);
430 print_help(DONE_SET);
440 scroll_rows(first, begin, end, 3, 0);
451 scroll_rows(first, begin, end, 3, 0);
462 while ((curr = first)) {
468 print_top(NULL, NULL);