/linux-2.6.21.1-rsbac-1.3.4/rsbac/help/net_getname.c

Go to the documentation of this file.
00001 /*
00002  * net_getname.c: Getname functions for the Network
00003  *
00004  * Author and Copyright (C) 1999-2005 Amon Ott (ao@rsbac.org)
00005  *
00006  *      This program is free software; you can redistribute it and/or
00007  *      modify it under the terms of the GNU General Public License as
00008  *      published by the Free Software Foundation, version 2.
00009  *
00010  * Last modified 13/03/2002.
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",                  /* 0 */
00052         "UNIX",                 /* 1 Unix domain sockets */
00053         "INET",                 /* 2 Internet IP Protocol */
00054         "AX25",                 /* 3 Amateur Radio AX.25 */
00055         "IPX",                  /* 4 Novell IPX */
00056         "APPLETALK",            /* 5 AppleTalk DDP */
00057         "NETROM",               /* 6 Amateur Radio NET/ROM */
00058         "BRIDGE",               /* 7 Multiprotocol bridge */
00059         "ATMPVC",               /* 8 ATM PVCs */
00060         "X25",                  /* 9 Reserved for X.25 project */
00061         "INET6",                /* 10 IP version 6 */
00062         "ROSE",                 /* 11 Amateur Radio X.25 PLP */
00063         "DECnet",               /* 12 Reserved for DECnet project */
00064         "NETBEUI",              /* 13 Reserved for 802.2LLC project */
00065         "SECURITY",             /* 14 Security callback pseudo AF */
00066         "KEY",                  /* 15 PF_KEY key management API */
00067         "NETLINK",              /* 16 */
00068         "PACKET",               /* 17 Packet family */
00069         "ASH",                  /* 18 Ash */
00070         "ECONET",               /* 19 Acorn Econet  */
00071         "ATMSVC",               /* 20 ATM SVCs */
00072         "(undefined)",          /* 21 */
00073         "SNA",                  /* 22 Linux SNA Project (nutters!) */
00074         "IRDA",                 /* 23 IRDA sockets */
00075         "PPPOX",                /* 24 PPPoX sockets */
00076         "WANPIPE",              /* 25 Wanpipe API Sockets */
00077         "(undefined)",          /* 26 */
00078         "(undefined)",          /* 27 */
00079         "(undefined)",          /* 28 */
00080         "(undefined)",          /* 29 */
00081         "(undefined)",          /* 30 */
00082         "BLUETOOTH",            /* 31 Bluetooth sockets */
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},             /* 0 Dummy protocol for TCP */
00094         {"ICMP", 1},            /* Internet Control Message Protocol */
00095         {"IGMP", 2},            /* Internet Group Management Protocol   */
00096         {"IPIP", 4},            /* IPIP tunnels (older KA9Q tunnels use 94) */
00097         {"TCP", 6},             /* Transmission Control Protocol */
00098         {"EGP", 8},             /* Exterior Gateway Protocol */
00099         {"PUP", 12},            /* PUP protocol */
00100         {"UDP", 17},            /* User Datagram Protocol */
00101         {"IDP", 22},            /* XNS IDP protocol */
00102         {"RSVP", 46},           /* RSVP protocol */
00103         {"GRE", 47},            /* Cisco GRE tunnels (rfc 1701,1702) */
00104         {"IPV6", 41},           /* IPv6-in-IPv4 tunnelling */
00105         {"PIM", 103},           /* Protocol Independent Multicast */
00106         {"ESP", 50},            /* Encapsulation Security Payload protocol */
00107         {"AH", 51},             /* Authentication Header protocol */
00108         {"COMP", 108},          /* Compression Header protocol */
00109         {"RAW", 255},           /* Raw IP packets */
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",               /* 1 stream (connection) socket */
00116         "DGRAM",                /* 2 datagram (conn.less) socket */
00117         "RAW",                  /* 3 raw socket */
00118         "RDM",                  /* 4 reliably-delivered message */
00119         "SEQPACKET",            /* 5 sequential packet socket */
00120         "(undefined)",          /* 6 */
00121         "(undefined)",          /* 7 */
00122         "(undefined)",          /* 8 */
00123         "(undefined)",          /* 9 */
00124         "PACKET",               /* 10 linux specific way of */
00125         /* getting packets at the dev */
00126         /* level.  For writing rarp and */
00127         /* other similar things on the */
00128         /* user level. */
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

Generated on Wed May 16 11:53:48 2007 for RSBAC by  doxygen 1.5.1