]> git.decadent.org.uk Git - ap-utils.git/blob - lib/set_community.c
d7fc47dab81892a462c6009de144dd9637f3cff2
[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 #include "ap-curses.h"
27
28 #define COMMUNITY_TOP_HEADER _("Set community/password")
29 #define COMMUNITY_HEADER1 _("Key Access level")
30 #define COMMUNITY_HEADER2 _("Community/Password")
31 #define COMMUNITY_USER  _("[U] User")
32 #define COMMUNITY_ADMIN  _("[A] Administrator")
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
41     char AuthorizedUserPass[3][12] = {
42         {0x2B, 0x06, 0x01, 0x04, 0x01, 0x83, 0x1A, 0x01, 0x01, 0x09, 0x01,
43          0x00},
44         {0x2B, 0x06, 0x01, 0x04, 0x01, 0x87, 0x29, 0x02, 0x01, 0x02, 0x01,
45          0x00},
46        {0x2B, 0x06, 0x01, 0x04, 0x01, 0xe0, 0x3e, 0x01, 0x01, 0x09, 0x01,
47          0x00}
48     };
49     char AuthorizedAdminPass[3][12] = {
50         {0x2B, 0x06, 0x01, 0x04, 0x01, 0x83, 0x1A, 0x01, 0x01, 0x09, 0x02,
51          0x00},
52         {0x2B, 0x06, 0x01, 0x04, 0x01, 0x87, 0x29, 0x02, 0x01, 0x02, 0x02,
53          0x00},
54         {0x2B, 0x06, 0x01, 0x04, 0x01, 0xe0, 0x3e, 0x01, 0x01, 0x09, 0x02,
55          0x00}
56     };
57     char AuthorizedManufactPass[] =
58         { 0x2B, 0x06, 0x01, 0x04, 0x01, 0x83, 0x1A, 0x01, 0x01, 0x09, 0x03,
59         0x00
60     };
61
62     varbind varbinds[3];
63     char user[16], admin[16], manufact[16];
64     int i;
65
66     if (ap_type == ATMEL12350) {
67         AuthorizedManufactPass[5] = 0xE0;
68         AuthorizedManufactPass[6] = 0x3E;
69     }
70
71     user[0] = admin[0] = manufact[0] = '\0';
72     print_title(COMMUNITY_TOP_HEADER);
73
74     mvwaddstr(main_sub, 0, 0, COMMUNITY_HEADER1);
75     mvwaddstr(main_sub, 0, 25, COMMUNITY_HEADER2);
76     mvwaddstr(main_sub, 1, 0, COMMUNITY_USER);
77     mvwaddstr(main_sub, 2, 0, COMMUNITY_ADMIN);
78
79     if (ap_type == ATMEL410 || ap_type == ATMEL12350) {
80         mvwaddstr(main_sub, 3, 0, _("[M] Manufacturer"));
81     }
82     wrefresh(main_sub);
83
84     noecho();
85     print_help(COMMUNITY_HELP);
86     while (1) {
87         switch (getch()) {
88         default:
89             continue;
90         case 'U':
91         case 'u':
92 /*          get_value(user, 1, 25, sizeof(user), ANY_STRING, 0, 0, NULL); */
93             get_pass(user, 1, 25, sizeof(user));
94             continue;
95         case 'A':
96         case 'a':
97 /*          get_value(admin, 2, 25, sizeof(admin), ANY_STRING, 0, 0, NULL); */
98             get_pass(admin, 2, 25, sizeof(admin));
99             continue;
100         case 'M':
101         case 'm':
102             if (ap_type == ATMEL410 || ap_type == ATMEL12350)
103 /*
104                 get_value(manufact, 3, 25, sizeof(manufact), ANY_STRING,
105                     0, 0, NULL);
106 */
107                 get_pass(manufact, 3, 25, 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_title("");
155     clear_main(0);
156 }