s3:misc make use of server_[event/messaging]_context directly
[kamenim/samba.git] / source3 / rpc_server / srv_samr_nt.c
index 6b40385744694bb997282c44403c7edd312e7d43..499f959475e05048c560f13071f338e0d0fc3c0f 100644 (file)
@@ -35,6 +35,8 @@
 #include "smbd/globals.h"
 #include "../libcli/auth/libcli_auth.h"
 #include "../librpc/gen_ndr/srv_samr.h"
+#include "rpc_server/srv_samr_util.h"
+#include "../lib/crypto/arcfour.h"
 
 #undef DBGC_CLASS
 #define DBGC_CLASS DBGC_RPC_SRV
@@ -73,7 +75,7 @@ struct samr_alias_info {
 };
 
 typedef struct disp_info {
-       DOM_SID sid; /* identify which domain this is. */
+       struct dom_sid sid; /* identify which domain this is. */
        struct pdb_search *users; /* querydispinfo 1 and 4 */
        struct pdb_search *machines; /* querydispinfo 2 */
        struct pdb_search *groups; /* querydispinfo 3 and 5, enumgroups */
@@ -120,15 +122,15 @@ static const struct generic_mapping ali_generic_mapping = {
 /*******************************************************************
 *******************************************************************/
 
-static NTSTATUS make_samr_object_sd( TALLOC_CTX *ctx, SEC_DESC **psd, size_t *sd_size,
+static NTSTATUS make_samr_object_sd( TALLOC_CTX *ctx, struct security_descriptor **psd, size_t *sd_size,
                                      const struct generic_mapping *map,
-                                    DOM_SID *sid, uint32 sid_access )
+                                    struct dom_sid *sid, uint32 sid_access )
 {
-       DOM_SID domadmin_sid;
-       SEC_ACE ace[5];         /* at most 5 entries */
+       struct dom_sid domadmin_sid;
+       struct security_ace ace[5];             /* at most 5 entries */
        size_t i = 0;
 
-       SEC_ACL *psa = NULL;
+       struct security_acl *psa = NULL;
 
        /* basic access for Everyone */
 
@@ -145,8 +147,8 @@ static NTSTATUS make_samr_object_sd( TALLOC_CTX *ctx, SEC_DESC **psd, size_t *sd
        /* Add Full Access for Domain Admins if we are a DC */
 
        if ( IS_DC ) {
-               sid_copy( &domadmin_sid, get_global_sam_sid() );
-               sid_append_rid( &domadmin_sid, DOMAIN_GROUP_RID_ADMINS );
+               sid_compose(&domadmin_sid, get_global_sam_sid(),
+                           DOMAIN_RID_ADMINS);
                init_sec_ace(&ace[i++], &domadmin_sid,
                        SEC_ACE_TYPE_ACCESS_ALLOWED, map->generic_all, 0);
        }
@@ -175,7 +177,7 @@ static NTSTATUS make_samr_object_sd( TALLOC_CTX *ctx, SEC_DESC **psd, size_t *sd
  level of access for further checks.
 ********************************************************************/
 
-NTSTATUS access_check_object( SEC_DESC *psd, NT_USER_TOKEN *token,
+NTSTATUS access_check_object( struct security_descriptor *psd, NT_USER_TOKEN *token,
                                           SE_PRIV *rights, uint32 rights_mask,
                                           uint32 des_access, uint32 *acc_granted,
                                          const char *debug )
@@ -265,9 +267,9 @@ void map_max_allowed_access(const NT_USER_TOKEN *nt_token,
 
        /* Full access for DOMAIN\Domain Admins. */
        if ( IS_DC ) {
-               DOM_SID domadmin_sid;
-               sid_copy( &domadmin_sid, get_global_sam_sid() );
-               sid_append_rid( &domadmin_sid, DOMAIN_GROUP_RID_ADMINS );
+               struct dom_sid domadmin_sid;
+               sid_compose(&domadmin_sid, get_global_sam_sid(),
+                           DOMAIN_RID_ADMINS);
                if (is_sid_in_token(nt_token, &domadmin_sid)) {
                        *pacc_requested |= GENERIC_ALL_ACCESS;
                        return;
@@ -405,7 +407,7 @@ static void set_disp_info_cache_timeout(DISP_INFO *disp_info, time_t secs_fromno
                  (unsigned int)secs_fromnow ));
 
        disp_info->cache_timeout_event = event_add_timed(
-               smbd_event_context(), NULL,
+               server_event_context(), NULL,
                timeval_current_ofs(secs_fromnow, 0),
                disp_info_cache_idle_timeout_handler, (void *)disp_info);
 }
@@ -535,7 +537,7 @@ NTSTATUS _samr_OpenDomain(pipes_struct *p,
 {
        struct samr_connect_info *cinfo;
        struct samr_domain_info *dinfo;
-       SEC_DESC *psd = NULL;
+       struct security_descriptor *psd = NULL;
        uint32    acc_granted;
        uint32    des_access = r->in.access_mask;
        NTSTATUS  status;
@@ -672,7 +674,7 @@ NTSTATUS _samr_SetSecurity(pipes_struct *p,
 {
        struct samr_user_info *uinfo;
        uint32 i;
-       SEC_ACL *dacl;
+       struct security_acl *dacl;
        bool ret;
        struct samu *sampass=NULL;
        NTSTATUS status;
@@ -729,7 +731,7 @@ NTSTATUS _samr_SetSecurity(pipes_struct *p,
 /*******************************************************************
   build correct perms based on policies and password times for _samr_query_sec_obj
 *******************************************************************/
-static bool check_change_pw_access(TALLOC_CTX *mem_ctx, DOM_SID *user_sid)
+static bool check_change_pw_access(TALLOC_CTX *mem_ctx, struct dom_sid *user_sid)
 {
        struct samu *sampass=NULL;
        bool ret;
@@ -773,11 +775,11 @@ NTSTATUS _samr_QuerySecurity(pipes_struct *p,
        struct samr_group_info *ginfo;
        struct samr_alias_info *ainfo;
        NTSTATUS status;
-       SEC_DESC * psd = NULL;
+       struct security_descriptor * psd = NULL;
        size_t sd_size = 0;
 
        cinfo = policy_handle_find(p, r->in.handle,
-                                  STD_RIGHT_READ_CONTROL_ACCESS, NULL,
+                                  SEC_STD_READ_CONTROL, NULL,
                                   struct samr_connect_info, &status);
        if (NT_STATUS_IS_OK(status)) {
                DEBUG(5,("_samr_QuerySecurity: querying security on SAM\n"));
@@ -787,7 +789,7 @@ NTSTATUS _samr_QuerySecurity(pipes_struct *p,
        }
 
        dinfo = policy_handle_find(p, r->in.handle,
-                                  STD_RIGHT_READ_CONTROL_ACCESS, NULL,
+                                  SEC_STD_READ_CONTROL, NULL,
                                   struct samr_domain_info, &status);
        if (NT_STATUS_IS_OK(status)) {
                DEBUG(5,("_samr_QuerySecurity: querying security on Domain "
@@ -802,7 +804,7 @@ NTSTATUS _samr_QuerySecurity(pipes_struct *p,
        }
 
        uinfo = policy_handle_find(p, r->in.handle,
-                                  STD_RIGHT_READ_CONTROL_ACCESS, NULL,
+                                  SEC_STD_READ_CONTROL, NULL,
                                   struct samr_user_info, &status);
        if (NT_STATUS_IS_OK(status)) {
                DEBUG(10,("_samr_QuerySecurity: querying security on user "
@@ -823,7 +825,7 @@ NTSTATUS _samr_QuerySecurity(pipes_struct *p,
        }
 
        ginfo = policy_handle_find(p, r->in.handle,
-                                  STD_RIGHT_READ_CONTROL_ACCESS, NULL,
+                                  SEC_STD_READ_CONTROL, NULL,
                                   struct samr_group_info, &status);
        if (NT_STATUS_IS_OK(status)) {
                /*
@@ -841,7 +843,7 @@ NTSTATUS _samr_QuerySecurity(pipes_struct *p,
        }
 
        ainfo = policy_handle_find(p, r->in.handle,
-                                  STD_RIGHT_READ_CONTROL_ACCESS, NULL,
+                                  SEC_STD_READ_CONTROL, NULL,
                                   struct samr_alias_info, &status);
        if (NT_STATUS_IS_OK(status)) {
                /*
@@ -1920,7 +1922,6 @@ NTSTATUS _samr_ChangePasswordUser(pipes_struct *p,
 NTSTATUS _samr_ChangePasswordUser2(pipes_struct *p,
                                   struct samr_ChangePasswordUser2 *r)
 {
-       struct smbd_server_connection *sconn = smbd_server_conn;
        NTSTATUS status;
        fstring user_name;
        fstring wks;
@@ -1937,7 +1938,7 @@ NTSTATUS _samr_ChangePasswordUser2(pipes_struct *p,
         * function.
         */
 
-       (void)map_username(sconn, user_name);
+       (void)map_username(user_name);
 
        /*
         * UNIX username case mangling not required, pass_oem_change
@@ -1967,7 +1968,6 @@ NTSTATUS _samr_ChangePasswordUser2(pipes_struct *p,
 NTSTATUS _samr_OemChangePasswordUser2(pipes_struct *p,
                                      struct samr_OemChangePasswordUser2 *r)
 {
-       struct smbd_server_connection *sconn = smbd_server_conn;
        NTSTATUS status;
        fstring user_name;
        const char *wks = NULL;
@@ -1986,7 +1986,7 @@ NTSTATUS _samr_OemChangePasswordUser2(pipes_struct *p,
         * function.
         */
 
-       (void)map_username(sconn, user_name);
+       (void)map_username(user_name);
 
        /*
         * UNIX username case mangling not required, pass_oem_change
@@ -2020,7 +2020,6 @@ NTSTATUS _samr_OemChangePasswordUser2(pipes_struct *p,
 NTSTATUS _samr_ChangePasswordUser3(pipes_struct *p,
                                   struct samr_ChangePasswordUser3 *r)
 {
-       struct smbd_server_connection *sconn = smbd_server_conn;
        NTSTATUS status;
        fstring user_name;
        const char *wks = NULL;
@@ -2043,7 +2042,7 @@ NTSTATUS _samr_ChangePasswordUser3(pipes_struct *p,
         * function.
         */
 
-       (void)map_username(sconn, user_name);
+       (void)map_username(user_name);
 
        /*
         * UNIX username case mangling not required, pass_oem_change
@@ -2235,10 +2234,10 @@ NTSTATUS _samr_OpenUser(pipes_struct *p,
                        struct samr_OpenUser *r)
 {
        struct samu *sampass=NULL;
-       DOM_SID sid;
+       struct dom_sid sid;
        struct samr_domain_info *dinfo;
        struct samr_user_info *uinfo;
-       SEC_DESC *psd = NULL;
+       struct security_descriptor *psd = NULL;
        uint32    acc_granted;
        uint32    des_access = r->in.access_mask;
        uint32_t extra_access = 0;
@@ -2319,13 +2318,13 @@ NTSTATUS _samr_OpenUser(pipes_struct *p,
                }
                /*
                 * Cheat - allow GENERIC_RIGHTS_USER_WRITE if pipe user is
-                * in DOMAIN_GROUP_RID_ADMINS. This is almost certainly not
+                * in DOMAIN_RID_ADMINS. This is almost certainly not
                 * what Windows does but is a hack for people who haven't
                 * set up privileges on groups in Samba.
                 */
                if (acb_info & (ACB_SVRTRUST|ACB_DOMTRUST)) {
                        if (lp_enable_privileges() && nt_token_check_domain_rid(p->server_info->ptok,
-                                                       DOMAIN_GROUP_RID_ADMINS)) {
+                                                       DOMAIN_RID_ADMINS)) {
                                des_access &= ~GENERIC_RIGHTS_USER_WRITE;
                                extra_access = GENERIC_RIGHTS_USER_WRITE;
                                DEBUG(4,("_samr_OpenUser: Allowing "
@@ -2397,6 +2396,32 @@ static NTSTATUS init_samr_parameters_string(TALLOC_CTX *mem_ctx,
        return NT_STATUS_OK;
 }
 
+/*************************************************************************
+ *************************************************************************/
+
+static struct samr_LogonHours get_logon_hours_from_pdb(TALLOC_CTX *mem_ctx,
+                                                      struct samu *pw)
+{
+       struct samr_LogonHours hours;
+       const int units_per_week = 168;
+
+       ZERO_STRUCT(hours);
+       hours.bits = talloc_array(mem_ctx, uint8_t, units_per_week);
+       if (!hours.bits) {
+               return hours;
+       }
+
+       hours.units_per_week = units_per_week;
+       memset(hours.bits, 0xFF, units_per_week);
+
+       if (pdb_get_hours(pw)) {
+               memcpy(hours.bits, pdb_get_hours(pw),
+                      MIN(pdb_get_hours_len(pw), units_per_week));
+       }
+
+       return hours;
+}
+
 /*************************************************************************
  get_user_info_1.
  *************************************************************************/
@@ -2404,9 +2429,9 @@ static NTSTATUS init_samr_parameters_string(TALLOC_CTX *mem_ctx,
 static NTSTATUS get_user_info_1(TALLOC_CTX *mem_ctx,
                                struct samr_UserInfo1 *r,
                                struct samu *pw,
-                               DOM_SID *domain_sid)
+                               struct dom_sid *domain_sid)
 {
-       const DOM_SID *sid_group;
+       const struct dom_sid *sid_group;
        uint32_t primary_gid;
 
        become_root();
@@ -2453,9 +2478,9 @@ static NTSTATUS get_user_info_2(TALLOC_CTX *mem_ctx,
 static NTSTATUS get_user_info_3(TALLOC_CTX *mem_ctx,
                                struct samr_UserInfo3 *r,
                                struct samu *pw,
-                               DOM_SID *domain_sid)
+                               struct dom_sid *domain_sid)
 {
-       const DOM_SID *sid_user, *sid_group;
+       const struct dom_sid *sid_user, *sid_group;
        uint32_t rid, primary_gid;
 
        sid_user = pdb_get_user_sid(pw);
@@ -2524,9 +2549,9 @@ static NTSTATUS get_user_info_4(TALLOC_CTX *mem_ctx,
 static NTSTATUS get_user_info_5(TALLOC_CTX *mem_ctx,
                                struct samr_UserInfo5 *r,
                                struct samu *pw,
-                               DOM_SID *domain_sid)
+                               struct dom_sid *domain_sid)
 {
-       const DOM_SID *sid_user, *sid_group;
+       const struct dom_sid *sid_user, *sid_group;
        uint32_t rid, primary_gid;
 
        sid_user = pdb_get_user_sid(pw);
@@ -2732,13 +2757,19 @@ static NTSTATUS get_user_info_17(TALLOC_CTX *mem_ctx,
 static NTSTATUS get_user_info_18(pipes_struct *p,
                                 TALLOC_CTX *mem_ctx,
                                 struct samr_UserInfo18 *r,
-                                DOM_SID *user_sid)
+                                struct dom_sid *user_sid)
 {
        struct samu *smbpass=NULL;
        bool ret;
+       const uint8_t *nt_pass = NULL;
+       const uint8_t *lm_pass = NULL;
 
        ZERO_STRUCTP(r);
 
+       if (p->server_info->system) {
+               goto query;
+       }
+
        if (p->auth.auth_type != PIPE_AUTH_TYPE_NTLMSSP || p->auth.auth_type != PIPE_AUTH_TYPE_SPNEGO_NTLMSSP) {
                return NT_STATUS_ACCESS_DENIED;
        }
@@ -2747,6 +2778,7 @@ static NTSTATUS get_user_info_18(pipes_struct *p,
                return NT_STATUS_ACCESS_DENIED;
        }
 
+ query:
        /*
         * Do *NOT* do become_root()/unbecome_root() here ! JRA.
         */
@@ -2770,10 +2802,17 @@ static NTSTATUS get_user_info_18(pipes_struct *p,
                return NT_STATUS_ACCOUNT_DISABLED;
        }
 
-       r->lm_pwd_active = true;
-       r->nt_pwd_active = true;
-       memcpy(r->lm_pwd.hash, pdb_get_lanman_passwd(smbpass), 16);
-       memcpy(r->nt_pwd.hash, pdb_get_nt_passwd(smbpass), 16);
+       lm_pass = pdb_get_lanman_passwd(smbpass);
+       if (lm_pass != NULL) {
+               memcpy(r->lm_pwd.hash, lm_pass, 16);
+               r->lm_pwd_active = true;
+       }
+
+       nt_pass = pdb_get_nt_passwd(smbpass);
+       if (nt_pass != NULL) {
+               memcpy(r->nt_pwd.hash, nt_pass, 16);
+               r->nt_pwd_active = true;
+       }
        r->password_expired = 0; /* FIXME */
 
        TALLOC_FREE(smbpass);
@@ -2826,11 +2865,11 @@ static NTSTATUS get_user_info_20(TALLOC_CTX *mem_ctx,
 static NTSTATUS get_user_info_21(TALLOC_CTX *mem_ctx,
                                 struct samr_UserInfo21 *r,
                                 struct samu *pw,
-                                DOM_SID *domain_sid,
+                                struct dom_sid *domain_sid,
                                 uint32_t acc_granted)
 {
        NTSTATUS status;
-       const DOM_SID *sid_user, *sid_group;
+       const struct dom_sid *sid_user, *sid_group;
        uint32_t rid, primary_gid;
        NTTIME force_password_change;
        time_t must_change_time;
@@ -2943,7 +2982,7 @@ NTSTATUS _samr_QueryUserInfo(pipes_struct *p,
        NTSTATUS status;
        union samr_UserInfo *user_info = NULL;
        struct samr_user_info *uinfo;
-       DOM_SID domain_sid;
+       struct dom_sid domain_sid;
        uint32 rid;
        bool ret = false;
        struct samu *pwd = NULL;
@@ -3160,7 +3199,7 @@ NTSTATUS _samr_GetGroupsForUser(pipes_struct *p,
 {
        struct samr_user_info *uinfo;
        struct samu *sam_pass=NULL;
-       DOM_SID *sids;
+       struct dom_sid *sids;
        struct samr_RidWithAttribute dom_gid;
        struct samr_RidWithAttribute *gids = NULL;
        uint32 primary_group_rid;
@@ -3746,13 +3785,13 @@ NTSTATUS _samr_CreateUser2(pipes_struct *p,
                           struct samr_CreateUser2 *r)
 {
        const char *account = NULL;
-       DOM_SID sid;
+       struct dom_sid sid;
        uint32_t acb_info = r->in.acct_flags;
        struct samr_domain_info *dinfo;
        struct samr_user_info *uinfo;
        NTSTATUS nt_status;
        uint32 acc_granted;
-       SEC_DESC *psd;
+       struct security_descriptor *psd;
        size_t    sd_size;
        /* check this, when giving away 'add computer to domain' privs */
        uint32    des_access = GENERIC_RIGHTS_USER_ALL_ACCESS;
@@ -3811,7 +3850,7 @@ NTSTATUS _samr_CreateUser2(pipes_struct *p,
                se_priv_copy(&se_rights, &se_priv_none);
                can_add_account = nt_token_check_domain_rid(
                        p->server_info->ptok,
-                       DOMAIN_GROUP_RID_ADMINS );
+                       DOMAIN_RID_ADMINS );
        }
 
        DEBUG(5, ("_samr_CreateUser2: %s can add this account : %s\n",
@@ -3953,7 +3992,7 @@ NTSTATUS _samr_Connect2(pipes_struct *p,
 {
        struct samr_connect_info *info = NULL;
        struct policy_handle hnd;
-       SEC_DESC *psd = NULL;
+       struct security_descriptor *psd = NULL;
        uint32    acc_granted;
        uint32    des_access = r->in.access_mask;
        NTSTATUS  nt_status;
@@ -4081,7 +4120,7 @@ NTSTATUS _samr_LookupDomain(pipes_struct *p,
        NTSTATUS status;
        struct samr_connect_info *info;
        const char *domain_name;
-       DOM_SID *sid = NULL;
+       struct dom_sid *sid = NULL;
 
        /* win9x user manager likes to use SAMR_ACCESS_ENUM_DOMAINS here.
           Reverted that change so we will work with RAS servers again */
@@ -4174,11 +4213,11 @@ NTSTATUS _samr_EnumDomains(pipes_struct *p,
 NTSTATUS _samr_OpenAlias(pipes_struct *p,
                         struct samr_OpenAlias *r)
 {
-       DOM_SID sid;
+       struct dom_sid sid;
        uint32 alias_rid = r->in.rid;
        struct samr_alias_info *ainfo;
        struct samr_domain_info *dinfo;
-       SEC_DESC *psd = NULL;
+       struct security_descriptor *psd = NULL;
        uint32    acc_granted;
        uint32    des_access = r->in.access_mask;
        size_t    sd_size;
@@ -5317,7 +5356,7 @@ NTSTATUS _samr_GetAliasMembership(pipes_struct *p,
 
        NTSTATUS status;
 
-       DOM_SID *members;
+       struct dom_sid *members;
 
        DEBUG(5,("_samr_GetAliasMembership: %d\n", __LINE__));
 
@@ -5334,7 +5373,7 @@ NTSTATUS _samr_GetAliasMembership(pipes_struct *p,
                return NT_STATUS_OBJECT_TYPE_MISMATCH;
 
        if (r->in.sids->num_sids) {
-               members = TALLOC_ARRAY(p->mem_ctx, DOM_SID, r->in.sids->num_sids);
+               members = TALLOC_ARRAY(p->mem_ctx, struct dom_sid, r->in.sids->num_sids);
 
                if (members == NULL)
                        return NT_STATUS_NO_MEMORY;
@@ -5384,7 +5423,7 @@ NTSTATUS _samr_GetMembersInAlias(pipes_struct *p,
        size_t i;
        size_t num_sids = 0;
        struct lsa_SidPtr *sids = NULL;
-       DOM_SID *pdb_sids = NULL;
+       struct dom_sid *pdb_sids = NULL;
 
        ainfo = policy_handle_find(p, r->in.alias_handle,
                                   SAMR_ALIAS_ACCESS_GET_MEMBERS, NULL,
@@ -5660,7 +5699,7 @@ NTSTATUS _samr_DeleteUser(pipes_struct *p,
        DEBUG(5, ("_samr_DeleteUser: %d\n", __LINE__));
 
        uinfo = policy_handle_find(p, r->in.user_handle,
-                                  STD_RIGHT_DELETE_ACCESS, NULL,
+                                  SEC_STD_DELETE, NULL,
                                   struct samr_user_info, &status);
        if (!NT_STATUS_IS_OK(status)) {
                return status;
@@ -5728,7 +5767,7 @@ NTSTATUS _samr_DeleteDomainGroup(pipes_struct *p,
        DEBUG(5, ("samr_DeleteDomainGroup: %d\n", __LINE__));
 
        ginfo = policy_handle_find(p, r->in.group_handle,
-                                  STD_RIGHT_DELETE_ACCESS, NULL,
+                                  SEC_STD_DELETE, NULL,
                                   struct samr_group_info, &status);
        if (!NT_STATUS_IS_OK(status)) {
                return status;
@@ -5778,7 +5817,7 @@ NTSTATUS _samr_DeleteDomAlias(pipes_struct *p,
        DEBUG(5, ("_samr_DeleteDomAlias: %d\n", __LINE__));
 
        ainfo = policy_handle_find(p, r->in.alias_handle,
-                                  STD_RIGHT_DELETE_ACCESS, NULL,
+                                  SEC_STD_DELETE, NULL,
                                   struct samr_alias_info, &status);
        if (!NT_STATUS_IS_OK(status)) {
                return status;
@@ -5837,8 +5876,9 @@ NTSTATUS _samr_CreateDomainGroup(pipes_struct *p,
                return status;
        }
 
-       if (!sid_equal(&dinfo->sid, get_global_sam_sid()))
+       if (!sid_check_is_domain(&dinfo->sid)) {
                return NT_STATUS_ACCESS_DENIED;
+       }
 
        name = r->in.name->string;
        if (name == NULL) {
@@ -5884,7 +5924,7 @@ NTSTATUS _samr_CreateDomainGroup(pipes_struct *p,
 NTSTATUS _samr_CreateDomAlias(pipes_struct *p,
                              struct samr_CreateDomAlias *r)
 {
-       DOM_SID info_sid;
+       struct dom_sid info_sid;
        const char *name = NULL;
        struct samr_domain_info *dinfo;
        struct samr_alias_info *ainfo;
@@ -5898,8 +5938,9 @@ NTSTATUS _samr_CreateDomAlias(pipes_struct *p,
                return result;
        }
 
-       if (!sid_equal(&dinfo->sid, get_global_sam_sid()))
+       if (!sid_check_is_domain(&dinfo->sid)) {
                return NT_STATUS_ACCESS_DENIED;
+       }
 
        name = r->in.alias_name->string;
 
@@ -6239,11 +6280,11 @@ NTSTATUS _samr_OpenGroup(pipes_struct *p,
                         struct samr_OpenGroup *r)
 
 {
-       DOM_SID info_sid;
+       struct dom_sid info_sid;
        GROUP_MAP map;
        struct samr_domain_info *dinfo;
        struct samr_group_info *ginfo;
-       SEC_DESC         *psd = NULL;
+       struct security_descriptor         *psd = NULL;
        uint32            acc_granted;
        uint32            des_access = r->in.access_mask;
        size_t            sd_size;
@@ -6277,8 +6318,9 @@ NTSTATUS _samr_OpenGroup(pipes_struct *p,
 
        /* this should not be hard-coded like this */
 
-       if (!sid_equal(&dinfo->sid, get_global_sam_sid()))
+       if (!sid_check_is_domain(&dinfo->sid)) {
                return NT_STATUS_ACCESS_DENIED;
+       }
 
        sid_compose(&info_sid, &dinfo->sid, r->in.rid);
 
@@ -6694,19 +6736,20 @@ static enum samr_ValidationStatus samr_ValidatePassword_Change(TALLOC_CTX *mem_c
 {
        NTSTATUS status;
 
-       if (req->password.string) {
-               if (strlen(req->password.string) < dom_pw_info->min_password_length) {
+       if (req->password.string == NULL) {
+               return SAMR_VALIDATION_STATUS_SUCCESS;
+       }
+       if (strlen(req->password.string) < dom_pw_info->min_password_length) {
+               ZERO_STRUCT(rep->info);
+               return SAMR_VALIDATION_STATUS_PWD_TOO_SHORT;
+       }
+       if (dom_pw_info->password_properties & DOMAIN_PASSWORD_COMPLEX) {
+               status = check_password_complexity(req->account.string,
+                                                  req->password.string,
+                                                  NULL);
+               if (!NT_STATUS_IS_OK(status)) {
                        ZERO_STRUCT(rep->info);
-                       return SAMR_VALIDATION_STATUS_PWD_TOO_SHORT;
-               }
-               if (dom_pw_info->password_properties & DOMAIN_PASSWORD_COMPLEX) {
-                       status = check_password_complexity(req->account.string,
-                                                          req->password.string,
-                                                          NULL);
-                       if (!NT_STATUS_IS_OK(status)) {
-                               ZERO_STRUCT(rep->info);
-                               return SAMR_VALIDATION_STATUS_NOT_COMPLEX_ENOUGH;
-                       }
+                       return SAMR_VALIDATION_STATUS_NOT_COMPLEX_ENOUGH;
                }
        }
 
@@ -6723,19 +6766,20 @@ static enum samr_ValidationStatus samr_ValidatePassword_Reset(TALLOC_CTX *mem_ct
 {
        NTSTATUS status;
 
-       if (req->password.string) {
-               if (strlen(req->password.string) < dom_pw_info->min_password_length) {
+       if (req->password.string == NULL) {
+               return SAMR_VALIDATION_STATUS_SUCCESS;
+       }
+       if (strlen(req->password.string) < dom_pw_info->min_password_length) {
+               ZERO_STRUCT(rep->info);
+               return SAMR_VALIDATION_STATUS_PWD_TOO_SHORT;
+       }
+       if (dom_pw_info->password_properties & DOMAIN_PASSWORD_COMPLEX) {
+               status = check_password_complexity(req->account.string,
+                                                  req->password.string,
+                                                  NULL);
+               if (!NT_STATUS_IS_OK(status)) {
                        ZERO_STRUCT(rep->info);
-                       return SAMR_VALIDATION_STATUS_PWD_TOO_SHORT;
-               }
-               if (dom_pw_info->password_properties & DOMAIN_PASSWORD_COMPLEX) {
-                       status = check_password_complexity(req->account.string,
-                                                          req->password.string,
-                                                          NULL);
-                       if (!NT_STATUS_IS_OK(status)) {
-                               ZERO_STRUCT(rep->info);
-                               return SAMR_VALIDATION_STATUS_NOT_COMPLEX_ENOUGH;
-                       }
+                       return SAMR_VALIDATION_STATUS_NOT_COMPLEX_ENOUGH;
                }
        }