]> git.decadent.org.uk Git - ap-utils.git/blob - lib/set_community.c
22f6c20edd21d8c0266f249a04ba8df0461b29a9
[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, 37, 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, 37, sizeof(user), ANY_STRING, 0, 0, NULL); */
92             get_pass(user, 1, 37, sizeof(user));
93             continue;
94         case 'A':
95         case 'a':
96 /*          get_value(admin, 2, 37, sizeof(admin), ANY_STRING, 0, 0, NULL); */
97             get_pass(admin, 2, 37, sizeof(admin));
98             continue;
99         case 'M':
100         case 'm':
101             if (ap_type == ATMEL410 || ap_type == ATMEL12350)
102 /*
103                 get_value(manufact, 3, 37, sizeof(manufact), ANY_STRING,
104                     0, 0, NULL);
105 */
106                 get_pass(manufact, 3, 37, sizeof(manufact));
107             continue;
108         case 'Q':
109         case 'q':
110             goto quit;
111         case 'W':
112         case 'w':
113             i = 0;
114             if (strlen(user)) {
115                 varbinds[i].oid = AuthorizedUserPass[ap_type];
116                 varbinds[i].len_oid = sizeof(AuthorizedUserPass[ap_type]);
117                 varbinds[i].value = user;
118                 varbinds[i].len_val = strlen(user);
119                 varbinds[i].type = STRING_VALUE;
120                 i++;
121             }
122             if (strlen(admin)) {
123                 varbinds[i].oid = AuthorizedAdminPass[ap_type];
124                 varbinds[i].len_oid = sizeof(AuthorizedAdminPass[ap_type]);
125                 varbinds[i].value = admin;
126                 varbinds[i].len_val = strlen(admin);
127                 varbinds[i].type = STRING_VALUE;
128                 i++;
129             }
130             if ((ap_type == ATMEL410 || ap_type == ATMEL12350) && strlen(manufact)) {
131                 varbinds[i].oid = AuthorizedManufactPass;
132                 varbinds[i].len_oid = sizeof(AuthorizedManufactPass);
133                 varbinds[i].value = manufact;
134                 varbinds[i].len_val = strlen(manufact);
135                 varbinds[i].type = STRING_VALUE;
136                 i++;
137             }
138             print_help(WAIT_SET);
139             if (snmp(varbinds, i, SET) <= 0) {
140                 print_helperr(ERR_SET);
141                 goto exit;
142             }
143             wbkgd(main_sub, A_NORMAL);
144             wrefresh(main_sub);
145             break;
146         }
147         break;
148     }
149
150     print_help(DONE_SET);
151   exit:
152     getch();
153   quit:
154     print_help("");
155     print_top(NULL, NULL);
156     clear_main(0);
157 }