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