Make sure share_info.tdb is open before attempting to delete an entry
[ira/wip.git] / source3 / lib / sharesec.c
index 5eaa25ac59356079c2a9c8992b0179a636d7a2e2..3866ff083fcfd0fa861eecbcdf6e9764e74ff1fd 100644 (file)
@@ -29,7 +29,7 @@ static struct db_context *share_db; /* used for share security descriptors */
 
 /* Map generic permissions to file object specific permissions */
 
-const struct generic_mapping file_generic_mapping;
+extern const struct generic_mapping file_generic_mapping;
 
 static int delete_fn(struct db_record *rec, void *priv)
 {
@@ -41,7 +41,7 @@ static bool share_info_db_init(void)
 {
        const char *vstring = "INFO/version";
        int32 vers_id;
+
        if (share_db != NULL) {
                return True;
        }
@@ -53,7 +53,7 @@ static bool share_info_db_init(void)
                        state_path("share_info.tdb"), strerror(errno) ));
                return False;
        }
+
        vers_id = dbwrap_fetch_int32(share_db, vstring);
        if (vers_id == SHARE_DATABASE_VERSION_V2) {
                return true;
@@ -124,7 +124,7 @@ static bool share_info_db_init(void)
 
 SEC_DESC *get_share_security_default( TALLOC_CTX *ctx, size_t *psize, uint32 def_access)
 {
-       SEC_ACCESS sa;
+       uint32_t sa;
        SEC_ACE ace;
        SEC_ACL *psa = NULL;
        SEC_DESC *psd = NULL;
@@ -132,7 +132,7 @@ SEC_DESC *get_share_security_default( TALLOC_CTX *ctx, size_t *psize, uint32 def
 
        se_map_generic(&spec_access, &file_generic_mapping);
 
-       init_sec_access(&sa, def_access | spec_access );
+       sa = (def_access | spec_access );
        init_sec_ace(&ace, &global_sid_World, SEC_ACE_TYPE_ACCESS_ALLOWED, sa, 0);
 
        if ((psa = make_sec_acl(ctx, NT4_ACL_REVISION, 1, &ace)) != NULL) {
@@ -252,6 +252,10 @@ bool delete_share_security(const char *servicename)
        char *key;
        NTSTATUS status;
 
+       if (!share_info_db_init()) {
+               return False;
+       }
+
        if (!(key = talloc_asprintf(talloc_tos(), "SECDESC/%s",
                                    servicename))) {
                return False;
@@ -279,7 +283,6 @@ bool share_access_check(const NT_USER_TOKEN *token, const char *sharename,
        NTSTATUS status;
        SEC_DESC *psd = NULL;
        size_t sd_size;
-       bool ret = True;
 
        psd = get_share_security(talloc_tos(), sharename, &sd_size);
 
@@ -287,11 +290,11 @@ bool share_access_check(const NT_USER_TOKEN *token, const char *sharename,
                return True;
        }
 
-       ret = se_access_check(psd, token, desired_access, &granted, &status);
+       status = se_access_check(psd, token, desired_access, &granted);
 
        TALLOC_FREE(psd);
 
-       return ret;
+       return NT_STATUS_IS_OK(status);
 }
 
 /***************************************************************************
@@ -332,7 +335,7 @@ bool parse_usershare_acl(TALLOC_CTX *ctx, const char *acl_str, SEC_DESC **ppsd)
        }
 
        for (i = 0; i < num_aces; i++) {
-               SEC_ACCESS sa;
+               uint32_t sa;
                uint32 g_access;
                uint32 s_access;
                DOM_SID sid;
@@ -380,7 +383,7 @@ bool parse_usershare_acl(TALLOC_CTX *ctx, const char *acl_str, SEC_DESC **ppsd)
                pacl++; /* Go past any ',' */
 
                se_map_generic(&s_access, &file_generic_mapping);
-               init_sec_access(&sa, g_access | s_access );
+               sa = (g_access | s_access);
                init_sec_ace(&ace_list[i], &sid, type, sa, 0);
        }