s3-selftest: enable smb2 torture tests against samba3.
[samba.git] / source3 / winbindd / winbindd_dual_srv.c
index f0bbee9f31871d98434ec61c48c4ae282c1fd150..4c6fb97e7092852aafeda7a7b42b5cdb1bd22fef 100644 (file)
 #include "winbindd/winbindd.h"
 #include "winbindd/winbindd_proto.h"
 #include "librpc/gen_ndr/srv_wbint.h"
+#include "../librpc/gen_ndr/cli_netlogon.h"
+#include "idmap.h"
 
-void _wbint_Ping(pipes_struct *p, struct wbint_Ping *r)
+void _wbint_Ping(struct pipes_struct *p, struct wbint_Ping *r)
 {
        *r->out.out_data = r->in.in_data;
 }
 
-NTSTATUS _wbint_LookupSid(pipes_struct *p, struct wbint_LookupSid *r)
+NTSTATUS _wbint_LookupSid(struct pipes_struct *p, struct wbint_LookupSid *r)
 {
        struct winbindd_domain *domain = wb_child_domain();
        char *dom_name;
@@ -54,7 +56,7 @@ NTSTATUS _wbint_LookupSid(pipes_struct *p, struct wbint_LookupSid *r)
        return NT_STATUS_OK;
 }
 
-NTSTATUS _wbint_LookupName(pipes_struct *p, struct wbint_LookupName *r)
+NTSTATUS _wbint_LookupName(struct pipes_struct *p, struct wbint_LookupName *r)
 {
        struct winbindd_domain *domain = wb_child_domain();
 
@@ -67,7 +69,7 @@ NTSTATUS _wbint_LookupName(pipes_struct *p, struct wbint_LookupName *r)
                r->out.sid, r->out.type);
 }
 
-NTSTATUS _wbint_Sid2Uid(pipes_struct *p, struct wbint_Sid2Uid *r)
+NTSTATUS _wbint_Sid2Uid(struct pipes_struct *p, struct wbint_Sid2Uid *r)
 {
        uid_t uid;
        NTSTATUS status;
@@ -81,7 +83,7 @@ NTSTATUS _wbint_Sid2Uid(pipes_struct *p, struct wbint_Sid2Uid *r)
        return NT_STATUS_OK;
 }
 
-NTSTATUS _wbint_Sid2Gid(pipes_struct *p, struct wbint_Sid2Gid *r)
+NTSTATUS _wbint_Sid2Gid(struct pipes_struct *p, struct wbint_Sid2Gid *r)
 {
        gid_t gid;
        NTSTATUS status;
@@ -95,19 +97,19 @@ NTSTATUS _wbint_Sid2Gid(pipes_struct *p, struct wbint_Sid2Gid *r)
        return NT_STATUS_OK;
 }
 
-NTSTATUS _wbint_Uid2Sid(pipes_struct *p, struct wbint_Uid2Sid *r)
+NTSTATUS _wbint_Uid2Sid(struct pipes_struct *p, struct wbint_Uid2Sid *r)
 {
        return idmap_uid_to_sid(r->in.dom_name ? r->in.dom_name : "",
                                r->out.sid, r->in.uid);
 }
 
-NTSTATUS _wbint_Gid2Sid(pipes_struct *p, struct wbint_Gid2Sid *r)
+NTSTATUS _wbint_Gid2Sid(struct pipes_struct *p, struct wbint_Gid2Sid *r)
 {
        return idmap_gid_to_sid(r->in.dom_name ? r->in.dom_name : "",
                                r->out.sid, r->in.gid);
 }
 
-NTSTATUS _wbint_AllocateUid(pipes_struct *p, struct wbint_AllocateUid *r)
+NTSTATUS _wbint_AllocateUid(struct pipes_struct *p, struct wbint_AllocateUid *r)
 {
        struct unixid xid;
        NTSTATUS status;
@@ -120,7 +122,7 @@ NTSTATUS _wbint_AllocateUid(pipes_struct *p, struct wbint_AllocateUid *r)
        return NT_STATUS_OK;
 }
 
-NTSTATUS _wbint_AllocateGid(pipes_struct *p, struct wbint_AllocateGid *r)
+NTSTATUS _wbint_AllocateGid(struct pipes_struct *p, struct wbint_AllocateGid *r)
 {
        struct unixid xid;
        NTSTATUS status;
@@ -133,7 +135,7 @@ NTSTATUS _wbint_AllocateGid(pipes_struct *p, struct wbint_AllocateGid *r)
        return NT_STATUS_OK;
 }
 
-NTSTATUS _wbint_QueryUser(pipes_struct *p, struct wbint_QueryUser *r)
+NTSTATUS _wbint_QueryUser(struct pipes_struct *p, struct wbint_QueryUser *r)
 {
        struct winbindd_domain *domain = wb_child_domain();
 
@@ -145,7 +147,7 @@ NTSTATUS _wbint_QueryUser(pipes_struct *p, struct wbint_QueryUser *r)
                                           r->out.info);
 }
 
-NTSTATUS _wbint_LookupUserAliases(pipes_struct *p,
+NTSTATUS _wbint_LookupUserAliases(struct pipes_struct *p,
                                  struct wbint_LookupUserAliases *r)
 {
        struct winbindd_domain *domain = wb_child_domain();
@@ -159,7 +161,7 @@ NTSTATUS _wbint_LookupUserAliases(pipes_struct *p,
                &r->out.rids->num_rids, &r->out.rids->rids);
 }
 
-NTSTATUS _wbint_LookupUserGroups(pipes_struct *p,
+NTSTATUS _wbint_LookupUserGroups(struct pipes_struct *p,
                                 struct wbint_LookupUserGroups *r)
 {
        struct winbindd_domain *domain = wb_child_domain();
@@ -173,7 +175,7 @@ NTSTATUS _wbint_LookupUserGroups(pipes_struct *p,
                &r->out.sids->num_sids, &r->out.sids->sids);
 }
 
-NTSTATUS _wbint_QuerySequenceNumber(pipes_struct *p,
+NTSTATUS _wbint_QuerySequenceNumber(struct pipes_struct *p,
                                    struct wbint_QuerySequenceNumber *r)
 {
        struct winbindd_domain *domain = wb_child_domain();
@@ -185,7 +187,7 @@ NTSTATUS _wbint_QuerySequenceNumber(pipes_struct *p,
        return domain->methods->sequence_number(domain, r->out.sequence);
 }
 
-NTSTATUS _wbint_LookupGroupMembers(pipes_struct *p,
+NTSTATUS _wbint_LookupGroupMembers(struct pipes_struct *p,
                                   struct wbint_LookupGroupMembers *r)
 {
        struct winbindd_domain *domain = wb_child_domain();
@@ -223,7 +225,8 @@ NTSTATUS _wbint_LookupGroupMembers(pipes_struct *p,
        return NT_STATUS_OK;
 }
 
-NTSTATUS _wbint_QueryUserList(pipes_struct *p, struct wbint_QueryUserList *r)
+NTSTATUS _wbint_QueryUserList(struct pipes_struct *p,
+                             struct wbint_QueryUserList *r)
 {
        struct winbindd_domain *domain = wb_child_domain();
 
@@ -236,7 +239,8 @@ NTSTATUS _wbint_QueryUserList(pipes_struct *p, struct wbint_QueryUserList *r)
                &r->out.users->userinfos);
 }
 
-NTSTATUS _wbint_QueryGroupList(pipes_struct *p, struct wbint_QueryGroupList *r)
+NTSTATUS _wbint_QueryGroupList(struct pipes_struct *p,
+                              struct wbint_QueryGroupList *r)
 {
        struct winbindd_domain *domain = wb_child_domain();
        uint32_t i, num_groups;
@@ -273,10 +277,12 @@ NTSTATUS _wbint_QueryGroupList(pipes_struct *p, struct wbint_QueryGroupList *r)
 
        r->out.groups->num_principals = num_groups;
        r->out.groups->principals = result;
+
+       TALLOC_FREE(groups);
        return NT_STATUS_OK;
 }
 
-NTSTATUS _wbint_DsGetDcName(pipes_struct *p, struct wbint_DsGetDcName *r)
+NTSTATUS _wbint_DsGetDcName(struct pipes_struct *p, struct wbint_DsGetDcName *r)
 {
        struct winbindd_domain *domain = wb_child_domain();
        struct rpc_pipe_client *netlogon_pipe;
@@ -357,7 +363,7 @@ done:
        return status;
 }
 
-NTSTATUS _wbint_LookupRids(pipes_struct *p, struct wbint_LookupRids *r)
+NTSTATUS _wbint_LookupRids(struct pipes_struct *p, struct wbint_LookupRids *r)
 {
        struct winbindd_domain *domain = wb_child_domain();
        char *domain_name;
@@ -397,19 +403,19 @@ NTSTATUS _wbint_LookupRids(pipes_struct *p, struct wbint_LookupRids *r)
        return NT_STATUS_OK;
 }
 
-NTSTATUS _wbint_CheckMachineAccount(pipes_struct *p,
+NTSTATUS _wbint_CheckMachineAccount(struct pipes_struct *p,
                                    struct wbint_CheckMachineAccount *r)
 {
        struct winbindd_domain *domain;
        int num_retries = 0;
        NTSTATUS status;
 
-again:
        domain = wb_child_domain();
        if (domain == NULL) {
                return NT_STATUS_REQUEST_NOT_ACCEPTED;
        }
 
+again:
        invalidate_cm_connection(&domain->conn);
 
        {
@@ -449,7 +455,7 @@ again:
        return status;
 }
 
-NTSTATUS _wbint_ChangeMachineAccount(pipes_struct *p,
+NTSTATUS _wbint_ChangeMachineAccount(struct pipes_struct *p,
                                     struct wbint_ChangeMachineAccount *r)
 {
        struct winbindd_domain *domain;
@@ -509,70 +515,51 @@ again:
        return status;
 }
 
-
-NTSTATUS _wbint_SetMapping(pipes_struct *p, struct wbint_SetMapping *r)
+NTSTATUS _wbint_PingDc(struct pipes_struct *p, struct wbint_PingDc *r)
 {
-       struct id_map map;
-
-       map.sid = r->in.sid;
-       map.xid.id = r->in.id;
-       map.status = ID_MAPPED;
+       NTSTATUS status;
+       struct winbindd_domain *domain;
+       struct rpc_pipe_client *netlogon_pipe;
+       union netr_CONTROL_QUERY_INFORMATION info;
+       WERROR werr;
+       fstring logon_server;
 
-       switch (r->in.type) {
-       case WBINT_ID_TYPE_UID:
-               map.xid.type = ID_TYPE_UID;
-               break;
-       case WBINT_ID_TYPE_GID:
-               map.xid.type = ID_TYPE_GID;
-               break;
-       default:
-               return NT_STATUS_INVALID_PARAMETER;
+       domain = wb_child_domain();
+       if (domain == NULL) {
+               return NT_STATUS_REQUEST_NOT_ACCEPTED;
        }
 
-       return idmap_set_mapping(&map);
-}
+       status = cm_connect_netlogon(domain, &netlogon_pipe);
+        if (!NT_STATUS_IS_OK(status)) {
+                DEBUG(3, ("could not open handle to NETLOGON pipe\n"));
+               return status;
+        }
 
-NTSTATUS _wbint_RemoveMapping(pipes_struct *p, struct wbint_RemoveMapping *r)
-{
-       struct id_map map;
+       fstr_sprintf(logon_server, "\\\\%s", domain->dcname);
 
-       map.sid = r->in.sid;
-       map.xid.id = r->in.id;
-       map.status = ID_MAPPED;
+       /*
+        * This provokes a WERR_NOT_SUPPORTED error message. This is
+        * documented in the wspp docs. I could not get a successful
+        * call to work, but the main point here is testing that the
+        * netlogon pipe works.
+        */
+       status = rpccli_netr_LogonControl(netlogon_pipe, p->mem_ctx,
+                                         logon_server, NETLOGON_CONTROL_QUERY,
+                                         2, &info, &werr);
 
-       switch (r->in.type) {
-       case WBINT_ID_TYPE_UID:
-               map.xid.type = ID_TYPE_UID;
-               break;
-       case WBINT_ID_TYPE_GID:
-               map.xid.type = ID_TYPE_GID;
-               break;
-       default:
-               return NT_STATUS_INVALID_PARAMETER;
+       if (NT_STATUS_EQUAL(status, NT_STATUS_IO_TIMEOUT)) {
+               DEBUG(2, ("rpccli_netr_LogonControl timed out\n"));
+               invalidate_cm_connection(&domain->conn);
+               return status;
        }
 
-       return idmap_remove_mapping(&map);
-}
-
-NTSTATUS _wbint_SetHWM(pipes_struct *p, struct wbint_SetHWM *r)
-{
-       struct unixid id;
-       NTSTATUS status;
-
-       id.id = r->in.id;
-
-       switch (id.type) {
-       case WBINT_ID_TYPE_UID:
-               id.type = ID_TYPE_UID;
-               status = idmap_set_uid_hwm(&id);
-               break;
-       case ID_TYPE_GID:
-               id.type = ID_TYPE_GID;
-               status = idmap_set_gid_hwm(&id);
-               break;
-       default:
-               status = NT_STATUS_INVALID_PARAMETER;
-               break;
+       if (!NT_STATUS_EQUAL(status, NT_STATUS_CTL_FILE_NOT_SUPPORTED)) {
+               DEBUG(2, ("rpccli_netr_LogonControl returned %s, expected "
+                         "NT_STATUS_CTL_FILE_NOT_SUPPORTED\n",
+                         nt_errstr(status)));
+               return status;
        }
-       return status;
+
+       DEBUG(5, ("winbindd_dual_ping_dc succeeded\n"));
+       return NT_STATUS_OK;
 }