libcli/security Provide a common, top level libcli/security/security.h
[ira/wip.git] / source3 / libnet / libnet_samsync_passdb.c
index 27c7aac7e7806581e541fc5ec9d4d750f385189d..9d72194c03a534af916af09fd72b316d4c7ba3c0 100644 (file)
@@ -24,7 +24,8 @@
 */
 
 #include "includes.h"
-#include "libnet/libnet.h"
+#include "libnet/libnet_samsync.h"
+#include "../libcli/security/security.h"
 
 /* Convert a struct samu_DELTA to a struct samu. */
 #define STRING_CHANGED (old_string && !new_string) ||\
@@ -299,8 +300,8 @@ static NTSTATUS fetch_account_info(TALLOC_CTX *mem_ctx,
        struct samu *sam_account=NULL;
        GROUP_MAP map;
        struct group *grp;
-       DOM_SID user_sid;
-       DOM_SID group_sid;
+       struct dom_sid user_sid;
+       struct dom_sid group_sid;
        struct passwd *passwd = NULL;
        fstring sid_string;
 
@@ -318,8 +319,7 @@ static NTSTATUS fetch_account_info(TALLOC_CTX *mem_ctx,
                goto done;
        }
 
-       sid_copy(&user_sid, get_global_sam_sid());
-       sid_append_rid(&user_sid, r->rid);
+       sid_compose(&user_sid, get_global_sam_sid(), r->rid);
 
        DEBUG(3, ("Attempting to find SID %s for user %s in the passdb\n",
                  sid_to_fstring(sid_string, &user_sid), account));
@@ -386,7 +386,7 @@ static NTSTATUS fetch_group_info(TALLOC_CTX *mem_ctx,
        fstring name;
        fstring comment;
        struct group *grp = NULL;
-       DOM_SID group_sid;
+       struct dom_sid group_sid;
        fstring sid_string;
        GROUP_MAP map;
        bool insert = true;
@@ -395,8 +395,7 @@ static NTSTATUS fetch_group_info(TALLOC_CTX *mem_ctx,
        fstrcpy(comment, r->description.string);
 
        /* add the group to the mapping table */
-       sid_copy(&group_sid, get_global_sam_sid());
-       sid_append_rid(&group_sid, rid);
+       sid_compose(&group_sid, get_global_sam_sid(), rid);
        sid_to_fstring(sid_string, &group_sid);
 
        if (pdb_getgrsid(&map, group_sid)) {
@@ -451,7 +450,7 @@ static NTSTATUS fetch_group_mem_info(TALLOC_CTX *mem_ctx,
        int i;
        char **nt_members = NULL;
        char **unix_members;
-       DOM_SID group_sid;
+       struct dom_sid group_sid;
        GROUP_MAP map;
        struct group *grp;
 
@@ -459,8 +458,7 @@ static NTSTATUS fetch_group_mem_info(TALLOC_CTX *mem_ctx,
                return NT_STATUS_OK;
        }
 
-       sid_copy(&group_sid, get_global_sam_sid());
-       sid_append_rid(&group_sid, rid);
+       sid_compose(&group_sid, get_global_sam_sid(), rid);
 
        if (!get_domain_group_from_sid(group_sid, &map)) {
                DEBUG(0, ("Could not find global group %d\n", rid));
@@ -485,14 +483,13 @@ static NTSTATUS fetch_group_mem_info(TALLOC_CTX *mem_ctx,
 
        for (i=0; i < r->num_rids; i++) {
                struct samu *member = NULL;
-               DOM_SID member_sid;
+               struct dom_sid member_sid;
 
                if ( !(member = samu_new(mem_ctx)) ) {
                        return NT_STATUS_NO_MEMORY;
                }
 
-               sid_copy(&member_sid, get_global_sam_sid());
-               sid_append_rid(&member_sid, r->rids[i]);
+               sid_compose(&member_sid, get_global_sam_sid(), r->rids[i]);
 
                if (!pdb_getsampwsid(member, &member_sid)) {
                        DEBUG(1, ("Found bogus group member: %d (member_sid=%s group=%s)\n",
@@ -573,12 +570,12 @@ static NTSTATUS fetch_group_mem_info(TALLOC_CTX *mem_ctx,
 static NTSTATUS fetch_alias_info(TALLOC_CTX *mem_ctx,
                                 uint32_t rid,
                                 struct netr_DELTA_ALIAS *r,
-                                const DOM_SID *dom_sid)
+                                const struct dom_sid *dom_sid)
 {
        fstring name;
        fstring comment;
        struct group *grp = NULL;
-       DOM_SID alias_sid;
+       struct dom_sid alias_sid;
        fstring sid_string;
        GROUP_MAP map;
        bool insert = true;
@@ -587,8 +584,7 @@ static NTSTATUS fetch_alias_info(TALLOC_CTX *mem_ctx,
        fstrcpy(comment, r->description.string);
 
        /* Find out whether the group is already mapped */
-       sid_copy(&alias_sid, dom_sid);
-       sid_append_rid(&alias_sid, rid);
+       sid_compose(&alias_sid, dom_sid, rid);
        sid_to_fstring(sid_string, &alias_sid);
 
        if (pdb_getgrsid(&map, alias_sid)) {
@@ -613,7 +609,7 @@ static NTSTATUS fetch_alias_info(TALLOC_CTX *mem_ctx,
        map.gid = grp->gr_gid;
        map.sid = alias_sid;
 
-       if (sid_equal(dom_sid, &global_sid_Builtin))
+       if (dom_sid_equal(dom_sid, &global_sid_Builtin))
                map.sid_name_use = SID_NAME_WKN_GRP;
        else
                map.sid_name_use = SID_NAME_ALIAS;
@@ -635,7 +631,7 @@ static NTSTATUS fetch_alias_info(TALLOC_CTX *mem_ctx,
 static NTSTATUS fetch_alias_mem(TALLOC_CTX *mem_ctx,
                                uint32_t rid,
                                struct netr_DELTA_ALIAS_MEMBER *r,
-                               const DOM_SID *dom_sid)
+                               const struct dom_sid *dom_sid)
 {
        return NT_STATUS_OK;
 }
@@ -676,21 +672,24 @@ static NTSTATUS fetch_domain_info(TALLOC_CTX *mem_ctx,
        }
 
 
-       if (!pdb_set_account_policy(AP_PASSWORD_HISTORY,
+       if (!pdb_set_account_policy(PDB_POLICY_PASSWORD_HISTORY,
                                    r->password_history_length))
                return nt_status;
 
-       if (!pdb_set_account_policy(AP_MIN_PASSWORD_LEN,
+       if (!pdb_set_account_policy(PDB_POLICY_MIN_PASSWORD_LEN,
                                    r->min_password_length))
                return nt_status;
 
-       if (!pdb_set_account_policy(AP_MAX_PASSWORD_AGE, (uint32)u_max_age))
+       if (!pdb_set_account_policy(PDB_POLICY_MAX_PASSWORD_AGE,
+                                   (uint32)u_max_age))
                return nt_status;
 
-       if (!pdb_set_account_policy(AP_MIN_PASSWORD_AGE, (uint32)u_min_age))
+       if (!pdb_set_account_policy(PDB_POLICY_MIN_PASSWORD_AGE,
+                                   (uint32)u_min_age))
                return nt_status;
 
-       if (!pdb_set_account_policy(AP_TIME_TO_LOGOUT, (uint32)u_logout))
+       if (!pdb_set_account_policy(PDB_POLICY_TIME_TO_LOGOUT,
+                                   (uint32)u_logout))
                return nt_status;
 
        if (lockstr) {
@@ -699,21 +698,23 @@ static NTSTATUS fetch_domain_info(TALLOC_CTX *mem_ctx,
                u_lockoutreset = uint64s_nt_time_to_unix_abs(&lockstr->reset_count);
                u_lockouttime = uint64s_nt_time_to_unix_abs((uint64_t *)&lockstr->lockout_duration);
 
-               if (!pdb_set_account_policy(AP_BAD_ATTEMPT_LOCKOUT,
+               if (!pdb_set_account_policy(PDB_POLICY_BAD_ATTEMPT_LOCKOUT,
                                            lockstr->bad_attempt_lockout))
                        return nt_status;
 
-               if (!pdb_set_account_policy(AP_RESET_COUNT_TIME, (uint32_t)u_lockoutreset/60))
+               if (!pdb_set_account_policy(PDB_POLICY_RESET_COUNT_TIME,
+                                           (uint32_t)u_lockoutreset/60))
                        return nt_status;
 
                if (u_lockouttime != -1)
                        u_lockouttime /= 60;
 
-               if (!pdb_set_account_policy(AP_LOCK_ACCOUNT_DURATION, (uint32_t)u_lockouttime))
+               if (!pdb_set_account_policy(PDB_POLICY_LOCK_ACCOUNT_DURATION,
+                                           (uint32_t)u_lockouttime))
                        return nt_status;
        }
 
-       if (!pdb_set_account_policy(AP_USER_MUST_LOGON_TO_CHG_PASS,
+       if (!pdb_set_account_policy(PDB_POLICY_USER_MUST_LOGON_TO_CHG_PASS,
                                    r->logon_to_chgpass))
                return nt_status;