]> git.decadent.org.uk Git - ap-utils.git/blob - lib/set_community.c
Imported Upstream version 1.5~pre1
[ap-utils.git] / lib / set_community.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  *
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.
9  *
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.
14  *
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
18  *
19  */
20 #include <stdio.h>
21 #include <unistd.h>
22 #include <fcntl.h>
23 #include <stdlib.h>
24 #include <string.h>
25 #include "ap-utils.h"
26
27 #define COMMUNITY_TOP_HEADER _("Set community/password")
28 #define COMMUNITY_HEADER1 _("Key Access level")
29 #define COMMUNITY_HEADER2 _("Community/Password")
30 #define COMMUNITY_USER  _("[U] User ")
31 #define COMMUNITY_ADMIN  _("[A] Administrator ")
32 #define COMMUNITY_MANUF  _("[M] Manufacturer ")
33 #define COMMUNITY_HELP _("[key] - set community/password; W - write config to AP; Q - quit to menu")
34
35 extern WINDOW *main_sub;
36 extern short ap_type;
37
38 void AuthorizedSettings()
39 {
40     char AuthorizedUserPass[3][12] = {
41         {0x2B, 0x06, 0x01, 0x04, 0x01, 0x83, 0x1A, 0x01, 0x01, 0x09, 0x01,
42          0x00},
43         {0x2B, 0x06, 0x01, 0x04, 0x01, 0x87, 0x29, 0x02, 0x01, 0x02, 0x01,
44          0x00},
45        {0x2B, 0x06, 0x01, 0x04, 0x01, 0xE0, 0x3E, 0x01, 0x01, 0x09, 0x01,
46          0x00}
47     };
48     char AuthorizedAdminPass[3][12] = {
49         {0x2B, 0x06, 0x01, 0x04, 0x01, 0x83, 0x1A, 0x01, 0x01, 0x09, 0x02,
50          0x00},
51         {0x2B, 0x06, 0x01, 0x04, 0x01, 0x87, 0x29, 0x02, 0x01, 0x02, 0x02,
52          0x00},
53         {0x2B, 0x06, 0x01, 0x04, 0x01, 0xE0, 0x3E, 0x01, 0x01, 0x09, 0x02,
54          0x00}
55     };
56     char AuthorizedManufactPass[] =
57         { 0x2B, 0x06, 0x01, 0x04, 0x01, 0x83, 0x1A, 0x01, 0x01, 0x09, 0x03,
58         0x00
59     };
60
61     varbind varbinds[3];
62     char user[16], admin[16], manufact[16];
63     int i;
64
65     if (ap_type == ATMEL12350) {
66         AuthorizedManufactPass[5] = 0xE0;
67         AuthorizedManufactPass[6] = 0x3E;
68     }
69
70     user[0] = admin[0] = manufact[0] = '\0';
71     print_top(NULL, COMMUNITY_TOP_HEADER);
72
73     mvwaddstr(main_sub, 0, 0, COMMUNITY_HEADER1);
74     mvwaddstr(main_sub, 0, 25, COMMUNITY_HEADER2);
75     mvwaddstr(main_sub, 1, 0, COMMUNITY_USER);
76     mvwaddstr(main_sub, 2, 0, COMMUNITY_ADMIN);
77
78     if (ap_type == ATMEL410 || ap_type == ATMEL12350) {
79         mvwaddstr(main_sub, 3, 0, COMMUNITY_MANUF);
80     }
81     wrefresh(main_sub);
82
83     noecho();
84     print_help(COMMUNITY_HELP);
85     while (1) {
86         switch (getch()) {
87         default:
88             continue;
89         case 'U':
90         case 'u':
91 /*          get_value(user, 1, 25, sizeof(user), ANY_STRING, 0, 0, NULL); */
92             get_pass(user, 1, strlen(COMMUNITY_USER), sizeof(user));
93             continue;
94         case 'A':
95         case 'a':
96 /*          get_value(admin, 2, 25, sizeof(admin), ANY_STRING, 0, 0, NULL); */
97             get_pass(admin, 2, strlen(COMMUNITY_ADMIN), sizeof(admin));
98             continue;
99         case 'M':
100         case 'm':
101             if (ap_type == ATMEL410 || ap_type == ATMEL12350)
102 /*
103                 get_value(manufact, 3, 25, sizeof(manufact), ANY_STRING,
104                     0, 0, NULL);
105 */
106                 get_pass(manufact, 3, strlen(COMMUNITY_MANUF),
107                     sizeof(manufact));
108             continue;
109         case 'Q':
110         case 'q':
111             goto quit;
112         case 'W':
113         case 'w':
114             i = 0;
115             if (strlen(user)) {
116                 varbinds[i].oid = AuthorizedUserPass[ap_type];
117                 varbinds[i].len_oid = sizeof(AuthorizedUserPass[ap_type]);
118                 varbinds[i].value = user;
119                 varbinds[i].len_val = strlen(user);
120                 varbinds[i].type = STRING_VALUE;
121                 i++;
122             }
123             if (strlen(admin)) {
124                 varbinds[i].oid = AuthorizedAdminPass[ap_type];
125                 varbinds[i].len_oid = sizeof(AuthorizedAdminPass[ap_type]);
126                 varbinds[i].value = admin;
127                 varbinds[i].len_val = strlen(admin);
128                 varbinds[i].type = STRING_VALUE;
129                 i++;
130             }
131             if ((ap_type == ATMEL410 || ap_type == ATMEL12350) && strlen(manufact)) {
132                 varbinds[i].oid = AuthorizedManufactPass;
133                 varbinds[i].len_oid = sizeof(AuthorizedManufactPass);
134                 varbinds[i].value = manufact;
135                 varbinds[i].len_val = strlen(manufact);
136                 varbinds[i].type = STRING_VALUE;
137                 i++;
138             }
139             print_help(WAIT_SET);
140             if (snmp(varbinds, i, SET) <= 0) {
141                 print_helperr(ERR_SET);
142                 goto exit;
143             }
144             break;
145         }
146         break;
147     }
148
149     print_help(DONE_SET);
150   exit:
151     getch();
152   quit:
153     print_help("");
154     print_top(NULL, NULL);
155     clear_main(0);
156 }