pdb_ldap: Raise level for debug message to avoid log file flooding.
[kai/samba-autobuild/.git] / source3 / passdb / pdb_ldap.c
index 9ce659e818899d029d5ef69db58b3bdb36dd45de..ddbb53a9b9719b76e1514c60f4731293e6755857 100644 (file)
@@ -946,7 +946,7 @@ static bool init_sam_from_ldap(struct ldapsam_privates *ldap_state,
                                }
                        }
                        if (hex_failed) {
-                               DEBUG(0,("init_sam_from_ldap: Failed to get password history for user %s\n",
+                               DEBUG(2,("init_sam_from_ldap: Failed to get password history for user %s\n",
                                        username));
                                memset(pwhist, '\0', pwHistLen * PW_HISTORY_ENTRY_LEN);
                        }
@@ -2723,8 +2723,8 @@ static NTSTATUS ldapsam_enum_group_members(struct pdb_methods *methods,
                                                                 entry, "sambaSID",
                                                                 mem_ctx);
                        if (!sidstr) {
-                               DEBUG(0, ("Severe DB error, sambaSamAccount can't miss "
-                                         "the sambaSID attribute\n"));
+                               DEBUG(0, ("Severe DB error, %s can't miss the sambaSID"
+                                         "attribute\n", LDAP_OBJ_SAMBASAMACCOUNT));
                                ret = NT_STATUS_INTERNAL_DB_CORRUPTION;
                                goto done;
                        }
@@ -2774,8 +2774,7 @@ static NTSTATUS ldapsam_enum_group_members(struct pdb_methods *methods,
                                                    entry,
                                                    get_global_sam_sid(),
                                                    &rid)) {
-                       DEBUG(0, ("Severe DB error, sambaSamAccount can't miss "
-                                 "the sambaSID attribute\n"));
+                       DEBUG(0, ("Severe DB error, %s can't miss the samba SID"                                                                "attribute\n", LDAP_OBJ_SAMBASAMACCOUNT));
                        ret = NT_STATUS_INTERNAL_DB_CORRUPTION;
                        goto done;
                }
@@ -2981,8 +2980,8 @@ static NTSTATUS ldapsam_map_posixgroup(TALLOC_CTX *mem_ctx,
        int rc;
 
        filter = talloc_asprintf(mem_ctx,
-                                "(&(objectClass=posixGroup)(gidNumber=%u))",
-                                map->gid);
+                                "(&(objectClass=%s)(gidNumber=%u))",
+                                LDAP_OBJ_POSIXGROUP, map->gid);
        if (filter == NULL) {
                return NT_STATUS_NO_MEMORY;
        }
@@ -3005,7 +3004,7 @@ static NTSTATUS ldapsam_map_posixgroup(TALLOC_CTX *mem_ctx,
 
        mods = NULL;
        smbldap_set_mod(&mods, LDAP_MOD_ADD, "objectClass",
-                       "sambaGroupMapping");
+                       LDAP_OBJ_GROUPMAP);
        smbldap_make_mod(ldap_state->smbldap_state->ldap_struct, entry, &mods, "sambaSid",
                         sid_string_talloc(mem_ctx, &map->sid));
        smbldap_make_mod(ldap_state->smbldap_state->ldap_struct, entry, &mods, "sambaGroupType",
@@ -3125,10 +3124,9 @@ static NTSTATUS ldapsam_add_group_mapping_entry(struct pdb_methods *methods,
        mods = NULL;
 
        smbldap_make_mod(ldap_state->smbldap_state->ldap_struct, NULL, &mods, "objectClass",
-                        "sambaSidEntry");
+                        LDAP_OBJ_SID_ENTRY);
        smbldap_make_mod(ldap_state->smbldap_state->ldap_struct, NULL, &mods, "objectClass",
-                        "sambaGroupMapping");
-
+                        LDAP_OBJ_GROUPMAP);
        smbldap_make_mod(ldap_state->smbldap_state->ldap_struct, NULL, &mods, "sambaSid",
                         sid_string_talloc(mem_ctx, &map->sid));
        smbldap_make_mod(ldap_state->smbldap_state->ldap_struct, NULL, &mods, "sambaGroupType",
@@ -4186,8 +4184,8 @@ static char *get_ldap_filter(TALLOC_CTX *mem_ctx, const char *username)
        char *escaped = NULL;
        char *result = NULL;
 
-       asprintf(&filter, "(&%s(objectclass=sambaSamAccount))",
-                "(uid=%u)");
+       asprintf(&filter, "(&%s(objectclass=%s))",
+                         "(uid=%u)", LDAP_OBJ_SAMBASAMACCOUNT);
        if (filter == NULL) goto done;
 
        escaped = escape_ldap_string_alloc(username);
@@ -4666,7 +4664,9 @@ static bool ldapgroup2displayentry(struct ldap_search_state *state,
                        DEBUG(0,("unkown group type: %d\n", group_type));
                        return False;
        }
-       
+
+       result->acct_flags = 0;
+
        return True;
 }
 
@@ -4692,9 +4692,10 @@ static bool ldapsam_search_grouptype(struct pdb_methods *methods,
        state->connection = ldap_state->smbldap_state;
        state->scope = LDAP_SCOPE_SUBTREE;
        state->filter = talloc_asprintf(search->mem_ctx,
-                                       "(&(objectclass=sambaGroupMapping)"
-                                       "(sambaGroupType=%d)(sambaSID=%s*))", 
-                                       type, sid_to_fstring(tmp, sid));
+                                       "(&(objectclass=%s)"
+                                       "(sambaGroupType=%d)(sambaSID=%s*))",
+                                        LDAP_OBJ_GROUPMAP,
+                                        type, sid_to_fstring(tmp, sid));
        state->attrs = talloc_attrs(search->mem_ctx, "cn", "sambaSid",
                                    "displayName", "description",
                                    "sambaGroupType", NULL);
@@ -5003,7 +5004,7 @@ static NTSTATUS ldapsam_create_user(struct pdb_methods *my_methods,
        rc = smbldap_search_suffix(ldap_state->smbldap_state, filter, NULL, &result);
        if (rc != LDAP_SUCCESS) {
                DEBUG(0,("ldapsam_create_user: ldap search failed!\n"));
-               return NT_STATUS_UNSUCCESSFUL;
+               return NT_STATUS_ACCESS_DENIED;
        }
        talloc_autofree_ldapmsg(tmp_ctx, result);
 
@@ -5694,7 +5695,7 @@ static NTSTATUS ldapsam_set_primary_group(struct pdb_methods *my_methods,
        DEBUG(0,("ldapsam_set_primary_group: Attempt to set primary group for user [%s]\n", pdb_get_username(sampass)));
 
        if (!sid_to_gid(pdb_get_group_sid(sampass), &gid)) {
-               DEBUG(0,("ldapsam_set_primary_group: failed to retieve gid from user's group SID!\n"));
+               DEBUG(0,("ldapsam_set_primary_group: failed to retrieve gid from user's group SID!\n"));
                return NT_STATUS_UNSUCCESSFUL;
        }
        gidstr = talloc_asprintf(mem_ctx, "%d", gid);
@@ -5786,6 +5787,7 @@ static char *trusteddom_dn(struct ldapsam_privates *ldap_state,
 }
 
 static bool get_trusteddom_pw_int(struct ldapsam_privates *ldap_state,
+                                 TALLOC_CTX *mem_ctx,
                                  const char *domain, LDAPMessage **entry)
 {
        int rc;
@@ -5808,6 +5810,10 @@ static bool get_trusteddom_pw_int(struct ldapsam_privates *ldap_state,
        rc = smbldap_search(ldap_state->smbldap_state, trusted_dn, scope,
                            filter, attrs, attrsonly, &result);
 
+       if (result != NULL) {
+               talloc_autofree_ldapmsg(mem_ctx, result);
+       }
+
        if (rc == LDAP_NO_SUCH_OBJECT) {
                *entry = NULL;
                return True;
@@ -5821,15 +5827,15 @@ static bool get_trusteddom_pw_int(struct ldapsam_privates *ldap_state,
 
        if (num_result > 1) {
                DEBUG(1, ("ldapsam_get_trusteddom_pw: more than one "
-                         "sambaTrustedDomainPassword object for domain '%s'"
-                         "?!\n", domain));
+                         "%s object for domain '%s'?!\n",
+                         LDAP_OBJ_TRUSTDOM_PASSWORD, domain));
                return False;
        }
 
        if (num_result == 0) {
                DEBUG(1, ("ldapsam_get_trusteddom_pw: no "
-                         "sambaTrustedDomainPassword object for domain %s.\n",
-                         domain));
+                         "%s object for domain %s.\n",
+                         LDAP_OBJ_TRUSTDOM_PASSWORD, domain));
                *entry = NULL;
        } else {
                *entry = ldap_first_entry(priv2ld(ldap_state), result);
@@ -5850,7 +5856,7 @@ static bool ldapsam_get_trusteddom_pw(struct pdb_methods *methods,
 
        DEBUG(10, ("ldapsam_get_trusteddom_pw called for domain %s\n", domain));
 
-       if (!get_trusteddom_pw_int(ldap_state, domain, &entry) ||
+       if (!get_trusteddom_pw_int(ldap_state, talloc_tos(), domain, &entry) ||
            (entry == NULL))
        {
                return False;
@@ -5921,13 +5927,13 @@ static bool ldapsam_set_trusteddom_pw(struct pdb_methods *methods,
         * get the current entry (if there is one) in order to put the
         * current password into the previous password attribute
         */
-       if (!get_trusteddom_pw_int(ldap_state, domain, &entry)) {
+       if (!get_trusteddom_pw_int(ldap_state, talloc_tos(), domain, &entry)) {
                return False;
        }
 
        mods = NULL;
        smbldap_make_mod(priv2ld(ldap_state), entry, &mods, "objectClass",
-                        "sambaTrustedDomainPassword");
+                        LDAP_OBJ_TRUSTDOM_PASSWORD);
        smbldap_make_mod(priv2ld(ldap_state), entry, &mods, "sambaDomainName",
                         domain);
        smbldap_make_mod(priv2ld(ldap_state), entry, &mods, "sambaSID",
@@ -5936,6 +5942,9 @@ static bool ldapsam_set_trusteddom_pw(struct pdb_methods *methods,
                         talloc_asprintf(talloc_tos(), "%li", time(NULL)));
        smbldap_make_mod(priv2ld(ldap_state), entry, &mods,
                         "sambaClearTextPassword", pwd);
+
+       talloc_autofree_ldapmod(talloc_tos(), mods);
+
        if (entry != NULL) {
                prev_pwd = smbldap_talloc_single_attribute(priv2ld(ldap_state),
                                entry, "sambaClearTextPassword", talloc_tos());
@@ -5973,7 +5982,7 @@ static bool ldapsam_del_trusteddom_pw(struct pdb_methods *methods,
        LDAPMessage *entry = NULL;
        const char *trusted_dn;
 
-       if (!get_trusteddom_pw_int(ldap_state, domain, &entry)) {
+       if (!get_trusteddom_pw_int(ldap_state, talloc_tos(), domain, &entry)) {
                return False;
        }
 
@@ -6024,6 +6033,10 @@ static NTSTATUS ldapsam_enum_trusteddoms(struct pdb_methods *methods,
                            attrsonly,
                            &result);
 
+       if (result != NULL) {
+               talloc_autofree_ldapmsg(mem_ctx, result);
+       }
+
        if (rc != LDAP_SUCCESS) {
                return NT_STATUS_UNSUCCESSFUL;
        }