net_getname.c

Go to the documentation of this file.
00001 /************************************ */
00002 /* Rule Set Based Access Control      */
00003 /*                                    */
00004 /* Author and (c) 1999-2002:          */
00005 /* Amon Ott <ao@rsbac.org>            */
00006 /*                                    */
00007 /* Getname functions for Network      */
00008 /* Last modified: 13/Mar/2002         */
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",            /* 0 */
00053                       "UNIX",           /* 1 Unix domain sockets */
00054                       "INET",           /* 2 Internet IP Protocol */
00055                       "AX25",           /* 3 Amateur Radio AX.25 */
00056                       "IPX",            /* 4 Novell IPX */
00057                       "APPLETALK",      /* 5 AppleTalk DDP */
00058                       "NETROM",         /* 6 Amateur Radio NET/ROM */
00059                       "BRIDGE",         /* 7 Multiprotocol bridge */
00060                       "ATMPVC",         /* 8 ATM PVCs */
00061                       "X25",            /* 9 Reserved for X.25 project */
00062                       "INET6",          /* 10 IP version 6 */
00063                       "ROSE",           /* 11 Amateur Radio X.25 PLP */
00064                       "DECnet",         /* 12 Reserved for DECnet project */
00065                       "NETBEUI",        /* 13 Reserved for 802.2LLC project */
00066                       "SECURITY",       /* 14 Security callback pseudo AF */
00067                       "KEY",            /* 15 PF_KEY key management API */
00068                       "NETLINK",        /* 16 */
00069                       "PACKET",         /* 17 Packet family */
00070                       "ASH",            /* 18 Ash */
00071                       "ECONET",         /* 19 Acorn Econet      */
00072                       "ATMSVC",         /* 20 ATM SVCs */
00073                       "(undefined)",    /* 21 */
00074                       "SNA",            /* 22 Linux SNA Project (nutters!) */
00075                       "IRDA",           /* 23 IRDA sockets */
00076                       "PPPOX",          /* 24 PPPoX sockets */
00077                       "WANPIPE",        /* 25 Wanpipe API Sockets */
00078                       "(undefined)",    /* 26 */
00079                       "(undefined)",    /* 27 */
00080                       "(undefined)",    /* 28 */
00081                       "(undefined)",    /* 29 */
00082                       "(undefined)",    /* 30 */
00083                       "BLUETOOTH",      /* 31 Bluetooth sockets */
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},       /* 0 Dummy protocol for TCP */
00095                       {"ICMP", 1},      /* Internet Control Message Protocol */
00096                       {"IGMP", 2},      /* Internet Group Management Protocol   */
00097                       {"IPIP", 4},      /* IPIP tunnels (older KA9Q tunnels use 94) */
00098                       {"TCP", 6},       /* Transmission Control Protocol */
00099                       {"EGP", 8},       /* Exterior Gateway Protocol */
00100                       {"PUP", 12},      /* PUP protocol */
00101                       {"UDP", 17},      /* User Datagram Protocol */
00102                       {"IDP", 22},      /* XNS IDP protocol */
00103                       {"RSVP", 46},     /* RSVP protocol */
00104                       {"GRE", 47},      /* Cisco GRE tunnels (rfc 1701,1702) */
00105                       {"IPV6", 41},     /* IPv6-in-IPv4 tunnelling */
00106                       {"PIM", 103},     /* Protocol Independent Multicast */
00107                       {"ESP", 50},      /* Encapsulation Security Payload protocol */
00108                       {"AH", 51},       /* Authentication Header protocol */
00109                       {"COMP", 108},    /* Compression Header protocol */
00110                       {"RAW", 255},     /* Raw IP packets */
00111                       {"MAX", RSBAC_NET_PROTO_MAX} };
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 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

Generated on Sun May 21 14:30:56 2006 for RSBAC by  doxygen 1.4.2