void codepage_initialise(int client_codepage);
void add_char_string(char *s);
-/*The following definitions come from lib/cmd_interp.c */
-
-void free_cmd_set_array(uint32 num_entries, struct command_set **entries);
-struct command_set *add_cmd_set_to_array(uint32 *len, struct command_set ***array,
- const struct command_set *cmd);
-void add_command_set(const struct command_set *cmds);
-void cmd_set_no_autoconnect(void);
-int command_main(int argc, char *argv[]);
-
/*The following definitions come from lib/crc32.c */
uint32 crc32_calc_buffer( char *buffer, uint32 count);
uint32 *enum_ctx, uint32 *num_domains,
char ***domain_names, DOM_SID **domain_sids);
+/*The following definitions come from libsmb/cli_samr.c */
+
+struct cli_state *cli_samr_initialise(struct cli_state *cli, char *system_name,
+ struct ntuser_creds *creds);
+void cli_samr_shutdown(struct cli_state *cli);
+uint32 cli_samr_connect(struct cli_state *cli, char *srv_name,
+ uint32 access_mask, POLICY_HND *connect_pol);
+uint32 cli_samr_close(struct cli_state *cli, POLICY_HND *connect_pol);
+uint32 cli_samr_open_domain(struct cli_state *cli, POLICY_HND *connect_pol,
+ uint32 access_mask, DOM_SID *domain_sid,
+ POLICY_HND *domain_pol);
+uint32 cli_samr_open_user(struct cli_state *cli, POLICY_HND *domain_pol,
+ uint32 access_mask, uint32 user_rid,
+ POLICY_HND *user_pol);
+uint32 cli_samr_open_group(struct cli_state *cli, POLICY_HND *domain_pol,
+ uint32 access_mask, uint32 group_rid,
+ POLICY_HND *group_pol);
+uint32 cli_samr_query_userinfo(struct cli_state *cli, POLICY_HND *user_pol,
+ uint16 switch_value, SAM_USERINFO_CTR *ctr);
+uint32 cli_samr_query_groupinfo(struct cli_state *cli, POLICY_HND *group_pol,
+ uint32 info_level, GROUP_INFO_CTR *ctr);
+uint32 cli_samr_query_usergroups(struct cli_state *cli, POLICY_HND *user_pol,
+ uint32 *num_groups, DOM_GID **gid);
+uint32 cli_samr_query_groupmem(struct cli_state *cli, POLICY_HND *group_pol,
+ uint32 *num_mem, uint32 **rid, uint32 **attr);
+
+/*The following definitions come from libsmb/cli_spoolss.c */
+
+struct cli_state *cli_spoolss_initialise(struct cli_state *cli,
+ char *system_name,
+ struct ntuser_creds *creds);
+void cli_spoolss_shutdown(struct cli_state *cli);
+uint32 cli_spoolss_open_printer_ex(struct cli_state *cli, char *printername,
+ char *datatype, uint32 access_required,
+ char *station, char *username,
+ POLICY_HND *pol);
+uint32 cli_spoolss_close_printer(struct cli_state *cli, POLICY_HND *pol);
+uint32 cli_spoolss_enum_printers(struct cli_state *cli, uint32 flags,
+ uint32 level, int *returned,
+ PRINTER_INFO_CTR *ctr);
+uint32 cli_spoolss_enum_ports(struct cli_state *cli, uint32 level,
+ int *returned, PORT_INFO_CTR *ctr);
+uint32 cli_spoolss_getprinter(struct cli_state *cli, POLICY_HND *pol,
+ uint32 level, PRINTER_INFO_CTR *ctr);
+uint32 cli_spoolss_getprinterdriver (
+ struct cli_state *cli,
+ POLICY_HND *pol,
+ uint32 level,
+ char* env,
+ PRINTER_DRIVER_CTR *ctr
+);
+uint32 cli_spoolss_enumprinterdrivers (
+ struct cli_state *cli,
+ uint32 level,
+ char* env,
+ uint32 *returned,
+ PRINTER_DRIVER_CTR *ctr
+);
+uint32 cli_spoolss_getprinterdriverdir (
+ struct cli_state *cli,
+ uint32 level,
+ char* env,
+ DRIVER_DIRECTORY_CTR *ctr
+);
+uint32 cli_spoolss_addprinterdriver (
+ struct cli_state *cli,
+ uint32 level,
+ PRINTER_DRIVER_CTR *ctr
+);
+uint32 cli_spoolss_addprinterex (
+ struct cli_state *cli,
+ uint32 level,
+ PRINTER_INFO_CTR *ctr
+);
+
/*The following definitions come from libsmb/cliconnect.c */
BOOL cli_session_setup(struct cli_state *cli,
POLICY_HND *pol, uint16 switch_value, void* usr);
BOOL do_samr_close(struct cli_state *cli, POLICY_HND *hnd);
-/*The following definitions come from rpc_client/cli_spoolss.c */
-
-uint32 spoolss_enum_printerdrivers(const char *srv_name, const char *environment,
- uint32 level, NEW_BUFFER *buffer, uint32 offered,
- uint32 *needed, uint32 *returned);
-uint32 spoolss_enum_printers(uint32 flags, fstring srv_name, uint32 level,
- NEW_BUFFER *buffer, uint32 offered,
- uint32 *needed, uint32 *returned);
-uint32 spoolss_enum_ports(fstring srv_name, uint32 level,
- NEW_BUFFER *buffer, uint32 offered,
- uint32 *needed, uint32 *returned);
-uint32 spoolss_enum_jobs(const POLICY_HND *hnd, uint32 firstjob, uint32 numofjobs,
- uint32 level, NEW_BUFFER *buffer, uint32 offered,
- uint32 *needed, uint32 *returned);
-uint32 spoolss_enum_printerdata(const POLICY_HND *hnd, uint32 idx,
- uint32 *valuelen, uint16 *value, uint32 *rvaluelen,
- uint32 *type, uint32 *datalen, uint8 *data,
- uint32 *rdatalen);
-uint32 spoolss_getprinter(const POLICY_HND *hnd, uint32 level,
- NEW_BUFFER *buffer, uint32 offered,
- uint32 *needed);
-uint32 spoolss_getprinterdriver(const POLICY_HND *hnd,
- const char *environment, uint32 level,
- NEW_BUFFER *buffer, uint32 offered,
- uint32 *needed);
-BOOL spoolss_open_printer_ex( const char *printername,
- const char *datatype, uint32 access_required,
- const char *station, const char *username,
- POLICY_HND *hnd);
-BOOL spoolss_addprinterex(POLICY_HND *hnd, const char* srv_name, PRINTER_INFO_2 *info2);
-BOOL spoolss_closeprinter(POLICY_HND *hnd);
-uint32 spoolss_getprinterdata(const POLICY_HND *hnd, UNISTR2 *valuename,
- uint32 in_size,
- uint32 *type,
- uint32 *out_size,
- uint8 *data,
- uint32 *needed);
-uint32 spoolss_getprinterdriverdir(fstring srv_name, fstring env_name, uint32 level,
- NEW_BUFFER *buffer, uint32 offered,
- uint32 *needed);
-uint32 spoolss_addprinterdriver(const char *srv_name, uint32 level, PRINTER_DRIVER_CTR *info);
-
/*The following definitions come from rpc_client/cli_spoolss_notify.c */
BOOL spoolss_disconnect_from_client( struct cli_state *cli);
char *server_name, uint32 switch_value,
WKS_INFO_100 *wks100);
-/*The following definitions come from rpc_client/msrpc_spoolss.c */
-
-void init_buffer(NEW_BUFFER *buffer, uint32 size, TALLOC_CTX *ctx);
-void decode_port_info_1(NEW_BUFFER *buffer, uint32 returned,
- PORT_INFO_1 **info);
-void decode_port_info_2(NEW_BUFFER *buffer, uint32 returned,
- PORT_INFO_2 **info);
-BOOL msrpc_spoolss_enum_printers(char* srv_name, uint32 flags,
- uint32 level, PRINTER_INFO_CTR ctr);
-BOOL msrpc_spoolss_enum_ports(char* srv_name,
- uint32 level, PORT_INFO_CTR *ctr);
-uint32 msrpc_spoolss_getprinterdata( const char* printer_name,
- const char* station,
- const char* user_name,
- const char* value_name,
- uint32 *type,
- NEW_BUFFER *buffer,
- void *fn);
-BOOL msrpc_spoolss_enum_jobs( const char* printer_name,
- const char* station, const char* user_name,
- uint32 level,
- void ***ctr, JOB_INFO_FN(fn));
-BOOL msrpc_spoolss_enum_printerdata( const char* printer_name,
- const char* station, const char* user_name );
-BOOL msrpc_spoolss_getprinter( const char* printer_name, const uint32 level,
- const char* station, const char* user_name,
- PRINTER_INFO_CTR ctr);
-BOOL msrpc_spoolss_getprinterdriver( const char* printer_name,
- const char *environment, const uint32 level,
- const char* station, const char* user_name,
- PRINTER_DRIVER_CTR ctr);
-BOOL msrpc_spoolss_enumprinterdrivers( const char* srv_name,
- const char *environment, const uint32 level,
- PRINTER_DRIVER_CTR ctr);
-BOOL msrpc_spoolss_getprinterdriverdir(char* srv_name, char* env_name, uint32 level, DRIVER_DIRECTORY_CTR ctr);
-
/*The following definitions come from rpc_client/ncacn_np_use.c */
BOOL ncacn_np_use_del(const char *srv_name, const char *pipe_name,
uint32 access_required,
const fstring clientname,
const fstring user_name);
-BOOL make_spoolss_q_addprinterex(TALLOC_CTX *ctx, SPOOL_Q_ADDPRINTEREX *q_u, const char *srv_name,
- const char* clientname, const char* user_name,
- uint32 level, PRINTER_INFO_2 *info);
-BOOL make_spool_printer_info_2(TALLOC_CTX *ctx, SPOOL_PRINTER_INFO_LEVEL_2 **spool_info2,
- PRINTER_INFO_2 *info);
+BOOL make_spoolss_q_addprinterex(
+ SPOOL_Q_ADDPRINTEREX *q_u,
+ const char *srv_name,
+ const char* clientname,
+ const char* user_name,
+ uint32 level,
+ PRINTER_INFO_CTR *ctr);
+BOOL make_spool_printer_info_2(
+ SPOOL_PRINTER_INFO_LEVEL_2 **spool_info2,
+ PRINTER_INFO_2 *info
+);
BOOL spoolss_io_q_open_printer_ex(char *desc, SPOOL_Q_OPEN_PRINTER_EX *q_u, prs_struct *ps, int depth);
BOOL spoolss_io_r_open_printer_ex(char *desc, SPOOL_R_OPEN_PRINTER_EX *r_u, prs_struct *ps, int depth);
BOOL make_spoolss_q_getprinterdata(SPOOL_Q_GETPRINTERDATA *q_u,
BOOL spoolss_io_q_schedulejob(char *desc, SPOOL_Q_SCHEDULEJOB *q_u, prs_struct *ps, int depth);
BOOL spoolss_io_r_setjob(char *desc, SPOOL_R_SETJOB *r_u, prs_struct *ps, int depth);
BOOL spoolss_io_q_setjob(char *desc, SPOOL_Q_SETJOB *q_u, prs_struct *ps, int depth);
-BOOL new_spoolss_io_r_enumprinterdrivers(char *desc, SPOOL_R_ENUMPRINTERDRIVERS *r_u, prs_struct *ps, int depth);
+BOOL spoolss_io_r_enumprinterdrivers(char *desc, SPOOL_R_ENUMPRINTERDRIVERS *r_u, prs_struct *ps, int depth);
BOOL make_spoolss_q_enumprinterdrivers(SPOOL_Q_ENUMPRINTERDRIVERS *q_u,
const char *name,
const char *environment,
prs_struct *ps, int depth);
BOOL smb_io_unibuffer(char *desc, UNISTR2 *buffer, prs_struct *ps, int depth);
BOOL spool_io_printer_driver_info_level(char *desc, SPOOL_PRINTER_DRIVER_INFO_LEVEL *il, prs_struct *ps, int depth);
-BOOL make_spoolss_q_addprinterdriver(TALLOC_CTX *ctx, SPOOL_Q_ADDPRINTERDRIVER *q_u,
- const char* srv_name, uint32 level,
- PRINTER_DRIVER_CTR *info);
-BOOL make_spool_driver_info_3(TALLOC_CTX *ctx, SPOOL_PRINTER_DRIVER_INFO_LEVEL_3 *spool_drv_info,
- DRIVER_INFO_3 *info3);
-BOOL make_spool_buffer5(TALLOC_CTX *ctx, BUFFER5 *buf5, uint32 len, uint16 *src);
+BOOL make_spoolss_q_addprinterdriver(
+ SPOOL_Q_ADDPRINTERDRIVER *q_u,
+ const char* srv_name,
+ uint32 level,
+ PRINTER_DRIVER_CTR *info);
+BOOL make_spool_driver_info_3(
+ SPOOL_PRINTER_DRIVER_INFO_LEVEL_3 *spool_drv_info,
+ DRIVER_INFO_3 *info3
+);
+BOOL make_spool_buffer5(BUFFER5 *buf5, uint32 len, uint16 *src);
BOOL spoolss_io_q_addprinterdriver(char *desc, SPOOL_Q_ADDPRINTERDRIVER *q_u, prs_struct *ps, int depth);
BOOL spoolss_io_r_addprinterdriver(char *desc, SPOOL_R_ADDPRINTERDRIVER *q_u, prs_struct *ps, int depth);
BOOL uni_2_asc_printer_driver_3(SPOOL_PRINTER_DRIVER_INFO_LEVEL_3 *uni,
/*The following definitions come from rpcclient/cmd_lsarpc.c */
-uint32 cmd_lsa_lookup_sids(struct client_info *info, int argc, char *argv[]);
-uint32 cmd_lsa_lookup_names(struct client_info *info, int argc, char *argv[]);
-void add_lsa_commands(void);
+
+/*The following definitions come from rpcclient/cmd_samr.c */
+
/*The following definitions come from rpcclient/cmd_spoolss.c */
BOOL get_short_archi(char *short_archi, char *long_archi);
-uint32 cmd_spoolss_enum_printers(struct client_info *info, int argc, char *argv[]);
-uint32 cmd_spoolss_enum_ports(struct client_info *info, int argc, char *argv[]);
-uint32 cmd_spoolss_enum_printerdata(struct client_info *info, int argc, char *argv[]);
-uint32 cmd_spoolss_getprinter(struct client_info *info, int argc, char *argv[]);
-uint32 cmd_spoolss_enum_jobs(struct client_info *info, int argc, char *argv[]);
-uint32 cmd_spoolss_open_printer_ex(struct client_info *info, int argc, char *argv[]);
-uint32 cmd_spoolss_getprinterdata(struct client_info *info, int argc, char *argv[]);
-uint32 cmd_spoolss_getprinterdriver(struct client_info *info, int argc, char *argv[]);
-uint32 cmd_spoolss_enumprinterdrivers(struct client_info *info, int argc, char *argv[]);
-uint32 cmd_spoolss_getprinterdriverdir(struct client_info *info, int argc, char *argv[]);
-uint32 cmd_spoolss_addprinterex(struct client_info *info, int argc, char *argv[]);
-uint32 cmd_spoolss_addprinterdriver(struct client_info *info, int argc, char *argv[]);
void set_drv_info_3_env (DRIVER_INFO_3 *info, const char *arch);
-BOOL init_drv_info_3_members (DRIVER_INFO_3 *info, char *args);
-void free_drv_info_3 (DRIVER_INFO_3 *info);
-
-/*The following definitions come from rpcclient/display_sec.c */
-
-void display_sec_desc(FILE *out_hnd, enum action_type action, SEC_DESC *const sec);
-
-/*The following definitions come from rpcclient/display_spool.c */
-
-void display_printer_info_ctr(FILE *out_hnd, enum action_type action, uint32 level,
- uint32 count, PRINTER_INFO_CTR ctr);
-void display_port_info_ctr(FILE *out_hnd, enum action_type action, uint32 level,
- uint32 count, PORT_INFO_CTR *ctr);
-void display_port_info_1(FILE *out_hnd, enum action_type action, PORT_INFO_1 *i1);
-void display_port_info_2(FILE *out_hnd, enum action_type action, PORT_INFO_2 *i2);
-void display_printer_enumdata(FILE *out_hnd, enum action_type action, uint32 idx,
- uint32 valuelen, uint16 *value, uint32 rvaluelen,
- uint32 type,
- uint32 datalen, uint8 *data, uint32 rdatalen);
-void display_job_info_2(FILE *out_hnd, enum action_type action,
- JOB_INFO_2 *const i2);
-void display_job_info_1(FILE *out_hnd, enum action_type action,
- JOB_INFO_1 *const i1);
-void display_job_info_2_ctr(FILE *out_hnd, enum action_type action,
- uint32 count, JOB_INFO_2 *const *const ctr);
-void display_job_info_1_ctr(FILE *out_hnd, enum action_type action,
- uint32 count, JOB_INFO_1 *const *const ctr);
-void display_job_info_ctr(FILE *out_hnd, enum action_type action,
- uint32 level, uint32 count,
- void *const *const ctr);
-void display_printer_driver_ctr(FILE *out_hnd, enum action_type action, uint32 level,
- uint32 count, PRINTER_DRIVER_CTR ctr);
-void display_printerdriverdir_info_ctr(FILE *out_hnd, enum action_type action, uint32 level,
- DRIVER_DIRECTORY_CTR ctr);
/*The following definitions come from rpcclient/rpcclient.c */
-
-/*The following definitions come from rpcclient/spoolss_cmds.c */
-
-void add_spl_commands(void);
+void fetch_domain_sid(struct cli_state *cli);
+void init_rpcclient_creds(struct ntuser_creds *creds, char* username,
+ char* domain, char* password);
+void add_command_set(struct cmd_set *cmd_set);
+struct cli_state *setup_connection(struct cli_state *cli, char *system_name,
+ struct ntuser_creds *creds);
/*The following definitions come from smbd/blocking.c */
typedef struct driver_info_ctr_info
{
- union
- {
- DRIVER_DIRECTORY_1 info_1;
- }
- driver;
+ DRIVER_DIRECTORY_1 *info1;
}
DRIVER_DIRECTORY_CTR;
-/*
+/*
Unix SMB/Netbios implementation.
- Version 1.9.
- SMB parameters and setup
- Copyright (C) Andrew Tridgell 1992-1998
- Copyright (C) Luke Kenneth Casson Leighton 1996-1998
- Copyright (C) Jeremy Allison 1998
+ Version 2.2
+ RPC pipe client
+
+ Copyright (C) Tim Potter 2000
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 _RPCCLIENT_H
-#define _RPCCLIENT_H
-
-#define report fprintf
-
-struct tar_client_info
-{
- int blocksize;
- BOOL inc;
- BOOL reset;
- BOOL excl;
- char type;
- int attrib;
- char **cliplist;
- int clipn;
- int tp;
- int num_files;
- int buf_size;
- int bytes_written;
- char *buf;
- int handle;
- int print_mode;
- char *file_mode;
-};
-
-struct nt_client_info
-{
- /************* \PIPE\NETLOGON stuff ******************/
-
- fstring mach_acct;
-
- uint8 sess_key[16];
- DOM_CRED clnt_cred;
- DOM_CRED rtn_cred;
-
- NET_ID_INFO_CTR ctr;
- NET_USER_INFO_3 user_info3;
-
- /************** \PIPE\winreg stuff ********************/
-
- POLICY_HND reg_pol_connect;
-
- /************** \PIPE\lsarpc stuff ********************/
-
- POLICY_HND lsa_info_pol;
-
- /* domain member */
- DOM_SID level3_sid;
- DOM_SID level5_sid;
-
- /* domain controller */
- fstring level3_dom;
- fstring level5_dom;
-
- /************** \PIPE\samr stuff ********************/
+#ifndef RPCCLIENT_H
+#define RPCCLIENT_H
- POLICY_HND samr_pol_connect;
- POLICY_HND samr_pol_open_domain;
- POLICY_HND samr_pol_open_user;
-
- struct acct_info *sam;
- int num_sam_entries;
-};
-
-/* struct client_info
-{
- struct in_addr dest_ip;
- fstring dest_host;
- fstring query_host;
- uint8 name_type;
-
- fstring myhostname;
- fstring mach_acct;
-
- pstring cur_dir;
- pstring base_dir;
- pstring file_sel;
-
- fstring service;
- fstring share;
- fstring svc_type;
-
- time_t newer_than;
- int archive_level;
- int dir_total;
- int put_total_time_ms;
- int put_total_size;
- int get_total_time_ms;
- int get_total_size;
- int print_mode;
- BOOL translation;
- BOOL recurse_dir;
- BOOL prompt;
- BOOL lowercase;
- BOOL abort_mget;
-
- struct tar_client_info tar;
- struct nt_client_info dom;
-}; */
-
-typedef struct client_info
-{
- struct in_addr dest_ip;
- fstring dest_host;
-
- fstring myhostname;
-
- struct tar_client_info tar;
- struct nt_client_info dom;
-
- BOOL reuse;
- BOOL show_prompt;
-} CLIENT_INFO;
-
-
-enum action_type {ACTION_HEADER, ACTION_ENUMERATE, ACTION_FOOTER};
-
-/****************************************************************************
- This defines the commands supported by this client
- ****************************************************************************/
-struct command_set
-{
+struct cmd_set {
char *name;
- uint32 (*fn)(struct client_info*, int, char*[]);
+ uint32 (*fn)(struct cli_state*, int argc, char **argv);
char *description;
- char* (*compl_args[2])(char*, int);
};
-
-#endif /* _RPCCLIENT_H */
+#endif /* RPCCLIENT_H */
/*******************************************************************
* init a structure.
********************************************************************/
-
-BOOL make_spoolss_q_addprinterex(TALLOC_CTX *ctx, SPOOL_Q_ADDPRINTEREX *q_u, const char *srv_name,
- const char* clientname, const char* user_name,
- uint32 level, PRINTER_INFO_2 *info)
+BOOL make_spoolss_q_addprinterex(
+ SPOOL_Q_ADDPRINTEREX *q_u,
+ const char *srv_name,
+ const char* clientname,
+ const char* user_name,
+ uint32 level,
+ PRINTER_INFO_CTR *ctr)
{
DEBUG(5,("make_spoolss_q_addprinterex\n"));
+
+ if (!ctr) return False;
q_u->server_name_ptr = (srv_name!=NULL)?1:0;
init_unistr2(&q_u->server_name, srv_name, strlen(srv_name));
q_u->level = level;
q_u->info.level = level;
- q_u->info.info_ptr = (info!=NULL)?1:0;
+ q_u->info.info_ptr = (ctr->printers_2!=NULL)?1:0;
switch (level)
{
case 2:
/* init q_u->info.info2 from *info */
- if (!make_spool_printer_info_2( ctx, &q_u->info.info_2, info))
+ if (!make_spool_printer_info_2(&q_u->info.info_2, ctr->printers_2))
{
DEBUG(0,("make_spoolss_q_addprinterex: Unable to fill SPOOL_Q_ADDPRINTEREX struct!\n"));
return False;
create a SPOOL_PRINTER_INFO_2 stuct from a PRINTER_INFO_2 struct
*******************************************************************/
-BOOL make_spool_printer_info_2(TALLOC_CTX *ctx, SPOOL_PRINTER_INFO_LEVEL_2 **spool_info2,
- PRINTER_INFO_2 *info)
+BOOL make_spool_printer_info_2(
+ SPOOL_PRINTER_INFO_LEVEL_2 **spool_info2,
+ PRINTER_INFO_2 *info
+)
{
SPOOL_PRINTER_INFO_LEVEL_2 *inf;
/* allocate the necessary memory */
- inf = (SPOOL_PRINTER_INFO_LEVEL_2*)talloc_zero(ctx,sizeof(SPOOL_PRINTER_INFO_LEVEL_2));
+ inf = (SPOOL_PRINTER_INFO_LEVEL_2*)malloc(sizeof(SPOOL_PRINTER_INFO_LEVEL_2));
if (spool_info2 == NULL)
{
DEBUG(0,("make_spool_printer_info_2: Unable to allocate SPOOL_PRINTER_INFO_LEVEL_2 sruct!\n"));
Parse a SPOOL_R_ENUMPRINTERDRIVERS structure.
********************************************************************/
-BOOL new_spoolss_io_r_enumprinterdrivers(char *desc, SPOOL_R_ENUMPRINTERDRIVERS *r_u, prs_struct *ps, int depth)
+BOOL spoolss_io_r_enumprinterdrivers(char *desc, SPOOL_R_ENUMPRINTERDRIVERS *r_u, prs_struct *ps, int depth)
{
- prs_debug(ps, depth, desc, "new_spoolss_io_r_enumprinterdrivers");
+ prs_debug(ps, depth, desc, "spoolss_io_r_enumprinterdrivers");
depth++;
if (!prs_align(ps))
init a SPOOL_Q_ADDPRINTERDRIVER struct
******************************************************************/
-BOOL make_spoolss_q_addprinterdriver(TALLOC_CTX *ctx, SPOOL_Q_ADDPRINTERDRIVER *q_u,
- const char* srv_name, uint32 level,
- PRINTER_DRIVER_CTR *info)
+BOOL make_spoolss_q_addprinterdriver(
+ SPOOL_Q_ADDPRINTERDRIVER *q_u,
+ const char* srv_name,
+ uint32 level,
+ PRINTER_DRIVER_CTR *info)
{
DEBUG(5,("make_spoolss_q_addprinterdriver\n"));
WinNT and Win2k */
case 3 :
q_u->info.info_3=(SPOOL_PRINTER_DRIVER_INFO_LEVEL_3*)
- talloc_zero(ctx, sizeof(SPOOL_PRINTER_DRIVER_INFO_LEVEL_3));
- make_spool_driver_info_3(ctx,q_u->info.info_3, info->info3);
+ malloc(sizeof(SPOOL_PRINTER_DRIVER_INFO_LEVEL_3));
+ memset (q_u->info.info_3, 0x0, sizeof(SPOOL_PRINTER_DRIVER_INFO_LEVEL_3));
+ make_spool_driver_info_3(q_u->info.info_3, info->info3);
break;
/* info level 6 is supported by WinME and Win2k */
return True;
}
-BOOL make_spool_driver_info_3(TALLOC_CTX *ctx, SPOOL_PRINTER_DRIVER_INFO_LEVEL_3 *spool_drv_info,
- DRIVER_INFO_3 *info3)
+BOOL make_spool_driver_info_3(
+ SPOOL_PRINTER_DRIVER_INFO_LEVEL_3 *spool_drv_info,
+ DRIVER_INFO_3 *info3
+)
{
uint32 len = 0;
uint16 *ptr = info3->dependentfiles;
}
spool_drv_info->dependentfiles_ptr = (info3->dependentfiles!=NULL)?1:0;
spool_drv_info->dependentfilessize = len;
- if(!make_spool_buffer5(ctx, &spool_drv_info->dependentfiles, len, info3->dependentfiles))
+ if(!make_spool_buffer5(&spool_drv_info->dependentfiles, len, info3->dependentfiles))
return False;
return True;
make a BUFFER5 struct from a uint16*
******************************************************************/
-BOOL make_spool_buffer5(TALLOC_CTX *ctx, BUFFER5 *buf5, uint32 len, uint16 *src)
+BOOL make_spool_buffer5(BUFFER5 *buf5, uint32 len, uint16 *src)
{
buf5->buf_len = len;
- if((buf5->buffer=(uint16*)talloc(ctx, sizeof(uint16)*len)) == NULL)
+ if((buf5->buffer=(uint16*)malloc(sizeof(uint16)*len)) == NULL)
{
DEBUG(0,("make_spool_buffer5: Unable to talloc memory for buffer!\n"));
return False;
/*
Unix SMB/Netbios implementation.
- Version 1.9.
- NT Domain Authentication SMB / MSRPC client
- Copyright (C) Andrew Tridgell 1994-1997
- Copyright (C) Luke Kenneth Casson Leighton 1996-1997
-
+ Version 2.2
+ RPC pipe client
+
+ Copyright (C) Tim Potter 2000
+
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
#include "includes.h"
-extern FILE *out_hnd;
-
-/* Convert SID_NAME_USE values to strings */
-
-struct sid_name {
- enum SID_NAME_USE name_type;
- char *name;
-} sid_name_type_str[] = {
- { SID_NAME_UNKNOWN, "UNKNOWN" },
- { SID_NAME_USER, "User" },
- { SID_NAME_DOM_GRP, "Domain Group" },
- { SID_NAME_DOMAIN, "Domain" },
- { SID_NAME_ALIAS, "Local Group"} ,
- { SID_NAME_WKN_GRP, "Well-known Group" },
- { SID_NAME_DELETED, "Deleted" },
- { SID_NAME_INVALID, "Invalid" },
- { SID_NAME_USE_NONE, NULL }
-};
+extern int DEBUGLEVEL;
+extern pstring server;
-static char *get_sid_name_type_str(enum SID_NAME_USE name_type)
+/* Look up domain related information on a remote host */
+static uint32 cmd_lsa_query_info_policy(struct cli_state *cli, int argc, char **argv)
{
- int i = 0;
-
- while(sid_name_type_str[i].name) {
- if (name_type == sid_name_type_str[i].name_type) {
- return sid_name_type_str[i].name;
- }
- i++;
+ POLICY_HND pol;
+ uint32 result = NT_STATUS_UNSUCCESSFUL;
+ BOOL got_policy_hnd = False;
+ DOM_SID dom_sid;
+ fstring sid_str, domain_name;
+ uint32 info_class = 3;
+
+ if (argc > 2) {
+ printf("Usage: %s [info_class]\n", argv[0]);
+ return 0;
}
- return NULL;
-}
+ if (argc == 2) {
+ info_class = atoi(argv[1]);
+ }
+
+ /* Initialise RPC connection */
+ if (!cli_nt_session_open (cli, PIPE_LSARPC)) {
+ fprintf (stderr, "Could not initialize samr pipe!\n");
+ return NT_STATUS_UNSUCCESSFUL;
+ }
-/* Look up a list of sids */
+ if ((result = cli_lsa_open_policy(cli, True,
+ SEC_RIGHTS_MAXIMUM_ALLOWED,
+ &pol)) != NT_STATUS_NOPROBLEMO) {
+ goto done;
+ }
-uint32 cmd_lsa_lookup_sids(struct client_info *info, int argc, char *argv[])
-{
- POLICY_HND lsa_pol;
- fstring srv_name;
- char **names;
- DOM_SID *sids;
- int num_sids = 0, num_names, i;
- uint32 *types, result;
+ got_policy_hnd = True;
- /* Check command arguments */
+ /* Lookup info policy */
- if (argc == 1) {
- fprintf(out_hnd, "lsa_lookupsids sid1 [sid2...]\n");
- return NT_STATUS_INVALID_PARAMETER;
+ if ((result = cli_lsa_query_info_policy(cli, &pol, info_class,
+ domain_name, &dom_sid))
+ != NT_STATUS_NOPROBLEMO) {
+ goto done;
}
- sids = (DOM_SID *)malloc((argc - 1) * sizeof(DOM_SID));
+ sid_to_string(sid_str, &dom_sid);
+
+ printf("domain %s has sid %s\n", domain_name, sid_str);
+
+done:
- for (i = 1; i < argc; i++) {
- if (string_to_sid(&sids[num_sids], argv[i])) {
- num_sids++;
- } else {
- fprintf(out_hnd, "could not parse sid %s\n", argv[i]);
- }
+ if (got_policy_hnd) {
+ cli_lsa_close(cli, &pol);
}
- fstrcpy(srv_name, "\\\\");
- fstrcat(srv_name, info->dest_host);
- strupper(srv_name);
+ cli_nt_session_close(cli);
- /* Lookup domain controller; receive a policy handle */
+ return result;
+}
- result = lsa_open_policy(srv_name, &lsa_pol, True,
- SEC_RIGHTS_MAXIMUM_ALLOWED);
+/* Resolve a list of names to a list of sids */
- if (result != 0) {
- report(out_hnd, "open policy failed: %s\n",
- get_nt_error_msg(result));
- return result;
+static uint32 cmd_lsa_lookup_names(struct cli_state *cli, int argc, char **argv)
+{
+ POLICY_HND pol;
+ uint32 result = NT_STATUS_UNSUCCESSFUL;
+ BOOL got_policy_hnd = False;
+ DOM_SID *sids;
+ uint32 *types;
+ int num_names, i;
+
+ if (argc == 1) {
+ printf("Usage: %s [name1 [name2 [...]]]\n", argv[0]);
+ return 0;
}
- /* Send lsa lookup sids call */
+ /* Initialise RPC connection */
+ if (!cli_nt_session_open (cli, PIPE_LSARPC)) {
+ fprintf (stderr, "Could not initialize samr pipe!\n");
+ return NT_STATUS_UNSUCCESSFUL;
+ }
- result = lsa_lookup_sids(&lsa_pol, num_sids, sids, &names,
- &types, &num_names);
- if (result != 0) {
- report(out_hnd, "lookup names failed: %s\n",
- get_nt_error_msg(result));
- return result;
+ if ((result = cli_lsa_open_policy(cli, True,
+ SEC_RIGHTS_MAXIMUM_ALLOWED,
+ &pol)) != NT_STATUS_NOPROBLEMO) {
+ goto done;
}
- result = lsa_close(&lsa_pol);
+ got_policy_hnd = True;
- if (result != 0) {
- report(out_hnd, "lsa close failed: %s\n",
- get_nt_error_msg(result));
- return result;
- }
+ /* Lookup the names */
- /* Print output */
+ if ((result = cli_lsa_lookup_names(
+ cli, &pol, argc - 1, &argv[1], &sids, &types, &num_names) !=
+ NT_STATUS_NOPROBLEMO)) {
+ goto done;
+ }
- if (names != NULL) {
- report(out_hnd, "Lookup SIDS:\n");
+ /* Print results */
- for (i = 0; i < num_names; i++) {
- fstring temp;
+ for (i = 0; i < num_names; i++) {
+ fstring sid_str;
- sid_to_string(temp, &sids[i]);
+ sid_to_string(sid_str, &sids[i]);
+ printf("%s\t\t%s (%d)\n", argv[i + 1], sid_str,
+ types[i]);
+ }
- report(out_hnd, "SID: %s -> %s (%d: %s)\n",
- temp, names[i] ? names[i] : "(null)",
- types[i], get_sid_name_type_str((enum SID_NAME_USE)types[i]));
+ safe_free(sids);
+ safe_free(types);
- if (names[i] != NULL) {
- free(names[i]);
- }
- }
+ done:
- free(names);
+ if (got_policy_hnd) {
+ cli_lsa_close(cli, &pol);
}
- if (types) {
- free(types);
- }
+ cli_nt_session_close(cli);
return result;
}
-/* Look up a list of names */
+/* Resolve a list of SIDs to a list of names */
-uint32 cmd_lsa_lookup_names(struct client_info *info, int argc, char *argv[])
+static uint32 cmd_lsa_lookup_sids(struct cli_state *cli, int argc, char **argv)
{
- POLICY_HND lsa_pol;
- fstring srv_name;
- int num_names, i, num_sids;
+ POLICY_HND pol;
+ uint32 result = NT_STATUS_UNSUCCESSFUL;
+ BOOL got_policy_hnd = False;
DOM_SID *sids;
char **names;
- uint32 *types, result;
-
- /* Check command arguments */
+ uint32 *types;
+ int num_names, i;
if (argc == 1) {
- fprintf(out_hnd, "lsa_lookupnames name1 [name2...]\n");
- return NT_STATUS_INVALID_PARAMETER;
+ printf("Usage: %s [sid1 [sid2 [...]]]\n", argv[0]);
+ return 0;
}
- names = (char **)malloc((argc - 1) * sizeof(char *));
- num_names = argc - 1;
+ /* Initialise RPC connection */
+ if (!cli_nt_session_open (cli, PIPE_LSARPC)) {
+ fprintf (stderr, "Could not initialize samr pipe!\n");
+ return NT_STATUS_UNSUCCESSFUL;
+ }
- for (i = 1; i < argc; i++) {
- names[i - 1] = argv[i];
+ if ((result = cli_lsa_open_policy(cli, True,
+ SEC_RIGHTS_MAXIMUM_ALLOWED,
+ &pol)) != NT_STATUS_NOPROBLEMO) {
+ goto done;
}
- fstrcpy(srv_name, "\\\\");
- fstrcat(srv_name, info->dest_host);
- strupper(srv_name);
+ got_policy_hnd = True;
- /* Lookup domain controller; receive a policy handle */
+ /* Convert arguments to sids */
- result = lsa_open_policy(srv_name, &lsa_pol, True,
- SEC_RIGHTS_MAXIMUM_ALLOWED);
+ sids = (DOM_SID *)malloc(sizeof(DOM_SID) * (argc - 1));
- if (result != 0) {
- report(out_hnd, "open policy failed: %s\n",
- get_nt_error_msg(result));
- return result;
+ if (!sids) {
+ printf("out of memory\n");
+ goto done;
}
- /* Send lsa lookup names call */
+ for (i = 0; i < argc - 1; i++) {
+ string_to_sid(&sids[i], argv[i + 1]);
+ }
- result = lsa_lookup_names(&lsa_pol, num_names, names, &sids,
- &types, &num_sids);
+ /* Lookup the SIDs */
- if (result != 0) {
- report(out_hnd, "lookup sids failed: %s\n",
- get_nt_error_msg(result));
- return result;
+ if ((result = cli_lsa_lookup_sids(cli, &pol, argc - 1, sids,
+ &names, &types, &num_names) !=
+ NT_STATUS_NOPROBLEMO)) {
+ goto done;
}
- result = lsa_close(&lsa_pol);
+ /* Print results */
- if (result != 0) {
- report(out_hnd, "lsa close failed: %s\n",
- get_nt_error_msg(result));
- return result;
+ for (i = 0; i < num_names; i++) {
+ fstring sid_str;
+
+ sid_to_string(sid_str, &sids[i]);
+ printf("%s\t\t%s (%d)\n", sid_str, names[i] ? names[i] :
+ "*unknown*", types[i]);
}
- /* Print output */
+ safe_free(sids);
+ safe_free(types);
+
+ for (i = 0; i < num_names; i++) {
+ safe_free(names[i]);
+ }
- if (sids != NULL) {
- fstring temp;
+ safe_free(names);
- report(out_hnd, "Lookup Names:\n");
- for (i = 0; i < num_sids; i++) {
- sid_to_string(temp, &sids[i]);
- report(out_hnd, "Name: %s -> %s (%d: %s)\n",
- names[i], temp, types[i],
- get_sid_name_type_str((enum SID_NAME_USE)types[i]));
-#if 0
- if (sids[i] != NULL) {
- free(sids[i]);
- }
-#endif
- }
+ done:
- free(sids);
+ if (got_policy_hnd) {
+ cli_lsa_close(cli, &pol);
}
+ cli_nt_session_close(cli);
+
return result;
}
-/* rpcclient interface */
+/* Enumerate list of trusted domains */
+
+static uint32 cmd_lsa_enum_trust_dom(struct cli_state *cli, int argc, char **argv)
+{
+ POLICY_HND pol;
+ uint32 result = NT_STATUS_UNSUCCESSFUL;
+ BOOL got_policy_hnd = False;
+ DOM_SID *domain_sids;
+ char **domain_names;
+ int num_domains, enum_ctx = 0, i;
+
+ if (argc != 1) {
+ printf("Usage: %s\n", argv[0]);
+ return 0;
+ }
+
+ /* Initialise RPC connection */
+ if (!cli_nt_session_open (cli, PIPE_LSARPC)) {
+ fprintf (stderr, "Could not initialize samr pipe!\n");
+ return NT_STATUS_UNSUCCESSFUL;
+ }
-static const struct command_set lsa_commands[] = {
+ if ((result = cli_lsa_open_policy(cli, True,
+ SEC_RIGHTS_MAXIMUM_ALLOWED,
+ &pol)) != NT_STATUS_NOPROBLEMO) {
+ goto done;
+ }
- { "LSARPC", NULL, NULL, {NULL, NULL} },
+ got_policy_hnd = True;
- { "lsa_lookup_sids", cmd_lsa_lookup_sids },
- { "lsa_lookup_names", cmd_lsa_lookup_names },
+ /* Lookup list of trusted domains */
- {"", NULL, NULL, {NULL, NULL}}
-};
+ if ((result = cli_lsa_enum_trust_dom(cli, &pol, &enum_ctx,
+ &num_domains, &domain_names,
+ &domain_sids)
+ != NT_STATUS_NOPROBLEMO)) {
+ goto done;
+ }
+ /* Print results */
-void add_lsa_commands(void)
-{
- add_command_set(lsa_commands);
+ for (i = 0; i < num_domains; i++) {
+ fstring sid_str;
+
+ sid_to_string(sid_str, &domain_sids[i]);
+ printf("%s\t\t%s\n", domain_names[i] ? domain_names[i] :
+ "*unknown*", sid_str);
+ }
+
+ safe_free(domain_sids);
+
+ for (i = 0; i < num_domains; i++) {
+ safe_free(domain_names[i]);
+ }
+
+ safe_free(domain_names);
+
+ done:
+
+ if (got_policy_hnd) {
+ cli_lsa_close(cli, &pol);
+ }
+
+ cli_nt_session_close(cli);
+
+ return result;
}
+
+/* List of commands exported by this module */
+
+struct cmd_set lsarpc_commands[] = {
+ { "LSARPC", NULL, "" },
+ { "lsaquery", cmd_lsa_query_info_policy, "Query info policy" },
+ { "lookupsids", cmd_lsa_lookup_sids, "Convert SIDs to names" },
+ { "lookupnames",cmd_lsa_lookup_names, "Convert names to SIDs" },
+ { "enumtrust", cmd_lsa_enum_trust_dom, "Enumerate trusted domains" },
+ { NULL, NULL, NULL }
+};
/*
Unix SMB/Netbios implementation.
- Version 1.9.
- NT Domain Authentication SMB / MSRPC client
- Copyright (C) Andrew Tridgell 1994-1997
- Copyright (C) Luke Kenneth Casson Leighton 1996-1997
-
+ Version 2.2
+ RPC pipe client
+
+ Copyright (C) Andrew Tridgell 1992-2000,
+ Copyright (C) Luke Kenneth Casson Leighton 1996-2000,
+ Copyright (C) Elrond 2000
+ Copyright (C) Tim Potter 2000
+
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
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
-
-
-#ifdef SYSLOG
-#undef SYSLOG
-#endif
-
#include "includes.h"
-extern int DEBUGLEVEL;
-
-#define DEBUG_TESTING
-
-extern struct cli_state *smb_cli;
-
-extern FILE* out_hnd;
-
+extern DOM_SID domain_sid;
/****************************************************************************
-SAM password change
-****************************************************************************/
-void cmd_sam_ntchange_pwd(struct client_info *info)
+ display sam_user_info_21 structure
+ ****************************************************************************/
+static void display_sam_user_info_21(SAM_USER_INFO_21 *usr)
{
- fstring srv_name;
- fstring domain;
- fstring sid;
- char *new_passwd;
- BOOL res = True;
- char nt_newpass[516];
- uchar nt_hshhash[16];
- uchar nt_newhash[16];
- uchar nt_oldhash[16];
- char lm_newpass[516];
- uchar lm_newhash[16];
- uchar lm_hshhash[16];
- uchar lm_oldhash[16];
-
- sid_to_string(sid, &info->dom.level5_sid);
- fstrcpy(domain, info->dom.level5_dom);
-
- fstrcpy(srv_name, "\\\\");
- fstrcat(srv_name, info->dest_host);
- strupper(srv_name);
-
- fprintf(out_hnd, "SAM NT Password Change\n");
-
-#if 0
- struct pwd_info new_pwd;
- pwd_read(&new_pwd, "New Password (ONCE: this is test code!):", True);
-#endif
- new_passwd = (char*)getpass("New Password (ONCE ONLY - get it right :-)");
-
- nt_lm_owf_gen(new_passwd, lm_newhash, nt_newhash);
- pwd_get_lm_nt_16(&(smb_cli->pwd), lm_oldhash, nt_oldhash );
- make_oem_passwd_hash(nt_newpass, new_passwd, nt_oldhash, True);
- make_oem_passwd_hash(lm_newpass, new_passwd, lm_oldhash, True);
- E_old_pw_hash(lm_newhash, lm_oldhash, lm_hshhash);
- E_old_pw_hash(lm_newhash, nt_oldhash, nt_hshhash);
-
- cli_nt_set_ntlmssp_flgs(smb_cli,
- NTLMSSP_NEGOTIATE_UNICODE |
- NTLMSSP_NEGOTIATE_OEM |
- NTLMSSP_NEGOTIATE_SIGN |
- NTLMSSP_NEGOTIATE_SEAL |
- NTLMSSP_NEGOTIATE_LM_KEY |
- NTLMSSP_NEGOTIATE_NTLM |
- NTLMSSP_NEGOTIATE_ALWAYS_SIGN |
- NTLMSSP_NEGOTIATE_00001000 |
- NTLMSSP_NEGOTIATE_00002000);
-
- /* open SAMR session. */
- res = res ? cli_nt_session_open(smb_cli, PIPE_SAMR) : False;
-
-#if 0
- /* establish a connection. */
- res = res ? do_samr_get_dom_pwinfo(smb_cli, srv_name) : False;
-
- /* establish a connection. */
- res = res ? do_samr_chgpasswd_user(smb_cli,
- srv_name, smb_cli->user_name,
- nt_newpass, nt_hshhash,
- lm_newpass, lm_hshhash) : False;
-#endif
- /* close the session */
- cli_nt_session_close(smb_cli);
-
- if (res)
- {
- fprintf(out_hnd, "NT Password changed OK\n");
- }
- else
- {
- fprintf(out_hnd, "NT Password change FAILED\n");
+ fstring temp;
+
+ unistr2_to_ascii(temp, &usr->uni_user_name, sizeof(temp)-1);
+ printf("\tUser Name :\t%s\n", temp);
+
+ unistr2_to_ascii(temp, &usr->uni_full_name, sizeof(temp)-1);
+ printf("\tFull Name :\t%s\n", temp);
+
+ unistr2_to_ascii(temp, &usr->uni_home_dir, sizeof(temp)-1);
+ printf("\tHome Drive :\t%s\n", temp);
+
+ unistr2_to_ascii(temp, &usr->uni_dir_drive, sizeof(temp)-1);
+ printf("\tDir Drive :\t%s\n", temp);
+
+ unistr2_to_ascii(temp, &usr->uni_profile_path, sizeof(temp)-1);
+ printf("\tProfile Path:\t%s\n", temp);
+
+ unistr2_to_ascii(temp, &usr->uni_logon_script, sizeof(temp)-1);
+ printf("\tLogon Script:\t%s\n", temp);
+
+ unistr2_to_ascii(temp, &usr->uni_acct_desc, sizeof(temp)-1);
+ printf("\tDescription :\t%s\n", temp);
+
+ unistr2_to_ascii(temp, &usr->uni_workstations, sizeof(temp)-1);
+ printf("\tWorkstations:\t%s\n", temp);
+
+ unistr2_to_ascii(temp, &usr->uni_unknown_str, sizeof(temp)-1);
+ printf("\tUnknown Str :\t%s\n", temp);
+
+ unistr2_to_ascii(temp, &usr->uni_munged_dial, sizeof(temp)-1);
+ printf("\tRemote Dial :\t%s\n", temp);
+
+ printf("\tLogon Time :\t%s\n",
+ http_timestring(nt_time_to_unix(&usr->logon_time)));
+ printf("\tLogoff Time :\t%s\n",
+ http_timestring(nt_time_to_unix(&usr->logoff_time)));
+ printf("\tKickoff Time :\t%s\n",
+ http_timestring(nt_time_to_unix(&usr->kickoff_time)));
+ printf("\tPassword last set Time :\t%s\n",
+ http_timestring(nt_time_to_unix(&usr->pass_last_set_time)));
+ printf("\tPassword can change Time :\t%s\n",
+ http_timestring(nt_time_to_unix(&usr->pass_can_change_time)));
+ printf("\tPassword must change Time:\t%s\n",
+ http_timestring(nt_time_to_unix(&usr->pass_must_change_time)));
+
+ printf("\tunknown_2[0..31]...\n"); /* user passwords? */
+
+ printf("\tuser_rid :\t%x\n" , usr->user_rid ); /* User ID */
+ printf("\tgroup_rid:\t%x\n" , usr->group_rid); /* Group ID */
+ printf("\tacb_info :\t%04x\n", usr->acb_info ); /* Account Control Info */
+
+ printf("\tunknown_3:\t%08x\n", usr->unknown_3); /* 0x00ff ffff */
+ printf("\tlogon_divs:\t%d\n", usr->logon_divs); /* 0x0000 00a8 which is 168 which is num hrs in a week */
+ printf("\tunknown_5:\t%08x\n", usr->unknown_5); /* 0x0002 0000 */
+
+ printf("\tpadding1[0..7]...\n");
+
+ if (usr->ptr_logon_hrs) {
+ printf("\tlogon_hrs[0..%d]...\n", usr->logon_hrs.len);
}
}
-
-/****************************************************************************
-experimental SAM encryted rpc test connection
-****************************************************************************/
-void cmd_sam_test(struct client_info *info)
+/**********************************************************************
+ * Query user information
+ */
+static uint32 cmd_samr_query_user(struct cli_state *cli, int argc, char **argv)
{
- fstring srv_name;
- fstring domain;
- fstring sid;
- BOOL res = True;
-
- sid_to_string(sid, &info->dom.level5_sid);
- fstrcpy(domain, info->dom.level5_dom);
-
-/*
- if (strlen(sid) == 0)
- {
- fprintf(out_hnd, "please use 'lsaquery' first, to ascertain the SID\n");
- return;
+ POLICY_HND connect_pol, domain_pol, user_pol;
+ uint32 result = NT_STATUS_UNSUCCESSFUL,
+ info_level = 21;
+ BOOL got_connect_pol = False,
+ got_domain_pol = False,
+ got_user_pol = False;
+ SAM_USERINFO_CTR user_ctr;
+ SAM_USER_INFO_21 info_21;
+ fstring server;
+
+ if (argc != 1) {
+ printf("Usage: %s\n", argv[0]);
+ return 0;
}
-*/
- fstrcpy(srv_name, "\\\\");
- fstrcat(srv_name, info->dest_host);
- strupper(srv_name);
-
- fprintf(out_hnd, "SAM Encryption Test\n");
-
- cli_nt_set_ntlmssp_flgs(smb_cli,
- NTLMSSP_NEGOTIATE_UNICODE |
- NTLMSSP_NEGOTIATE_OEM |
- NTLMSSP_NEGOTIATE_SIGN |
- NTLMSSP_NEGOTIATE_SEAL |
- NTLMSSP_NEGOTIATE_LM_KEY |
- NTLMSSP_NEGOTIATE_NTLM |
- NTLMSSP_NEGOTIATE_ALWAYS_SIGN |
- NTLMSSP_NEGOTIATE_00001000 |
- NTLMSSP_NEGOTIATE_00002000);
-
- /* open SAMR session. */
- res = res ? cli_nt_session_open(smb_cli, PIPE_SAMR) : False;
-
-#if 0
- /* establish a connection. */
- res = res ? do_samr_get_dom_pwinfo(smb_cli, srv_name) : False;
-#endif
-
- /* close the session */
- cli_nt_session_close(smb_cli);
-
- if (res)
- {
- DEBUG(5,("cmd_sam_test: succeeded\n"));
+
+ /* Initialise RPC connection */
+ if (!cli_nt_session_open (cli, PIPE_SAMR)) {
+ fprintf (stderr, "Could not initialize samr pipe!\n");
+ return NT_STATUS_UNSUCCESSFUL;
}
- else
- {
- DEBUG(5,("cmd_sam_test: failed\n"));
+
+ slprintf (server, sizeof(fstring), "\\\\%s", cli->desthost);
+ strupper (server);
+
+ if ((result = cli_samr_connect(cli, server, MAXIMUM_ALLOWED_ACCESS,
+ &connect_pol)) !=
+ NT_STATUS_NOPROBLEMO) {
+ goto done;
}
-}
+ got_connect_pol = True;
+ fetch_domain_sid(cli);
-/****************************************************************************
-experimental SAM users enum.
-****************************************************************************/
-void cmd_sam_enum_users(struct client_info *info)
-{
- fstring srv_name;
- fstring domain;
- fstring sid;
- DOM_SID sid1;
- int user_idx;
- BOOL res = True;
- BOOL request_user_info = False;
- BOOL request_group_info = False;
- uint16 num_entries = 0;
- uint16 unk_0 = 0x0;
- uint16 acb_mask = 0;
- uint16 unk_1 = 0x0;
- uint32 admin_rid = 0x304; /* absolutely no idea. */
- fstring tmp;
-
- sid_to_string(sid, &info->dom.level5_sid);
- fstrcpy(domain, info->dom.level5_dom);
-
- if (strlen(sid) == 0)
- {
- fprintf(out_hnd, "please use 'lsaquery' first, to ascertain the SID\n");
- return;
+ if ((result = cli_samr_open_domain(cli, &connect_pol,
+ MAXIMUM_ALLOWED_ACCESS,
+ &domain_sid, &domain_pol))
+ != NT_STATUS_NOPROBLEMO) {
+ goto done;
}
- init_dom_sid(&sid1, sid);
-
- fstrcpy(srv_name, "\\\\");
- fstrcat(srv_name, info->dest_host);
- strupper(srv_name);
+ got_domain_pol = True;
- /* a bad way to do token parsing... */
- if (next_token(NULL, tmp, NULL, sizeof(tmp)))
- {
- request_user_info |= strequal(tmp, "-u");
- request_group_info |= strequal(tmp, "-g");
+ if ((result = cli_samr_open_user(cli, &domain_pol,
+ MAXIMUM_ALLOWED_ACCESS,
+ 0x1f4, &user_pol))
+ != NT_STATUS_NOPROBLEMO) {
+ goto done;
}
- if (next_token(NULL, tmp, NULL, sizeof(tmp)))
- {
- request_user_info |= strequal(tmp, "-u");
- request_group_info |= strequal(tmp, "-g");
- }
+ got_user_pol = True;
-#ifdef DEBUG_TESTING
- if (next_token(NULL, tmp, NULL, sizeof(tmp)))
- {
- num_entries = (uint16)strtol(tmp, (char**)NULL, 16);
- }
+ ZERO_STRUCT(user_ctr);
+ ZERO_STRUCT(info_21);
- if (next_token(NULL, tmp, NULL, sizeof(tmp)))
- {
- unk_0 = (uint16)strtol(tmp, (char**)NULL, 16);
- }
+ user_ctr.info.id21 = &info_21;
- if (next_token(NULL, tmp, NULL, sizeof(tmp)))
- {
- acb_mask = (uint16)strtol(tmp, (char**)NULL, 16);
+ if ((result = cli_samr_query_userinfo(cli, &user_pol, info_level,
+ &user_ctr))
+ != NT_STATUS_NOPROBLEMO) {
+ goto done;
}
- if (next_token(NULL, tmp, NULL, sizeof(tmp)))
- {
- unk_1 = (uint16)strtol(tmp, (char**)NULL, 16);
- }
-#endif
-
- fprintf(out_hnd, "SAM Enumerate Users\n");
- fprintf(out_hnd, "From: %s To: %s Domain: %s SID: %s\n",
- info->myhostname, srv_name, domain, sid);
-
-#ifdef DEBUG_TESTING
- DEBUG(5,("Number of entries:%d unk_0:%04x acb_mask:%04x unk_1:%04x\n",
- num_entries, unk_0, acb_mask, unk_1));
-#endif
-
- /* open SAMR session. negotiate credentials */
- res = res ? cli_nt_session_open(smb_cli, PIPE_SAMR) : False;
-
- /* establish a connection. */
- res = res ? do_samr_connect(smb_cli,
- srv_name, 0x00000020,
- &info->dom.samr_pol_connect) : False;
-
- /* connect to the domain */
- res = res ? do_samr_open_domain(smb_cli,
- &info->dom.samr_pol_connect, admin_rid, &sid1,
- &info->dom.samr_pol_open_domain) : False;
-
- /* read some users */
- res = res ? do_samr_enum_dom_users(smb_cli,
- &info->dom.samr_pol_open_domain,
- num_entries, unk_0, acb_mask, unk_1, 0xffff,
- &info->dom.sam, &info->dom.num_sam_entries) : False;
-
- if (res && info->dom.num_sam_entries == 0)
- {
- fprintf(out_hnd, "No users\n");
- }
+ display_sam_user_info_21(&info_21);
- if (request_user_info || request_group_info)
- {
- /* query all the users */
- user_idx = 0;
-
- while (res && user_idx < info->dom.num_sam_entries)
- {
- uint32 user_rid = info->dom.sam[user_idx].smb_userid;
- SAM_USER_INFO_21 usr;
-
- fprintf(out_hnd, "User RID: %8x User Name: %s\n",
- user_rid,
- info->dom.sam[user_idx].acct_name);
-
- if (request_user_info)
- {
- /* send user info query, level 0x15 */
- if (get_samr_query_userinfo(smb_cli,
- &info->dom.samr_pol_open_domain,
- 0x15, user_rid, &usr))
- {
- display_sam_user_info_21(out_hnd, ACTION_HEADER , &usr);
- display_sam_user_info_21(out_hnd, ACTION_ENUMERATE, &usr);
- display_sam_user_info_21(out_hnd, ACTION_FOOTER , &usr);
- }
- }
-
- if (request_group_info)
- {
- uint32 num_groups;
- DOM_GID gid[LSA_MAX_GROUPS];
-
- /* send user group query */
- if (get_samr_query_usergroups(smb_cli,
- &info->dom.samr_pol_open_domain,
- user_rid, &num_groups, gid))
- {
- display_group_rid_info(out_hnd, ACTION_HEADER , num_groups, gid);
- display_group_rid_info(out_hnd, ACTION_ENUMERATE, num_groups, gid);
- display_group_rid_info(out_hnd, ACTION_FOOTER , num_groups, gid);
- }
- }
-
- user_idx++;
- }
- }
+done:
+ if (got_user_pol) cli_samr_close(cli, &user_pol);
+ if (got_domain_pol) cli_samr_close(cli, &domain_pol);
+ if (got_connect_pol) cli_samr_close(cli, &connect_pol);
- res = res ? do_samr_close(smb_cli,
- &info->dom.samr_pol_open_domain) : False;
+ cli_nt_session_close(cli);
- res = res ? do_samr_close(smb_cli,
- &info->dom.samr_pol_connect) : False;
+ return result;
+}
- /* close the session */
- cli_nt_session_close(smb_cli);
+/****************************************************************************
+ display group info
+ ****************************************************************************/
+static void display_group_info1(GROUP_INFO1 *info1)
+{
+ fstring temp;
+
+ unistr2_to_ascii(temp, &info1->uni_acct_name, sizeof(temp)-1);
+ printf("\tGroup Name:\t%s\n", temp);
+ unistr2_to_ascii(temp, &info1->uni_acct_desc, sizeof(temp)-1);
+ printf("\tDescription:\t%s\n", temp);
+ printf("\tunk1:%d\n", info1->unknown_1);
+ printf("\tNum Members:%d\n", info1->num_members);
+}
- if (info->dom.sam != NULL)
- {
- free(info->dom.sam);
- }
+/****************************************************************************
+ display group info
+ ****************************************************************************/
+static void display_group_info4(GROUP_INFO4 *info4)
+{
+ fstring desc;
- if (res)
- {
- DEBUG(5,("cmd_sam_enum_users: succeeded\n"));
- }
- else
- {
- DEBUG(5,("cmd_sam_enum_users: failed\n"));
- }
+ unistr2_to_ascii(desc, &info4->uni_acct_desc, sizeof(desc)-1);
+ printf("\tGroup Description:%s\n", desc);
}
-
/****************************************************************************
-experimental SAM user query.
-****************************************************************************/
-void cmd_sam_query_user(struct client_info *info)
+ display sam sync structure
+ ****************************************************************************/
+static void display_group_info_ctr(GROUP_INFO_CTR *ctr)
{
- fstring srv_name;
- fstring domain;
- fstring sid;
- DOM_SID sid1;
- int user_idx = 0; /* FIXME maybe ... */
- BOOL res = True;
- uint32 admin_rid = 0x304; /* absolutely no idea. */
- fstring rid_str ;
- fstring info_str;
- uint32 user_rid = 0;
- uint32 info_level = 0x15;
-
- SAM_USER_INFO_21 usr;
-
- sid_to_string(sid, &info->dom.level5_sid);
- fstrcpy(domain, info->dom.level5_dom);
-
- if (strlen(sid) == 0)
- {
- fprintf(out_hnd, "please use 'lsaquery' first, to ascertain the SID\n");
- return;
+ switch (ctr->switch_value1) {
+ case 1: {
+ display_group_info1(&ctr->group.info1);
+ break;
+ }
+ case 4: {
+ display_group_info4(&ctr->group.info4);
+ break;
+ }
}
+}
- init_dom_sid(&sid1, sid);
-
- fstrcpy(srv_name, "\\\\");
- fstrcat(srv_name, info->dest_host);
- strupper(srv_name);
+/***********************************************************************
+ * Query group information
+ */
+static uint32 cmd_samr_query_group(struct cli_state *cli, int argc, char **argv)
+{
+ POLICY_HND connect_pol, domain_pol, group_pol;
+ uint32 result = NT_STATUS_UNSUCCESSFUL, info_level = 1;
+ BOOL got_connect_pol = False, got_domain_pol = False,
+ got_group_pol = False;
+ GROUP_INFO_CTR group_ctr;
+ fstring server;
+
+ if (argc != 1) {
+ printf("Usage: %s\n", argv[0]);
+ return 0;
+ }
- if (next_token(NULL, rid_str , NULL, sizeof(rid_str )) &&
- next_token(NULL, info_str, NULL, sizeof(info_str)))
- {
- user_rid = (uint32)strtol(rid_str , (char**)NULL, 16);
- info_level = (uint32)strtol(info_str, (char**)NULL, 10);
+ /* Initialise RPC connection */
+ if (!cli_nt_session_open (cli, PIPE_SAMR)) {
+ fprintf (stderr, "Could not initialize samr pipe!\n");
+ return NT_STATUS_UNSUCCESSFUL;
}
+
+ slprintf (server, sizeof(fstring), "\\\\%s", cli->desthost);
+ strupper (server);
- fprintf(out_hnd, "SAM Query User: rid %x info level %d\n",
- user_rid, info_level);
- fprintf(out_hnd, "From: %s To: %s Domain: %s SID: %s\n",
- info->myhostname, srv_name, domain, sid);
-
- /* open SAMR session. negotiate credentials */
- res = res ? cli_nt_session_open(smb_cli, PIPE_SAMR) : False;
-
- /* establish a connection. */
- res = res ? do_samr_connect(smb_cli,
- srv_name, 0x00000020,
- &info->dom.samr_pol_connect) : False;
-
- /* connect to the domain */
- res = res ? do_samr_open_domain(smb_cli,
- &info->dom.samr_pol_connect, admin_rid, &sid1,
- &info->dom.samr_pol_open_domain) : False;
-
- fprintf(out_hnd, "User RID: %8x User Name: %s\n",
- user_rid,
- info->dom.sam[user_idx].acct_name);
-
- /* send user info query, level */
- if (get_samr_query_userinfo(smb_cli,
- &info->dom.samr_pol_open_domain,
- info_level, user_rid, &usr))
- {
- if (info_level == 0x15)
- {
- display_sam_user_info_21(out_hnd, ACTION_HEADER , &usr);
- display_sam_user_info_21(out_hnd, ACTION_ENUMERATE, &usr);
- display_sam_user_info_21(out_hnd, ACTION_FOOTER , &usr);
- }
+ if ((result = cli_samr_connect(cli, server, MAXIMUM_ALLOWED_ACCESS,
+ &connect_pol)) !=
+ NT_STATUS_NOPROBLEMO) {
+ goto done;
}
- res = res ? do_samr_close(smb_cli,
- &info->dom.samr_pol_connect) : False;
+ got_connect_pol = True;
+ fetch_domain_sid(cli);
- res = res ? do_samr_close(smb_cli,
- &info->dom.samr_pol_open_domain) : False;
+ if ((result = cli_samr_open_domain(cli, &connect_pol,
+ MAXIMUM_ALLOWED_ACCESS,
+ &domain_sid, &domain_pol))
+ != NT_STATUS_NOPROBLEMO) {
+ goto done;
+ }
- /* close the session */
- cli_nt_session_close(smb_cli);
+ got_domain_pol = True;
- if (res)
- {
- DEBUG(5,("cmd_sam_query_user: succeeded\n"));
+ if ((result = cli_samr_open_group(cli, &domain_pol,
+ MAXIMUM_ALLOWED_ACCESS,
+ 0x202, &group_pol))
+ != NT_STATUS_NOPROBLEMO) {
+ goto done;
}
- else
- {
- DEBUG(5,("cmd_sam_query_user: failed\n"));
+
+ got_group_pol = True;
+
+ ZERO_STRUCT(group_ctr);
+
+ if ((result = cli_samr_query_groupinfo(cli, &group_pol, info_level,
+ &group_ctr))
+ != NT_STATUS_NOPROBLEMO) {
+ goto done;
}
+
+ display_group_info_ctr(&group_ctr);
+
+done:
+ if (got_group_pol) cli_samr_close(cli, &group_pol);
+ if (got_domain_pol) cli_samr_close(cli, &domain_pol);
+ if (got_connect_pol) cli_samr_close(cli, &connect_pol);
+
+ cli_nt_session_close(cli);
+
+ return result;
}
+/* Query groups a user is a member of */
-/****************************************************************************
-experimental SAM groups query.
-****************************************************************************/
-void cmd_sam_query_groups(struct client_info *info)
+static uint32 cmd_samr_query_usergroups(struct cli_state *cli, int argc, char **argv)
{
- fstring srv_name;
- fstring domain;
- fstring sid;
- DOM_SID sid1;
- BOOL res = True;
- fstring info_str;
- uint32 switch_value = 2;
- uint32 admin_rid = 0x304; /* absolutely no idea. */
-
- sid_to_string(sid, &info->dom.level5_sid);
- fstrcpy(domain, info->dom.level5_dom);
-
- if (strlen(sid) == 0)
- {
- fprintf(out_hnd, "please use 'lsaquery' first, to ascertain the SID\n");
- return;
+ POLICY_HND connect_pol,
+ domain_pol,
+ user_pol;
+ uint32 result = NT_STATUS_UNSUCCESSFUL;
+ BOOL got_connect_pol = False,
+ got_domain_pol = False,
+ got_user_pol = False;
+ uint32 num_groups,
+ user_rid;
+ DOM_GID *user_gids;
+ int i;
+ fstring server;
+
+ if (argc != 2) {
+ printf("Usage: %s rid/name\n", argv[0]);
+ return 0;
}
- init_dom_sid(&sid1, sid);
+ sscanf(argv[1], "%i", &user_rid);
- fstrcpy(srv_name, "\\\\");
- fstrcat(srv_name, info->dest_host);
- strupper(srv_name);
+ /* Initialise RPC connection */
+ if (!cli_nt_session_open (cli, PIPE_SAMR)) {
+ fprintf (stderr, "Could not initialize samr pipe!\n");
+ return NT_STATUS_UNSUCCESSFUL;
+ }
- if (next_token(NULL, info_str, NULL, sizeof(info_str)))
- {
- switch_value = (uint32)strtol(info_str, (char**)NULL, 10);
+ slprintf (server, sizeof(fstring), "\\\\%s", cli->desthost);
+ strupper (server);
+
+ if ((result = cli_samr_connect(cli, server, MAXIMUM_ALLOWED_ACCESS,
+ &connect_pol)) !=
+ NT_STATUS_NOPROBLEMO) {
+ goto done;
}
- fprintf(out_hnd, "SAM Query Groups: info level %d\n", switch_value);
- fprintf(out_hnd, "From: %s To: %s Domain: %s SID: %s\n",
- info->myhostname, srv_name, domain, sid);
+ got_connect_pol = True;
+ fetch_domain_sid(cli);
- /* open SAMR session. negotiate credentials */
- res = res ? cli_nt_session_open(smb_cli, PIPE_SAMR) : False;
+ if ((result = cli_samr_open_domain(cli, &connect_pol,
+ MAXIMUM_ALLOWED_ACCESS,
+ &domain_sid, &domain_pol))
+ != NT_STATUS_NOPROBLEMO) {
+ goto done;
+ }
- /* establish a connection. */
- res = res ? do_samr_connect(smb_cli,
- srv_name, 0x00000020,
- &info->dom.samr_pol_connect) : False;
+ got_domain_pol = True;
- /* connect to the domain */
- res = res ? do_samr_open_domain(smb_cli,
- &info->dom.samr_pol_connect, admin_rid, &sid1,
- &info->dom.samr_pol_open_domain) : False;
+ if ((result = cli_samr_open_user(cli, &domain_pol,
+ MAXIMUM_ALLOWED_ACCESS,
+ user_rid, &user_pol))
+ != NT_STATUS_NOPROBLEMO) {
+ goto done;
+ }
- /* send a samr 0x8 command */
- res = res ? do_samr_query_dom_info(smb_cli,
- &info->dom.samr_pol_open_domain, switch_value) : False;
+ got_user_pol = True;
- res = res ? do_samr_close(smb_cli,
- &info->dom.samr_pol_connect) : False;
+ if ((result = cli_samr_query_usergroups(cli, &user_pol,
+ &num_groups, &user_gids))
+ != NT_STATUS_NOPROBLEMO) {
+ goto done;
+ }
- res = res ? do_samr_close(smb_cli,
- &info->dom.samr_pol_open_domain) : False;
+ for (i = 0; i < num_groups; i++) {
+ printf("\tgroup rid:[0x%x] attr:[0x%x]\n",
+ user_gids[i].g_rid, user_gids[i].attr);
+ }
- /* close the session */
- cli_nt_session_close(smb_cli);
+ done:
+ if (got_user_pol) cli_samr_close(cli, &user_pol);
+ if (got_domain_pol) cli_samr_close(cli, &domain_pol);
+ if (got_connect_pol) cli_samr_close(cli, &connect_pol);
- if (res)
- {
- DEBUG(5,("cmd_sam_query_groups: succeeded\n"));
- }
- else
- {
- DEBUG(5,("cmd_sam_query_groups: failed\n"));
- }
+ cli_nt_session_close(cli);
+
+ return result;
}
+/* Query members of a group */
-/****************************************************************************
-experimental SAM aliases query.
-****************************************************************************/
-void cmd_sam_enum_aliases(struct client_info *info)
+static uint32 cmd_samr_query_groupmem(struct cli_state *cli, int argc, char **argv)
{
- fstring srv_name;
- fstring domain;
- fstring sid;
- DOM_SID sid1;
- BOOL res = True;
- BOOL request_user_info = False;
- BOOL request_alias_info = False;
- uint32 admin_rid = 0x304; /* absolutely no idea. */
- fstring tmp;
-
- uint32 num_aliases = 3;
- uint32 alias_rid[3] = { DOMAIN_GROUP_RID_ADMINS, DOMAIN_GROUP_RID_USERS, DOMAIN_GROUP_RID_GUESTS };
- fstring alias_names [3];
- uint32 num_als_usrs[3];
-
- sid_to_string(sid, &info->dom.level3_sid);
- fstrcpy(domain, info->dom.level3_dom);
-#if 0
- fstrcpy(sid , "S-1-5-20");
-#endif
- if (strlen(sid) == 0)
- {
- fprintf(out_hnd, "please use 'lsaquery' first, to ascertain the SID\n");
- return;
+ POLICY_HND connect_pol, domain_pol, group_pol;
+ uint32 result = NT_STATUS_UNSUCCESSFUL;
+ BOOL got_connect_pol = False,
+ got_domain_pol = False,
+ got_group_pol = False;
+ uint32 num_members, *group_rids, *group_attrs, group_rid;
+ int i;
+ fstring server;
+
+ if (argc != 2) {
+ printf("Usage: %s rid/name\n", argv[0]);
+ return 0;
}
- init_dom_sid(&sid1, sid);
-
- fstrcpy(srv_name, "\\\\");
- fstrcat(srv_name, info->dest_host);
- strupper(srv_name);
+ sscanf(argv[1], "%i", &group_rid);
- /* a bad way to do token parsing... */
- if (next_token(NULL, tmp, NULL, sizeof(tmp)))
- {
- request_user_info |= strequal(tmp, "-u");
- request_alias_info |= strequal(tmp, "-g");
+ /* Initialise RPC connection */
+ if (!cli_nt_session_open (cli, PIPE_SAMR)) {
+ fprintf (stderr, "Could not initialize samr pipe!\n");
+ return NT_STATUS_UNSUCCESSFUL;
}
- if (next_token(NULL, tmp, NULL, sizeof(tmp)))
- {
- request_user_info |= strequal(tmp, "-u");
- request_alias_info |= strequal(tmp, "-g");
- }
+ slprintf (server, sizeof(fstring), "\\\\%s", cli->desthost);
+ strupper (server);
- fprintf(out_hnd, "SAM Enumerate Aliases\n");
- fprintf(out_hnd, "From: %s To: %s Domain: %s SID: %s\n",
- info->myhostname, srv_name, domain, sid);
-
- /* open SAMR session. negotiate credentials */
- res = res ? cli_nt_session_open(smb_cli, PIPE_SAMR) : False;
-
- /* establish a connection. */
- res = res ? do_samr_connect(smb_cli,
- srv_name, 0x00000020,
- &info->dom.samr_pol_connect) : False;
-
- /* connect to the domain */
- res = res ? do_samr_open_domain(smb_cli,
- &info->dom.samr_pol_connect, admin_rid, &sid1,
- &info->dom.samr_pol_open_domain) : False;
-
-#if 0
- /* send a query on the aliase */
- res = res ? do_samr_query_lookup_rids(smb_cli,
- &info->dom.samr_pol_open_domain, admin_rid, num_aliases, alias_rid,
- &num_aliases, alias_names, num_als_usrs) : False;
-#endif
-
- if (res)
- {
- display_alias_name_info(out_hnd, ACTION_HEADER , num_aliases, alias_names, num_als_usrs);
- display_alias_name_info(out_hnd, ACTION_ENUMERATE, num_aliases, alias_names, num_als_usrs);
- display_alias_name_info(out_hnd, ACTION_FOOTER , num_aliases, alias_names, num_als_usrs);
+ if ((result = cli_samr_connect(cli, server, MAXIMUM_ALLOWED_ACCESS,
+ &connect_pol)) !=
+ NT_STATUS_NOPROBLEMO) {
+ goto done;
}
-#if 0
+ got_connect_pol = True;
+ fetch_domain_sid(cli);
+
+ if ((result = cli_samr_open_domain(cli, &connect_pol,
+ MAXIMUM_ALLOWED_ACCESS,
+ &domain_sid, &domain_pol))
+ != NT_STATUS_NOPROBLEMO) {
+ goto done;
+ }
- /* read some users */
- res = res ? do_samr_enum_dom_users(smb_cli,
- &info->dom.samr_pol_open_domain,
- num_entries, unk_0, acb_mask, unk_1, 0xffff,
- info->dom.sam, &info->dom.num_sam_entries) : False;
+ got_domain_pol = True;
- if (res && info->dom.num_sam_entries == 0)
- {
- fprintf(out_hnd, "No users\n");
+ if ((result = cli_samr_open_group(cli, &domain_pol,
+ MAXIMUM_ALLOWED_ACCESS,
+ group_rid, &group_pol))
+ != NT_STATUS_NOPROBLEMO) {
+ goto done;
}
- if (request_user_info || request_alias_info)
- {
- /* query all the users */
- user_idx = 0;
-
- while (res && user_idx < info->dom.num_sam_entries)
- {
- uint32 user_rid = info->dom.sam[user_idx].smb_userid;
- SAM_USER_INFO_21 usr;
-
- fprintf(out_hnd, "User RID: %8x User Name: %s\n",
- user_rid,
- info->dom.sam[user_idx].acct_name);
-
- if (request_user_info)
- {
- /* send user info query, level 0x15 */
- if (get_samr_query_userinfo(smb_cli,
- &info->dom.samr_pol_open_domain,
- 0x15, user_rid, &usr))
- {
- display_sam_user_info_21(out_hnd, ACTION_HEADER , &usr);
- display_sam_user_info_21(out_hnd, ACTION_ENUMERATE, &usr);
- display_sam_user_info_21(out_hnd, ACTION_FOOTER , &usr);
- }
- }
-
- if (request_alias_info)
- {
- uint32 num_aliases;
- DOM_GID gid[LSA_MAX_GROUPS];
-
- /* send user aliase query */
- if (get_samr_query_useraliases(smb_cli,
- &info->dom.samr_pol_open_domain,
- user_rid, &num_aliases, gid))
- {
- display_alias_info(out_hnd, ACTION_HEADER , num_aliases, gid);
- display_alias_info(out_hnd, ACTION_ENUMERATE, num_aliases, gid);
- display_alias_info(out_hnd, ACTION_FOOTER , num_aliases, gid);
- }
- }
-
- user_idx++;
- }
+ got_group_pol = True;
+
+ if ((result = cli_samr_query_groupmem(cli, &group_pol,
+ &num_members, &group_rids,
+ &group_attrs))
+ != NT_STATUS_NOPROBLEMO) {
+ goto done;
}
-#endif
- res = res ? do_samr_close(smb_cli,
- &info->dom.samr_pol_connect) : False;
+ for (i = 0; i < num_members; i++) {
+ printf("\trid:[0x%x] attr:[0x%x]\n", group_rids[i],
+ group_attrs[i]);
+ }
- res = res ? do_samr_close(smb_cli,
- &info->dom.samr_pol_open_domain) : False;
+ done:
+ if (got_group_pol) cli_samr_close(cli, &group_pol);
+ if (got_domain_pol) cli_samr_close(cli, &domain_pol);
+ if (got_connect_pol) cli_samr_close(cli, &connect_pol);
- /* close the session */
- cli_nt_session_close(smb_cli);
+ cli_nt_session_close(cli);
- if (res)
- {
- DEBUG(5,("cmd_sam_enum_users: succeeded\n"));
- }
- else
- {
- DEBUG(5,("cmd_sam_enum_users: failed\n"));
- }
+ return result;
}
+/* List of commands exported by this module */
+
+struct cmd_set samr_commands[] = {
+ { "SAMR", NULL, "" },
+ { "queryuser", cmd_samr_query_user, "Query user info" },
+ { "querygroup", cmd_samr_query_group, "Query group info" },
+ { "queryusergroups", cmd_samr_query_usergroups, "Query user groups" },
+ { "querygroupmem", cmd_samr_query_groupmem, "Query group membership" },
+ { NULL, NULL, NULL }
+};
/*
Unix SMB/Netbios implementation.
- Version 1.9.
- NT Domain Authentication SMB / MSRPC client
- Copyright (C) Andrew Tridgell 1994-2000
- Copyright (C) Luke Kenneth Casson Leighton 1996-2000
- Copyright (C) Jean-Francois Micouleau 1999-2000
- Copyright (C) Gerald Carter 2000
-
+ Version 2.2
+ RPC pipe client
+
+ Copyright (C) Gerald Carter 2001
+ Copyright (C) Tim Potter 2000
+ Copyright (C) Andrew Tridgell 1992-1999
+ Copyright (C) Luke Kenneth Casson Leighton 1996-1999
+
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
*/
#include "includes.h"
-#include "nterr.h"
-#include "rpc_parse.h"
-#include "rpc_client.h"
-#include "rpcclient.h"
extern int DEBUGLEVEL;
-#define DEBUG_TESTING
-
-extern FILE* out_hnd;
-
-extern struct user_creds *usr_creds;
+extern pstring server;
+extern pstring global_myname;
+extern pstring username, password;
+extern pstring workgroup;
+
+struct table_node {
+ char *long_archi;
+ char *short_archi;
+ int version;
+};
+
+struct table_node archi_table[]= {
+
+ {"Windows 4.0", "WIN40", 0 },
+ {"Windows NT x86", "W32X86", 2 },
+ {"Windows NT R4000", "W32MIPS", 2 },
+ {"Windows NT Alpha_AXP", "W32ALPHA", 2 },
+ {"Windows NT PowerPC", "W32PPC", 2 },
+ {NULL, "", -1 }
+};
/****************************************************************************
function to do the mapping between the long architecture name and
****************************************************************************/
BOOL get_short_archi(char *short_archi, char *long_archi)
{
- struct table {
- char *long_archi;
- char *short_archi;
- };
-
- struct table archi_table[]=
- {
- {"Windows 4.0", "WIN40" },
- {"Windows NT x86", "W32X86" },
- {"Windows NT R4000", "W32MIPS" },
- {"Windows NT Alpha_AXP", "W32ALPHA" },
- {"Windows NT PowerPC", "W32PPC" },
- {NULL, "" }
- };
-
int i=-1;
DEBUG(107,("Getting architecture dependant directory\n"));
StrCaseCmp(long_archi, archi_table[i].long_archi) );
if (archi_table[i].long_archi==NULL) {
- DEBUGADD(107,("Unknown architecture [%s] !\n", long_archi));
+ DEBUGADD(10,("Unknown architecture [%s] !\n", long_archi));
return FALSE;
}
DEBUGADD(108,("long architecture: [%s]\n", long_archi));
DEBUGADD(108,("short architecture: [%s]\n", short_archi));
- return TRUE;
+ return True;
}
-/****************************************************************************
-nt spoolss query
-****************************************************************************/
-uint32 cmd_spoolss_enum_printers(struct client_info *info, int argc, char *argv[])
-{
- PRINTER_INFO_CTR ctr;
-
- uint32 flags;
- uint32 level = 1;
- fstring srv_name;
-
- ZERO_STRUCT(ctr);
- fstrcpy(srv_name, "\\\\");
- fstrcat(srv_name, info->dest_host);
- strupper(srv_name);
-
- flags=PRINTER_ENUM_LOCAL;
- report (out_hnd, "Flags = PRINTER_ENUM_LOCAL\n");
- if (msrpc_spoolss_enum_printers(srv_name, flags, level, ctr))
- DEBUG(5,("cmd_spoolss_enum_printer: query succeeded\n"));
- else
- report(out_hnd, "FAILED\n");
-
-
- flags=PRINTER_ENUM_NAME;
- report (out_hnd, "Flags = PRINTER_ENUM_NAME\n");
- if (msrpc_spoolss_enum_printers(srv_name, flags, level, ctr))
- DEBUG(5,("cmd_spoolss_enum_printer: query succeeded\n"));
- else
- report(out_hnd, "FAILED\n");
-
- flags=PRINTER_ENUM_SHARED|PRINTER_ENUM_NAME;
- report (out_hnd, "Flags = PRINTER_ENUM_SHARED|PRINTER_ENUM_NAME\n");
- if (msrpc_spoolss_enum_printers(srv_name, flags, level, ctr))
- DEBUG(5,("cmd_spoolss_enum_printer: query succeeded\n"));
- else
- report(out_hnd, "FAILED\n");
-
- flags=PRINTER_ENUM_CONNECTIONS;
- report (out_hnd, "Flags = PRINTER_ENUM_CONNECTIONS\n");
- if (msrpc_spoolss_enum_printers(srv_name, flags, level, ctr))
- DEBUG(5,("cmd_spoolss_enum_printer: query succeeded\n"));
- else
- report(out_hnd, "FAILED\n");
-
- flags=PRINTER_ENUM_NETWORK;
- report (out_hnd, "Flags = PRINTER_ENUM_NETWORK\n");
- if (msrpc_spoolss_enum_printers(srv_name, flags, level, ctr))
- DEBUG(5,("cmd_spoolss_enum_printer: query succeeded\n"));
- else
- report(out_hnd, "FAILED\n");
-
- flags=PRINTER_ENUM_REMOTE;
- report (out_hnd, "Flags = PRINTER_ENUM_REMOTE\n");
- if (msrpc_spoolss_enum_printers(srv_name, flags, level, ctr))
- DEBUG(5,("cmd_spoolss_enum_printer: query succeeded\n"));
- else
- report(out_hnd, "FAILED\n");
- return NT_STATUS_NOPROBLEMO;
+/**********************************************************************
+ * dummy function -- placeholder
+ */
+static uint32 cmd_spoolss_not_implemented (struct cli_state *cli,
+ int argc, char **argv)
+{
+ printf ("(*) This command is not currently implemented.\n");
+ return NT_STATUS_NO_PROBLEMO;
}
/****************************************************************************
-nt spoolss query
-****************************************************************************/
-uint32 cmd_spoolss_enum_ports(struct client_info *info, int argc, char *argv[])
+ display sec_ace structure
+ ****************************************************************************/
+static void display_sec_ace(SEC_ACE *ace)
{
- PORT_INFO_CTR ctr;
- uint32 level;
- fstring srv_name;
-
- if (argc < 2)
- {
- report (out_hnd, "spoolenumports <level>\n");
- return NT_STATUS_INVALID_PARAMETER;
- }
+ fstring sid_str;
-
- fstrcpy(srv_name, "\\\\");
- fstrcat(srv_name, info->dest_host);
- strupper(srv_name);
-
- level = atoi(argv[1]);
-
- if (msrpc_spoolss_enum_ports(srv_name, level, &ctr))
- DEBUG(5,("cmd_spoolss_enum_printer: query succeeded\n"));
- else
- report(out_hnd, "FAILED\n");
-
- return NT_STATUS_NOPROBLEMO;
+ sid_to_string(sid_str, &ace->sid);
+ printf("\t\tSID: %s\n", sid_str);
+
+ printf("\t\ttype:[%d], flags:[0x%02x], mask:[0x%08x]\n",
+ ace->type, ace->flags, ace->info.mask);
}
/****************************************************************************
-nt spoolss query
-****************************************************************************/
-uint32 cmd_spoolss_enum_printerdata(struct client_info *info, int argc, char *argv[])
+ display sec_acl structure
+ ****************************************************************************/
+static void display_sec_acl(SEC_ACL *acl)
{
- fstring srv_name;
- fstring station;
- char *printer_name;
+ if (acl->size != 0 && acl->num_aces != 0) {
+ int i;
- if (argc < 2) {
- report(out_hnd, "spoolenumdata <printer name>\n");
- return NT_STATUS_INVALID_PARAMETER;
+ printf("\t\tRevision:[%d]\n", acl->revision);
+ for (i = 0; i < acl->num_aces; i++) {
+ display_sec_ace(&acl->ace[i]);
+ }
}
+}
- printer_name = argv[1];
+/****************************************************************************
+ display sec_desc structure
+ ****************************************************************************/
+static void display_sec_desc(SEC_DESC *sec)
+{
+ fstring sid_str;
- fstrcpy(station, "\\\\");
- fstrcat(station, info->myhostname);
- strupper(station);
+ printf("\tRevision:[%d]\n", sec->revision);
- fstrcpy(srv_name, "\\\\");
- fstrcat(srv_name, info->dest_host);
- strupper(srv_name);
+ if (sec->off_owner_sid) {
+ sid_to_string(sid_str, sec->owner_sid);
+ printf("\tOwner SID: %s\n", sid_str);
+ }
- if (!strnequal("\\\\", printer_name, 2))
- {
- fstrcat(srv_name, "\\");
- fstrcat(srv_name, printer_name);
- printer_name = srv_name;
+ if (sec->off_grp_sid) {
+ sid_to_string(sid_str, sec->grp_sid);
+ printf("\tGroup SID: %s\n", sid_str);
}
- DEBUG(0,("spoolenumdata - printer: %s station: %s user: %s\n", printer_name, station, usr_creds->ntc.user_name));
+ if (sec->off_sacl) display_sec_acl(sec->sacl);
+ if (sec->off_dacl) display_sec_acl(sec->dacl);
+}
- if (msrpc_spoolss_enum_printerdata( printer_name, station,
- usr_creds->ntc.user_name))
- {
- DEBUG(0,("cmd_spoolss_enum_printerdata: query succeeded\n"));
+/***********************************************************************
+ * Get printer information
+ */
+static uint32 cmd_spoolss_open_printer_ex(struct cli_state *cli, int argc, char **argv)
+{
+ uint32 result = NT_STATUS_UNSUCCESSFUL;
+ pstring printername;
+ fstring server, user;
+ POLICY_HND hnd;
+
+ if (argc != 2) {
+ printf("Usage: %s <printername>\n", argv[0]);
return NT_STATUS_NOPROBLEMO;
}
- report(out_hnd, "FAILED\n");
- return NT_STATUS_UNSUCCESSFUL;
-}
+
+ if (!cli)
+ return NT_STATUS_UNSUCCESSFUL;
+
-/****************************************************************************
-nt spoolss query
-****************************************************************************/
-uint32 cmd_spoolss_getprinter(struct client_info *info, int argc, char *argv[])
-{
- PRINTER_INFO_CTR ctr;
- fstring srv_name;
- fstring station;
- char *printer_name;
- uint32 level;
+ slprintf (server, sizeof(fstring), "\\\\%s", cli->desthost);
+ strupper (server);
+ fstrcpy (user, cli->user_name);
+ fstrcpy (printername, argv[1]);
- ZERO_STRUCT(ctr);
+
+ /* Initialise RPC connection */
+ if (!cli_nt_session_open (cli, PIPE_SPOOLSS)) {
+ fprintf (stderr, "Could not initialize spoolss pipe!\n");
+ return NT_STATUS_UNSUCCESSFUL;
+ }
- if (argc < 2) {
- report(out_hnd, "spoolgetprinter <printer name>\n");
- return NT_STATUS_INVALID_PARAMETER;
- }
+ /* Open the printer handle */
+ result = cli_spoolss_open_printer_ex (cli, printername, "",
+ MAXIMUM_ALLOWED_ACCESS, server, user, &hnd);
- printer_name = argv[1];
+ if (result == NT_STATUS_NOPROBLEMO) {
+ printf ("Printer %s opened successfully\n", printername);
+ result = cli_spoolss_close_printer (cli, &hnd);
+ if (result != NT_STATUS_NOPROBLEMO) {
+ printf ("Error closing printer handle! (%s)\n", get_nt_error_msg(result));
+ }
+ }
- fstrcpy(station, "\\\\");
- fstrcat(station, info->myhostname);
- strupper(station);
+ cli_nt_session_close(cli);
- fstrcpy(srv_name, "\\\\");
- fstrcat(srv_name, info->dest_host);
- strupper(srv_name);
+ return result;
+}
- if (!strnequal("\\\\", printer_name, 2))
- {
- fstrcat(srv_name, "\\");
- fstrcat(srv_name, printer_name);
- printer_name = srv_name;
- }
- if (argc < 4)
- level=2;
- else
- level = atoi(argv[2]);
+/****************************************************************************
+printer info level 0 display function
+****************************************************************************/
+static void display_print_info_0(PRINTER_INFO_0 *i1)
+{
+ fstring name;
+ fstring the_server;
- if (msrpc_spoolss_getprinter(printer_name, level, station, "Administrator", ctr))
- DEBUG(5,("cmd_spoolss_getprinter: query succeeded\n"));
- else
- report(out_hnd, "FAILED\n");
+ unistr_to_ascii(name, i1->printername.buffer, sizeof(name) - 1);
+ unistr_to_ascii(the_server, i1->servername.buffer, sizeof(the_server) - 1);
- return NT_STATUS_NOPROBLEMO;
+ printf("\tprintername:[%s]\n", name);
+ printf("\tservername:[%s]\n", the_server);
+ printf("\tcjobs:[0x%x]\n", i1->cjobs);
+ printf("\ttotal_jobs:[0x%x]\n", i1->total_jobs);
+
+ printf("\t:date: [%d]-[%d]-[%d] (%d)\n", i1->year, i1->month,
+ i1->day, i1->dayofweek);
+ printf("\t:time: [%d]-[%d]-[%d]-[%d]\n", i1->hour, i1->minute,
+ i1->second, i1->milliseconds);
+
+ printf("\tglobal_counter:[0x%x]\n", i1->global_counter);
+ printf("\ttotal_pages:[0x%x]\n", i1->total_pages);
+
+ printf("\tmajorversion:[0x%x]\n", i1->major_version);
+ printf("\tbuildversion:[0x%x]\n", i1->build_version);
+
+ printf("\tunknown7:[0x%x]\n", i1->unknown7);
+ printf("\tunknown8:[0x%x]\n", i1->unknown8);
+ printf("\tunknown9:[0x%x]\n", i1->unknown9);
+ printf("\tsession_counter:[0x%x]\n", i1->session_counter);
+ printf("\tunknown11:[0x%x]\n", i1->unknown11);
+ printf("\tprinter_errors:[0x%x]\n", i1->printer_errors);
+ printf("\tunknown13:[0x%x]\n", i1->unknown13);
+ printf("\tunknown14:[0x%x]\n", i1->unknown14);
+ printf("\tunknown15:[0x%x]\n", i1->unknown15);
+ printf("\tunknown16:[0x%x]\n", i1->unknown16);
+ printf("\tchange_id:[0x%x]\n", i1->change_id);
+ printf("\tunknown18:[0x%x]\n", i1->unknown18);
+ printf("\tstatus:[0x%x]\n", i1->status);
+ printf("\tunknown20:[0x%x]\n", i1->unknown20);
+ printf("\tc_setprinter:[0x%x]\n", i1->c_setprinter);
+ printf("\tunknown22:[0x%x]\n", i1->unknown22);
+ printf("\tunknown23:[0x%x]\n", i1->unknown23);
+ printf("\tunknown24:[0x%x]\n", i1->unknown24);
+ printf("\tunknown25:[0x%x]\n", i1->unknown25);
+ printf("\tunknown26:[0x%x]\n", i1->unknown26);
+ printf("\tunknown27:[0x%x]\n", i1->unknown27);
+ printf("\tunknown28:[0x%x]\n", i1->unknown28);
+ printf("\tunknown29:[0x%x]\n", i1->unknown29);
}
+/****************************************************************************
+printer info level 1 display function
+****************************************************************************/
+static void display_print_info_1(PRINTER_INFO_1 *i1)
+{
+ fstring desc;
+ fstring name;
+ fstring comm;
+
+ unistr_to_ascii(desc, i1->description.buffer, sizeof(desc) - 1);
+ unistr_to_ascii(name, i1->name .buffer, sizeof(name) - 1);
+ unistr_to_ascii(comm, i1->comment .buffer, sizeof(comm) - 1);
+
+ printf("\tflags:[0x%x]\n", i1->flags);
+ printf("\tname:[%s]\n", name);
+ printf("\tdescription:[%s]\n", desc);
+ printf("\tcomment:[%s]\n\n", comm);
+}
-static void display_spool_job_info_ctr( const char* printer_name,
- const char* station,
- uint32 level,
- uint32 num, void *const *const ctr)
+/****************************************************************************
+printer info level 2 display function
+****************************************************************************/
+static void display_print_info_2(PRINTER_INFO_2 *i2)
{
- display_job_info_ctr(out_hnd, ACTION_HEADER , level, num, ctr);
- display_job_info_ctr(out_hnd, ACTION_ENUMERATE, level, num, ctr);
- display_job_info_ctr(out_hnd, ACTION_FOOTER , level, num, ctr);
+ fstring servername;
+ fstring printername;
+ fstring sharename;
+ fstring portname;
+ fstring drivername;
+ fstring comment;
+ fstring location;
+ fstring sepfile;
+ fstring printprocessor;
+ fstring datatype;
+ fstring parameters;
+
+ unistr_to_ascii(servername, i2->servername.buffer,
+ sizeof(servername) - 1);
+ unistr_to_ascii(printername, i2->printername.buffer,
+ sizeof(printername) - 1);
+ unistr_to_ascii(sharename, i2->sharename.buffer,
+ sizeof(sharename) - 1);
+ unistr_to_ascii(portname, i2->portname.buffer, sizeof(portname) - 1);
+ unistr_to_ascii(drivername, i2->drivername.buffer,
+ sizeof(drivername) - 1);
+ unistr_to_ascii(comment, i2->comment.buffer, sizeof(comment) - 1);
+ unistr_to_ascii(location, i2->location.buffer, sizeof(location) - 1);
+ unistr_to_ascii(sepfile, i2->sepfile.buffer, sizeof(sepfile) - 1);
+ unistr_to_ascii(printprocessor, i2->printprocessor.buffer,
+ sizeof(printprocessor) - 1);
+ unistr_to_ascii(datatype, i2->datatype.buffer, sizeof(datatype) - 1);
+ unistr_to_ascii(parameters, i2->parameters.buffer,
+ sizeof(parameters) - 1);
+
+ printf("\tservername:[%s]\n", servername);
+ printf("\tprintername:[%s]\n", printername);
+ printf("\tsharename:[%s]\n", sharename);
+ printf("\tportname:[%s]\n", portname);
+ printf("\tdrivername:[%s]\n", drivername);
+ printf("\tcomment:[%s]\n", comment);
+ printf("\tlocation:[%s]\n", location);
+ printf("\tsepfile:[%s]\n", sepfile);
+ printf("\tprintprocessor:[%s]\n", printprocessor);
+ printf("\tdatatype:[%s]\n", datatype);
+ printf("\tparameters:[%s]\n", parameters);
+ printf("\tattributes:[0x%x]\n", i2->attributes);
+ printf("\tpriority:[0x%x]\n", i2->priority);
+ printf("\tdefaultpriority:[0x%x]\n", i2->defaultpriority);
+ printf("\tstarttime:[0x%x]\n", i2->starttime);
+ printf("\tuntiltime:[0x%x]\n", i2->untiltime);
+ printf("\tstatus:[0x%x]\n", i2->status);
+ printf("\tcjobs:[0x%x]\n", i2->cjobs);
+ printf("\taverageppm:[0x%x]\n", i2->averageppm);
+
+ if (i2->secdesc) display_sec_desc(i2->secdesc);
}
/****************************************************************************
-nt spoolss query
+printer info level 3 display function
****************************************************************************/
-uint32 cmd_spoolss_enum_jobs(struct client_info *info, int argc, char *argv[])
+static void display_print_info_3(PRINTER_INFO_3 *i3)
{
- fstring srv_name;
- fstring station;
- char *printer_name;
+ printf("\tflags:[0x%x]\n", i3->flags);
- void **ctr = NULL;
- uint32 level = 1;
+ display_sec_desc(i3->secdesc);
+}
- if (argc < 2) {
- report(out_hnd, "spooljobs <printer name>\n");
- return NT_STATUS_INVALID_PARAMETER;
- }
+/* Enumerate printers */
+
+static uint32 cmd_spoolss_enum_printers(struct cli_state *cli, int argc, char **argv)
+{
+ uint32 result = NT_STATUS_UNSUCCESSFUL,
+ info_level = 1;
+ PRINTER_INFO_CTR ctr;
+ int returned;
+ uint32 i;
+
+ if (argc > 2)
+ {
+ printf("Usage: %s [level]\n", argv[0]);
+ return NT_STATUS_NOPROBLEMO;
+ }
- printer_name = argv[1];
+ if (argc == 2) {
+ info_level = atoi(argv[1]);
+ }
- fstrcpy(station, "\\\\");
- fstrcat(station, info->myhostname);
- strupper(station);
+ /* Initialise RPC connection */
+ if (!cli_nt_session_open (cli, PIPE_SPOOLSS)) {
+ fprintf (stderr, "Could not initialize spoolss pipe!\n");
+ return NT_STATUS_UNSUCCESSFUL;
+ }
- fstrcpy(srv_name, "\\\\");
- fstrcat(srv_name, info->dest_host);
- strupper(srv_name);
+ /* Enumerate printers -- Should we enumerate types other
+ than PRINTER_ENUM_LOCAL? Maybe accept as a parameter? --jerry */
+ ZERO_STRUCT(ctr);
+ result = cli_spoolss_enum_printers(cli, PRINTER_ENUM_LOCAL,
+ info_level, &returned, &ctr);
+
+ if (result == NT_STATUS_NOPROBLEMO) {
+ switch(info_level) {
+ case 0:
+ for (i=0; i<returned; i++) {
+ display_print_info_0(&(ctr.printers_0[i]));
+ }
+ break;
+ case 1:
+ for (i=0; i<returned; i++) {
+ display_print_info_1(&(ctr.printers_1[i]));
+ }
+ break;
+ case 2:
+ for (i=0; i<returned; i++) {
+ display_print_info_2(&(ctr.printers_2[i]));
+ }
+ break;
+ case 3:
+ for (i=0; i<returned; i++) {
+ display_print_info_3(&(ctr.printers_3[i]));
+ }
+ break;
+ default:
+ printf("unknown info level %d\n", info_level);
+ break;
+ }
+ }
- if (!strnequal("\\\\", printer_name, 2))
- {
- fstrcat(srv_name, "\\");
- fstrcat(srv_name, printer_name);
- printer_name = srv_name;
- }
+ cli_nt_session_close(cli);
- DEBUG(4,("spoolopen - printer: %s station: %s user: %s\n", printer_name,
- station, usr_creds->ntc.user_name));
+ return result;
+}
- if (msrpc_spoolss_enum_jobs( printer_name, station,
- usr_creds->ntc.user_name,
- level, &ctr, display_spool_job_info_ctr))
- {
- DEBUG(5,("cmd_spoolss_enum_jobs: query succeeded\n"));
- return NT_STATUS_NOPROBLEMO;
- }
- report(out_hnd, "FAILED\n");
- return NT_STATUS_UNSUCCESSFUL;
+/****************************************************************************
+port info level 1 display function
+****************************************************************************/
+static void display_port_info_1(PORT_INFO_1 *i1)
+{
+ fstring buffer;
+
+ unistr_to_ascii(buffer, i1->port_name.buffer, sizeof(buffer)-1);
+ printf("\tPort Name:\t[%s]\n", buffer);
}
/****************************************************************************
-nt spoolss query
+port info level 2 display function
****************************************************************************/
-uint32 cmd_spoolss_open_printer_ex(struct client_info *info, int argc, char *argv[])
+static void display_port_info_2(PORT_INFO_2 *i2)
{
- fstring srv_name;
- fstring station;
- char *printer_name;
- POLICY_HND hnd;
+ fstring buffer;
+
+ unistr_to_ascii(buffer, i2->port_name.buffer, sizeof(buffer) - 1);
+ printf("\tPort Name:\t[%s]\n", buffer);
+ unistr_to_ascii(buffer, i2->monitor_name.buffer, sizeof(buffer) - 1);
+ printf("\tMonitor Name:\t[%s]\n", buffer);
+ unistr_to_ascii(buffer, i2->description.buffer, sizeof(buffer) - 1);
+ printf("\tDescription:\t[%s]\n", buffer);
+ printf("\tPort Type:\t[%d]\n", i2->port_type);
+ printf("\tReserved:\t[%d]\n", i2->reserved);
+ printf("\n");
+}
- BOOL res = True;
+/* Enumerate ports */
- if (argc < 2)
- {
- report(out_hnd, "spoolopen <printer name>\n");
- return NT_STATUS_INVALID_PARAMETER;
- }
+static uint32 cmd_spoolss_enum_ports(struct cli_state *cli, int argc, char **argv)
+{
+ uint32 result = NT_STATUS_UNSUCCESSFUL,
+ info_level = 1;
+ PORT_INFO_CTR ctr;
+ int returned;
+
+ if (argc > 2) {
+ printf("Usage: %s [level]\n", argv[0]);
+ return NT_STATUS_NOPROBLEMO;
+ }
- printer_name = argv[1];
+ if (argc == 2) {
+ info_level = atoi(argv[1]);
+ }
- fstrcpy(station, "\\\\");
- fstrcat(station, info->myhostname);
- strupper(station);
+ /* Initialise RPC connection */
+ if (!cli_nt_session_open (cli, PIPE_SPOOLSS)) {
+ fprintf (stderr, "Could not initialize spoolss pipe!\n");
+ return NT_STATUS_UNSUCCESSFUL;
+ }
- fstrcpy(srv_name, "\\\\");
- fstrcat(srv_name, info->dest_host);
- strupper(srv_name);
+ /* Enumerate ports */
+ ZERO_STRUCT(ctr);
- if (!strnequal("\\\\", printer_name, 2))
- {
- fstrcat(srv_name, "\\");
- fstrcat(srv_name, printer_name);
- printer_name = srv_name;
- }
+ result = cli_spoolss_enum_ports(cli, info_level, &returned, &ctr);
- DEBUG(4,("spoolopen - printer: %s server: %s user: %s\n",
- printer_name, station, usr_creds->ntc.user_name));
+ if (result == NT_STATUS_NOPROBLEMO) {
+ int i;
- res = res ? spoolss_open_printer_ex( printer_name, "", PRINTER_ALL_ACCESS,
- station, "Administrator", &hnd) : False;
+ for (i = 0; i < returned; i++) {
+ switch (info_level) {
+ case 1:
+ display_port_info_1(&ctr.port.info_1[i]);
+ break;
+ case 2:
+ display_port_info_2(&ctr.port.info_2[i]);
+ break;
+ default:
+ printf("unknown info level %d\n", info_level);
+ break;
+ }
+ }
+ }
- res = res ? spoolss_closeprinter(&hnd) : False;
+ cli_nt_session_close(cli);
- if (res)
- {
- DEBUG(5,("cmd_spoolss_open_printer_ex: query succeeded\n"));
- report(out_hnd, "OK\n");
- return NT_STATUS_NOPROBLEMO;
- }
- DEBUG(5,("cmd_spoolss_open_printer_ex: query failed\n"));
- return NT_STATUS_UNSUCCESSFUL;
+ return result;
}
-/****************************************************************************
-nt spoolss query
-****************************************************************************/
-uint32 cmd_spoolss_getprinterdata(struct client_info *info, int argc, char *argv[])
+/***********************************************************************
+ * Get printer information
+ */
+static uint32 cmd_spoolss_getprinter(struct cli_state *cli, int argc, char **argv)
{
- fstring srv_name;
- fstring station;
- char *printer_name;
- char *value_name;
-
- NEW_BUFFER ctr;
- uint32 status;
- uint32 type = 1;
-
- if (argc < 3) {
- report(out_hnd, "spoolgetdata <printer name> <value name>\n");
- return NT_STATUS_INVALID_PARAMETER;
- }
+ POLICY_HND pol;
+ uint32 result,
+ info_level = 1;
+ BOOL opened_hnd = False;
+ PRINTER_INFO_CTR ctr;
+ fstring printername,
+ servername,
+ username;
- printer_name = argv[1];
- value_name = argv[2];
+ if (argc == 1 || argc > 3) {
+ printf("Usage: %s <printername> [level]\n", argv[0]);
+ return NT_STATUS_NOPROBLEMO;
+ }
- fstrcpy(station, "\\\\");
- fstrcat(station, info->myhostname);
- strupper(station);
+ /* Initialise RPC connection */
+ if (!cli_nt_session_open (cli, PIPE_SPOOLSS)) {
+ fprintf (stderr, "Could not initialize spoolss pipe!\n");
+ return NT_STATUS_UNSUCCESSFUL;
+ }
- fstrcpy(srv_name, "\\\\");
- fstrcat(srv_name, info->dest_host);
- strupper(srv_name);
+ /* Open a printer handle */
+ if (argc == 3) {
+ info_level = atoi(argv[2]);
+ }
- if (!strnequal("\\\\", printer_name, 2))
- {
- fstrcat(srv_name, "\\");
- fstrcat(srv_name, printer_name);
- printer_name = srv_name;
- }
+ slprintf (servername, sizeof(fstring), "\\\\%s", cli->desthost);
+ strupper (servername);
+ slprintf (printername, sizeof(fstring), "%s\\%s", servername, argv[1]);
+ fstrcpy (username, cli->user_name);
+
+ /* get a printer handle */
+ if ((result = cli_spoolss_open_printer_ex(
+ cli, printername, "", MAXIMUM_ALLOWED_ACCESS, servername,
+ username, &pol)) != NT_STATUS_NOPROBLEMO) {
+ goto done;
+ }
+
+ opened_hnd = True;
- DEBUG(4,("spoolgetdata - printer: %s station: %s value: %s\n",
- printer_name, station, value_name));
+ /* Get printer info */
+ if ((result = cli_spoolss_getprinter(cli, &pol, info_level, &ctr))
+ != NT_STATUS_NOPROBLEMO) {
+ goto done;
+ }
- status = msrpc_spoolss_getprinterdata( printer_name, station,
- /* "Administrateur", */
- usr_creds->ntc.user_name,
- value_name, &type,
- &ctr, NULL);
+ /* Display printer info */
+
+ switch (info_level) {
+ case 0:
+ display_print_info_0(ctr.printers_0);
+ break;
+ case 1:
+ display_print_info_1(ctr.printers_1);
+ break;
+ case 2:
+ display_print_info_2(ctr.printers_2);
+ break;
+ case 3:
+ display_print_info_3(ctr.printers_3);
+ break;
+ default:
+ printf("unknown info level %d\n", info_level);
+ break;
+ }
- if (status == NT_STATUS_NOPROBLEMO)
- {
- DEBUG(5,("cmd_spoolss_getprinterdata: query succeeded\n"));
- }
- else
- {
- report(out_hnd, "FAILED\n");
- }
+ done:
+ if (opened_hnd)
+ cli_spoolss_close_printer(cli, &pol);
+
+ cli_nt_session_close(cli);
- return status;
+ return result;
}
/****************************************************************************
-nt spoolss query
+printer info level 0 display function
****************************************************************************/
-uint32 cmd_spoolss_getprinterdriver(struct client_info *info, int argc, char *argv[])
+static void display_print_driver_1(DRIVER_INFO_1 *i1)
{
- PRINTER_DRIVER_CTR ctr;
- fstring srv_name;
- fstring station;
- char *printer_name;
- fstring environment;
- uint32 level;
+ fstring name;
+ if (i1 == NULL)
+ return;
- ZERO_STRUCT(ctr);
+ unistr_to_ascii(name, i1->name.buffer, sizeof(name)-1);
- if (argc < 2) {
- report(out_hnd, "spoolgetprinterdriver <printer name>\n");
- return NT_STATUS_INVALID_PARAMETER;
- }
-
- printer_name = argv[1];
-
- fstrcpy(station, "\\\\");
- fstrcat(station, info->myhostname);
- strupper(station);
-
- fstrcpy(srv_name, "\\\\");
- fstrcat(srv_name, info->dest_host);
- strupper(srv_name);
-
- if (!strnequal("\\\\", printer_name, 2))
- {
- fstrcat(srv_name, "\\");
- fstrcat(srv_name, printer_name);
- printer_name = srv_name;
- }
-
- report (out_hnd, "Environment = Windows NT x86\n");
- fstrcpy(environment, "Windows NT x86");
- level=3;
- if (msrpc_spoolss_getprinterdriver(printer_name, environment, level, station, "Administrator", ctr))
- DEBUG(5,("cmd_spoolss_getprinterdriver: query succeeded\n"));
- else
- report(out_hnd, "FAILED\n");
-
- report (out_hnd, "Environment = Windows 4.0\n");
- fstrcpy(environment, "Windows 4.0");
- level=3;
- if (msrpc_spoolss_getprinterdriver(printer_name, environment, level, station, "Administrator", ctr))
- DEBUG(5,("cmd_spoolss_getprinterdriver: query succeeded\n"));
- else
- report(out_hnd, "FAILED\n");
-
- return NT_STATUS_NOPROBLEMO;
+ printf ("Printer Driver Info 1:\n");
+ printf ("\tDriver Name: [%s]\n\n", name);
+
+ return;
}
/****************************************************************************
-nt spoolss query
+printer info level 1 display function
****************************************************************************/
-uint32 cmd_spoolss_enumprinterdrivers(struct client_info *info, int argc, char *argv[])
+static void display_print_driver_2(DRIVER_INFO_2 *i1)
{
- PRINTER_DRIVER_CTR ctr;
- fstring srv_name;
- fstring environment;
- uint32 level;
-
- ZERO_STRUCT(ctr);
- fstrcpy(srv_name, "\\\\");
- fstrcat(srv_name, info->dest_host);
- strupper(srv_name);
+ fstring name;
+ fstring architecture;
+ fstring driverpath;
+ fstring datafile;
+ fstring configfile;
+ if (i1 == NULL)
+ return;
+
+ unistr_to_ascii(name, i1->name.buffer, sizeof(name)-1);
+ unistr_to_ascii(architecture, i1->architecture.buffer, sizeof(architecture)-1);
+ unistr_to_ascii(driverpath, i1->driverpath.buffer, sizeof(driverpath)-1);
+ unistr_to_ascii(datafile, i1->datafile.buffer, sizeof(datafile)-1);
+ unistr_to_ascii(configfile, i1->configfile.buffer, sizeof(configfile)-1);
+
+ printf ("Printer Driver Info 2:\n");
+ printf ("\tVersion: [%x]\n", i1->version);
+ printf ("\tDriver Name: [%s]\n", name);
+ printf ("\tArchitecture: [%s]\n", architecture);
+ printf ("\tDriver Path: [%s]\n", driverpath);
+ printf ("\tDatafile: [%s]\n", datafile);
+ printf ("\tConfigfile: [%s]\n\n", configfile);
- fstrcpy(environment, "Windows NT x86");
- level=3;
-
- if (msrpc_spoolss_enumprinterdrivers(srv_name, environment, level, ctr))
- DEBUG(5,("cmd_spoolss_enumprinterdrivers: query succeeded\n"));
- else
- report(out_hnd, "FAILED\n");
-
- return NT_STATUS_NOPROBLEMO;
+ return;
}
/****************************************************************************
-nt spoolss query
+printer info level 2 display function
****************************************************************************/
-uint32 cmd_spoolss_getprinterdriverdir(struct client_info *info, int argc, char *argv[])
+static void display_print_driver_3(DRIVER_INFO_3 *i1)
{
- DRIVER_DIRECTORY_CTR ctr;
- int i;
-
- uint32 level = 1;
-
- fstring srv_name;
- fstring env;
-
- ZERO_STRUCT(ctr);
- fstrcpy(srv_name, "\\\\");
- fstrcat(srv_name, info->dest_host);
- strupper(srv_name);
-
- if (argc < 2) {
- report(out_hnd, "spoolgetprinterdriverdir <arch>\n");
- return NT_STATUS_NOPROBLEMO;
- }
-
- fstrcpy(env, argv[1]);
-
- for (i=3; i<=argc; i++) {
- fstrcat(env, " ");
- fstrcat(env, argv[i]);
- }
+ fstring name;
+ fstring architecture;
+ fstring driverpath;
+ fstring datafile;
+ fstring configfile;
+ fstring helpfile;
+ fstring dependentfiles;
+ fstring monitorname;
+ fstring defaultdatatype;
+
+ int length=0;
+ BOOL valid = True;
+
+ if (i1 == NULL)
+ return;
+
+ unistr_to_ascii(name, i1->name.buffer, sizeof(name)-1);
+ unistr_to_ascii(architecture, i1->architecture.buffer, sizeof(architecture)-1);
+ unistr_to_ascii(driverpath, i1->driverpath.buffer, sizeof(driverpath)-1);
+ unistr_to_ascii(datafile, i1->datafile.buffer, sizeof(datafile)-1);
+ unistr_to_ascii(configfile, i1->configfile.buffer, sizeof(configfile)-1);
+ unistr_to_ascii(helpfile, i1->helpfile.buffer, sizeof(helpfile)-1);
+
+ unistr_to_ascii(monitorname, i1->monitorname.buffer, sizeof(monitorname)-1);
+ unistr_to_ascii(defaultdatatype, i1->defaultdatatype.buffer, sizeof(defaultdatatype)-1);
+
+ printf ("Printer Driver Info 3:\n");
+ printf ("\tVersion: [%x]\n", i1->version);
+ printf ("\tDriver Name: [%s]\n",name );
+ printf ("\tArchitecture: [%s]\n", architecture);
+ printf ("\tDriver Path: [%s]\n", driverpath);
+ printf ("\tDatafile: [%s]\n", datafile);
+ printf ("\tConfigfile: [%s]\n", configfile);
+ printf ("\tHelpfile: [%s]\n\n", helpfile);
+
+ while (valid)
+ {
+ unistr_to_ascii(dependentfiles, i1->dependentfiles+length, sizeof(dependentfiles)-1);
+ length+=strlen(dependentfiles)+1;
+
+ if (strlen(dependentfiles) > 0)
+ {
+ printf ("\tDependentfiles: [%s]\n", dependentfiles);
+ }
+ else
+ {
+ valid = False;
+ }
+ }
+
+ printf ("\n");
- if (msrpc_spoolss_getprinterdriverdir(srv_name, env, level, ctr))
- DEBUG(5,("cmd_spoolss_getprinterdriverdir: query succeeded\n"));
- else
- report(out_hnd, "FAILED\n");
+ printf ("\tMonitorname: [%s]\n", monitorname);
+ printf ("\tDefaultdatatype: [%s]\n\n", defaultdatatype);
- return NT_STATUS_NOPROBLEMO;
+ return;
}
-/********************************************************************************
- send an AddPrinterEx() request
-********************************************************************************/
-uint32 cmd_spoolss_addprinterex(struct client_info *info, int argc, char *argv[])
+/***********************************************************************
+ * Get printer information
+ */
+static uint32 cmd_spoolss_getdriver(struct cli_state *cli, int argc, char **argv)
{
- fstring srv_name,
- printer_name,
- driver_name,
- port_name,
- share_name;
- POLICY_HND hnd;
- PRINTER_INFO_2 print_info_2;
- PORT_INFO_1 *port_info_1 = NULL;
- NEW_BUFFER buffer;
- uint32 status,
- needed,
- returned;
+ POLICY_HND pol;
+ uint32 result,
+ info_level = 3;
+ BOOL opened_hnd = False;
+ PRINTER_DRIVER_CTR ctr;
+ fstring printername,
+ server,
+ user;
uint32 i;
- fstring srv_port_name;
- BOOL valid_port = False;
- TALLOC_CTX *mem_ctx = NULL;
-
- fstrcpy(srv_name, "\\\\");
- fstrcat(srv_name, info->dest_host);
- strupper(srv_name);
-
- /* check (and copy) the command line arguments */
- if (argc < 5) {
- report(out_hnd, "spooladdprinterex <name> <shared name> <driver> <port>\n");
- return NT_STATUS_INVALID_PARAMETER;
- }
- else
+
+ if ((argc == 1) || (argc > 3))
{
- fstrcpy(printer_name, argv[1]);
- fstrcpy(share_name, argv[2]);
- fstrcpy(driver_name, argv[3]);
- fstrcpy(port_name, argv[4]);
+ printf("Usage: %s <printername> [level]\n", argv[0]);
+ return NT_STATUS_NOPROBLEMO;
}
-
- /* Verify that the specified port is ok; spoolss_enum_ports() should
- be a level 1 since all we need is the name */
- if ((mem_ctx=talloc_init()) == NULL)
+
+ /* Initialise RPC connection */
+ if (!cli_nt_session_open (cli, PIPE_SPOOLSS))
{
- DEBUG(0, ("cmd_spoolss_addprinterex: talloc_init() failed!\n"));
- return NT_STATUS_INVALID_PARAMETER;
+ fprintf (stderr, "Could not initialize spoolss pipe!\n");
+ return NT_STATUS_UNSUCCESSFUL;
}
- init_buffer (&buffer, 0, mem_ctx);
-
- /* send a NULL buffer first */
- status=spoolss_enum_ports(srv_name, 1, &buffer, 0,
- &needed, &returned);
-
- /* send the right amount of space this time */
- if (status==ERROR_INSUFFICIENT_BUFFER) {
- init_buffer(&buffer, needed, mem_ctx);
- status=spoolss_enum_ports(srv_name, 1, &buffer,
- needed, &needed, &returned);
-
- /* if the call succeeded, then decode the buffer into
- an PRINTER_INFO_1 structre */
- if (status == NT_STATUS_NO_PROBLEMO)
- {
- decode_port_info_1(&buffer, returned, &port_info_1);
- }
- else
- {
- report (out_hnd, "cmd_spoolss_addprinterex: FAILED to enumerate ports\n");
- return NT_STATUS_NOPROBLEMO;
- }
+
+ /* get the arguments need to open the printer handle */
+ slprintf (server, sizeof(fstring), "\\\\%s", cli->desthost);
+ strupper (server);
+ fstrcpy (user, cli->user_name);
+ fstrcpy (printername, argv[1]);
+ if (argc == 3)
+ info_level = atoi(argv[2]);
+
+ /* Open a printer handle */
+ if ((result=cli_spoolss_open_printer_ex (cli, printername, "",
+ MAXIMUM_ALLOWED_ACCESS, server, user, &pol)) != NT_STATUS_NO_PROBLEMO)
+ {
+ printf ("Error opening printer handle for %s!\n", printername);
+ return result;
}
-
- /*
- * now we have an array of port names and we can interate
- * through it to verify port_name before actually attempting
- * to add the printer on the server.
- */
- for (i=0; i<returned; i++)
+
+ opened_hnd = True;
+
+ /* loop through and print driver info level for each architecture */
+ for (i=0; archi_table[i].long_archi!=NULL; i++)
{
- /* compare port_info_1[i].port_name to the port_name specified */
- unistr_to_ascii(srv_port_name, port_info_1[i].port_name.buffer,
- sizeof(srv_port_name)-1);
- if (strequal(srv_port_name, port_name))
+ result = cli_spoolss_getprinterdriver (cli, &pol, info_level,
+ archi_table[i].long_archi, &ctr);
+
+ switch (result)
{
- valid_port = True;
+ case NT_STATUS_NO_PROBLEMO:
break;
+
+ case ERROR_UNKNOWN_PRINTER_DRIVER:
+ continue;
+
+ default:
+ printf ("Error getting driver for %s [%s] - %s\n", printername,
+ archi_table[i].long_archi, get_nt_error_msg(result));
+ continue;
}
- }
- if (!valid_port)
- {
- report (out_hnd, "cmd_spoolss_addprinterex: Invalid port specified!\n");
- return NT_STATUS_NOPROBLEMO;
+
+
+ printf ("\n[%s]\n", archi_table[i].long_archi);
+ switch (info_level)
+ {
+
+ case 1:
+ display_print_driver_1 (ctr.info1);
+ break;
+ case 2:
+ display_print_driver_2 (ctr.info2);
+ break;
+ case 3:
+ display_print_driver_3 (ctr.info3);
+ break;
+ default:
+ printf("unknown info level %d\n", info_level);
+ break;
+ }
+
+
}
- /*
- * Need to build the PRINTER_INFO_2 struct here.
- * I think it would be better only to deal with a PRINTER_INFO_2
- * and the abstract the creation of a SPOOL_PRINTER_INFO_LEVEL_2
- * from that rather than dealing with the struct passed directly
- * on the wire. We don't need the extra *_ptr fields, etc...
- * here anyways. --jerry
- */
- ZERO_STRUCTP(&print_info_2);
- /* init_unistr( &print_info_2.servername, srv_name); */
- init_unistr( &print_info_2.printername, printer_name);
- init_unistr( &print_info_2.sharename, share_name);
- init_unistr( &print_info_2.portname, port_name);
- init_unistr( &print_info_2.drivername, driver_name);
- init_unistr( &print_info_2.comment, "Created by rpcclient");
- init_unistr( &print_info_2.printprocessor, "winprint");
- init_unistr( &print_info_2.datatype, "RAW");
- print_info_2.devmode = NULL;
- print_info_2.secdesc = NULL;
- print_info_2.attributes = PRINTER_ATTRIBUTE_SHARED;
- print_info_2.priority = 0;
- print_info_2.defaultpriority = 0;
- print_info_2.starttime = 0;
- print_info_2.untiltime = 0;
+
+ /* cleanup */
+ if (opened_hnd)
+ cli_spoolss_close_printer (cli, &pol);
+ cli_nt_session_close (cli);
- /* These three fields must not be used by AddPrinter()
- as defined in the MS Platform SDK documentation.. --jerry
- print_info_2.status = 0;
- print_info_2.cjobs = 0;
- print_info_2.averageppm = 0;
- */
+ if (result==ERROR_UNKNOWN_PRINTER_DRIVER)
+ return NT_STATUS_NO_PROBLEMO;
+ else
+ return result;
+
+}
+/***********************************************************************
+ * Get printer information
+ */
+static uint32 cmd_spoolss_enum_drivers(struct cli_state *cli, int argc, char **argv)
+{
+ uint32 result,
+ info_level = 1;
+ PRINTER_DRIVER_CTR ctr;
+ fstring server;
+ uint32 i, j,
+ returned;
- /* if successful, spoolss_addprinterex() should return True and hnd
- should be a valid handle to an open printer */
- if (spoolss_addprinterex(&hnd, srv_name, &print_info_2))
+ if (argc > 2)
{
- DEBUG(0,("cmd_spoolss_addprinterex: [%s] added successfully.\n", printer_name));
- if (!spoolss_closeprinter( &hnd ))
- {
- report (out_hnd, "cmd_spoolss_addprinterex: spoolss_closeprinter FAILED!\n");
- }
+ printf("Usage: enumdrivers [level]\n");
+ return NT_STATUS_NOPROBLEMO;
}
- else
+
+ /* Initialise RPC connection */
+ if (!cli_nt_session_open (cli, PIPE_SPOOLSS))
{
- report (out_hnd, "cmd_spoolss_addprinterex: spoolss_addprinterex FAILED!\n");
+ fprintf (stderr, "Could not initialize spoolss pipe!\n");
+ return NT_STATUS_UNSUCCESSFUL;
}
-
- return NT_STATUS_NOPROBLEMO;
-}
-
-/********************************************************************************
- send an AddPrinterDriver() request
-********************************************************************************/
-uint32 cmd_spoolss_addprinterdriver(struct client_info *info, int argc, char *argv[])
-{
- PRINTER_DRIVER_CTR driver_info;
- DRIVER_INFO_3 info3;
- fstring arch;
- fstring srv_name;
- uint32 result = NT_STATUS_NO_PROBLEMO;
-
- /* parse the command arguements */
- if (argc < 3)
- {
- report (out_hnd, "spooladdprinterdriver <arch>\\\n");
- report (out_hnd, "\t<Long Printer Name>:<Driver File Name>:<Data File Name>:\\\n");
- report (out_hnd, "\t<Config File Name>:<Help File Name>:<Language Monitor Name>:\\\n");
- report (out_hnd, "\t<Default Data Type>:<Comma Separated list of Files>\n");
+ /* get the arguments need to open the printer handle */
+ slprintf (server, sizeof(fstring), "\\\\%s", cli->desthost);
+ strupper (server);
+ if (argc == 2)
+ info_level = atoi(argv[1]);
- return NT_STATUS_INVALID_PARAMETER;
- }
- else
+
+ /* loop through and print driver info level for each architecture */
+ for (i=0; archi_table[i].long_archi!=NULL; i++)
{
- ZERO_STRUCT(info3);
-
- /* get the enviorment for the driver */
- if (!get_short_archi(arch, argv[1]))
- {
- report (out_hnd, "Unknown architechture [%s]\n", argv[1]);
- return NT_STATUS_INVALID_PARAMETER;
+ returned = 0;
+ result = cli_spoolss_enumprinterdrivers (cli, info_level,
+ archi_table[i].long_archi, &returned, &ctr);
+
+ if (returned == 0)
+ continue;
- }
- else
+
+ if (result != NT_STATUS_NO_PROBLEMO)
{
- set_drv_info_3_env(&info3, arch);
+ printf ("Error getting driver for environment [%s] - %s\n",
+ archi_table[i].long_archi, get_nt_error_msg(result));
+ continue;
}
- /* fill in the other struct members */
- if (!init_drv_info_3_members(&info3, argv[2]))
+ printf ("\n[%s]\n", archi_table[i].long_archi);
+ switch (info_level)
{
- report (out_hnd, "Invalid parameter list.\n");
- return NT_STATUS_INVALID_PARAMETER;
+
+ case 1:
+ for (j=0; j < returned; j++) {
+ display_print_driver_1 (&(ctr.info1[j]));
+ }
+ break;
+ case 2:
+ for (j=0; j < returned; j++) {
+ display_print_driver_2 (&(ctr.info2[j]));
+ }
+ break;
+ case 3:
+ for (j=0; j < returned; j++) {
+ display_print_driver_3 (&(ctr.info3[j]));
+ }
+ break;
+ default:
+ printf("unknown info level %d\n", info_level);
+ break;
}
}
- /* get the server name */
- fstrcpy(srv_name, "\\\\");
- fstrcat(srv_name, info->dest_host);
- strupper(srv_name);
+
+ /* cleanup */
+ cli_nt_session_close (cli);
- /* call AddPrinterDriver() woth an info level 3 */
- driver_info.info3 = &info3;
- if ((result=spoolss_addprinterdriver(srv_name, 3, &driver_info)) != NT_STATUS_NO_PROBLEMO)
+ if (result==ERROR_UNKNOWN_PRINTER_DRIVER)
+ return NT_STATUS_NO_PROBLEMO;
+ else
+ return result;
+
+}
+
+/****************************************************************************
+printer info level 1 display function
+****************************************************************************/
+static void display_printdriverdir_1(DRIVER_DIRECTORY_1 *i1)
+{
+ fstring name;
+ if (i1 == NULL)
+ return;
+
+ unistr_to_ascii(name, i1->name.buffer, sizeof(name)-1);
+
+ printf ("\tDirectory Name:[%s]\n", name);
+}
+
+/***********************************************************************
+ * Get printer driver directory information
+ */
+static uint32 cmd_spoolss_getdriverdir(struct cli_state *cli, int argc, char **argv)
+{
+ uint32 result;
+ fstring env;
+ DRIVER_DIRECTORY_CTR ctr;
+
+ if (argc > 2)
+ {
+ printf("Usage: %s [environment]\n", argv[0]);
+ return NT_STATUS_NOPROBLEMO;
+ }
+
+ /* Initialise RPC connection */
+ if (!cli_nt_session_open (cli, PIPE_SPOOLSS))
{
- report( out_hnd, "spoolss_addprinterdriver: Add Printer failed [%d]\n",
- result);
+ fprintf (stderr, "Could not initialize spoolss pipe!\n");
+ return NT_STATUS_UNSUCCESSFUL;
}
+
+ /* get the arguments need to open the printer handle */
+ if (argc == 2)
+ fstrcpy (env, argv[1]);
else
+ fstrcpy (env, "Windows NT x86");
+
+ /* Get the directory. Only use Info level 1 */
+ if ((result = cli_spoolss_getprinterdriverdir (cli, 1, env, &ctr))
+ != NT_STATUS_NO_PROBLEMO)
{
- fstring driver_name;
- unistr_to_ascii (driver_name, info3.name.buffer, sizeof(driver_name)-1);
- report( out_hnd, "cmd_spoolss_addprinterdriver: Printer Driver [%s] added successfully\n", driver_name);
+ return result;
}
+
- free_drv_info_3(&info3);
+ display_printdriverdir_1 (ctr.info1);
+
+ /* cleanup */
+ cli_nt_session_close (cli);
- return result;
-}
+ return result;
+
+}
/*******************************************************************************
set the version and environment fields of a DRIVER_INFO_3 struct
******************************************************************************/
void set_drv_info_3_env (DRIVER_INFO_3 *info, const char *arch)
{
- if (strcmp(arch, "WIN40") == 0)
- {
- info->version = 0;
- init_unistr(&info->architecture, "Windows 4.0");
- }
- else if (strcmp(arch, "W32X86") == 0)
- {
- info->version = 2;
- init_unistr(&info->architecture, "Windows NT x86");
- }
- else if (strcmp(arch, "W32MIPS") == 0)
- {
- info->version = 2;
- init_unistr(&info->architecture, "Windows NT R4000");
- }
- else if (strcmp(arch, "W32ALPHA") == 0)
- {
- info->version = 2;
- init_unistr(&info->architecture, "Windows NT Alpha_AXP");
- }
- else if (strcmp(arch, "W32PPC") == 0)
+
+ int i;
+
+ for (i=0; archi_table[i].long_archi != NULL; i++)
{
- info->version = 2;
- init_unistr(&info->architecture, "Windows NT PowerPC");
+ if (strcmp(arch, archi_table[i].short_archi) == 0)
+ {
+ info->version = archi_table[i].version;
+ init_unistr (&info->architecture, archi_table[i].long_archi);
+ break;
+ }
}
- else
+
+ if (archi_table[i].long_archi == NULL)
{
DEBUG(0, ("set_drv_info_3_env: Unknown arch [%s]\n", arch));
}
return;
}
+
/**************************************************************************
wrapper for strtok to get the next parameter from a delimited list.
Needed to handle the empty parameter string denoted by "NULL"
<Config File Name>:<Help File Name>:<Language Monitor Name>:\
<Default Data Type>:<Comma Separated list of Files>
*******************************************************************************/
-BOOL init_drv_info_3_members (DRIVER_INFO_3 *info, char *args)
+static BOOL init_drv_info_3_members (DRIVER_INFO_3 *info, char *args)
{
char *str, *str2;
uint32 len, i;
return True;
}
-/*****************************************************************************
- free any dynamically allocated members
- ****************************************************************************/
-void free_drv_info_3 (DRIVER_INFO_3 *info)
+
+static uint32 cmd_spoolss_addprinterdriver (struct cli_state *cli, int argc, char **argv)
{
- if (info->dependentfiles != NULL)
+ uint32 result,
+ level = 3;
+ PRINTER_DRIVER_CTR ctr;
+ DRIVER_INFO_3 info3;
+ fstring arch;
+ fstring driver_name;
+
+ /* parse the command arguements */
+ if (argc != 3)
+ {
+ printf ("Usage: %s <Environment>\\\n", argv[0]);
+ printf ("\t<Long Printer Name>:<Driver File Name>:<Data File Name>:\\\n");
+ printf ("\t<Config File Name>:<Help File Name>:<Language Monitor Name>:\\\n");
+ printf ("\t<Default Data Type>:<Comma Separated list of Files>\n");
+
+ return NT_STATUS_NOPROBLEMO;
+ }
+
+ /* Initialise RPC connection */
+ if (!cli_nt_session_open (cli, PIPE_SPOOLSS))
{
- free(info->dependentfiles);
- info->dependentfiles = NULL;
+ fprintf (stderr, "Could not initialize spoolss pipe!\n");
+ return NT_STATUS_UNSUCCESSFUL;
}
+
+
+ /* Fill in the DRIVER_INFO_3 struct */
+ ZERO_STRUCT(info3);
+ if (!get_short_archi(arch, argv[1]))
+ {
+ printf ("Error Unknown architechture [%s]\n", argv[1]);
+ return NT_STATUS_INVALID_PARAMETER;
+ }
+ else
+ set_drv_info_3_env(&info3, arch);
+
+ if (!init_drv_info_3_members(&info3, argv[2]))
+ {
+ printf ("Error Invalid parameter list - %s.\n", argv[2]);
+ return NT_STATUS_INVALID_PARAMETER;
+ }
+
+
+ /* Get the directory. Only use Info level 1 */
+ ctr.info3 = &info3;
+ if ((result = cli_spoolss_addprinterdriver (cli, level, &ctr))
+ != NT_STATUS_NO_PROBLEMO)
+ {
+ return result;
+ }
+
+ unistr_to_ascii (driver_name, info3.name.buffer, sizeof(driver_name)-1);
+ printf ("Printer Driver %s successfully installed.\n", driver_name);
+
+ /* cleanup */
+ cli_nt_session_close (cli);
- return;
+ return result;
+
}
+static uint32 cmd_spoolss_addprinterex (struct cli_state *cli, int argc, char **argv)
+{
+ uint32 result,
+ level = 2;
+ PRINTER_INFO_CTR ctr;
+ PRINTER_INFO_2 info2;
+ fstring server;
+
+ /* parse the command arguements */
+ if (argc != 5)
+ {
+ printf ("Usage: %s <name> <shared name> <driver> <port>\n", argv[0]);
+ return NT_STATUS_NOPROBLEMO;
+ }
+
+ slprintf (server, sizeof(fstring), "\\\\%s", cli->desthost);
+ strupper (server);
+
+ /* Initialise RPC connection */
+ if (!cli_nt_session_open (cli, PIPE_SPOOLSS))
+ {
+ fprintf (stderr, "Could not initialize spoolss pipe!\n");
+ return NT_STATUS_UNSUCCESSFUL;
+ }
+
+
+ /* Fill in the DRIVER_INFO_3 struct */
+ ZERO_STRUCT(info2);
+#if 0 /* JERRY */
+ init_unistr( &info2.servername, server);
+#endif
+ init_unistr( &info2.printername, argv[1]);
+ init_unistr( &info2.sharename, argv[2]);
+ init_unistr( &info2.drivername, argv[3]);
+ init_unistr( &info2.portname, argv[4]);
+ init_unistr( &info2.comment, "Created by rpcclient");
+ init_unistr( &info2.printprocessor, "winprint");
+ init_unistr( &info2.datatype, "RAW");
+ info2.devmode = NULL;
+ info2.secdesc = NULL;
+ info2.attributes = PRINTER_ATTRIBUTE_SHARED;
+ info2.priority = 0;
+ info2.defaultpriority = 0;
+ info2.starttime = 0;
+ info2.untiltime = 0;
+
+ /* These three fields must not be used by AddPrinter()
+ as defined in the MS Platform SDK documentation..
+ --jerry
+ info2.status = 0;
+ info2.cjobs = 0;
+ info2.averageppm = 0;
+ */
+
+
+
+ /* Get the directory. Only use Info level 1 */
+ ctr.printers_2 = &info2;
+ if ((result = cli_spoolss_addprinterex (cli, level, &ctr))
+ != NT_STATUS_NO_PROBLEMO)
+ {
+ return result;
+ }
+
+ printf ("Printer %s successfully installed.\n", argv[1]);
+
+ /* cleanup */
+ cli_nt_session_close (cli);
+
+ return result;
+
+}
+
+/* List of commands exported by this module */
+struct cmd_set spoolss_commands[] = {
+
+ { "SPOOLSS", NULL, "" },
+ { "adddriver", cmd_spoolss_addprinterdriver, "Add a print driver" },
+ { "addprinter", cmd_spoolss_addprinterex, "Add a printer" },
+ { "enumdata", cmd_spoolss_not_implemented, "Enumerate printer data (*)" },
+ { "enumjobs", cmd_spoolss_not_implemented, "Enumerate print jobs (*)" },
+ { "enumports", cmd_spoolss_enum_ports, "Enumerate printer ports" },
+ { "enumdrivers", cmd_spoolss_enum_drivers, "Enumerate installed printer drivers" },
+ { "enumprinters", cmd_spoolss_enum_printers, "Enumerate printers" },
+ { "getdata", cmd_spoolss_not_implemented, "Get print driver data (*)" },
+ { "getdriver", cmd_spoolss_getdriver, "Get print driver information" },
+ { "getdriverdir", cmd_spoolss_getdriverdir, "Get print driver upload directory" },
+ { "getprinter", cmd_spoolss_getprinter, "Get printer info" },
+ { "openprinter", cmd_spoolss_open_printer_ex, "Open printer handle" },
+ { NULL, NULL, NULL }
+};
/*
Unix SMB/Netbios implementation.
- Version 1.9.
- SMB client
- Copyright (C) Andrew Tridgell 1994-2000
- Copyright (C) Luke Kenneth Casson Leighton 1996-2000
-
+ Version 2.2
+ RPC pipe client
+
+ Copyright (C) Tim Potter 2000
+
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
*/
#include "includes.h"
-#include "ntdomain.h"
-#include "rpcclient.h"
+
+extern int DEBUGLEVEL;
+extern fstring debugf;
+
+/* Various pipe commands */
+extern struct cmd_set lsarpc_commands[];
+extern struct cmd_set samr_commands[];
+extern struct cmd_set spoolss_commands[];
+
+
+DOM_SID domain_sid;
+/***********************************************************************
+ * read in username/password credentials from a file
+ */
+static void read_authfile (
+ char *filename,
+ char* username,
+ char* password,
+ char* domain
+)
+{
+ FILE *auth;
+ fstring buf;
+ uint16 len = 0;
+ char *ptr, *val, *param;
+
+ if ((auth=sys_fopen(filename, "r")) == NULL)
+ {
+ printf ("ERROR: Unable to open credentials file!\n");
+ return;
+ }
+
+ while (!feof(auth))
+ {
+ /* get a line from the file */
+ if (!fgets (buf, sizeof(buf), auth))
+ continue;
+
+ len = strlen(buf);
+
+ /* skip empty lines */
+ if ((len) && (buf[len-1]=='\n'))
+ {
+ buf[len-1] = '\0';
+ len--;
+ }
+ if (len == 0)
+ continue;
+
+ /* break up the line into parameter & value.
+ will need to eat a little whitespace possibly */
+ param = buf;
+ if (!(ptr = strchr (buf, '=')))
+ continue;
+ val = ptr+1;
+ *ptr = '\0';
+
+ /* eat leading white space */
+ while ((*val!='\0') && ((*val==' ') || (*val=='\t')))
+ val++;
+
+ if (strwicmp("password", param) == 0)
+ fstrcpy (password, val);
+ else if (strwicmp("username", param) == 0)
+ fstrcpy (username, val);
+ else if (strwicmp("domain", param) == 0)
+ fstrcpy (domain, val);
+
+ memset(buf, 0, sizeof(buf));
+ }
+ fclose(auth);
+
+ return;
+}
+
+static char* next_command (
+ char** cmdstr
+)
+{
+ static pstring command;
+ char *p;
+
+ if (!cmdstr || !(*cmdstr))
+ return NULL;
+
+ p = strchr(*cmdstr, ';');
+ if (p)
+ *p = '\0';
+ pstrcpy(command, *cmdstr);
+ *cmdstr = p;
+
+ return command;
+}
+
+static void get_username (char *username)
+{
+ if (getenv("USER"))
+ pstrcpy(username,getenv("USER"));
+
+ if (*username == 0 && getenv("LOGNAME"))
+ pstrcpy(username,getenv("LOGNAME"));
+
+ if (*username == 0) {
+ pstrcpy(username,"GUEST");
+ }
+
+ return;
+}
+
+/* Fetch the SID for this domain */
+void fetch_domain_sid(struct cli_state *cli)
+{
+ POLICY_HND pol;
+ uint32 result = 0, info_class = 5;
+ fstring domain_name;
+ static BOOL got_domain_sid;
+
+ if (got_domain_sid) return;
+
+
+ if (!cli_nt_session_open (cli, PIPE_LSARPC)) {
+ fprintf(stderr, "could not initialise lsa pipe\n");
+ goto error;
+ }
+
+ if ((result = cli_lsa_open_policy(cli, True,
+ SEC_RIGHTS_MAXIMUM_ALLOWED,
+ &pol) != NT_STATUS_NOPROBLEMO)) {
+ goto error;
+ }
+
+ if ((result = cli_lsa_query_info_policy(cli, &pol, info_class,
+ domain_name, &domain_sid))
+ != NT_STATUS_NOPROBLEMO) {
+ goto error;
+ }
+
+ got_domain_sid = True;
+
+ cli_lsa_close(cli, &pol);
+ cli_nt_session_close(cli);
+
+ return;
+
+ error:
+ fprintf(stderr, "could not obtain sid for domain %s\n", cli->domain);
+
+ if (result != NT_STATUS_NOPROBLEMO) {
+ fprintf(stderr, "error: %s\n", get_nt_error_msg(result));
+ }
+
+ exit(1);
+}
+
+/* Initialise client credentials for authenticated pipe access */
+
+void init_rpcclient_creds(struct ntuser_creds *creds, char* username,
+ char* domain, char* password)
+{
+ ZERO_STRUCTP(creds);
+
+ if (lp_encrypted_passwords()) {
+ pwd_make_lm_nt_16(&creds->pwd, password);
+ } else {
+ pwd_set_cleartext(&creds->pwd, password);
+ }
+
+ fstrcpy(creds->user_name, username);
+ fstrcpy(creds->domain, domain);
+}
+
+/* List to hold groups of commands */
+
+static struct cmd_list {
+ struct cmd_list *prev, *next;
+ struct cmd_set *cmd_set;
+} *cmd_list;
+
+static uint32 cmd_help(struct cli_state *cli, int argc, char **argv)
+{
+ struct cmd_list *temp_list;
+
+ for (temp_list = cmd_list; temp_list; temp_list = temp_list->next) {
+ struct cmd_set *temp_set = temp_list->cmd_set;
+
+ while(temp_set->name) {
+ printf("%15s\t\t%s\n", temp_set->name,
+ temp_set->description);
+ temp_set++;
+ }
+ }
+
+ return 0;
+}
+
+static uint32 cmd_debuglevel(struct cli_state *cli, int argc, char **argv)
+{
+ if (argc > 2) {
+ printf("Usage: %s [debuglevel]\n", argv[0]);
+ return NT_STATUS_NOPROBLEMO;
+ }
+
+ if (argc == 2) {
+ DEBUGLEVEL = atoi(argv[1]);
+ }
+
+ printf("debuglevel is %d\n", DEBUGLEVEL);
+
+ return NT_STATUS_NOPROBLEMO;
+}
+
+static uint32 cmd_quit(struct cli_state *cli, int argc, char **argv)
+{
+ exit(0);
+}
+
+/* Build in rpcclient commands */
+
+static struct cmd_set rpcclient_commands[] = {
+ { "GENERAL OPTIONS", NULL, "" },
+ { "help", cmd_help, "Print list of commands" },
+ { "?", cmd_help, "Print list of commands" },
+ { "debuglevel", cmd_debuglevel, "Set debug level" },
+ { "exit", cmd_quit, "Exit program" },
+ { "quit", cmd_quit, "Exit program" },
+
+ { NULL, NULL, NULL }
+};
+
+static struct cmd_set separator_command[] = {
+ { "---------------", NULL, "----------------------" },
+ { NULL, NULL, NULL }
+};
+
+
+void add_command_set(struct cmd_set *cmd_set)
+{
+ struct cmd_list *entry;
+
+ if (!(entry = (struct cmd_list *)malloc(sizeof(struct cmd_list)))) {
+ DEBUG(0, ("out of memory\n"));
+ return;
+ }
+
+ ZERO_STRUCTP(entry);
+
+ entry->cmd_set = cmd_set;
+ DLIST_ADD(cmd_list, entry);
+}
+
+static uint32 do_cmd(struct cli_state *cli, struct cmd_set *cmd_entry, char *cmd)
+{
+ char *p = cmd, **argv = NULL;
+ uint32 result;
+ pstring buf;
+ int argc = 1, i;
+
+ next_token(&p, buf, " ", sizeof(buf));
+
+ /* Count number of arguments first time through the loop then
+ allocate memory and strdup them. */
+
+ again:
+ while(next_token(NULL, buf, " ", sizeof(buf))) {
+ if (argv) {
+ argv[argc] = strdup(buf);
+ }
+
+ argc++;
+ }
+
+ if (!argv) {
+
+ /* Create argument list */
+
+ argv = (char **)malloc(sizeof(char *) * argc);
+
+ if (!argv) {
+ fprintf(stderr, "out of memoryx\n");
+ return 0;
+ }
+
+ p = cmd;
+ next_token(&p, buf, " ", sizeof(buf));
+ argv[0] = strdup(buf);
+ argc = 1;
+
+ goto again;
+ }
+
+ /* Call the function */
+ if (cmd_entry->fn) {
+ result = cmd_entry->fn(cli, argc, argv);
+ }
+ else {
+ fprintf (stderr, "Invalid command\n");
+ result = NT_STATUS_INVALID_PARAMETER;
+ }
+
+
+ /* Cleanup */
+ for (i = 0; i < argc; i++) {
+ free(argv[i]);
+ }
+
+ free(argv);
+
+ return result;
+}
+
+/* Process a command entered at the prompt or as part of -c */
+
+static uint32 process_cmd(struct cli_state *cli, char *cmd)
+{
+ struct cmd_list *temp_list;
+ BOOL found = False;
+ pstring buf;
+ char *p = cmd;
+ uint32 result;
+
+ if (!next_token(&p, buf, " ", sizeof(buf))) {
+ return 0;
+ }
+
+ /* Search for matching commands */
+
+ for (temp_list = cmd_list; temp_list; temp_list = temp_list->next) {
+ struct cmd_set *temp_set = temp_list->cmd_set;
+
+ while(temp_set->name) {
+ if (strequal(buf, temp_set->name)) {
+ found = True;
+ result = do_cmd(cli, temp_set, cmd);
+ goto done;
+ }
+ temp_set++;
+ }
+ }
+
+ done:
+ if (!found && buf[0]) {
+ printf("command not found: %s\n", buf);
+ return 0;
+ }
+
+ if (result != 0) {
+ printf("result was %s\n", get_nt_error_msg(result));
+ }
+
+ return result;
+}
+
+/************************************************************************/
+struct cli_state *setup_connection(struct cli_state *cli, char *system_name,
+ struct ntuser_creds *creds)
+{
+ struct in_addr dest_ip;
+ struct nmb_name calling, called;
+ fstring dest_host;
+ extern pstring global_myname;
+ struct ntuser_creds anon;
+
+ /* Initialise cli_state information */
+ if (!cli_initialise(cli)) {
+ return NULL;
+ }
+
+ if (!creds) {
+ ZERO_STRUCT(anon);
+ anon.pwd.null_pwd = 1;
+ creds = &anon;
+ }
+
+ cli_init_creds(cli, creds);
+
+ /* Establish a SMB connection */
+ if (!resolve_srv_name(system_name, dest_host, &dest_ip)) {
+ return NULL;
+ }
+
+ make_nmb_name(&called, dns_to_netbios_name(dest_host), 0x20);
+ make_nmb_name(&calling, dns_to_netbios_name(global_myname), 0);
+
+ if (!cli_establish_connection(cli, dest_host, &dest_ip, &calling,
+ &called, "IPC$", "IPC", False, True)) {
+ return NULL;
+ }
+
+ return cli;
+}
+
+
+/* Print usage information */
+static void usage(char *pname)
+{
+ printf("Usage: %s server [options]\n", pname);
+
+ printf("\t-A authfile file containing user credentials\n");
+ printf("\t-c \"command string\" execute semicolon separated cmds\n");
+ printf("\t-d debuglevel set the debuglevel\n");
+ printf("\t-l logfile name of logfile to use as opposed to stdout\n");
+ printf("\t-h Print this help message.\n");
+ printf("\t-N don't ask for a password\n");
+ printf("\t-s configfile specify an alternative config file\n");
+ printf("\t-U username set the network username\n");
+ printf("\t-W domain set the domain name for user account\n");
+ printf("\n");
+}
+
+/* Main function */
int main(int argc, char *argv[])
{
-#if 0
- add_lsa_commands();
- add_net_commands();
- add_evt_commands();
- add_sam_commands();
- add_svc_commands();
- add_reg_commands();
- add_ntl_commands();
- add_at_commands();
- add_dfs_commands();
-#endif
- add_spl_commands();
+ extern char *optarg;
+ extern int optind;
+ struct in_addr dest_ip;
+ extern pstring global_myname;
+ BOOL got_pass = False;
+ BOOL interactive = True;
+ BOOL have_ip = False;
+ int opt;
+ int olddebug;
+ pstring cmdstr = "",
+ servicesf = CONFIGFILE;
+ struct ntuser_creds creds;
+ struct cli_state cli;
+ fstring password,
+ username,
+ domain,
+ server;
+
+ charset_initialise();
+ setlinebuf(stdout);
+
+#ifdef HAVE_LIBREADLINE
+ /* Allow conditional parsing of the ~/.inputrc file. */
+ rl_readline_name = "rpcclient";
+#endif
+
+ DEBUGLEVEL = 1;
+
+ /* Parse options */
+ if (argc < 2) {
+ usage(argv[0]);
+ return 0;
+ }
+
+ pstrcpy(server, argv[1]);
+
+ argv++;
+ argc--;
+
+ while ((opt = getopt(argc, argv, "A:s:Nd:I:U:W:c:l:")) != EOF) {
+ switch (opt) {
+ case 'A':
+ /* only get the username, password, and domain from the file */
+ read_authfile (optarg, username, password, domain);
+ if (strlen (password))
+ got_pass = True;
+ break;
+
+ case 'c':
+ pstrcpy(cmdstr, optarg);
+ break;
+
+ case 'd':
+ DEBUGLEVEL = atoi(optarg);
+ break;
+
+ case 'I':
+ dest_ip = *interpret_addr2(optarg);
+ have_ip = True;
+ break;
+
+ case 'l':
+ slprintf(debugf, sizeof(debugf) - 1, "%s.client", optarg);
+ interactive = False;
+ break;
+
+ case 'N':
+ got_pass = True;
+ break;
+
+ case 's':
+ pstrcpy(servicesf, optarg);
+ break;
+
+ case 'U': {
+ char *lp;
+ pstrcpy(username,optarg);
+ if ((lp=strchr(username,'%'))) {
+ *lp = 0;
+ pstrcpy(password,lp+1);
+ got_pass = True;
+ memset(strchr(optarg,'%')+1,'X',strlen(password));
+ }
+ break;
+ }
+
+ case 'W':
+ pstrcpy(domain, optarg);
+ break;
+
+ case 'h':
+ default:
+ usage(argv[0]);
+ exit(1);
+ }
+ }
+
+ /* the following functions are part of the Samba debugging
+ facilities. See lib/debug.c */
+ setup_logging (argv[0], interactive);
+ if (!interactive)
+ reopen_logs();
+
+ /* Load smb.conf file */
+ /* FIXME! How to get this DEBUGLEVEL to last over lp_load()? */
+ olddebug = DEBUGLEVEL;
+ if (!lp_load(servicesf,True,False,False)) {
+ fprintf(stderr, "Can't load %s\n", servicesf);
+ }
+ DEBUGLEVEL = olddebug;
+
+ codepage_initialise(lp_client_code_page());
+ load_interfaces();
+
+ TimeInit();
+
+ get_myname((*global_myname)?NULL:global_myname);
+ strupper(global_myname);
+
+ /*
+ * initialize the credentials struct. Get password
+ * from stdin if necessary
+ */
+ if (!strlen(username))
+ get_username (username);
+
+ if (!got_pass) {
+ init_rpcclient_creds (&creds, username, domain, "");
+ pwd_read(&creds.pwd, "Enter Password: ", lp_encrypted_passwords());
+ }
+ else {
+ init_rpcclient_creds (&creds, username, domain, password);
+ }
+ memset(password,'X',strlen(password));
- return command_main(argc, argv);
+ /* open a connection to the specified server */
+ ZERO_STRUCTP (&cli);
+ if (!setup_connection (&cli, server, &creds)) {
+ return 0;
+ }
+
+ /* There are no pointers in ntuser_creds struct so zero it out */
+ ZERO_STRUCTP (&creds);
+
+
+ /* Load command lists */
+ add_command_set(rpcclient_commands);
+ add_command_set(separator_command);
+
+ add_command_set(spoolss_commands);
+ add_command_set(separator_command);
+
+ add_command_set(lsarpc_commands);
+ add_command_set(separator_command);
+
+ add_command_set(samr_commands);
+ add_command_set(separator_command);
+
+
+ /* Do anything specified with -c */
+ if (cmdstr[0]) {
+ char *cmd;
+ char *p = cmdstr;
+ uint32 result;
+
+ while((cmd=next_command(&p)) != NULL) {
+ result = process_cmd(&cli, cmd);
+ }
+
+ return 0;
+ }
+
+
+ /* Loop around accepting commands */
+ while(1) {
+ pstring prompt, cmd;
+ uint32 result;
+
+ ZERO_STRUCT(cmd);
+
+ slprintf(prompt, sizeof(prompt) - 1, "rpcclient $> ");
+
+#if HAVE_READLINE
+ cmd = readline(prompt);
+#else
+ printf("%s", prompt);
+
+ if (!fgets(cmd, sizeof(cmd) - 1, stdin)) {
+ break;
+ }
+
+ cmd[strlen(cmd) - 1] = '\0';
+#endif
+ result = process_cmd(&cli, cmd);
+ }
+
+ return 0;
}
+