Main Page   Alphabetical List   Data Structures   File List   Data Fields   Globals   Related Pages  

access.c File Reference

Go to the source code of this file.

Functions

int match_hostname (char *host, char *tok)
int match_address (char *addr, char *tok)
int access_match (char *list, char *addr, char *host)
int allow_access (char *addr, char *host, char *allow_list, char *deny_list)


Function Documentation

int match_hostname char *    host,
char *    tok
[static]
 

Definition at line 27 of file access.c.

References fnmatch(), and host.

Referenced by access_match().

00028 {
00029         if (!host || !*host) return 0;
00030         return (fnmatch(tok, host, 0) == 0);
00031 }

int match_address char *    addr,
char *    tok
[static]
 

Definition at line 34 of file access.c.

References FERROR, and rprintf().

Referenced by access_match().

00035 {
00036         char *p;
00037         unsigned long a, t, mask = (unsigned long)~0;
00038 
00039         if (!addr || !*addr) return 0;
00040 
00041         if (!isdigit(* (unsigned char *) tok)) return 0;
00042 
00043         p = strchr(tok,'/');
00044         if (p) *p = 0;
00045 
00046         a = inet_addr(addr);
00047         t = inet_addr(tok);
00048 
00049         if (p) {
00050                 *p = '/';
00051         }
00052 
00053         if (t == INADDR_NONE) {
00054                 rprintf(FERROR,"malformed address %s\n", tok);
00055                 return 0;
00056         }
00057 
00058         a = ntohl(a);
00059         t = ntohl(t);
00060 
00061         if (p) {
00062                 if (strchr(p+1,'.')) {
00063                         mask = inet_addr(p+1);
00064                         if (mask == INADDR_NONE) {
00065                                 rprintf(FERROR,"malformed mask in %s\n", tok);
00066                                 return 0;
00067                         }
00068                         mask = ntohl(mask);
00069                 } else {
00070                         int bits = atoi(p+1);
00071                         if (bits == 0) return 1;
00072                         if (bits <= 0 || bits > 32) {
00073                                 rprintf(FERROR,"malformed mask in %s\n", tok);
00074                                 return 0;
00075                         }
00076                         mask &= (mask << (32-bits));
00077                 }
00078         }
00079 
00080         return ((a&mask) == (t&mask));
00081 }

int access_match char *    list,
char *    addr,
char *    host
[static]
 

Definition at line 83 of file access.c.

References host, match_address(), match_hostname(), out_of_memory(), strdup(), and strlower().

Referenced by allow_access().

00084 {
00085         char *tok;
00086         char *list2 = strdup(list);
00087 
00088         if (!list2) out_of_memory("access_match");
00089 
00090         strlower(list2);
00091         if (host) strlower(host);
00092 
00093         for (tok=strtok(list2," ,\t"); tok; tok=strtok(NULL," ,\t")) {
00094                 if (match_hostname(host, tok) || match_address(addr, tok)) {
00095                         free(list2);
00096                         return 1;
00097                 }
00098         }
00099 
00100         free(list2);
00101         return 0;
00102 }

int allow_access char *    addr,
char *    host,
char *    allow_list,
char *    deny_list
 

Definition at line 104 of file access.c.

References access_match(), and host.

Referenced by rsync_module().

00105 {
00106         /* if theres no deny list and no allow list then allow access */
00107         if ((!deny_list || !*deny_list) && (!allow_list || !*allow_list))
00108                 return 1;
00109 
00110         /* if there is an allow list but no deny list then allow only hosts
00111            on the allow list */
00112         if (!deny_list || !*deny_list)
00113                 return(access_match(allow_list, addr, host));
00114 
00115         /* if theres a deny list but no allow list then allow
00116            all hosts not on the deny list */
00117         if (!allow_list || !*allow_list)
00118                 return(!access_match(deny_list,addr,host));
00119 
00120         /* if there are both type of list then allow all hosts on the
00121            allow list */
00122         if (access_match(allow_list,addr,host))
00123                 return 1;
00124 
00125         /* if there are both type of list and it's not on the allow then
00126            allow it if its not on the deny */
00127         if (access_match(deny_list,addr,host))
00128                 return 0;
00129 
00130         return 1;
00131 }


Generated on Tue Apr 16 12:37:37 2002 for rsync by doxygen1.2.15