r14840: - rename some functions
authorStefan Metzmacher <metze@samba.org>
Fri, 31 Mar 2006 11:05:33 +0000 (11:05 +0000)
committerGerald (Jerry) Carter <jerry@samba.org>
Wed, 10 Oct 2007 18:59:41 +0000 (13:59 -0500)
- stack specific functions on top of generic ones

metze
(This used to be commit e391f3c98aae600c5f64d5975dd55567a09c3100)

source4/dsdb/samdb/ldb_modules/kludge_acl.c
source4/dsdb/samdb/samdb_privilege.c
source4/libcli/security/security_token.c

index 53acb778991e6b0d0a2fb52a614d7008f4322a42..f7efdb65e4aebed64b80ca454cb4933a8bad1c4a 100644 (file)
@@ -65,19 +65,22 @@ static enum user_is what_is_user(struct ldb_module *module)
                return ANONYMOUS;
        }
        
-       if (is_system_token(session_info->security_token)) {
+       if (security_token_is_system(session_info->security_token)) {
                return SYSTEM;
        }
 
-       if (is_administrator_token(session_info->security_token)) {
+       if (security_token_is_anonymous(session_info->security_token)) {
+               return ANONYMOUS;
+       }
+
+       if (security_token_has_builtin_administrators(session_info->security_token)) {
                return ADMINISTRATOR;
        }
-       if (is_authenticated_token(session_info->security_token)) {
+
+       if (security_token_has_nt_authenticated_users(session_info->security_token)) {
                return USER;
        }
-       if (is_anonymous_token(session_info->security_token)) {
-               return ANONYMOUS;
-       }
+
        return ANONYMOUS;
 }
 
index c1a6f2005b3eaceefccdd7fea939e035f196336b..d4c1471e1cc9515b65edf9a3adad9f5b782204b3 100644 (file)
@@ -83,12 +83,12 @@ _PUBLIC_ NTSTATUS samdb_privilege_setup(struct security_token *token)
        NTSTATUS status;
 
        /* Shortcuts to prevent recursion and avoid lookups */
-       if (is_system_token(token)) {
+       if (security_token_is_system(token)) {
                token->privilege_mask = ~0;
                return NT_STATUS_OK;
        }
 
-       if (is_anonymous_token(token)) {
+       if (security_token_is_anonymous(token)) {
                token->privilege_mask = 0;
                return NT_STATUS_OK;
        }
index 7ee3a68916d388cb5a3cf05251bbeed326395522..5fcde246ef8ded5586b00ee98bc83badecbf3fab 100644 (file)
@@ -170,55 +170,65 @@ void security_token_debug(int dbg_lev, const struct security_token *token)
 
 /* These really should be cheaper... */
 
-BOOL is_system_token(struct security_token *token) 
+BOOL security_token_is_sid(struct security_token *token, const struct dom_sid *sid)
 {
-       TALLOC_CTX *mem_ctx = talloc_new(token);
-       if (dom_sid_equal(token->user_sid, dom_sid_parse_talloc(mem_ctx, SID_NT_SYSTEM))) {
-               talloc_free(mem_ctx);
+       if (dom_sid_equal(token->user_sid, sid)) {
                return True;
        }
-       talloc_free(mem_ctx);
        return False;
 }
 
-BOOL is_anonymous_token(struct security_token *token) 
+BOOL security_token_is_sid_string(struct security_token *token, const char *sid_string)
 {
-       TALLOC_CTX *mem_ctx = talloc_new(token);
-       if (dom_sid_equal(token->user_sid, dom_sid_parse_talloc(mem_ctx, SID_NT_ANONYMOUS))) {
-               talloc_free(mem_ctx);
-               return True;
-       }
-       talloc_free(mem_ctx);
-       return False;
+       BOOL ret;
+       struct dom_sid *sid = dom_sid_parse_talloc(token, sid_string);
+       if (!sid) return False;
+
+       ret = security_token_is_sid(token, sid);
+
+       talloc_free(sid);
+       return ret;
 }
 
-BOOL is_authenticated_token(struct security_token *token)
+BOOL security_token_is_system(struct security_token *token) 
 {
-       TALLOC_CTX *mem_ctx = talloc_new(token);
-       int i;
-       struct dom_sid *authenticated = dom_sid_parse_talloc(mem_ctx, SID_NT_AUTHENTICATED_USERS);
-       for (i = 0; i < token->num_sids; i++) {
-               if (dom_sid_equal(token->sids[i], authenticated)) {
-                       talloc_free(mem_ctx);
-                       return True;
-               }
-       }
-       talloc_free(mem_ctx);
-       return False;
+       return security_token_is_sid_string(token, SID_NT_SYSTEM);
 }
 
-BOOL is_administrator_token(struct security_token *token) 
+BOOL security_token_is_anonymous(struct security_token *token) 
+{
+       return security_token_is_sid_string(token, SID_NT_ANONYMOUS);
+}
+
+BOOL security_token_has_sid(struct security_token *token, struct dom_sid *sid)
 {
-       TALLOC_CTX *mem_ctx = talloc_new(token);
        int i;
-       struct dom_sid *administrators = dom_sid_parse_talloc(mem_ctx, SID_BUILTIN_ADMINISTRATORS);
        for (i = 0; i < token->num_sids; i++) {
-               if (dom_sid_equal(token->sids[i], administrators)) {
-                       talloc_free(mem_ctx);
+               if (dom_sid_equal(token->sids[i], sid)) {
                        return True;
                }
        }
-       talloc_free(mem_ctx);
        return False;
 }
 
+BOOL security_token_has_sid_string(struct security_token *token, const char *sid_string)
+{
+       BOOL ret;
+       struct dom_sid *sid = dom_sid_parse_talloc(token, sid_string);
+       if (!sid) return False;
+
+       ret = security_token_has_sid(token, sid);
+
+       talloc_free(sid);
+       return ret;
+}
+
+BOOL security_token_has_builtin_administrators(struct security_token *token)
+{
+       return security_token_has_sid_string(token, SID_BUILTIN_ADMINISTRATORS);
+}
+
+BOOL security_token_has_nt_authenticated_users(struct security_token *token)
+{
+       return security_token_has_sid_string(token, SID_NT_AUTHENTICATED_USERS);
+}