From d2ea6d5ae759bd2c842b5836d778b5a52b8af477 Mon Sep 17 00:00:00 2001 From: Gerald Carter Date: Fri, 4 Oct 2002 19:11:36 +0000 Subject: merge of working dsrolegetprimdominfo() client code from APP_HEAD (This used to be commit f70caa25e4ee198151b915cf2bc0a26b2d0e243d) --- source3/Makefile.in | 7 +-- source3/include/ntdomain.h | 1 + source3/include/rpc_dce.h | 1 + source3/include/rpc_ds.h | 91 +++++++++++++++++++++++++++++++++ source3/include/smb.h | 2 +- source3/libsmb/cliconnect.c | 2 +- source3/rpc_client/cli_ds.c | 63 +++++++++++++++++++++++ source3/rpc_client/cli_pipe.c | 2 +- source3/rpc_parse/parse_ds.c | 113 +++++++++++++++++++++++++++++++++++++++++ source3/rpc_parse/parse_rpc.c | 4 +- source3/rpcclient/cmd_ds.c | 59 +++++++++++++++++++++ source3/rpcclient/cmd_lsarpc.c | 8 --- source3/rpcclient/rpcclient.c | 2 + 13 files changed, 339 insertions(+), 16 deletions(-) create mode 100644 source3/include/rpc_ds.h create mode 100644 source3/rpc_client/cli_ds.c create mode 100644 source3/rpc_parse/parse_ds.c create mode 100644 source3/rpcclient/cmd_ds.c (limited to 'source3') diff --git a/source3/Makefile.in b/source3/Makefile.in index 3e884b11ed..11cec4a783 100644 --- a/source3/Makefile.in +++ b/source3/Makefile.in @@ -178,7 +178,8 @@ LIBMSRPC_OBJ = rpc_client/cli_lsarpc.o rpc_client/cli_samr.o \ rpc_client/cli_netlogon.o rpc_client/cli_srvsvc.o \ rpc_client/cli_wkssvc.o rpc_client/cli_dfs.o \ rpc_client/cli_reg.o rpc_client/cli_pipe.o \ - rpc_client/cli_spoolss.o rpc_client/cli_spoolss_notify.o + rpc_client/cli_spoolss.o rpc_client/cli_spoolss_notify.o \ + rpc_client/cli_ds.o LIBMSRPC_SERVER_OBJ = libsmb/trust_passwd.o @@ -205,7 +206,7 @@ RPC_PARSE_OBJ1 = rpc_parse/parse_prs.o rpc_parse/parse_sec.o \ RPC_PARSE_OBJ = rpc_parse/parse_lsa.o rpc_parse/parse_net.o \ rpc_parse/parse_reg.o rpc_parse/parse_rpc.o \ rpc_parse/parse_samr.o rpc_parse/parse_srv.o \ - rpc_parse/parse_wks.o \ + rpc_parse/parse_wks.o rpc_parse/parse_ds.o \ rpc_parse/parse_spoolss.o rpc_parse/parse_dfs.o \ $(REGOBJS_OBJ) @@ -352,7 +353,7 @@ RPCCLIENT_OBJ1 = rpcclient/rpcclient.o rpcclient/cmd_lsarpc.o \ rpcclient/cmd_samr.o rpcclient/cmd_spoolss.o \ rpcclient/cmd_netlogon.o rpcclient/cmd_srvsvc.o \ rpcclient/cmd_dfs.o rpcclient/cmd_reg.o \ - rpcclient/display_sec.o + rpcclient/display_sec.o rpcclient/cmd_ds.o RPCCLIENT_OBJ = $(RPCCLIENT_OBJ1) \ $(PARAM_OBJ) $(LIBSMB_OBJ) $(UBIQX_OBJ) $(LIB_OBJ) \ diff --git a/source3/include/ntdomain.h b/source3/include/ntdomain.h index ffb9c96b72..628035885e 100644 --- a/source3/include/ntdomain.h +++ b/source3/include/ntdomain.h @@ -374,5 +374,6 @@ struct acct_info #include "rpc_wkssvc.h" #include "rpc_spoolss.h" #include "rpc_dfs.h" +#include "rpc_ds.h" #endif /* _NT_DOMAIN_H */ diff --git a/source3/include/rpc_dce.h b/source3/include/rpc_dce.h index 61316de89c..3e615dab80 100644 --- a/source3/include/rpc_dce.h +++ b/source3/include/rpc_dce.h @@ -89,6 +89,7 @@ enum NTLM_MESSAGE_TYPE /* Maximum PDU fragment size. */ #define MAX_PDU_FRAG_LEN 0x1630 +/* #define MAX_PDU_FRAG_LEN 0x10b8 this is what w2k sets */ /* * Actual structure of a DCE UUID diff --git a/source3/include/rpc_ds.h b/source3/include/rpc_ds.h new file mode 100644 index 0000000000..c01d10554e --- /dev/null +++ b/source3/include/rpc_ds.h @@ -0,0 +1,91 @@ +/* + Unix SMB/CIFS implementation. + SMB parameters and setup + Copyright (C) Gerald Carter 2002 + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +*/ + +#ifndef _RPC_DS_H /* _RPC_LSA_H */ +#define _RPC_DS_H + +#include "rpc_misc.h" + + +/* Opcodes available on PIPE_LSARPC_DS */ + +#define DS_GETPRIMDOMINFO 0x00 + + +/* macros for RPC's */ + +#define DSROLE_PRIMARY_DS_RUNNING 0x00000001 +#define DSROLE_PRIMARY_DS_MIXED_MODE 0x00000002 +#define DSROLE_UPGRADE_IN_PROGRESS 0x00000004 +#define DSROLE_PRIMARY_DOMAIN_GUID_PRESENT 0x01000000 + +typedef struct +{ + uint16 machine_role; + uint16 unknown; /* 0x6173 -- maybe just alignment? */ + + uint32 flags; + + uint32 netbios_ptr; + uint32 dnsname_ptr; + uint32 forestname_ptr; + + GUID domain_guid; + + UNISTR2 netbios_domain; + /* these 2 might be reversed in order. I can't tell from + my tests as both values are the same --jerry */ + UNISTR2 dns_domain; + UNISTR2 forest_domain; +} DSROLE_PRIMARY_DOMAIN_INFO_BASIC; + +typedef struct +{ + DSROLE_PRIMARY_DOMAIN_INFO_BASIC *basic; +} DS_DOMINFO_CTR; + +/* info levels for ds_getprimdominfo() */ + +#define DsRolePrimaryDomainInfoBasic 1 + + +/* DS_Q_GETPRIMDOMINFO - DsGetPrimaryDomainInformation() request */ +typedef struct +{ + uint16 level; +} DS_Q_GETPRIMDOMINFO; + +/* DS_R_GETPRIMDOMINFO - DsGetPrimaryDomainInformation() response */ +typedef struct +{ + uint32 ptr; + + uint16 level; + uint16 unknown0; /* 0x455c -- maybe just alignment? */ + + DS_DOMINFO_CTR info; + + NTSTATUS status; +} DS_R_GETPRIMDOMINFO; + + + + +#endif /* _RPC_DS_H */ diff --git a/source3/include/smb.h b/source3/include/smb.h index 5bf79b75fe..b5ab504415 100644 --- a/source3/include/smb.h +++ b/source3/include/smb.h @@ -188,7 +188,7 @@ typedef smb_ucs2_t wfstring[FSTRING_LEN]; #define PIPE_NETDFS "\\PIPE\\netdfs" #define PI_LSARPC 0 -#define PI_LSARPC_V2 1 +#define PI_LSARPC_DS 1 #define PI_SAMR 2 #define PI_NETLOGON 3 #define PI_SRVSVC 4 diff --git a/source3/libsmb/cliconnect.c b/source3/libsmb/cliconnect.c index 3951e3c776..f005ac21f3 100644 --- a/source3/libsmb/cliconnect.c +++ b/source3/libsmb/cliconnect.c @@ -344,7 +344,7 @@ static BOOL cli_session_setup_nt1(struct cli_state *cli, char *user, /* Have plaintext orginal */ set_signing_on_cli(cli, pass, ntpword); } - + return True; } diff --git a/source3/rpc_client/cli_ds.c b/source3/rpc_client/cli_ds.c new file mode 100644 index 0000000000..d6985bf876 --- /dev/null +++ b/source3/rpc_client/cli_ds.c @@ -0,0 +1,63 @@ +/* + Unix SMB/CIFS implementation. + RPC pipe client + Copyright (C) Gerald Carter 2002, + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +*/ + +#include "includes.h" + +/* implementations of client side DsXXX() functions */ + +NTSTATUS cli_ds_getprimarydominfo( struct cli_state *cli, TALLOC_CTX *mem_ctx, + uint16 level, DS_DOMINFO_CTR *ctr) +{ + prs_struct qbuf, rbuf; + DS_Q_GETPRIMDOMINFO q; + DS_R_GETPRIMDOMINFO r; + NTSTATUS result; + + ZERO_STRUCT(q); + ZERO_STRUCT(r); + + /* Initialise parse structures */ + + prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL); + prs_init(&rbuf, 0, mem_ctx, UNMARSHALL); + + q.level = level; + + if (!ds_io_q_getprimdominfo("", &q, &qbuf, 0) + || !rpc_api_pipe_req(cli, DS_GETPRIMDOMINFO, &qbuf, &rbuf)) + { + result = NT_STATUS_UNSUCCESSFUL; + goto done; + } + + /* Unmarshall response */ + + if (!ds_io_r_getprimdominfo("", &r, &rbuf, 0)) { + result = NT_STATUS_UNSUCCESSFUL; + goto done; + } + + memcpy( ctr, &r.info, sizeof(DS_DOMINFO_CTR) ); + result = r.status; + +done: + return result; +} + diff --git a/source3/rpc_client/cli_pipe.c b/source3/rpc_client/cli_pipe.c index b6b58d2237..2732c53e5c 100644 --- a/source3/rpc_client/cli_pipe.c +++ b/source3/rpc_client/cli_pipe.c @@ -599,7 +599,7 @@ static BOOL create_rpc_bind_req(prs_struct *rpc_out, BOOL do_auth, uint32 rpc_ca } /* create the request RPC_HDR */ - init_rpc_hdr(&hdr, RPC_BIND, 0x0, rpc_call_id, + init_rpc_hdr(&hdr, RPC_BIND, 0x3, rpc_call_id, RPC_HEADER_LEN + RPC_HDR_RB_LEN + prs_offset(&auth_info), auth_len); diff --git a/source3/rpc_parse/parse_ds.c b/source3/rpc_parse/parse_ds.c new file mode 100644 index 0000000000..ec5ea45cc8 --- /dev/null +++ b/source3/rpc_parse/parse_ds.c @@ -0,0 +1,113 @@ +/* + * Unix SMB/CIFS implementation. + * RPC Pipe client / server routines + * Copyright (C) Gerald Carter 2002 + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + */ + +#include "includes.h" + +static BOOL ds_io_dominfobasic( char *desc, prs_struct *ps, int depth, DSROLE_PRIMARY_DOMAIN_INFO_BASIC **basic) +{ + DSROLE_PRIMARY_DOMAIN_INFO_BASIC *p = *basic; + + if ( UNMARSHALLING(ps) ) + p = *basic = (DSROLE_PRIMARY_DOMAIN_INFO_BASIC *)prs_alloc_mem(ps, sizeof(DSROLE_PRIMARY_DOMAIN_INFO_BASIC)); + + if ( !p ) + return False; + + if ( !prs_uint16("machine_role", ps, depth, &p->machine_role) ) + return False; + if ( !prs_uint16("unknown", ps, depth, &p->unknown) ) + return False; + + if ( !prs_uint32("flags", ps, depth, &p->flags) ) + return False; + + if ( !prs_uint32("netbios_ptr", ps, depth, &p->netbios_ptr) ) + return False; + if ( !prs_uint32("dnsname_ptr", ps, depth, &p->dnsname_ptr) ) + return False; + if ( !prs_uint32("forestname_ptr", ps, depth, &p->forestname_ptr) ) + return False; + + if ( !prs_uint8s(False, "domain_guid", ps, depth, p->domain_guid.info, GUID_SIZE) ) + return False; + + if ( !smb_io_unistr2( "netbios_domain", &p->netbios_domain, p->netbios_ptr, ps, depth) ) + return False; + if ( !smb_io_unistr2( "dns_domain", &p->dns_domain, p->dnsname_ptr, ps, depth) ) + return False; + if ( !smb_io_unistr2( "forest_domain", &p->forest_domain, p->forestname_ptr, ps, depth) ) + return False; + + return True; + +} + +BOOL ds_io_q_getprimdominfo( char *desc, DS_Q_GETPRIMDOMINFO *q_u, prs_struct *ps, int depth) +{ + prs_debug(ps, depth, desc, "ds_io_q_getprimdominfo"); + depth++; + + if(!prs_align(ps)) + return False; + + if ( !prs_uint16( "level", ps, depth, &q_u->level ) ) + return False; + + return True; +} + +BOOL ds_io_r_getprimdominfo( char *desc, DS_R_GETPRIMDOMINFO *r_u, prs_struct *ps, int depth) +{ + prs_debug(ps, depth, desc, "ds_io_r_getprimdominfo"); + depth++; + + if(!prs_align(ps)) + return False; + + if ( !prs_uint32( "ptr", ps, depth, &r_u->ptr ) ) + return False; + + if ( r_u->ptr ) + { + if ( !prs_uint16( "level", ps, depth, &r_u->level ) ) + return False; + + if ( !prs_uint16( "unknown0", ps, depth, &r_u->unknown0 ) ) + return False; + + switch ( r_u->level ) + { + case DsRolePrimaryDomainInfoBasic: + if ( !ds_io_dominfobasic( "dominfobasic", ps, depth, &r_u->info.basic ) ) + return False; + break; + default: + return False; + } + } + + if ( !prs_align(ps) ) + return False; + + if ( !prs_ntstatus("status", ps, depth, &r_u->status ) ) + return False; + + return True; +} diff --git a/source3/rpc_parse/parse_rpc.c b/source3/rpc_parse/parse_rpc.c index 590268bed5..247c83aecd 100644 --- a/source3/rpc_parse/parse_rpc.c +++ b/source3/rpc_parse/parse_rpc.c @@ -75,7 +75,7 @@ interface/version dce/rpc pipe identification }, 0x00 \ } -#define SYNT_LSARPC_V0_WIN2K \ +#define SYNT_LSARPC_V0_DS \ { \ { \ 0x3919286a, 0xb10c, 0x11d0, \ @@ -147,7 +147,7 @@ struct pipe_id_info pipe_names [] = { /* client pipe , abstract syntax , server pipe , transfer syntax */ { PIPE_LSARPC , SYNT_LSARPC_V0 , PIPE_LSASS , TRANS_SYNT_V2 }, - { PIPE_LSARPC , SYNT_LSARPC_V0_WIN2K , PIPE_LSASS , TRANS_SYNT_V2 }, + { PIPE_LSARPC , SYNT_LSARPC_V0_DS , PIPE_LSASS , TRANS_SYNT_V2 }, { PIPE_SAMR , SYNT_SAMR_V1 , PIPE_LSASS , TRANS_SYNT_V2 }, { PIPE_NETLOGON, SYNT_NETLOGON_V1 , PIPE_LSASS , TRANS_SYNT_V2 }, { PIPE_SRVSVC , SYNT_SRVSVC_V3 , PIPE_NTSVCS , TRANS_SYNT_V2 }, diff --git a/source3/rpcclient/cmd_ds.c b/source3/rpcclient/cmd_ds.c new file mode 100644 index 0000000000..9a2114e07e --- /dev/null +++ b/source3/rpcclient/cmd_ds.c @@ -0,0 +1,59 @@ +/* + Unix SMB/CIFS implementation. + RPC pipe client + + Copyright (C) Gerald Carter 2002 + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +*/ + +#include "includes.h" +#include "rpcclient.h" + +/* Look up domain related information on a remote host */ + +static NTSTATUS cmd_ds_dsrole_getprimarydominfo(struct cli_state *cli, + TALLOC_CTX *mem_ctx, int argc, + char **argv) +{ + NTSTATUS result; + DS_DOMINFO_CTR ctr; + + result = cli_ds_getprimarydominfo( cli, mem_ctx, DsRolePrimaryDomainInfoBasic, &ctr ); + if ( NT_STATUS_IS_OK(result) ) + { + printf ("Machine Role = [%d]\n", ctr.basic->machine_role); + + if ( ctr.basic->flags & DSROLE_PRIMARY_DS_RUNNING ) { + printf( "Directory Service is running.\n"); + printf( "Domain is in %s mode.\n", (ctr.basic->flags & DSROLE_PRIMARY_DS_MIXED_MODE) ? "mized" : "native" ); + } + else + printf( "Directory Service not running on server\n"); + } + + return result; +} + +/* List of commands exported by this module */ + +struct cmd_set ds_commands[] = { + + { "LSARPC-DS" }, + + { "dsroledominfo", cmd_ds_dsrole_getprimarydominfo, PI_LSARPC_DS, "Get Primary Domain Information", "" }, + + { NULL } +}; diff --git a/source3/rpcclient/cmd_lsarpc.c b/source3/rpcclient/cmd_lsarpc.c index af5bb2066b..8eb8ce8754 100644 --- a/source3/rpcclient/cmd_lsarpc.c +++ b/source3/rpcclient/cmd_lsarpc.c @@ -525,13 +525,6 @@ static NTSTATUS cmd_lsa_query_secobj(struct cli_state *cli, } -static NTSTATUS cmd_lsa_dsrole_getprimarydominfo(struct cli_state *cli, - TALLOC_CTX *mem_ctx, int argc, - char **argv) -{ - return NT_STATUS_OK; -} - /* List of commands exported by this module */ struct cmd_set lsarpc_commands[] = { @@ -548,7 +541,6 @@ struct cmd_set lsarpc_commands[] = { { "lsaenumprivsaccount", cmd_lsa_enum_privsaccounts, PI_LSARPC, "Enumerate the privileges of an SID", "" }, { "lsalookupprivvalue", cmd_lsa_lookupprivvalue, PI_LSARPC, "Get a privilege value given its name", "" }, { "lsaquerysecobj", cmd_lsa_query_secobj, PI_LSARPC, "Query LSA security object", "" }, - { "lsarpcbind", cmd_lsa_dsrole_getprimarydominfo, PI_LSARPC_V2, "Test 2k UUID in rpc bind", "" }, { NULL } }; diff --git a/source3/rpcclient/rpcclient.c b/source3/rpcclient/rpcclient.c index 9c6cd3794b..c34f3b08ad 100644 --- a/source3/rpcclient/rpcclient.c +++ b/source3/rpcclient/rpcclient.c @@ -402,10 +402,12 @@ extern struct cmd_set netlogon_commands[]; extern struct cmd_set srvsvc_commands[]; extern struct cmd_set dfs_commands[]; extern struct cmd_set reg_commands[]; +extern struct cmd_set ds_commands[]; static struct cmd_set *rpcclient_command_list[] = { rpcclient_commands, lsarpc_commands, + ds_commands, samr_commands, spoolss_commands, netlogon_commands, -- cgit