r11853: Add Dsr_GetSiteName (handy for experimenting with GPOs).
authorGünther Deschner <gd@samba.org>
Tue, 22 Nov 2005 14:10:49 +0000 (14:10 +0000)
committerGerald (Jerry) Carter <jerry@samba.org>
Wed, 10 Oct 2007 16:05:30 +0000 (11:05 -0500)
Guenther
(This used to be commit c54430a7b5e40d3bdf8afdc813eb722c0a3b861e)

source3/include/rpc_netlogon.h
source3/rpc_client/cli_netlogon.c
source3/rpc_parse/parse_net.c
source3/rpcclient/cmd_netlogon.c

index bc4c41cd1f3aaf6a4ef6c53fab76c61330b2c122..fdf2f08c03cbf0454c0665f5259a8d92445e6e48 100644 (file)
@@ -40,6 +40,7 @@
 #define NET_TRUST_DOM_LIST     0x13
 #define NET_DSR_GETDCNAME      0x14
 #define NET_AUTH3              0x1a
+#define NET_DSR_GETSITENAME    0x1c
 
 /* Secure Channel types.  used in NetrServerAuthenticate negotiation */
 #define SEC_CHAN_WKSTA   2
@@ -968,4 +969,18 @@ typedef struct net_r_dsr_getdcname {
        WERROR result;
 } NET_R_DSR_GETDCNAME;
 
+/* NET_Q_DSR_GESITENAME */
+typedef struct net_q_dsr_getsitename {
+       uint32 ptr_computer_name;
+       UNISTR2 uni_computer_name;
+} NET_Q_DSR_GETSITENAME;
+
+/* NET_R_DSR_GETSITENAME */
+typedef struct net_r_dsr_getsitename {
+       uint32 ptr_site_name;
+       UNISTR2 uni_site_name;
+       WERROR result;
+} NET_R_DSR_GETSITENAME;
+
+
 #endif /* _RPC_NETLOGON_H */
index f12f7d09fa7094a620efa79ac5cb57bd3a91742e..e3cc97cdc6b7e48fb24d8a0072fcc6272a00ea35 100644 (file)
@@ -539,6 +539,47 @@ WERROR rpccli_netlogon_dsr_getdcname(struct rpc_pipe_client *cli,
        return WERR_OK;
 }
 
+/* Dsr_GetSiteName */
+
+WERROR rpccli_netlogon_dsr_getsitename(struct rpc_pipe_client *cli,
+                                      TALLOC_CTX *mem_ctx,
+                                      const char *computer_name,
+                                      char **site_name)
+{
+       prs_struct qbuf, rbuf;
+       NET_Q_DSR_GETSITENAME q;
+       NET_R_DSR_GETSITENAME r;
+
+       ZERO_STRUCT(q);
+       ZERO_STRUCT(r);
+
+       /* Initialize input parameters */
+
+       init_net_q_dsr_getsitename(&q, computer_name);
+
+       /* Marshall data and send request */
+
+       CLI_DO_RPC_WERR(cli, mem_ctx, PI_NETLOGON, NET_DSR_GETSITENAME,
+                       q, r,
+                       qbuf, rbuf,
+                       net_io_q_dsr_getsitename,
+                       net_io_r_dsr_getsitename,
+                       WERR_GENERAL_FAILURE);
+
+       if (!W_ERROR_IS_OK(r.result)) {
+               return r.result;
+       }
+
+       if ((site_name != NULL) &&
+           (rpcstr_pull_unistr2_talloc(mem_ctx, site_name,
+                                       &r.uni_site_name) < 1)) {
+               return WERR_GENERAL_FAILURE;
+       }
+
+       return WERR_OK;
+}
+
+
 
 /* Sam synchronisation */
 
index 3732ab3a725950b78a4f4747bec184eb93c0da60..ce2a085f4787edae1ef8d406d6046f0382e8a8c1 100644 (file)
@@ -3389,3 +3389,75 @@ BOOL net_io_r_dsr_getdcname(const char *desc, NET_R_DSR_GETDCNAME *r_t,
 
        return True;
 }
+
+/*******************************************************************
+ Inits a NET_Q_DSR_GETSITENAME structure.
+********************************************************************/
+
+void init_net_q_dsr_getsitename(NET_Q_DSR_GETSITENAME *r_t, const char *computer_name)
+{
+       DEBUG(5, ("init_net_q_dsr_getsitename\n"));
+
+       r_t->ptr_computer_name = (computer_name != NULL);
+       init_unistr2(&r_t->uni_computer_name, computer_name, UNI_STR_TERMINATE);
+}
+
+/*******************************************************************
+ Reads or writes an NET_Q_DSR_GETSITENAME structure.
+********************************************************************/
+
+BOOL net_io_q_dsr_getsitename(const char *desc, NET_Q_DSR_GETSITENAME *r_t,
+                             prs_struct *ps, int depth)
+{
+       if (r_t == NULL)
+               return False;
+
+       prs_debug(ps, depth, desc, "net_io_q_dsr_getsitename");
+       depth++;
+
+       if (!prs_uint32("ptr_computer_name", ps, depth, &r_t->ptr_computer_name))
+               return False;
+
+       if (!smb_io_unistr2("computer_name", &r_t->uni_computer_name,
+                           r_t->ptr_computer_name, ps, depth))
+               return False;
+
+       if (!prs_align(ps))
+               return False;
+
+       return True;
+}
+
+/*******************************************************************
+ Reads or writes an NET_R_DSR_GETSITENAME structure.
+********************************************************************/
+
+BOOL net_io_r_dsr_getsitename(const char *desc, NET_R_DSR_GETSITENAME *r_t,
+                             prs_struct *ps, int depth)
+{
+       if (r_t == NULL)
+               return False;
+
+       prs_debug(ps, depth, desc, "net_io_r_dsr_getsitename");
+       depth++;
+
+       if (!prs_uint32("ptr_site_name", ps, depth, &r_t->ptr_site_name))
+               return False;
+
+       if (!prs_align(ps))
+               return False;
+
+       if (!smb_io_unistr2("site_name", &r_t->uni_site_name,
+                           r_t->ptr_site_name, ps, depth))
+               return False;
+
+       if (!prs_align(ps))
+               return False;
+
+       if (!prs_werror("result", ps, depth, &r_t->result))
+               return False;
+
+       return True;
+}
+
+
index 20f11bc3c93b859a3459ea457797fa739cfdb24e..9377f8fde8cc8e4e558278f338b0adf7f0de89d3 100644 (file)
@@ -99,6 +99,31 @@ static WERROR cmd_netlogon_dsr_getdcname(struct rpc_pipe_client *cli,
        return result;
 }
 
+static WERROR cmd_netlogon_dsr_getsitename(struct rpc_pipe_client *cli,
+                                          TALLOC_CTX *mem_ctx, int argc,
+                                          const char **argv)
+{
+       WERROR result;
+       char *sitename;
+
+       if (argc != 2) {
+               fprintf(stderr, "Usage: %s computername\n", argv[0]);
+               return WERR_OK;
+       }
+
+       result = rpccli_netlogon_dsr_getsitename(cli, mem_ctx, argv[1], &sitename);
+
+       if (!W_ERROR_IS_OK(result)) {
+               printf("rpccli_netlogon_dsr_gesitename returned %s\n",
+                      nt_errstr(werror_to_ntstatus(result)));
+               return result;
+       }
+
+       printf("Computer %s is on Site: %s\n", argv[1], sitename);
+
+       return WERR_OK;
+}
+
 static NTSTATUS cmd_netlogon_logon_ctrl(struct rpc_pipe_client *cli, 
                                         TALLOC_CTX *mem_ctx, int argc, 
                                         const char **argv)
@@ -347,6 +372,7 @@ struct cmd_set netlogon_commands[] = {
        { "logonctrl2", RPC_RTYPE_NTSTATUS, cmd_netlogon_logon_ctrl2, NULL, PI_NETLOGON, NULL, "Logon Control 2",     "" },
        { "getdcname", RPC_RTYPE_NTSTATUS, cmd_netlogon_getdcname, NULL, PI_NETLOGON, NULL, "Get trusted DC name",     "" },
        { "dsr_getdcname", RPC_RTYPE_WERROR, NULL, cmd_netlogon_dsr_getdcname, PI_NETLOGON, NULL, "Get trusted DC name",     "" },
+       { "dsr_getsitename", RPC_RTYPE_WERROR, NULL, cmd_netlogon_dsr_getsitename, PI_NETLOGON, NULL, "Get sitename",     "" },
        { "logonctrl",  RPC_RTYPE_NTSTATUS, cmd_netlogon_logon_ctrl,  NULL, PI_NETLOGON, NULL, "Logon Control",       "" },
        { "samsync",    RPC_RTYPE_NTSTATUS, cmd_netlogon_sam_sync,    NULL, PI_NETLOGON, NULL, "Sam Synchronisation", "" },
        { "samdeltas",  RPC_RTYPE_NTSTATUS, cmd_netlogon_sam_deltas,  NULL, PI_NETLOGON, NULL, "Query Sam Deltas",    "" },