summaryrefslogtreecommitdiff
path: root/source3/lib/access.c
diff options
context:
space:
mode:
authorJeremy Allison <jra@samba.org>2002-11-12 23:20:50 +0000
committerJeremy Allison <jra@samba.org>2002-11-12 23:20:50 +0000
commit2f194322d419350f35a48dff750066894d68eccf (patch)
treeb0501eaf874ca8e740a51a8e0f29d261e32e0093 /source3/lib/access.c
parentf2b669b37fecda2687860eba4a15801dc89855dc (diff)
downloadsamba-2f194322d419350f35a48dff750066894d68eccf.tar.gz
samba-2f194322d419350f35a48dff750066894d68eccf.tar.bz2
samba-2f194322d419350f35a48dff750066894d68eccf.zip
Removed global_myworkgroup, global_myname, global_myscope. Added liberal
dashes of const. This is a rather large check-in, some things may break. It does compile though :-). Jeremy. (This used to be commit f755711df8f74f9b8e8c1a2b0d07d02a931eeb89)
Diffstat (limited to 'source3/lib/access.c')
-rw-r--r--source3/lib/access.c165
1 files changed, 79 insertions, 86 deletions
diff --git a/source3/lib/access.c b/source3/lib/access.c
index a39bc6df76..50efdcc5f0 100644
--- a/source3/lib/access.c
+++ b/source3/lib/access.c
@@ -15,17 +15,20 @@
#define ALLONES ((uint32)0xFFFFFFFF)
/* masked_match - match address against netnumber/netmask */
-static int masked_match(char *tok, char *slash, char *s)
+static BOOL masked_match(const char *tok, const char *slash, const char *s)
{
uint32 net;
uint32 mask;
uint32 addr;
+ fstring tok_cpy;
if ((addr = interpret_addr(s)) == INADDR_NONE)
return (False);
- *slash = 0;
- net = interpret_addr(tok);
- *slash = '/';
+
+ fstrcpy(tok_cpy, tok);
+ tok_cpy[PTR_DIFF(slash,tok)] = '\0';
+ net = interpret_addr(tok_cpy);
+ tok_cpy[PTR_DIFF(slash,tok)] = '/';
if (strlen(slash + 1) > 2) {
mask = interpret_addr(slash + 1);
@@ -41,11 +44,11 @@ static int masked_match(char *tok, char *slash, char *s)
}
/* string_match - match string against token */
-static int string_match(char *tok,char *s, char *invalid_char)
+static BOOL string_match(const char *tok,const char *s, char *invalid_char)
{
size_t tok_len;
size_t str_len;
- char *cut;
+ const char *cut;
*invalid_char = '\0';
@@ -73,7 +76,8 @@ static int string_match(char *tok,char *s, char *invalid_char)
char *hostname = NULL;
BOOL netgroup_ok = False;
- if (!mydomain) yp_get_default_domain(&mydomain);
+ if (!mydomain)
+ yp_get_default_domain(&mydomain);
if (!mydomain) {
DEBUG(0,("Unable to get default yp domain.\n"));
@@ -94,7 +98,8 @@ static int string_match(char *tok,char *s, char *invalid_char)
SAFE_FREE(hostname);
- if (netgroup_ok) return(True);
+ if (netgroup_ok)
+ return(True);
#else
DEBUG(0,("access: netgroup support is not configured\n"));
return (False);
@@ -122,20 +127,19 @@ static int string_match(char *tok,char *s, char *invalid_char)
return (False);
}
-
/* client_match - match host name and address against token */
-static int client_match(char *tok,char *item)
+static BOOL client_match(const char *tok, const char *item)
{
- char **client = (char **)item;
- int match;
+ const char **client = (const char **)item;
+ BOOL match;
char invalid_char = '\0';
- /*
- * Try to match the address first. If that fails, try to match the host
- * name if available.
- */
+ /*
+ * Try to match the address first. If that fails, try to match the host
+ * name if available.
+ */
- if ((match = string_match(tok, client[1], &invalid_char)) == 0) {
+ if ((match = string_match(tok, client[1], &invalid_char)) == 0) {
if(invalid_char)
DEBUG(0,("client_match: address match failing due to invalid character '%c' found in \
token '%s' in an allow/deny hosts line.\n", invalid_char, tok ));
@@ -148,50 +152,51 @@ token '%s' in an allow/deny hosts line.\n", invalid_char, tok ));
token '%s' in an allow/deny hosts line.\n", invalid_char, tok ));
}
- return (match);
+ return (match);
}
/* list_match - match an item against a list of tokens with exceptions */
-static int list_match(char **list,char *item, int (*match_fn)(char *, char *))
+static BOOL list_match(const char **list,const char *item,
+ BOOL (*match_fn)(const char *, const char *))
{
- int match = False;
-
- if (!list) return False;
-
- /*
- * Process tokens one at a time. We have exhausted all possible matches
- * when we reach an "EXCEPT" token or the end of the list. If we do find
- * a match, look for an "EXCEPT" list and recurse to determine whether
- * the match is affected by any exceptions.
- */
-
- for (; *list ; list++) {
- if (strcasecmp(*list, "EXCEPT") == 0) /* EXCEPT: give up */
- break;
- if ((match = (*match_fn) (*list, item))) /* True or FAIL */
- break;
- }
- /* Process exceptions to True or FAIL matches. */
-
- if (match != False) {
- while (*list && strcasecmp(*list, "EXCEPT"))
- list++;
-
- for (; *list; list++) {
- if ((*match_fn) (*list, item)) /* Exception Found */
- return False;
+ BOOL match = False;
+
+ if (!list)
+ return False;
+
+ /*
+ * Process tokens one at a time. We have exhausted all possible matches
+ * when we reach an "EXCEPT" token or the end of the list. If we do find
+ * a match, look for an "EXCEPT" list and recurse to determine whether
+ * the match is affected by any exceptions.
+ */
+
+ for (; *list ; list++) {
+ if (strcasecmp(*list, "EXCEPT") == 0) /* EXCEPT: give up */
+ break;
+ if ((match = (*match_fn) (*list, item))) /* True or FAIL */
+ break;
}
- }
+ /* Process exceptions to True or FAIL matches. */
- return (match);
-}
+ if (match != False) {
+ while (*list && strcasecmp(*list, "EXCEPT"))
+ list++;
+ for (; *list; list++) {
+ if ((*match_fn) (*list, item)) /* Exception Found */
+ return False;
+ }
+ }
+
+ return (match);
+}
/* return true if access should be allowed */
-static BOOL allow_access_internal(char **deny_list,char **allow_list,
- char *cname,char *caddr)
+static BOOL allow_access_internal(const char **deny_list,const char **allow_list,
+ const char *cname, const char *caddr)
{
- char *client[2];
+ const char *client[2];
client[0] = cname;
client[1] = caddr;
@@ -203,9 +208,9 @@ static BOOL allow_access_internal(char **deny_list,char **allow_list,
* Patch from Steve Langasek vorlon@netexpress.net.
*/
if (deny_list &&
- list_match(deny_list,(char *)client,client_match) &&
+ list_match(deny_list,(const char *)client,client_match) &&
(!allow_list ||
- !list_match(allow_list,(char *)client, client_match))) {
+ !list_match(allow_list,(const char *)client, client_match))) {
return False;
}
return True;
@@ -220,32 +225,31 @@ static BOOL allow_access_internal(char **deny_list,char **allow_list,
/* if there is an allow list but no deny list then allow only hosts
on the allow list */
if (!deny_list || *deny_list == 0)
- return(list_match(allow_list,(char *)client,client_match));
+ return(list_match(allow_list,(const char *)client,client_match));
/* if theres a deny list but no allow list then allow
all hosts not on the deny list */
if (!allow_list || *allow_list == 0)
- return(!list_match(deny_list,(char *)client,client_match));
+ return(!list_match(deny_list,(const char *)client,client_match));
/* if there are both types of list then allow all hosts on the
allow list */
- if (list_match(allow_list,(char *)client,client_match))
+ if (list_match(allow_list,(const char *)client,client_match))
return (True);
/* if there are both types of list and it's not on the allow then
allow it if its not on the deny */
- if (list_match(deny_list,(char *)client,client_match))
+ if (list_match(deny_list,(const char *)client,client_match))
return (False);
return (True);
}
/* return true if access should be allowed */
-BOOL allow_access(char **deny_list,char **allow_list,
+BOOL allow_access(const char **deny_list, const char **allow_list,
const char *cname, const char *caddr)
{
BOOL ret;
-
char *nc_cname = smb_xstrdup(cname);
char *nc_caddr = smb_xstrdup(caddr);
@@ -258,31 +262,29 @@ BOOL allow_access(char **deny_list,char **allow_list,
/* return true if the char* contains ip addrs only. Used to avoid
gethostbyaddr() calls */
-static BOOL only_ipaddrs_in_list(char** list)
+
+static BOOL only_ipaddrs_in_list(const char** list)
{
- BOOL only_ip = True;
+ BOOL only_ip = True;
- if (!list) return True;
+ if (!list)
+ return True;
- for (; *list ; list++)
- {
+ for (; *list ; list++) {
/* factor out the special strings */
if (!strcasecmp(*list, "ALL") || !strcasecmp(*list, "FAIL") ||
- !strcasecmp(*list, "EXCEPT"))
- {
+ !strcasecmp(*list, "EXCEPT")) {
continue;
}
- if (!is_ipaddress(*list))
- {
+ if (!is_ipaddress(*list)) {
char *p;
/*
* if we failed, make sure that it was not because the token
* was a network/netmask pair. Only network/netmask pairs
* have a '/' in them
*/
- if ((p=strchr_m(*list, '/')) == NULL)
- {
+ if ((p=strchr_m(*list, '/')) == NULL) {
only_ip = False;
DEBUG(3,("only_ipaddrs_in_list: list has non-ip address (%s)\n", *list));
break;
@@ -294,40 +296,31 @@ static BOOL only_ipaddrs_in_list(char** list)
}
/* return true if access should be allowed to a service for a socket */
-BOOL check_access(int sock, char **allow_list, char **deny_list)
+BOOL check_access(int sock, const char **allow_list, const char **deny_list)
{
BOOL ret = False;
BOOL only_ip = False;
- if ((!deny_list || *deny_list==0) && (!allow_list || *allow_list==0))
- {
+ if ((!deny_list || *deny_list==0) && (!allow_list || *allow_list==0))
ret = True;
- }
- if (!ret)
- {
+ if (!ret) {
/* bypass gethostbyaddr() calls if the lists only contain IP addrs */
- if (only_ipaddrs_in_list(allow_list) && only_ipaddrs_in_list(deny_list))
- {
+ if (only_ipaddrs_in_list(allow_list) && only_ipaddrs_in_list(deny_list)) {
only_ip = True;
DEBUG (3, ("check_access: no hostnames in host allow/deny list.\n"));
ret = allow_access(deny_list,allow_list, "", get_socket_addr(sock));
- }
- else
- {
+ } else {
DEBUG (3, ("check_access: hostnames in host allow/deny list.\n"));
ret = allow_access(deny_list,allow_list, get_socket_name(sock,True),
get_socket_addr(sock));
}
- if (ret)
- {
+ if (ret) {
DEBUG(2,("Allowed connection from %s (%s)\n",
only_ip ? "" : get_socket_name(sock,True),
get_socket_addr(sock)));
- }
- else
- {
+ } else {
DEBUG(0,("Denied connection from %s (%s)\n",
only_ip ? "" : get_socket_name(sock,True),
get_socket_addr(sock)));