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 <linux/socket.h>
00022 #include <string.h>
00023 #endif
00024 
00025 static char net_temp_syscall_list[NTS_none+1][19] = {
00026                           "new_template",
00027                           "copy_template",
00028                           "delete_template",
00029                           "check_id",
00030                           "get_address",
00031                           "get_address_family",
00032                           "get_valid_len",
00033                           "get_type",
00034                           "get_protocol",
00035                           "get_netdev",
00036                           "get_min_port",
00037                           "get_max_port",
00038                           "get_name",
00039                           "set_address",
00040                           "set_address_family",
00041                           "set_valid_len",
00042                           "set_type",
00043                           "set_protocol",
00044                           "set_netdev",
00045                           "set_min_port",
00046                           "set_max_port",
00047                           "set_name",
00048                           "none" };
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 struct proto_desc_t
00086   {
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 static char rsbac_net_type_list[RSBAC_NET_TYPE_MAX+1][19] = {
00113                       "ANY",
00114                       "STREAM",         /* 1 stream (connection) socket */
00115                       "DGRAM",          /* 2 datagram (conn.less) socket */
00116                       "RAW",            /* 3 raw socket */
00117                       "RDM",            /* 4 reliably-delivered message */
00118                       "SEQPACKET",      /* 5 sequential packet socket */
00119                       "(undefined)",    /* 6 */
00120                       "(undefined)",    /* 7 */
00121                       "(undefined)",    /* 8 */
00122                       "(undefined)",    /* 9 */
00123                       "PACKET",         /* 10 linux specific way of */
00124                                         /* getting packets at the dev */
00125                                         /* level.  For writing rarp and */
00126                                         /* other similar things on the */
00127                                         /* user level. */
00128                       "MAX" };
00129 
00130 /*****************************************/
00131 
00132 char * rsbac_get_net_temp_syscall_name(char * name,
00133                                  enum rsbac_net_temp_syscall_t value)
00134   {
00135     if(!name)
00136       return(NULL);
00137     if(value > NTS_none)
00138       strcpy(name, "ERROR!");
00139     else
00140       strcpy(name, net_temp_syscall_list[value]);
00141     return(name);
00142   };
00143 
00144 #ifndef __KERNEL__
00145 enum rsbac_net_temp_syscall_t rsbac_get_net_temp_syscall_nr(const char * name)
00146   {
00147     enum  rsbac_net_temp_syscall_t i;
00148 
00149     if(!name)
00150       return(NTS_none);
00151     for (i = 0; i < NTS_none; i++)
00152       {
00153         if (!strcmp(name, net_temp_syscall_list[i]))
00154           {
00155             return(i);
00156           }
00157       }
00158     return(NTS_none);
00159   };
00160 #endif
00161 
00162 #ifdef __KERNEL__
00163 #if defined(CONFIG_RSBAC_REG) || defined(CONFIG_RSBAC_REG_MAINT)
00164 EXPORT_SYMBOL(rsbac_get_net_family_name);
00165 #endif
00166 #endif
00167 char * rsbac_get_net_family_name(char * name,
00168                            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       {
00188         if (!strcmp(name, net_family_list[i]))
00189           {
00190             return(i);
00191           }
00192       }
00193     return(AF_MAX);
00194   };
00195 #endif
00196 
00197 #ifdef __KERNEL__
00198 #if defined(CONFIG_RSBAC_REG) || defined(CONFIG_RSBAC_REG_MAINT)
00199 EXPORT_SYMBOL(rsbac_get_net_protocol_name);
00200 #endif
00201 #endif
00202 char * rsbac_get_net_protocol_name(char * name,
00203                              u_int value)
00204   {
00205     int i;
00206 
00207     if(!name)
00208       return(NULL);
00209     if(value >= RSBAC_NET_PROTO_MAX)
00210       strcpy(name, "ERROR!");
00211     else
00212       {
00213         for (i = 0; i < NR_PROTO; i++)
00214           {
00215             if (net_protocol_list[i].nr == value)
00216               {
00217                 strcpy(name, net_protocol_list[i].name);
00218                 return name;
00219               }
00220           }
00221         sprintf(name, "%u", value);
00222       }
00223     return(name);
00224   };
00225 
00226 #ifndef __KERNEL__
00227 int rsbac_get_net_protocol_nr(const char * name)
00228   {
00229     int i;
00230 
00231     if(!name)
00232       return(RSBAC_NET_PROTO_MAX);
00233     for (i = 0; i < NR_PROTO; i++)
00234       {
00235         if (!strcmp(name, net_protocol_list[i].name))
00236           {
00237             return(net_protocol_list[i].nr);
00238           }
00239       }
00240     return(RSBAC_NET_PROTO_MAX);
00241   };
00242 #endif
00243 
00244 #ifdef __KERNEL__
00245 #if defined(CONFIG_RSBAC_REG) || defined(CONFIG_RSBAC_REG_MAINT)
00246 EXPORT_SYMBOL(rsbac_get_net_type_name);
00247 #endif
00248 #endif
00249 char * rsbac_get_net_type_name(char * name,
00250                          u_int value)
00251   {
00252     if(!name)
00253       return(NULL);
00254     if(value > RSBAC_NET_TYPE_MAX)
00255       strcpy(name, "ERROR!");
00256     else
00257       strcpy(name, rsbac_net_type_list[value]);
00258     return(name);
00259   };
00260 
00261 #ifndef __KERNEL__
00262 int rsbac_get_net_type_nr(const char * name)
00263   {
00264     int i;
00265 
00266     if(!name)
00267       return(RSBAC_NET_TYPE_MAX);
00268     for (i = 0; i < RSBAC_NET_TYPE_MAX; i++)
00269       {
00270         if (!strcmp(name, rsbac_net_type_list[i]))
00271           {
00272             return(i);
00273           }
00274       }
00275     return(RSBAC_NET_TYPE_MAX);
00276   };
00277 #endif
00278 
00279 #ifdef __KERNEL__
00280 int rsbac_net_str_to_inet(char * str, __u32 * addr)
00281   {
00282     char * end;
00283     __u32 s0,s1,s2,s3;
00284 
00285     if(!str || !addr)
00286       return -RSBAC_EINVALIDPOINTER;
00287     end = str;
00288     while(*end)
00289       {
00290         if(   (*end != '.')
00291            && (*end != '\n')
00292            && (*end != ' ')
00293            && (   (*end < '0')
00294                || (*end > '9')
00295               )
00296           )
00297           return -RSBAC_EINVALIDVALUE;
00298         end++;
00299       }
00300     s0 = simple_strtoul(str, &end, 10);
00301     if(!*end || (s0 > 255))
00302       return -RSBAC_EINVALIDVALUE;
00303     end++;
00304     s1 = simple_strtoul(end, &end, 10);
00305     if(!*end || (s1 > 255))
00306       return -RSBAC_EINVALIDVALUE;
00307     end++;
00308     s2 = simple_strtoul(end, &end, 10);
00309     if(!*end || (s2 > 255))
00310       return -RSBAC_EINVALIDVALUE;
00311     end++;
00312     s3 = simple_strtoul(end, &end, 10);
00313     if(*end || (s3 > 255))
00314       return -RSBAC_EINVALIDVALUE;
00315     *addr = s0 | (s1 << 8) | (s2 << 16) | (s3 << 24);
00316     return 0;
00317   }
00318 #endif

Generated on Fri Jun 17 09:45:26 2005 for RSBAC by  doxygen 1.4.2