00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013 #include <rsbac/types.h>
00014 #include <rsbac/getname.h>
00015 #include <rsbac/net_getname.h>
00016 #include <rsbac/helpers.h>
00017 #include <rsbac/error.h>
00018
00019 #ifdef __KERNEL__
00020 #include <linux/string.h>
00021 #include <linux/module.h>
00022 #else
00023 #include <linux/socket.h>
00024 #include <string.h>
00025 #include <stdio.h>
00026 #endif
00027
00028 static char net_temp_syscall_list[NTS_none + 1][19] = {
00029 "new_template",
00030 "copy_template",
00031 "delete_template",
00032 "check_id",
00033 "get_address",
00034 "get_address_family",
00035 "get_type",
00036 "get_protocol",
00037 "get_netdev",
00038 "get_ports",
00039 "get_name",
00040 "set_address",
00041 "set_address_family",
00042 "set_type",
00043 "set_protocol",
00044 "set_netdev",
00045 "set_ports",
00046 "set_name",
00047 "none"
00048 };
00049
00050 static char net_family_list[AF_MAX + 1][19] = {
00051 "ANY",
00052 "UNIX",
00053 "INET",
00054 "AX25",
00055 "IPX",
00056 "APPLETALK",
00057 "NETROM",
00058 "BRIDGE",
00059 "ATMPVC",
00060 "X25",
00061 "INET6",
00062 "ROSE",
00063 "DECnet",
00064 "NETBEUI",
00065 "SECURITY",
00066 "KEY",
00067 "NETLINK",
00068 "PACKET",
00069 "ASH",
00070 "ECONET",
00071 "ATMSVC",
00072 "(undefined)",
00073 "SNA",
00074 "IRDA",
00075 "PPPOX",
00076 "WANPIPE",
00077 "(undefined)",
00078 "(undefined)",
00079 "(undefined)",
00080 "(undefined)",
00081 "(undefined)",
00082 "BLUETOOTH",
00083 "MAX"
00084 };
00085
00086 struct proto_desc_t {
00087 char name[19];
00088 int nr;
00089 };
00090 #define NR_PROTO 18
00091
00092 static struct proto_desc_t net_protocol_list[NR_PROTO] = {
00093 {"ANY", 0},
00094 {"ICMP", 1},
00095 {"IGMP", 2},
00096 {"IPIP", 4},
00097 {"TCP", 6},
00098 {"EGP", 8},
00099 {"PUP", 12},
00100 {"UDP", 17},
00101 {"IDP", 22},
00102 {"RSVP", 46},
00103 {"GRE", 47},
00104 {"IPV6", 41},
00105 {"PIM", 103},
00106 {"ESP", 50},
00107 {"AH", 51},
00108 {"COMP", 108},
00109 {"RAW", 255},
00110 {"MAX", RSBAC_NET_PROTO_MAX}
00111 };
00112
00113 static char rsbac_net_type_list[RSBAC_NET_TYPE_MAX + 1][19] = {
00114 "ANY",
00115 "STREAM",
00116 "DGRAM",
00117 "RAW",
00118 "RDM",
00119 "SEQPACKET",
00120 "(undefined)",
00121 "(undefined)",
00122 "(undefined)",
00123 "(undefined)",
00124 "PACKET",
00125
00126
00127
00128
00129 "MAX"
00130 };
00131
00132
00133
00134 char *rsbac_get_net_temp_syscall_name(char *name,
00135 enum rsbac_net_temp_syscall_t value)
00136 {
00137 if (!name)
00138 return (NULL);
00139 if (value > NTS_none)
00140 strcpy(name, "ERROR!");
00141 else
00142 strcpy(name, net_temp_syscall_list[value]);
00143 return (name);
00144 };
00145
00146 #ifndef __KERNEL__
00147 enum rsbac_net_temp_syscall_t rsbac_get_net_temp_syscall_nr(const char
00148 *name)
00149 {
00150 enum rsbac_net_temp_syscall_t i;
00151
00152 if (!name)
00153 return (NTS_none);
00154 for (i = 0; i < NTS_none; i++) {
00155 if (!strcmp(name, net_temp_syscall_list[i])) {
00156 return (i);
00157 }
00158 }
00159 return (NTS_none);
00160 };
00161 #endif
00162
00163 #ifdef __KERNEL__
00164 #if defined(CONFIG_RSBAC_REG) || defined(CONFIG_RSBAC_REG_MAINT)
00165 EXPORT_SYMBOL(rsbac_get_net_family_name);
00166 #endif
00167 #endif
00168 char *rsbac_get_net_family_name(char *name, u_int value)
00169 {
00170 if (!name)
00171 return (NULL);
00172 if (value > AF_MAX)
00173 strcpy(name, "ERROR!");
00174 else
00175 strcpy(name, net_family_list[value]);
00176 return (name);
00177 };
00178
00179 #ifndef __KERNEL__
00180 int rsbac_get_net_family_nr(const char *name)
00181 {
00182 int i;
00183
00184 if (!name)
00185 return (AF_MAX);
00186 for (i = 0; i < AF_MAX; i++) {
00187 if (!strcmp(name, net_family_list[i])) {
00188 return (i);
00189 }
00190 }
00191 return (AF_MAX);
00192 };
00193 #endif
00194
00195 #ifdef __KERNEL__
00196 #if defined(CONFIG_RSBAC_REG) || defined(CONFIG_RSBAC_REG_MAINT)
00197 EXPORT_SYMBOL(rsbac_get_net_protocol_name);
00198 #endif
00199 #endif
00200 char *rsbac_get_net_protocol_name(char *name, u_int value)
00201 {
00202 int i;
00203
00204 if (!name)
00205 return (NULL);
00206 if (value >= RSBAC_NET_PROTO_MAX)
00207 strcpy(name, "ERROR!");
00208 else {
00209 for (i = 0; i < NR_PROTO; i++) {
00210 if (net_protocol_list[i].nr == value) {
00211 strcpy(name, net_protocol_list[i].name);
00212 return name;
00213 }
00214 }
00215 sprintf(name, "%u", value);
00216 }
00217 return (name);
00218 };
00219
00220 #ifndef __KERNEL__
00221 int rsbac_get_net_protocol_nr(const char *name)
00222 {
00223 int i;
00224
00225 if (!name)
00226 return (RSBAC_NET_PROTO_MAX);
00227 for (i = 0; i < NR_PROTO; i++) {
00228 if (!strcmp(name, net_protocol_list[i].name)) {
00229 return (net_protocol_list[i].nr);
00230 }
00231 }
00232 return (RSBAC_NET_PROTO_MAX);
00233 };
00234 #endif
00235
00236 #ifdef __KERNEL__
00237 #if defined(CONFIG_RSBAC_REG) || defined(CONFIG_RSBAC_REG_MAINT)
00238 EXPORT_SYMBOL(rsbac_get_net_type_name);
00239 #endif
00240 #endif
00241 char *rsbac_get_net_type_name(char *name, u_int value)
00242 {
00243 if (!name)
00244 return (NULL);
00245 if (value > RSBAC_NET_TYPE_MAX)
00246 strcpy(name, "ERROR!");
00247 else
00248 strcpy(name, rsbac_net_type_list[value]);
00249 return (name);
00250 };
00251
00252 #ifndef __KERNEL__
00253 int rsbac_get_net_type_nr(const char *name)
00254 {
00255 int i;
00256
00257 if (!name)
00258 return (RSBAC_NET_TYPE_MAX);
00259 for (i = 0; i < RSBAC_NET_TYPE_MAX; i++) {
00260 if (!strcmp(name, rsbac_net_type_list[i])) {
00261 return (i);
00262 }
00263 }
00264 return (RSBAC_NET_TYPE_MAX);
00265 };
00266 #endif
00267
00268 #ifdef __KERNEL__
00269 int rsbac_net_str_to_inet(char *str, __u32 * addr)
00270 {
00271 char *end;
00272 __u32 s0, s1, s2, s3;
00273
00274 if (!str || !addr)
00275 return -RSBAC_EINVALIDPOINTER;
00276 end = str;
00277 while (*end) {
00278 if ((*end != '.')
00279 && (*end != '\n')
00280 && (*end != ' ')
00281 && ((*end < '0')
00282 || (*end > '9')
00283 )
00284 )
00285 return -RSBAC_EINVALIDVALUE;
00286 end++;
00287 }
00288 s0 = simple_strtoul(str, &end, 10);
00289 if (!*end || (s0 > 255))
00290 return -RSBAC_EINVALIDVALUE;
00291 end++;
00292 s1 = simple_strtoul(end, &end, 10);
00293 if (!*end || (s1 > 255))
00294 return -RSBAC_EINVALIDVALUE;
00295 end++;
00296 s2 = simple_strtoul(end, &end, 10);
00297 if (!*end || (s2 > 255))
00298 return -RSBAC_EINVALIDVALUE;
00299 end++;
00300 s3 = simple_strtoul(end, &end, 10);
00301 if (*end || (s3 > 255))
00302 return -RSBAC_EINVALIDVALUE;
00303 *addr = s3 | (s2 << 8) | (s1 << 16) | (s0 << 24);
00304 *addr = htonl(*addr);
00305 return 0;
00306 }
00307 #endif