s4:netlogon: Implement netr_GetDcName() similar to netr_DsGetDCName()
authorStefan Metzmacher <metze@samba.org>
Thu, 4 Dec 2008 10:56:51 +0000 (11:56 +0100)
committerStefan Metzmacher <metze@samba.org>
Thu, 4 Dec 2008 11:48:39 +0000 (12:48 +0100)
metze

source4/rpc_server/netlogon/dcerpc_netlogon.c

index ccc1fc515fb5af3da6e179a65d91665a152fe24c..2854980284065ff7d70ee931f7cc463a0e5c3805 100644 (file)
@@ -803,7 +803,40 @@ static NTSTATUS dcesrv_netr_AccountSync(struct dcesrv_call_state *dce_call, TALL
 static WERROR dcesrv_netr_GetDcName(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
                       struct netr_GetDcName *r)
 {
-       DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
+       const char * const attrs[] = { NULL };
+       void *sam_ctx;
+       struct ldb_message **res;
+       struct ldb_dn *domain_dn;
+       int ret;
+       const char *dcname;
+
+       sam_ctx = samdb_connect(mem_ctx, dce_call->event_ctx,
+                               dce_call->conn->dce_ctx->lp_ctx,
+                               dce_call->conn->auth_state.session_info);
+       if (sam_ctx == NULL) {
+               return WERR_DS_SERVICE_UNAVAILABLE;
+       }
+
+       domain_dn = samdb_domain_to_dn(sam_ctx, mem_ctx,
+                                      r->in.domainname);
+       if (domain_dn == NULL) {
+               return WERR_DS_SERVICE_UNAVAILABLE;
+       }
+
+       ret = gendb_search_dn(sam_ctx, mem_ctx, domain_dn, &res, attrs);
+       if (ret != 1) {
+               return WERR_NO_SUCH_DOMAIN;
+       }
+
+       /* TODO: - return real IP address
+        *       - check all r->in.* parameters (server_unc is ignored by w2k3!)
+        */
+       dcname = talloc_asprintf(mem_ctx, "\\\\%s",
+                                lp_netbios_name(dce_call->conn->dce_ctx->lp_ctx));
+       W_ERROR_HAVE_NO_MEMORY(dcname);
+
+       *r->out.dcname = dcname;
+       return WERR_OK;
 }