From f5769109447d8da0f09b102d444a816ad97a00dc Mon Sep 17 00:00:00 2001 From: Kai Blin Date: Fri, 9 May 2008 23:22:12 +0200 Subject: net: Remove globals (This used to be commit 1e9319cf88b65a2a8d4f5099a1fe5297e405ed2e) --- source3/utils/net.c | 404 +++++++++--------- source3/utils/net.h | 88 ++-- source3/utils/net_ads.c | 351 ++++++++-------- source3/utils/net_ads_gpo.c | 42 +- source3/utils/net_cache.c | 30 +- source3/utils/net_conf.c | 147 ++++--- source3/utils/net_dom.c | 66 +-- source3/utils/net_groupmap.c | 55 ++- source3/utils/net_help.c | 50 +-- source3/utils/net_idmap.c | 25 +- source3/utils/net_lookup.c | 38 +- source3/utils/net_rap.c | 265 ++++++------ source3/utils/net_registry.c | 25 +- source3/utils/net_rpc.c | 880 +++++++++++++++++++++++---------------- source3/utils/net_rpc_audit.c | 47 ++- source3/utils/net_rpc_join.c | 21 +- source3/utils/net_rpc_printer.c | 116 ++++-- source3/utils/net_rpc_registry.c | 69 +-- source3/utils/net_rpc_rights.c | 52 +-- source3/utils/net_rpc_samsync.c | 12 +- source3/utils/net_rpc_service.c | 50 ++- source3/utils/net_rpc_sh_acct.c | 78 ++-- source3/utils/net_rpc_shell.c | 45 +- source3/utils/net_sam.c | 145 ++++--- source3/utils/net_status.c | 16 +- source3/utils/net_time.c | 38 +- source3/utils/net_usershare.c | 65 +-- source3/utils/net_util.c | 3 +- source3/utils/netlookup.c | 21 +- 29 files changed, 1768 insertions(+), 1476 deletions(-) (limited to 'source3/utils') diff --git a/source3/utils/net.c b/source3/utils/net.c index 19ba4f0e8a..db7f6c090c 100644 --- a/source3/utils/net.c +++ b/source3/utils/net.c @@ -5,12 +5,16 @@ Copyright (C) 2001 Jim McDonough (jmcd@us.ibm.com) Copyright (C) 2001 Andrew Tridgell (tridge@samba.org) Copyright (C) 2001 Andrew Bartlett (abartlet@samba.org) + Copyright (C) 2008 Kai Blin (kai@samba.org) Originally written by Steve and Jim. Largely rewritten by tridge in November 2001. Reworked again by abartlet in December 2001 + Another overhaul, moving functionality into plug-ins loaded on demand by Kai + in May 2008. + 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 3 of the License, or @@ -54,45 +58,6 @@ /* end of internationalization section */ /***********************************************************************/ -/* Yes, these buggers are globals.... */ -const char *opt_requester_name = NULL; -const char *opt_host = NULL; -const char *opt_password = NULL; -const char *opt_user_name = NULL; -bool opt_user_specified = False; -const char *opt_workgroup = NULL; -int opt_long_list_entries = 0; -int opt_reboot = 0; -int opt_force = 0; -int opt_stdin = 0; -int opt_port = 0; -int opt_verbose = 0; -int opt_maxusers = -1; -const char *opt_comment = ""; -const char *opt_container = NULL; -int opt_flags = -1; -int opt_timeout = 0; -const char *opt_target_workgroup = NULL; -int opt_machine_pass = 0; -int opt_localgroup = False; -int opt_domaingroup = False; -static int do_talloc_report=False; -const char *opt_newntname = ""; -int opt_rid = 0; -int opt_acls = 0; -int opt_attrs = 0; -int opt_timestamps = 0; -const char *opt_exclude = NULL; -const char *opt_destination = NULL; -int opt_testmode = False; - -int opt_have_ip = False; -struct sockaddr_storage opt_dest_ip; -bool smb_encrypt; -struct libnetapi_ctx *netapi_ctx = NULL; - -extern bool AllowDebugChange; - uint32 get_sec_channel_type(const char *param) { if (!(param && *param)) { @@ -118,35 +83,37 @@ uint32 get_sec_channel_type(const char *param) run a function from a function table. If not found then call the specified usage function */ -int net_run_function(int argc, const char **argv, struct functable *table, - int (*usage_fn)(int argc, const char **argv)) +int net_run_function(struct net_context *c, int argc, const char **argv, + struct functable *table, + int (*usage_fn)(struct net_context *c, + int argc, const char **argv)) { int i; if (argc < 1) { d_printf("\nUsage: \n"); - return usage_fn(argc, argv); + return usage_fn(c, argc, argv); } for (i=0; table[i].funcname; i++) { if (StrCaseCmp(argv[0], table[i].funcname) == 0) - return table[i].fn(argc-1, argv+1); + return table[i].fn(c, argc-1, argv+1); } d_fprintf(stderr, "No command: %s\n", argv[0]); - return usage_fn(argc, argv); + return usage_fn(c, argc, argv); } /* * run a function from a function table. */ -int net_run_function2(int argc, const char **argv, const char *whoami, - struct functable2 *table) +int net_run_function2(struct net_context *c, int argc, const char **argv, + const char *whoami, struct functable2 *table) { int i; if (argc != 0) { for (i=0; table[i].funcname; i++) { if (StrCaseCmp(argv[0], table[i].funcname) == 0) - return table[i].fn(argc-1, argv+1); + return table[i].fn(c, argc-1, argv+1); } } @@ -162,7 +129,8 @@ int net_run_function2(int argc, const char **argv, const char *whoami, Connect to \\server\service. ****************************************************************************/ -NTSTATUS connect_to_service(struct cli_state **c, +NTSTATUS connect_to_service(struct net_context *c, + struct cli_state **cli_ctx, struct sockaddr_storage *server_ss, const char *server_name, const char *service_name, @@ -170,16 +138,16 @@ NTSTATUS connect_to_service(struct cli_state **c, { NTSTATUS nt_status; - opt_password = net_prompt_pass(opt_user_name); - if (!opt_password) { + c->opt_password = net_prompt_pass(c, c->opt_user_name); + if (!c->opt_password) { return NT_STATUS_NO_MEMORY; } - nt_status = cli_full_connection(c, NULL, server_name, - server_ss, opt_port, + nt_status = cli_full_connection(cli_ctx, NULL, server_name, + server_ss, c->opt_port, service_name, service_type, - opt_user_name, opt_workgroup, - opt_password, 0, Undefined, NULL); + c->opt_user_name, c->opt_workgroup, + c->opt_password, 0, Undefined, NULL); if (!NT_STATUS_IS_OK(nt_status)) { d_fprintf(stderr, "Could not connect to server %s\n", server_name); @@ -199,11 +167,11 @@ NTSTATUS connect_to_service(struct cli_state **c, return nt_status; } - if (smb_encrypt) { - nt_status = cli_force_encryption(*c, - opt_user_name, - opt_password, - opt_workgroup); + if (c->smb_encrypt) { + nt_status = cli_force_encryption(*cli_ctx, + c->opt_user_name, + c->opt_password, + c->opt_workgroup); if (NT_STATUS_EQUAL(nt_status,NT_STATUS_NOT_SUPPORTED)) { d_printf("Encryption required and " @@ -224,8 +192,8 @@ NTSTATUS connect_to_service(struct cli_state **c, } if (!NT_STATUS_IS_OK(nt_status)) { - cli_shutdown(*c); - *c = NULL; + cli_shutdown(*cli_ctx); + *cli_ctx = NULL; } } @@ -236,25 +204,28 @@ NTSTATUS connect_to_service(struct cli_state **c, Connect to \\server\ipc$. ****************************************************************************/ -NTSTATUS connect_to_ipc(struct cli_state **c, +NTSTATUS connect_to_ipc(struct net_context *c, + struct cli_state **cli_ctx, struct sockaddr_storage *server_ss, const char *server_name) { - return connect_to_service(c, server_ss, server_name, "IPC$", "IPC"); + return connect_to_service(c, cli_ctx, server_ss, server_name, "IPC$", + "IPC"); } /**************************************************************************** Connect to \\server\ipc$ anonymously. ****************************************************************************/ -NTSTATUS connect_to_ipc_anonymous(struct cli_state **c, +NTSTATUS connect_to_ipc_anonymous(struct net_context *c, + struct cli_state **cli_ctx, struct sockaddr_storage *server_ss, const char *server_name) { NTSTATUS nt_status; - nt_status = cli_full_connection(c, opt_requester_name, server_name, - server_ss, opt_port, + nt_status = cli_full_connection(cli_ctx, c->opt_requester_name, + server_name, server_ss, c->opt_port, "IPC$", "IPC", "", "", "", 0, Undefined, NULL); @@ -292,28 +263,31 @@ static char *get_user_and_realm(const char *username) Connect to \\server\ipc$ using KRB5. ****************************************************************************/ -NTSTATUS connect_to_ipc_krb5(struct cli_state **c, +NTSTATUS connect_to_ipc_krb5(struct net_context *c, + struct cli_state **cli_ctx, struct sockaddr_storage *server_ss, const char *server_name) { NTSTATUS nt_status; char *user_and_realm = NULL; - opt_password = net_prompt_pass(opt_user_name); - if (!opt_password) { + /* FIXME: Should get existing kerberos ticket if possible. */ + c->opt_password = net_prompt_pass(c, c->opt_user_name); + if (!c->opt_password) { return NT_STATUS_NO_MEMORY; } - user_and_realm = get_user_and_realm(opt_user_name); + user_and_realm = get_user_and_realm(c->opt_user_name); if (!user_and_realm) { return NT_STATUS_NO_MEMORY; } - nt_status = cli_full_connection(c, NULL, server_name, - server_ss, opt_port, + nt_status = cli_full_connection(cli_ctx, NULL, server_name, + server_ss, c->opt_port, "IPC$", "IPC", - user_and_realm, opt_workgroup, - opt_password, CLI_FULL_CONNECTION_USE_KERBEROS, + user_and_realm, c->opt_workgroup, + c->opt_password, + CLI_FULL_CONNECTION_USE_KERBEROS, Undefined, NULL); SAFE_FREE(user_and_realm); @@ -323,15 +297,15 @@ NTSTATUS connect_to_ipc_krb5(struct cli_state **c, return nt_status; } - if (smb_encrypt) { - nt_status = cli_cm_force_encryption(*c, + if (c->smb_encrypt) { + nt_status = cli_cm_force_encryption(*cli_ctx, user_and_realm, - opt_password, - opt_workgroup, + c->opt_password, + c->opt_workgroup, "IPC$"); if (!NT_STATUS_IS_OK(nt_status)) { - cli_shutdown(*c); - *c = NULL; + cli_shutdown(*cli_ctx); + *cli_ctx = NULL; } } @@ -347,7 +321,8 @@ NTSTATUS connect_to_ipc_krb5(struct cli_state **c, * * @return Normal NTSTATUS return. **/ -NTSTATUS connect_dst_pipe(struct cli_state **cli_dst, struct rpc_pipe_client **pp_pipe_hnd, int pipe_num) +NTSTATUS connect_dst_pipe(struct net_context *c, struct cli_state **cli_dst, + struct rpc_pipe_client **pp_pipe_hnd, int pipe_num) { NTSTATUS nt_status; char *server_name = SMB_STRDUP("127.0.0.1"); @@ -358,15 +333,15 @@ NTSTATUS connect_dst_pipe(struct cli_state **cli_dst, struct rpc_pipe_client **p return NT_STATUS_NO_MEMORY; } - if (opt_destination) { + if (c->opt_destination) { SAFE_FREE(server_name); - if ((server_name = SMB_STRDUP(opt_destination)) == NULL) { + if ((server_name = SMB_STRDUP(c->opt_destination)) == NULL) { return NT_STATUS_NO_MEMORY; } } /* make a connection to a named pipe */ - nt_status = connect_to_ipc(&cli_tmp, NULL, server_name); + nt_status = connect_to_ipc(c, &cli_tmp, NULL, server_name); if (!NT_STATUS_IS_OK(nt_status)) { SAFE_FREE(server_name); return nt_status; @@ -391,7 +366,7 @@ NTSTATUS connect_dst_pipe(struct cli_state **cli_dst, struct rpc_pipe_client **p Use the local machine account (krb) and password for this session. ****************************************************************************/ -int net_use_krb_machine_account(void) +int net_use_krb_machine_account(struct net_context *c) { char *user_name = NULL; @@ -400,11 +375,12 @@ int net_use_krb_machine_account(void) exit(1); } - opt_password = secrets_fetch_machine_password(opt_target_workgroup, NULL, NULL); + c->opt_password = secrets_fetch_machine_password( + c->opt_target_workgroup, NULL, NULL); if (asprintf(&user_name, "%s$@%s", global_myname(), lp_realm()) == -1) { return -1; } - opt_user_name = user_name; + c->opt_user_name = user_name; return 0; } @@ -412,7 +388,7 @@ int net_use_krb_machine_account(void) Use the machine account name and password for this session. ****************************************************************************/ -int net_use_machine_account(void) +int net_use_machine_account(struct net_context *c) { char *user_name = NULL; @@ -421,30 +397,32 @@ int net_use_machine_account(void) exit(1); } - opt_password = secrets_fetch_machine_password(opt_target_workgroup, NULL, NULL); + c->opt_password = secrets_fetch_machine_password( + c->opt_target_workgroup, NULL, NULL); if (asprintf(&user_name, "%s$", global_myname()) == -1) { return -1; } - opt_user_name = user_name; + c->opt_user_name = user_name; return 0; } -bool net_find_server(const char *domain, +bool net_find_server(struct net_context *c, + const char *domain, unsigned flags, struct sockaddr_storage *server_ss, char **server_name) { - const char *d = domain ? domain : opt_target_workgroup; + const char *d = domain ? domain : c->opt_target_workgroup; - if (opt_host) { - *server_name = SMB_STRDUP(opt_host); + if (c->opt_host) { + *server_name = SMB_STRDUP(c->opt_host); } - if (opt_have_ip) { - *server_ss = opt_dest_ip; + if (c->opt_have_ip) { + *server_ss = c->opt_dest_ip; if (!*server_name) { char addr[INET6_ADDRSTRLEN]; - print_sockaddr(addr, sizeof(addr), &opt_dest_ip); + print_sockaddr(addr, sizeof(addr), &c->opt_dest_ip); *server_name = SMB_STRDUP(addr); } } else if (*server_name) { @@ -530,14 +508,16 @@ bool net_find_pdc(struct sockaddr_storage *server_ss, return true; } -NTSTATUS net_make_ipc_connection(unsigned flags, struct cli_state **pcli) +NTSTATUS net_make_ipc_connection(struct net_context *c, unsigned flags, + struct cli_state **pcli) { - return net_make_ipc_connection_ex(NULL, NULL, NULL, flags, pcli); + return net_make_ipc_connection_ex(c, NULL, NULL, NULL, flags, pcli); } -NTSTATUS net_make_ipc_connection_ex(const char *domain, const char *server, - struct sockaddr_storage *pss, unsigned flags, - struct cli_state **pcli) +NTSTATUS net_make_ipc_connection_ex(struct net_context *c ,const char *domain, + const char *server, + struct sockaddr_storage *pss, + unsigned flags, struct cli_state **pcli) { char *server_name = NULL; struct sockaddr_storage server_ss; @@ -545,7 +525,8 @@ NTSTATUS net_make_ipc_connection_ex(const char *domain, const char *server, NTSTATUS nt_status; if ( !server || !pss ) { - if (!net_find_server(domain, flags, &server_ss, &server_name)) { + if (!net_find_server(c, domain, flags, &server_ss, + &server_name)) { d_fprintf(stderr, "Unable to find a suitable server\n"); nt_status = NT_STATUS_UNSUCCESSFUL; goto done; @@ -556,9 +537,11 @@ NTSTATUS net_make_ipc_connection_ex(const char *domain, const char *server, } if (flags & NET_FLAGS_ANONYMOUS) { - nt_status = connect_to_ipc_anonymous(&cli, &server_ss, server_name); + nt_status = connect_to_ipc_anonymous(c, &cli, &server_ss, + server_name); } else { - nt_status = connect_to_ipc(&cli, &server_ss, server_name); + nt_status = connect_to_ipc(c, &cli, &server_ss, + server_name); } /* store the server in the affinity cache if it was a PDC */ @@ -580,46 +563,46 @@ done: return nt_status; } -static int net_user(int argc, const char **argv) +static int net_user(struct net_context *c, int argc, const char **argv) { - if (net_ads_check() == 0) - return net_ads_user(argc, argv); + if (net_ads_check(c) == 0) + return net_ads_user(c, argc, argv); /* if server is not specified, default to PDC? */ - if (net_rpc_check(NET_FLAGS_PDC)) - return net_rpc_user(argc, argv); + if (net_rpc_check(c, NET_FLAGS_PDC)) + return net_rpc_user(c, argc, argv); - return net_rap_user(argc, argv); + return net_rap_user(c, argc, argv); } -static int net_group(int argc, const char **argv) +static int net_group(struct net_context *c, int argc, const char **argv) { - if (net_ads_check() == 0) - return net_ads_group(argc, argv); + if (net_ads_check(c) == 0) + return net_ads_group(c, argc, argv); - if (argc == 0 && net_rpc_check(NET_FLAGS_PDC)) - return net_rpc_group(argc, argv); + if (argc == 0 && net_rpc_check(c, NET_FLAGS_PDC)) + return net_rpc_group(c,argc, argv); - return net_rap_group(argc, argv); + return net_rap_group(c, argc, argv); } -static int net_join(int argc, const char **argv) +static int net_join(struct net_context *c, int argc, const char **argv) { - if (net_ads_check_our_domain() == 0) { - if (net_ads_join(argc, argv) == 0) + if (net_ads_check_our_domain(c) == 0) { + if (net_ads_join(c, argc, argv) == 0) return 0; else d_fprintf(stderr, "ADS join did not work, falling back to RPC...\n"); } - return net_rpc_join(argc, argv); + return net_rpc_join(c, argc, argv); } -static int net_changetrustpw(int argc, const char **argv) +static int net_changetrustpw(struct net_context *c, int argc, const char **argv) { - if (net_ads_check_our_domain() == 0) - return net_ads_changetrustpw(argc, argv); + if (net_ads_check_our_domain(c) == 0) + return net_ads_changetrustpw(c, argc, argv); - return net_rpc_changetrustpw(argc, argv); + return net_rpc_changetrustpw(c, argc, argv); } static void set_line_buffering(FILE *f) @@ -627,19 +610,20 @@ static void set_line_buffering(FILE *f) setvbuf(f, NULL, _IOLBF, 0); } -static int net_changesecretpw(int argc, const char **argv) +static int net_changesecretpw(struct net_context *c, int argc, + const char **argv) { char *trust_pw; uint32 sec_channel_type = SEC_CHAN_WKSTA; - if(opt_force) { - if (opt_stdin) { + if(c->opt_force) { + if (c->opt_stdin) { set_line_buffering(stdin); set_line_buffering(stdout); set_line_buffering(stderr); } - trust_pw = get_pass("Enter machine password: ", opt_stdin); + trust_pw = get_pass("Enter machine password: ", c->opt_stdin); if (!secrets_store_machine_password(trust_pw, lp_workgroup(), sec_channel_type)) { d_fprintf(stderr, "Unable to write the machine account password in the secrets database"); @@ -658,24 +642,24 @@ static int net_changesecretpw(int argc, const char **argv) return 0; } -static int net_share(int argc, const char **argv) +static int net_share(struct net_context *c, int argc, const char **argv) { - if (net_rpc_check(0)) - return net_rpc_share(argc, argv); - return net_rap_share(argc, argv); + if (net_rpc_check(c, 0)) + return net_rpc_share(c, argc, argv); + return net_rap_share(c, argc, argv); } -static int net_file(int argc, const char **argv) +static int net_file(struct net_context *c, int argc, const char **argv) { - if (net_rpc_check(0)) - return net_rpc_file(argc, argv); - return net_rap_file(argc, argv); + if (net_rpc_check(c, 0)) + return net_rpc_file(c, argc, argv); + return net_rap_file(c, argc, argv); } /* Retrieve our local SID or the SID for the specified name */ -static int net_getlocalsid(int argc, const char **argv) +static int net_getlocalsid(struct net_context *c, int argc, const char **argv) { DOM_SID sid; const char *name; @@ -713,7 +697,7 @@ static int net_getlocalsid(int argc, const char **argv) return 0; } -static int net_setlocalsid(int argc, const char **argv) +static int net_setlocalsid(struct net_context *c, int argc, const char **argv) { DOM_SID sid; @@ -733,7 +717,7 @@ static int net_setlocalsid(int argc, const char **argv) return 0; } -static int net_setdomainsid(int argc, const char **argv) +static int net_setdomainsid(struct net_context *c, int argc, const char **argv) { DOM_SID sid; @@ -753,7 +737,7 @@ static int net_setdomainsid(int argc, const char **argv) return 0; } -static int net_getdomainsid(int argc, const char **argv) +static int net_getdomainsid(struct net_context *c, int argc, const char **argv) { DOM_SID domain_sid; fstring sid_str; @@ -789,20 +773,20 @@ static int net_getdomainsid(int argc, const char **argv) sid_to_fstring(sid_str, &domain_sid); d_printf("SID for local machine %s is: %s\n", global_myname(), sid_str); - if (!secrets_fetch_domain_sid(opt_workgroup, &domain_sid)) { + if (!secrets_fetch_domain_sid(c->opt_workgroup, &domain_sid)) { d_fprintf(stderr, "Could not fetch domain SID\n"); return 1; } sid_to_fstring(sid_str, &domain_sid); - d_printf("SID for domain %s is: %s\n", opt_workgroup, sid_str); + d_printf("SID for domain %s is: %s\n", c->opt_workgroup, sid_str); return 0; } #ifdef WITH_FAKE_KASERVER -int net_help_afs(int argc, const char **argv) +int net_help_afs(struct net_context *c, int argc, const char **argv) { d_printf(" net afs key filename\n" "\tImports a OpenAFS KeyFile into our secrets.tdb\n\n"); @@ -811,7 +795,7 @@ int net_help_afs(int argc, const char **argv) return -1; } -static int net_afs_key(int argc, const char **argv) +static int net_afs_key(struct net_context *c, int argc, const char **argv) { int fd; struct afs_keyfile keyfile; @@ -844,7 +828,8 @@ static int net_afs_key(int argc, const char **argv) return 0; } -static int net_afs_impersonate(int argc, const char **argv) +static int net_afs_impersonate(struct net_context *c, int argc, + const char **argv) { char *token; @@ -869,7 +854,7 @@ static int net_afs_impersonate(int argc, const char **argv) return 0; } -static int net_afs(int argc, const char **argv) +static int net_afs(struct net_context *c, int argc, const char **argv) { struct functable func[] = { {"key", net_afs_key}, @@ -877,7 +862,7 @@ static int net_afs(int argc, const char **argv) {"help", net_help_afs}, {NULL, NULL} }; - return net_run_function(argc, argv, func, net_help_afs); + return net_run_function(c, argc, argv, func, net_help_afs); } #endif /* WITH_FAKE_KASERVER */ @@ -917,7 +902,7 @@ static uint32 get_maxrid(void) return max_rid; } -static int net_maxrid(int argc, const char **argv) +static int net_maxrid(struct net_context *c, int argc, const char **argv) { uint32 rid; @@ -939,16 +924,16 @@ static int net_maxrid(int argc, const char **argv) /**************************************************************************** ****************************************************************************/ -const char *net_prompt_pass(const char *user) +const char *net_prompt_pass(struct net_context *c, const char *user) { char *prompt = NULL; const char *pass = NULL; - if (opt_password) { - return opt_password; + if (c->opt_password) { + return c->opt_password; } - if (opt_machine_pass) { + if (c->opt_machine_pass) { return NULL; } @@ -1023,49 +1008,50 @@ static struct functable net_func[] = { int argc_new = 0; const char ** argv_new; poptContext pc; + TALLOC_CTX *frame = talloc_stackframe(); + struct net_context *c = talloc_zero(frame, struct net_context); struct poptOption long_options[] = { {"help", 'h', POPT_ARG_NONE, 0, 'h'}, - {"workgroup", 'w', POPT_ARG_STRING, &opt_target_workgroup}, - {"user", 'U', POPT_ARG_STRING, &opt_user_name, 'U'}, + {"workgroup", 'w', POPT_ARG_STRING, &c->opt_target_workgroup}, + {"user", 'U', POPT_ARG_STRING, &c->opt_user_name, 'U'}, {"ipaddress", 'I', POPT_ARG_STRING, 0,'I'}, - {"port", 'p', POPT_ARG_INT, &opt_port}, - {"myname", 'n', POPT_ARG_STRING, &opt_requester_name}, - {"server", 'S', POPT_ARG_STRING, &opt_host}, + {"port", 'p', POPT_ARG_INT, &c->opt_port}, + {"myname", 'n', POPT_ARG_STRING, &c->opt_requester_name}, + {"server", 'S', POPT_ARG_STRING, &c->opt_host}, {"encrypt", 'e', POPT_ARG_NONE, NULL, 'e', "Encrypt SMB transport (UNIX extended servers only)" }, - {"container", 'c', POPT_ARG_STRING, &opt_container}, - {"comment", 'C', POPT_ARG_STRING, &opt_comment}, - {"maxusers", 'M', POPT_ARG_INT, &opt_maxusers}, - {"flags", 'F', POPT_ARG_INT, &opt_flags}, - {"long", 'l', POPT_ARG_NONE, &opt_long_list_entries}, - {"reboot", 'r', POPT_ARG_NONE, &opt_reboot}, - {"force", 'f', POPT_ARG_NONE, &opt_force}, - {"stdin", 'i', POPT_ARG_NONE, &opt_stdin}, - {"timeout", 't', POPT_ARG_INT, &opt_timeout}, - {"machine-pass",'P', POPT_ARG_NONE, &opt_machine_pass}, - {"myworkgroup", 'W', POPT_ARG_STRING, &opt_workgroup}, - {"verbose", 'v', POPT_ARG_NONE, &opt_verbose}, - {"test", 'T', POPT_ARG_NONE, &opt_testmode}, + {"container", 'c', POPT_ARG_STRING, &c->opt_container}, + {"comment", 'C', POPT_ARG_STRING, &c->opt_comment}, + {"maxusers", 'M', POPT_ARG_INT, &c->opt_maxusers}, + {"flags", 'F', POPT_ARG_INT, &c->opt_flags}, + {"long", 'l', POPT_ARG_NONE, &c->opt_long_list_entries}, + {"reboot", 'r', POPT_ARG_NONE, &c->opt_reboot}, + {"force", 'f', POPT_ARG_NONE, &c->opt_force}, + {"stdin", 'i', POPT_ARG_NONE, &c->opt_stdin}, + {"timeout", 't', POPT_ARG_INT, &c->opt_timeout}, + {"machine-pass",'P', POPT_ARG_NONE, &c->opt_machine_pass}, + {"myworkgroup", 'W', POPT_ARG_STRING, &c->opt_workgroup}, + {"verbose", 'v', POPT_ARG_NONE, &c->opt_verbose}, + {"test", 'T', POPT_ARG_NONE, &c->opt_testmode}, /* Options for 'net groupmap set' */ - {"local", 'L', POPT_ARG_NONE, &opt_localgroup}, - {"domain", 'D', POPT_ARG_NONE, &opt_domaingroup}, - {"ntname", 'N', POPT_ARG_STRING, &opt_newntname}, - {"rid", 'R', POPT_ARG_INT, &opt_rid}, + {"local", 'L', POPT_ARG_NONE, &c->opt_localgroup}, + {"domain", 'D', POPT_ARG_NONE, &c->opt_domaingroup}, + {"ntname", 'N', POPT_ARG_STRING, &c->opt_newntname}, + {"rid", 'R', POPT_ARG_INT, &c->opt_rid}, /* Options for 'net rpc share migrate' */ - {"acls", 0, POPT_ARG_NONE, &opt_acls}, - {"attrs", 0, POPT_ARG_NONE, &opt_attrs}, - {"timestamps", 0, POPT_ARG_NONE, &opt_timestamps}, - {"exclude", 'X', POPT_ARG_STRING, &opt_exclude}, - {"destination", 0, POPT_ARG_STRING, &opt_destination}, - {"tallocreport", 0, POPT_ARG_NONE, &do_talloc_report}, + {"acls", 0, POPT_ARG_NONE, &c->opt_acls}, + {"attrs", 0, POPT_ARG_NONE, &c->opt_attrs}, + {"timestamps", 0, POPT_ARG_NONE, &c->opt_timestamps}, + {"exclude", 'X', POPT_ARG_STRING, &c->opt_exclude}, + {"destination", 0, POPT_ARG_STRING, &c->opt_destination}, + {"tallocreport", 0, POPT_ARG_NONE, &c->do_talloc_report}, POPT_COMMON_SAMBA { 0, 0, 0, 0} }; - TALLOC_CTX *frame = talloc_stackframe(); - zero_addr(&opt_dest_ip); + zero_addr(&c->opt_dest_ip); load_case_tables(); @@ -1079,33 +1065,33 @@ static struct functable net_func[] = { while((opt = poptGetNextOpt(pc)) != -1) { switch (opt) { case 'h': - net_help(argc, argv); + net_help(c, argc, argv); exit(0); break; case 'e': - smb_encrypt=true; + c->smb_encrypt = true; break; case 'I': - if (!interpret_string_addr(&opt_dest_ip, + if (!interpret_string_addr(&c->opt_dest_ip, poptGetOptArg(pc), 0)) { d_fprintf(stderr, "\nInvalid ip address specified\n"); } else { - opt_have_ip = True; + c->opt_have_ip = true; } break; case 'U': - opt_user_specified = True; - opt_user_name = SMB_STRDUP(opt_user_name); - p = strchr(opt_user_name,'%'); + c->opt_user_specified = True; + c->opt_user_name = SMB_STRDUP(c->opt_user_name); + p = strchr(c->opt_user_name,'%'); if (p) { *p = 0; - opt_password = p+1; + c->opt_password = p+1; } break; default: d_fprintf(stderr, "\nInvalid option %s: %s\n", poptBadOption(pc, 0), poptStrerror(opt)); - net_help(argc, argv); + net_help(c, argc, argv); exit(1); } } @@ -1114,8 +1100,8 @@ static struct functable net_func[] = { * Don't load debug level from smb.conf. It should be * set by cmdline arg or remain default (0) */ - AllowDebugChange = False; - lp_load(get_dyn_CONFIGFILE(),True,False,False,True); + c->AllowDebugChange = false; + lp_load(get_dyn_CONFIGFILE(), true, false, false, true); argv_new = (const char **)poptGetArgs(pc); @@ -1127,24 +1113,24 @@ static struct functable net_func[] = { } } - if (do_talloc_report) { + if (c->do_talloc_report) { talloc_enable_leak_report(); } - if (opt_requester_name) { - set_global_myname(opt_requester_name); + if (c->opt_requester_name) { + set_global_myname(c->opt_requester_name); } - if (!opt_user_name && getenv("LOGNAME")) { - opt_user_name = getenv("LOGNAME"); + if (!c->opt_user_name && getenv("LOGNAME")) { + c->opt_user_name = getenv("LOGNAME"); } - if (!opt_workgroup) { - opt_workgroup = smb_xstrdup(lp_workgroup()); + if (!c->opt_workgroup) { + c->opt_workgroup = smb_xstrdup(lp_workgroup()); } - if (!opt_target_workgroup) { - opt_target_workgroup = smb_xstrdup(lp_workgroup()); + if (!c->opt_target_workgroup) { + c->opt_target_workgroup = smb_xstrdup(lp_workgroup()); } if (!init_names()) @@ -1156,22 +1142,22 @@ static struct functable net_func[] = { that it won't assert becouse we are not root */ sec_init(); - if (opt_machine_pass) { + if (c->opt_machine_pass) { /* it is very useful to be able to make ads queries as the machine account for testing purposes and for domain leave */ - net_use_krb_machine_account(); + net_use_krb_machine_account(c); } - if (!opt_password) { - opt_password = getenv("PASSWD"); + if (!c->opt_password) { + c->opt_password = getenv("PASSWD"); } - rc = net_run_function(argc_new-1, argv_new+1, net_func, net_help); + rc = net_run_function(c, argc_new-1, argv_new+1, net_func, net_help); DEBUG(2,("return code = %d\n", rc)); - libnetapi_free(netapi_ctx); + libnetapi_free(c->netapi_ctx); TALLOC_FREE(frame); return rc; diff --git a/source3/utils/net.h b/source3/utils/net.h index 4f390bb128..15b1dd402b 100644 --- a/source3/utils/net.h +++ b/source3/utils/net.h @@ -24,7 +24,8 @@ #include "lib/netapi/netapi.h" -typedef NTSTATUS (*rpc_command_fn)(const DOM_SID *, +typedef NTSTATUS (*rpc_command_fn)(struct net_context *c, + const DOM_SID *, const char *, struct cli_state *cli, struct rpc_pipe_client *, @@ -38,6 +39,7 @@ typedef struct copy_clistate { struct cli_state *cli_share_dst; char *cwd; uint16 attribute; + struct net_context *c; }copy_clistate; struct rpc_sh_ctx { @@ -54,10 +56,12 @@ struct rpc_sh_ctx { struct rpc_sh_cmd { const char *name; - struct rpc_sh_cmd *(*sub)(TALLOC_CTX *mem_ctx, + struct rpc_sh_cmd *(*sub)(struct net_context *c, + TALLOC_CTX *mem_ctx, struct rpc_sh_ctx *ctx); int pipe_idx; - NTSTATUS (*fn)(TALLOC_CTX *mem_ctx, struct rpc_sh_ctx *ctx, + NTSTATUS (*fn)(struct net_context *c, TALLOC_CTX *mem_ctx, + struct rpc_sh_ctx *ctx, struct rpc_pipe_client *pipe_hnd, int argc, const char **argv); const char *help; @@ -65,6 +69,47 @@ struct rpc_sh_cmd { enum netdom_domain_t { ND_TYPE_NT4, ND_TYPE_AD }; +struct net_context { + const char *opt_requester_name; + const char *opt_host; + const char *opt_password; + const char *opt_user_name; + bool opt_user_specified; + const char *opt_workgroup; + int opt_long_list_entries; + int opt_reboot; + int opt_force; + int opt_stdin; + int opt_port; + int opt_verbose; + int opt_maxusers; + const char *opt_comment; + const char *opt_container; + int opt_flags; + int opt_timeout; + const char *opt_target_workgroup; + int opt_machine_pass; + int opt_localgroup; + int opt_domaingroup; + int do_talloc_report; + const char *opt_newntname; + int opt_rid; + int opt_acls; + int opt_attrs; + int opt_timestamps; + const char *opt_exclude; + const char *opt_destination; + int opt_testmode; + + int opt_have_ip; + struct sockaddr_storage opt_dest_ip; + bool smb_encrypt; + struct libnetapi_ctx *netapi_ctx; + + bool AllowDebugChange; + const char *share_type[]; +}; + /* INCLUDE FILES */ #include "utils/net_proto.h" @@ -84,43 +129,6 @@ enum netdom_domain_t { ND_TYPE_NT4, ND_TYPE_AD }; /* net share operation modes */ #define NET_MODE_SHARE_MIGRATE 1 -extern int opt_maxusers; -extern const char *opt_comment; -extern const char *opt_container; -extern int opt_flags; - -extern const char *opt_comment; - -extern const char *opt_target_workgroup; -extern const char *opt_workgroup; -extern int opt_long_list_entries; -extern int opt_verbose; -extern int opt_reboot; -extern int opt_force; -extern int opt_machine_pass; -extern int opt_timeout; -extern const char *opt_host; -extern const char *opt_user_name; -extern const char *opt_password; -extern bool opt_user_specified; - -extern int opt_localgroup; -extern int opt_domaingroup; -extern const char *opt_newntname; -extern int opt_rid; -extern int opt_acls; -extern int opt_attrs; -extern int opt_timestamps; -extern const char *opt_exclude; -extern const char *opt_destination; -extern int opt_testmode; - -extern int opt_have_ip; -extern struct sockaddr_storage opt_dest_ip; -extern struct libnetapi_ctx *netapi_ctx; - -extern const char *share_type[]; - /* Structure for mapping accounts to groups */ /* Array element is the group rid */ typedef struct _groupmap { diff --git a/source3/utils/net_ads.c b/source3/utils/net_ads.c index bf34880177..5b84eb5522 100644 --- a/source3/utils/net_ads.c +++ b/source3/utils/net_ads.c @@ -27,7 +27,7 @@ #ifdef HAVE_ADS -int net_ads_usage(int argc, const char **argv) +int net_ads_usage(struct net_context *c, int argc, const char **argv) { d_printf("join [createupn[=principal]] [createcomputer=]\n"); d_printf(" Join the local machine to a ADS realm\n"); @@ -66,9 +66,9 @@ int net_ads_usage(int argc, const char **argv) /* when we do not have sufficient input parameters to contact a remote domain * we always fall back to our own realm - Guenther*/ -static const char *assume_own_realm(void) +static const char *assume_own_realm(struct net_context *c) { - if (!opt_host && strequal(lp_workgroup(), opt_target_workgroup)) { + if (!c->opt_host && strequal(lp_workgroup(), c->opt_target_workgroup)) { return lp_realm(); } @@ -78,7 +78,7 @@ static const char *assume_own_realm(void) /* do a cldap netlogon query */ -static int net_ads_cldap_netlogon(ADS_STRUCT *ads) +static int net_ads_cldap_netlogon(struct net_context *c, ADS_STRUCT *ads) { char addr[INET6_ADDRSTRLEN]; struct nbt_cldap_netlogon_5 reply; @@ -152,31 +152,31 @@ static int net_ads_cldap_netlogon(ADS_STRUCT *ads) this implements the CLDAP based netlogon lookup requests for finding the domain controller of a ADS domain */ -static int net_ads_lookup(int argc, const char **argv) +static int net_ads_lookup(struct net_context *c, int argc, const char **argv) { ADS_STRUCT *ads; - if (!ADS_ERR_OK(ads_startup_nobind(False, &ads))) { + if (!ADS_ERR_OK(ads_startup_nobind(c, false, &ads))) { d_fprintf(stderr, "Didn't find the cldap server!\n"); return -1; } if (!ads->config.realm) { - ads->config.realm = CONST_DISCARD(char *, opt_target_workgroup); + ads->config.realm = CONST_DISCARD(char *, c->opt_target_workgroup); ads->ldap.port = 389; } - return net_ads_cldap_netlogon(ads); + return net_ads_cldap_netlogon(c, ads); } -static int net_ads_info(int argc, const char **argv) +static int net_ads_info(struct net_context *c, int argc, const char **argv) { ADS_STRUCT *ads; char addr[INET6_ADDRSTRLEN]; - if (!ADS_ERR_OK(ads_startup_nobind(False, &ads))) { + if (!ADS_ERR_OK(ads_startup_nobind(c, false, &ads))) { d_fprintf(stderr, "Didn't find the ldap server!\n"); return -1; } @@ -214,7 +214,8 @@ static void use_in_memory_ccache(void) { setenv(KRB5_ENV_CCNAME, "MEMORY:net_ads", 1); } -static ADS_STATUS ads_startup_int(bool only_own_domain, uint32 auth_flags, ADS_STRUCT **ads_ret) +static ADS_STATUS ads_startup_int(struct net_context *c, bool only_own_domain, + uint32 auth_flags, ADS_STRUCT **ads_ret) { ADS_STRUCT *ads = NULL; ADS_STATUS status; @@ -235,37 +236,37 @@ retry_connect: if (only_own_domain) { realm = lp_realm(); } else { - realm = assume_own_realm(); + realm = assume_own_realm(c); } - ads = ads_init(realm, opt_target_workgroup, opt_host); + ads = ads_init(realm, c->opt_target_workgroup, c->opt_host); - if (!opt_user_name) { - opt_user_name = "administrator"; + if (!c->opt_user_name) { + c->opt_user_name = "administrator"; } - if (opt_user_specified) { + if (c->opt_user_specified) { need_password = True; } retry: - if (!opt_password && need_password && !opt_machine_pass) { - opt_password = net_prompt_pass(opt_user_name); - if (!opt_password) { + if (!c->opt_password && need_password && !c->opt_machine_pass) { + c->opt_password = net_prompt_pass(c, c->opt_user_name); + if (!c->opt_password) { ads_destroy(&ads); return ADS_ERROR(LDAP_NO_MEMORY); } } - if (opt_password) { + if (c->opt_password) { use_in_memory_ccache(); SAFE_FREE(ads->auth.password); - ads->auth.password = smb_xstrdup(opt_password); + ads->auth.password = smb_xstrdup(c->opt_password); } ads->auth.flags |= auth_flags; SAFE_FREE(ads->auth.user_name); - ads->auth.user_name = smb_xstrdup(opt_user_name); + ads->auth.user_name = smb_xstrdup(c->opt_user_name); /* * If the username is of the form "name@realm", @@ -304,7 +305,7 @@ retry: * This is done by reconnecting to ADS because only the first call to * ads_connect will give us our own sitename */ - if ((only_own_domain || !opt_host) && !tried_closest_dc) { + if ((only_own_domain || !c->opt_host) && !tried_closest_dc) { tried_closest_dc = True; /* avoid loop */ @@ -324,14 +325,14 @@ retry: return status; } -ADS_STATUS ads_startup(bool only_own_domain, ADS_STRUCT **ads) +ADS_STATUS ads_startup(struct net_context *c, bool only_own_domain, ADS_STRUCT **ads) { - return ads_startup_int(only_own_domain, 0, ads); + return ads_startup_int(c, only_own_domain, 0, ads); } -ADS_STATUS ads_startup_nobind(bool only_own_domain, ADS_STRUCT **ads) +ADS_STATUS ads_startup_nobind(struct net_context *c, bool only_own_domain, ADS_STRUCT **ads) { - return ads_startup_int(only_own_domain, ADS_AUTH_NO_BIND, ads); + return ads_startup_int(c, only_own_domain, ADS_AUTH_NO_BIND, ads); } /* @@ -359,32 +360,32 @@ static int net_ads_check_int(const char *realm, const char *workgroup, const cha return 0; } -int net_ads_check_our_domain(void) +int net_ads_check_our_domain(struct net_context *c) { return net_ads_check_int(lp_realm(), lp_workgroup(), NULL); } -int net_ads_check(void) +int net_ads_check(struct net_context *c) { - return net_ads_check_int(NULL, opt_workgroup, opt_host); + return net_ads_check_int(NULL, c->opt_workgroup, c->opt_host); } /* determine the netbios workgroup name for a domain */ -static int net_ads_workgroup(int argc, const char **argv) +static int net_ads_workgroup(struct net_context *c, int argc, const char **argv) { ADS_STRUCT *ads; char addr[INET6_ADDRSTRLEN]; struct nbt_cldap_netlogon_5 reply; - if (!ADS_ERR_OK(ads_startup_nobind(False, &ads))) { + if (!ADS_ERR_OK(ads_startup_nobind(c, false, &ads))) { d_fprintf(stderr, "Didn't find the cldap server!\n"); return -1; } if (!ads->config.realm) { - ads->config.realm = CONST_DISCARD(char *, opt_target_workgroup); + ads->config.realm = CONST_DISCARD(char *, c->opt_target_workgroup); ads->ldap.port = 389; } @@ -431,12 +432,12 @@ static bool usergrp_display(ADS_STRUCT *ads, char *field, void **values, void *d return True; } -static int net_ads_user_usage(int argc, const char **argv) +static int net_ads_user_usage(struct net_context *c, int argc, const char **argv) { - return net_help_user(argc, argv); + return net_help_user(c, argc, argv); } -static int ads_user_add(int argc, const char **argv) +static int ads_user_add(struct net_context *c, int argc, const char **argv) { ADS_STRUCT *ads; ADS_STATUS status; @@ -445,9 +446,9 @@ static int ads_user_add(int argc, const char **argv) int rc = -1; char *ou_str = NULL; - if (argc < 1) return net_ads_user_usage(argc, argv); + if (argc < 1) return net_ads_user_usage(c, argc, argv); - if (!ADS_ERR_OK(ads_startup(False, &ads))) { + if (!ADS_ERR_OK(ads_startup(c, false, &ads))) { return -1; } @@ -463,13 +464,13 @@ static int ads_user_add(int argc, const char **argv) goto done; } - if (opt_container) { - ou_str = SMB_STRDUP(opt_container); + if (c->opt_container) { + ou_str = SMB_STRDUP(c->opt_container); } else { ou_str = ads_default_ou_string(ads, WELL_KNOWN_GUID_USERS); } - status = ads_add_user_acct(ads, argv[0], ou_str, opt_comment); + status = ads_add_user_acct(ads, argv[0], ou_str, c->opt_comment); if (!ADS_ERR_OK(status)) { d_fprintf(stderr, "Could not add user %s: %s\n", argv[0], @@ -514,7 +515,7 @@ static int ads_user_add(int argc, const char **argv) return rc; } -static int ads_user_info(int argc, const char **argv) +static int ads_user_info(struct net_context *c, int argc, const char **argv) { ADS_STRUCT *ads; ADS_STATUS rc; @@ -525,7 +526,7 @@ static int ads_user_info(int argc, const char **argv) char *escaped_user; if (argc < 1) { - return net_ads_user_usage(argc, argv); + return net_ads_user_usage(c, argc, argv); } escaped_user = escape_ldap_string_alloc(argv[0]); @@ -535,7 +536,7 @@ static int ads_user_info(int argc, const char **argv) return -1; } - if (!ADS_ERR_OK(ads_startup(False, &ads))) { + if (!ADS_ERR_OK(ads_startup(c, false, &ads))) { SAFE_FREE(escaped_user); return -1; } @@ -571,7 +572,7 @@ static int ads_user_info(int argc, const char **argv) return 0; } -static int ads_user_delete(int argc, const char **argv) +static int ads_user_delete(struct net_context *c, int argc, const char **argv) { ADS_STRUCT *ads; ADS_STATUS rc; @@ -579,10 +580,10 @@ static int ads_user_delete(int argc, const char **argv) char *userdn; if (argc < 1) { - return net_ads_user_usage(argc, argv); + return net_ads_user_usage(c, argc, argv); } - if (!ADS_ERR_OK(ads_startup(False, &ads))) { + if (!ADS_ERR_OK(ads_startup(c, false, &ads))) { return -1; } @@ -608,7 +609,7 @@ static int ads_user_delete(int argc, const char **argv) return -1; } -int net_ads_user(int argc, const char **argv) +int net_ads_user(struct net_context *c, int argc, const char **argv) { struct functable func[] = { {"ADD", ads_user_add}, @@ -623,33 +624,33 @@ int net_ads_user(int argc, const char **argv) char *disp_fields[2] = {NULL, NULL}; if (argc == 0) { - if (!ADS_ERR_OK(ads_startup(False, &ads))) { + if (!ADS_ERR_OK(ads_startup(c, false, &ads))) { return -1; } - if (opt_long_list_entries) + if (c->opt_long_list_entries) d_printf("\nUser name Comment"\ "\n-----------------------------\n"); rc = ads_do_search_all_fn(ads, ads->config.bind_path, LDAP_SCOPE_SUBTREE, "(objectCategory=user)", - opt_long_list_entries ? longattrs : + c->opt_long_list_entries ? longattrs : shortattrs, usergrp_display, disp_fields); ads_destroy(&ads); return ADS_ERR_OK(rc) ? 0 : -1; } - return net_run_function(argc, argv, func, net_ads_user_usage); + return net_run_function(c, argc, argv, func, net_ads_user_usage); } -static int net_ads_group_usage(int argc, const char **argv) +static int net_ads_group_usage(struct net_context *c, int argc, const char **argv) { - return net_help_group(argc, argv); + return net_help_group(c, argc, argv); } -static int ads_group_add(int argc, const char **argv) +static int ads_group_add(struct net_context *c, int argc, const char **argv) { ADS_STRUCT *ads; ADS_STATUS status; @@ -658,10 +659,10 @@ static int ads_group_add(int argc, const char **argv) char *ou_str = NULL; if (argc < 1) { - return net_ads_group_usage(argc, argv); + return net_ads_group_usage(c, argc, argv); } - if (!ADS_ERR_OK(ads_startup(False, &ads))) { + if (!ADS_ERR_OK(ads_startup(c, false, &ads))) { return -1; } @@ -677,13 +678,13 @@ static int ads_group_add(int argc, const char **argv) goto done; } - if (opt_container) { - ou_str = SMB_STRDUP(opt_container); + if (c->opt_container) { + ou_str = SMB_STRDUP(c->opt_container); } else { ou_str = ads_default_ou_string(ads, WELL_KNOWN_GUID_USERS); } - status = ads_add_group_acct(ads, argv[0], ou_str, opt_comment); + status = ads_add_group_acct(ads, argv[0], ou_str, c->opt_comment); if (ADS_ERR_OK(status)) { d_printf("Group %s added\n", argv[0]); @@ -701,7 +702,7 @@ static int ads_group_add(int argc, const char **argv) return rc; } -static int ads_group_delete(int argc, const char **argv) +static int ads_group_delete(struct net_context *c, int argc, const char **argv) { ADS_STRUCT *ads; ADS_STATUS rc; @@ -709,10 +710,10 @@ static int ads_group_delete(int argc, const char **argv) char *groupdn; if (argc < 1) { - return net_ads_group_usage(argc, argv); + return net_ads_group_usage(c, argc, argv); } - if (!ADS_ERR_OK(ads_startup(False, &ads))) { + if (!ADS_ERR_OK(ads_startup(c, false, &ads))) { return -1; } @@ -738,7 +739,7 @@ static int ads_group_delete(int argc, const char **argv) return -1; } -int net_ads_group(int argc, const char **argv) +int net_ads_group(struct net_context *c, int argc, const char **argv) { struct functable func[] = { {"ADD", ads_group_add}, @@ -752,33 +753,33 @@ int net_ads_group(int argc, const char **argv) char *disp_fields[2] = {NULL, NULL}; if (argc == 0) { - if (!ADS_ERR_OK(ads_startup(False, &ads))) { + if (!ADS_ERR_OK(ads_startup(c, false, &ads))) { return -1; } - if (opt_long_list_entries) + if (c->opt_long_list_entries) d_printf("\nGroup name Comment"\ "\n-----------------------------\n"); rc = ads_do_search_all_fn(ads, ads->config.bind_path, LDAP_SCOPE_SUBTREE, "(objectCategory=group)", - opt_long_list_entries ? longattrs : + c->opt_long_list_entries ? longattrs : shortattrs, usergrp_display, disp_fields); ads_destroy(&ads); return ADS_ERR_OK(rc) ? 0 : -1; } - return net_run_function(argc, argv, func, net_ads_group_usage); + return net_run_function(c, argc, argv, func, net_ads_group_usage); } -static int net_ads_status(int argc, const char **argv) +static int net_ads_status(struct net_context *c, int argc, const char **argv) { ADS_STRUCT *ads; ADS_STATUS rc; LDAPMessage *res; - if (!ADS_ERR_OK(ads_startup(True, &ads))) { + if (!ADS_ERR_OK(ads_startup(c, true, &ads))) { return -1; } @@ -807,7 +808,7 @@ static int net_ads_status(int argc, const char **argv) with full control to the computer object's ACL. *******************************************************************/ -static int net_ads_leave(int argc, const char **argv) +static int net_ads_leave(struct net_context *c, int argc, const char **argv) { TALLOC_CTX *ctx; struct libnet_UnjoinCtx *r = NULL; @@ -832,10 +833,10 @@ static int net_ads_leave(int argc, const char **argv) } r->in.debug = true; - r->in.dc_name = opt_host; + r->in.dc_name = c->opt_host; r->in.domain_name = lp_realm(); - r->in.admin_account = opt_user_name; - r->in.admin_password = net_prompt_pass(opt_user_name); + r->in.admin_account = c->opt_user_name; + r->in.admin_password = net_prompt_pass(c, c->opt_user_name); r->in.modify_config = lp_config_backend_is_registry(); r->in.unjoin_flags = WKSSVC_JOIN_FLAGS_JOIN_TYPE | WKSSVC_JOIN_FLAGS_ACCOUNT_DELETE; @@ -876,7 +877,7 @@ static int net_ads_leave(int argc, const char **argv) return -1; } -static NTSTATUS net_ads_join_ok(void) +static NTSTATUS net_ads_join_ok(struct net_context *c) { ADS_STRUCT *ads = NULL; ADS_STATUS status; @@ -886,9 +887,9 @@ static NTSTATUS net_ads_join_ok(void) return NT_STATUS_ACCESS_DENIED; } - net_use_krb_machine_account(); + net_use_krb_machine_account(c); - status = ads_startup(True, &ads); + status = ads_startup(c, true, &ads); if (!ADS_ERR_OK(status)) { return ads_ntstatus(status); } @@ -900,13 +901,13 @@ static NTSTATUS net_ads_join_ok(void) /* check that an existing join is OK */ -int net_ads_testjoin(int argc, const char **argv) +int net_ads_testjoin(struct net_context *c, int argc, const char **argv) { NTSTATUS status; use_in_memory_ccache(); /* Display success or failure */ - status = net_ads_join_ok(); + status = net_ads_join_ok(c); if (!NT_STATUS_IS_OK(status)) { fprintf(stderr,"Join to domain is not valid: %s\n", get_friendly_nt_error_msg(status)); @@ -1074,7 +1075,7 @@ static NTSTATUS net_update_dns(TALLOC_CTX *mem_ctx, ADS_STRUCT *ads) /******************************************************************* ********************************************************************/ -static int net_ads_join_usage(int argc, const char **argv) +static int net_ads_join_usage(struct net_context *c, int argc, const char **argv) { d_printf("net ads join [options]\n"); d_printf("Valid options:\n"); @@ -1097,7 +1098,7 @@ static int net_ads_join_usage(int argc, const char **argv) /******************************************************************* ********************************************************************/ -int net_ads_join(int argc, const char **argv) +int net_ads_join(struct net_context *c, int argc, const char **argv) { TALLOC_CTX *ctx = NULL; struct libnet_JoinCtx *r = NULL; @@ -1180,9 +1181,9 @@ int net_ads_join(int argc, const char **argv) r->in.account_ou = create_in_ou; r->in.os_name = os_name; r->in.os_version = os_version; - r->in.dc_name = opt_host; - r->in.admin_account = opt_user_name; - r->in.admin_password = net_prompt_pass(opt_user_name); + r->in.dc_name = c->opt_host; + r->in.admin_account = c->opt_user_name; + r->in.admin_password = net_prompt_pass(c, c->opt_user_name); r->in.debug = true; r->in.modify_config = modify_config; r->in.join_flags = WKSSVC_JOIN_FLAGS_JOIN_TYPE | @@ -1256,7 +1257,7 @@ fail: /******************************************************************* ********************************************************************/ -static int net_ads_dns_usage(int argc, const char **argv) +static int net_ads_dns_usage(struct net_context *c, int argc, const char **argv) { #if defined(WITH_DNS_UPDATES) d_printf("net ads dns \n"); @@ -1273,7 +1274,7 @@ static int net_ads_dns_usage(int argc, const char **argv) /******************************************************************* ********************************************************************/ -static int net_ads_dns_register(int argc, const char **argv) +static int net_ads_dns_register(struct net_context *c, int argc, const char **argv) { #if defined(WITH_DNS_UPDATES) ADS_STRUCT *ads; @@ -1324,7 +1325,7 @@ static int net_ads_dns_register(int argc, const char **argv) DNS_ERROR do_gethostbyname(const char *server, const char *host); #endif -static int net_ads_dns_gethostbyname(int argc, const char **argv) +static int net_ads_dns_gethostbyname(struct net_context *c, int argc, const char **argv) { #if defined(WITH_DNS_UPDATES) DNS_ERROR err; @@ -1346,7 +1347,7 @@ static int net_ads_dns_gethostbyname(int argc, const char **argv) return 0; } -static int net_ads_dns(int argc, const char *argv[]) +static int net_ads_dns(struct net_context *c, int argc, const char *argv[]) { struct functable func[] = { {"REGISTER", net_ads_dns_register}, @@ -1354,13 +1355,13 @@ static int net_ads_dns(int argc, const char *argv[]) {NULL, NULL} }; - return net_run_function(argc, argv, func, net_ads_dns_usage); + return net_run_function(c, argc, argv, func, net_ads_dns_usage); } /******************************************************************* ********************************************************************/ -int net_ads_printer_usage(int argc, const char **argv) +int net_ads_printer_usage(struct net_context *c, int argc, const char **argv) { d_printf( "\nnet ads printer search " @@ -1380,13 +1381,13 @@ int net_ads_printer_usage(int argc, const char **argv) /******************************************************************* ********************************************************************/ -static int net_ads_printer_search(int argc, const char **argv) +static int net_ads_printer_search(struct net_context *c, int argc, const char **argv) { ADS_STRUCT *ads; ADS_STATUS rc; LDAPMessage *res = NULL; - if (!ADS_ERR_OK(ads_startup(False, &ads))) { + if (!ADS_ERR_OK(ads_startup(c, false, &ads))) { return -1; } @@ -1412,14 +1413,14 @@ static int net_ads_printer_search(int argc, const char **argv) return 0; } -static int net_ads_printer_info(int argc, const char **argv) +static int net_ads_printer_info(struct net_context *c, int argc, const char **argv) { ADS_STRUCT *ads; ADS_STATUS rc; const char *servername, *printername; LDAPMessage *res = NULL; - if (!ADS_ERR_OK(ads_startup(False, &ads))) { + if (!ADS_ERR_OK(ads_startup(c, false, &ads))) { return -1; } @@ -1459,7 +1460,7 @@ static int net_ads_printer_info(int argc, const char **argv) return 0; } -static int net_ads_printer_publish(int argc, const char **argv) +static int net_ads_printer_publish(struct net_context *c, int argc, const char **argv) { ADS_STRUCT *ads; ADS_STATUS rc; @@ -1474,14 +1475,14 @@ static int net_ads_printer_publish(int argc, const char **argv) char *srv_cn_escaped = NULL, *printername_escaped = NULL; LDAPMessage *res = NULL; - if (!ADS_ERR_OK(ads_startup(True, &ads))) { + if (!ADS_ERR_OK(ads_startup(c, true, &ads))) { talloc_destroy(mem_ctx); return -1; } if (argc < 1) { talloc_destroy(mem_ctx); - return net_ads_printer_usage(argc, argv); + return net_ads_printer_usage(c, argc, argv); } printername = argv[0]; @@ -1499,8 +1500,8 @@ static int net_ads_printer_publish(int argc, const char **argv) nt_status = cli_full_connection(&cli, global_myname(), servername, &server_ss, 0, "IPC$", "IPC", - opt_user_name, opt_workgroup, - opt_password ? opt_password : "", + c->opt_user_name, c->opt_workgroup, + c->opt_password ? c->opt_password : "", CLI_FULL_CONNECTION_USE_KERBEROS, Undefined, NULL); @@ -1578,7 +1579,7 @@ static int net_ads_printer_publish(int argc, const char **argv) return 0; } -static int net_ads_printer_remove(int argc, const char **argv) +static int net_ads_printer_remove(struct net_context *c, int argc, const char **argv) { ADS_STRUCT *ads; ADS_STATUS rc; @@ -1586,12 +1587,12 @@ static int net_ads_printer_remove(int argc, const char **argv) char *prt_dn; LDAPMessage *res = NULL; - if (!ADS_ERR_OK(ads_startup(True, &ads))) { + if (!ADS_ERR_OK(ads_startup(c, true, &ads))) { return -1; } if (argc < 1) { - return net_ads_printer_usage(argc, argv); + return net_ads_printer_usage(c, argc, argv); } if (argc > 1) { @@ -1631,7 +1632,7 @@ static int net_ads_printer_remove(int argc, const char **argv) return 0; } -static int net_ads_printer(int argc, const char **argv) +static int net_ads_printer(struct net_context *c, int argc, const char **argv) { struct functable func[] = { {"SEARCH", net_ads_printer_search}, @@ -1641,22 +1642,22 @@ static int net_ads_printer(int argc, const char **argv) {NULL, NULL} }; - return net_run_function(argc, argv, func, net_ads_printer_usage); + return net_run_function(c, argc, argv, func, net_ads_printer_usage); } -static int net_ads_password(int argc, const char **argv) +static int net_ads_password(struct net_context *c, int argc, const char **argv) { ADS_STRUCT *ads; - const char *auth_principal = opt_user_name; - const char *auth_password = opt_password; + const char *auth_principal = c->opt_user_name; + const char *auth_password = c->opt_password; char *realm = NULL; char *new_password = NULL; - char *c, *prompt; + char *chr, *prompt; const char *user; ADS_STATUS ret; - if (opt_user_name == NULL || opt_password == NULL) { + if (c->opt_user_name == NULL || c->opt_password == NULL) { d_fprintf(stderr, "You must supply an administrator username/password\n"); return -1; } @@ -1668,21 +1669,21 @@ static int net_ads_password(int argc, const char **argv) user = argv[0]; if (!strchr_m(user, '@')) { - asprintf(&c, "%s@%s", argv[0], lp_realm()); - user = c; + asprintf(&chr, "%s@%s", argv[0], lp_realm()); + user = chr; } use_in_memory_ccache(); - c = strchr_m(auth_principal, '@'); - if (c) { - realm = ++c; + chr = strchr_m(auth_principal, '@'); + if (chr) { + realm = ++chr; } else { realm = lp_realm(); } /* use the realm so we can eventually change passwords for users in realms other than default */ - if (!(ads = ads_init(realm, opt_workgroup, opt_host))) { + if (!(ads = ads_init(realm, c->opt_workgroup, c->opt_host))) { return -1; } @@ -1717,7 +1718,7 @@ static int net_ads_password(int argc, const char **argv) return 0; } -int net_ads_changetrustpw(int argc, const char **argv) +int net_ads_changetrustpw(struct net_context *c, int argc, const char **argv) { ADS_STRUCT *ads; char *host_principal; @@ -1729,11 +1730,11 @@ int net_ads_changetrustpw(int argc, const char **argv) return -1; } - net_use_krb_machine_account(); + net_use_krb_machine_account(c); use_in_memory_ccache(); - if (!ADS_ERR_OK(ads_startup(True, &ads))) { + if (!ADS_ERR_OK(ads_startup(c, true, &ads))) { return -1; } @@ -1769,7 +1770,7 @@ int net_ads_changetrustpw(int argc, const char **argv) /* help for net ads search */ -static int net_ads_search_usage(int argc, const char **argv) +static int net_ads_search_usage(struct net_context *c, int argc, const char **argv) { d_printf( "\nnet ads search \n"\ @@ -1778,7 +1779,7 @@ static int net_ads_search_usage(int argc, const char **argv) "attributes are a list of LDAP fields to show in the results\n\n"\ "Example: net ads search '(objectCategory=group)' sAMAccountName\n\n" ); - net_common_flags_usage(argc, argv); + net_common_flags_usage(c, argc, argv); return -1; } @@ -1786,7 +1787,7 @@ static int net_ads_search_usage(int argc, const char **argv) /* general ADS search function. Useful in diagnosing problems in ADS */ -static int net_ads_search(int argc, const char **argv) +static int net_ads_search(struct net_context *c, int argc, const char **argv) { ADS_STRUCT *ads; ADS_STATUS rc; @@ -1795,10 +1796,10 @@ static int net_ads_search(int argc, const char **argv) LDAPMessage *res = NULL; if (argc < 1) { - return net_ads_search_usage(argc, argv); + return net_ads_search_usage(c, argc, argv); } - if (!ADS_ERR_OK(ads_startup(False, &ads))) { + if (!ADS_ERR_OK(ads_startup(c, false, &ads))) { return -1; } @@ -1829,7 +1830,7 @@ static int net_ads_search(int argc, const char **argv) /* help for net ads search */ -static int net_ads_dn_usage(int argc, const char **argv) +static int net_ads_dn_usage(struct net_context *c, int argc, const char **argv) { d_printf( "\nnet ads dn \n"\ @@ -1839,7 +1840,7 @@ static int net_ads_dn_usage(int argc, const char **argv) "Example: net ads dn 'CN=administrator,CN=Users,DC=my,DC=domain' sAMAccountName\n\n" "Note: the DN must be provided properly escaped. See RFC 4514 for details\n\n" ); - net_common_flags_usage(argc, argv); + net_common_flags_usage(c, argc, argv); return -1; } @@ -1847,7 +1848,7 @@ static int net_ads_dn_usage(int argc, const char **argv) /* general ADS search function. Useful in diagnosing problems in ADS */ -static int net_ads_dn(int argc, const char **argv) +static int net_ads_dn(struct net_context *c, int argc, const char **argv) { ADS_STRUCT *ads; ADS_STATUS rc; @@ -1856,10 +1857,10 @@ static int net_ads_dn(int argc, const char **argv) LDAPMessage *res = NULL; if (argc < 1) { - return net_ads_dn_usage(argc, argv); + return net_ads_dn_usage(c, argc, argv); } - if (!ADS_ERR_OK(ads_startup(False, &ads))) { + if (!ADS_ERR_OK(ads_startup(c, false, &ads))) { return -1; } @@ -1889,7 +1890,7 @@ static int net_ads_dn(int argc, const char **argv) /* help for net ads sid search */ -static int net_ads_sid_usage(int argc, const char **argv) +static int net_ads_sid_usage(struct net_context *c, int argc, const char **argv) { d_printf( "\nnet ads sid \n"\ @@ -1898,7 +1899,7 @@ static int net_ads_sid_usage(int argc, const char **argv) "to show in the results\n\n"\ "Example: net ads sid 'S-1-5-32' distinguishedName\n\n" ); - net_common_flags_usage(argc, argv); + net_common_flags_usage(c, argc, argv); return -1; } @@ -1906,7 +1907,7 @@ static int net_ads_sid_usage(int argc, const char **argv) /* general ADS search function. Useful in diagnosing problems in ADS */ -static int net_ads_sid(int argc, const char **argv) +static int net_ads_sid(struct net_context *c, int argc, const char **argv) { ADS_STRUCT *ads; ADS_STATUS rc; @@ -1916,10 +1917,10 @@ static int net_ads_sid(int argc, const char **argv) DOM_SID sid; if (argc < 1) { - return net_ads_sid_usage(argc, argv); + return net_ads_sid_usage(c, argc, argv); } - if (!ADS_ERR_OK(ads_startup(False, &ads))) { + if (!ADS_ERR_OK(ads_startup(c, false, &ads))) { return -1; } @@ -1951,7 +1952,7 @@ static int net_ads_sid(int argc, const char **argv) } -static int net_ads_keytab_usage(int argc, const char **argv) +static int net_ads_keytab_usage(struct net_context *c, int argc, const char **argv) { d_printf( "net ads keytab \n"\ @@ -1973,12 +1974,12 @@ static int net_ads_keytab_usage(int argc, const char **argv) return -1; } -static int net_ads_keytab_flush(int argc, const char **argv) +static int net_ads_keytab_flush(struct net_context *c, int argc, const char **argv) { int ret; ADS_STRUCT *ads; - if (!ADS_ERR_OK(ads_startup(True, &ads))) { + if (!ADS_ERR_OK(ads_startup(c, true, &ads))) { return -1; } ret = ads_keytab_flush(ads); @@ -1986,14 +1987,14 @@ static int net_ads_keytab_flush(int argc, const char **argv) return ret; } -static int net_ads_keytab_add(int argc, const char **argv) +static int net_ads_keytab_add(struct net_context *c, int argc, const char **argv) { int i; int ret = 0; ADS_STRUCT *ads; d_printf("Processing principals to add...\n"); - if (!ADS_ERR_OK(ads_startup(True, &ads))) { + if (!ADS_ERR_OK(ads_startup(c, true, &ads))) { return -1; } for (i = 0; i < argc; i++) { @@ -2003,12 +2004,12 @@ static int net_ads_keytab_add(int argc, const char **argv) return ret; } -static int net_ads_keytab_create(int argc, const char **argv) +static int net_ads_keytab_create(struct net_context *c, int argc, const char **argv) { ADS_STRUCT *ads; int ret; - if (!ADS_ERR_OK(ads_startup(True, &ads))) { + if (!ADS_ERR_OK(ads_startup(c, true, &ads))) { return -1; } ret = ads_keytab_create_default(ads); @@ -2016,7 +2017,7 @@ static int net_ads_keytab_create(int argc, const char **argv) return ret; } -static int net_ads_keytab_list(int argc, const char **argv) +static int net_ads_keytab_list(struct net_context *c, int argc, const char **argv) { const char *keytab = NULL; @@ -2028,7 +2029,7 @@ static int net_ads_keytab_list(int argc, const char **argv) } -int net_ads_keytab(int argc, const char **argv) +int net_ads_keytab(struct net_context *c, int argc, const char **argv) { struct functable func[] = { {"ADD", net_ads_keytab_add}, @@ -2044,10 +2045,10 @@ int net_ads_keytab(int argc, const char **argv) use keytab functions.\n"); } - return net_run_function(argc, argv, func, net_ads_keytab_usage); + return net_run_function(c, argc, argv, func, net_ads_keytab_usage); } -static int net_ads_kerberos_usage(int argc, const char **argv) +static int net_ads_kerberos_usage(struct net_context *c, int argc, const char **argv) { d_printf( "net ads kerberos \n"\ @@ -2061,7 +2062,7 @@ static int net_ads_kerberos_usage(int argc, const char **argv) return -1; } -static int net_ads_kerberos_renew(int argc, const char **argv) +static int net_ads_kerberos_renew(struct net_context *c, int argc, const char **argv) { int ret = smb_krb5_renew_ticket(NULL, NULL, NULL, NULL); if (ret) { @@ -2071,7 +2072,7 @@ static int net_ads_kerberos_renew(int argc, const char **argv) return ret; } -static int net_ads_kerberos_pac(int argc, const char **argv) +static int net_ads_kerberos_pac(struct net_context *c, int argc, const char **argv) { struct PAC_DATA *pac = NULL; struct PAC_LOGON_INFO *info = NULL; @@ -2084,17 +2085,17 @@ static int net_ads_kerberos_pac(int argc, const char **argv) goto out; } - opt_password = net_prompt_pass(opt_user_name); + c->opt_password = net_prompt_pass(c, c->opt_user_name); status = kerberos_return_pac(mem_ctx, - opt_user_name, - opt_password, + c->opt_user_name, + c->opt_password, 0, NULL, NULL, NULL, - True, - True, + true, + true, 2592000, /* one month */ &pac); if (!NT_STATUS_IS_OK(status)) { @@ -2116,7 +2117,7 @@ static int net_ads_kerberos_pac(int argc, const char **argv) return ret; } -static int net_ads_kerberos_kinit(int argc, const char **argv) +static int net_ads_kerberos_kinit(struct net_context *c, int argc, const char **argv) { TALLOC_CTX *mem_ctx = NULL; int ret = -1; @@ -2127,16 +2128,16 @@ static int net_ads_kerberos_kinit(int argc, const char **argv) goto out; } - opt_password = net_prompt_pass(opt_user_name); + c->opt_password = net_prompt_pass(c, c->opt_user_name); - ret = kerberos_kinit_password_ext(opt_user_name, - opt_password, + ret = kerberos_kinit_password_ext(c->opt_user_name, + c->opt_password, 0, NULL, NULL, NULL, - True, - True, + true, + true, 2592000, /* one month */ &status); if (ret) { @@ -2147,7 +2148,7 @@ static int net_ads_kerberos_kinit(int argc, const char **argv) return ret; } -int net_ads_kerberos(int argc, const char **argv) +int net_ads_kerberos(struct net_context *c, int argc, const char **argv) { struct functable func[] = { {"KINIT", net_ads_kerberos_kinit}, @@ -2157,11 +2158,11 @@ int net_ads_kerberos(int argc, const char **argv) {NULL, NULL} }; - return net_run_function(argc, argv, func, net_ads_kerberos_usage); + return net_run_function(c, argc, argv, func, net_ads_kerberos_usage); } -int net_ads_help(int argc, const char **argv) +int net_ads_help(struct net_context *c, int argc, const char **argv) { struct functable func[] = { {"USER", net_ads_user_usage}, @@ -2178,10 +2179,10 @@ int net_ads_help(int argc, const char **argv) {NULL, NULL} }; - return net_run_function(argc, argv, func, net_ads_usage); + return net_run_function(c, argc, argv, func, net_ads_usage); } -int net_ads(int argc, const char **argv) +int net_ads(struct net_context *c, int argc, const char **argv) { struct functable func[] = { {"INFO", net_ads_info}, @@ -2207,7 +2208,7 @@ int net_ads(int argc, const char **argv) {NULL, NULL} }; - return net_run_function(argc, argv, func, net_ads_usage); + return net_run_function(c, argc, argv, func, net_ads_usage); } #else @@ -2218,60 +2219,60 @@ static int net_ads_noads(void) return -1; } -int net_ads_keytab(int argc, const char **argv) +int net_ads_keytab(struct net_context *c, int argc, const char **argv) { return net_ads_noads(); } -int net_ads_kerberos(int argc, const char **argv) +int net_ads_kerberos(struct net_context *c, int argc, const char **argv) { return net_ads_noads(); } -int net_ads_usage(int argc, const char **argv) +int net_ads_usage(struct net_context *c, int argc, const char **argv) { return net_ads_noads(); } -int net_ads_help(int argc, const char **argv) +int net_ads_help(struct net_context *c, int argc, const char **argv) { return net_ads_noads(); } -int net_ads_changetrustpw(int argc, const char **argv) +int net_ads_changetrustpw(struct net_context *c, int argc, const char **argv) { return net_ads_noads(); } -int net_ads_join(int argc, const char **argv) +int net_ads_join(struct net_context *c, int argc, const char **argv) { return net_ads_noads(); } -int net_ads_user(int argc, const char **argv) +int net_ads_user(struct net_context *c, int argc, const char **argv) { return net_ads_noads(); } -int net_ads_group(int argc, const char **argv) +int net_ads_group(struct net_context *c, int argc, const char **argv) { return net_ads_noads(); } /* this one shouldn't display a message */ -int net_ads_check(void) +int net_ads_check(struct net_context *c) { return -1; } -int net_ads_check_our_domain(void) +int net_ads_check_our_domain(struct net_context *c) { return -1; } -int net_ads(int argc, const char **argv) +int net_ads(struct net_context *c, int argc, const char **argv) { - return net_ads_usage(argc, argv); + return net_ads_usage(c, argc, argv); } #endif /* WITH_ADS */ diff --git a/source3/utils/net_ads_gpo.c b/source3/utils/net_ads_gpo.c index d71fa908e9..5ef96204f4 100644 --- a/source3/utils/net_ads_gpo.c +++ b/source3/utils/net_ads_gpo.c @@ -22,7 +22,7 @@ #ifdef HAVE_ADS -static int net_ads_gpo_usage(int argc, const char **argv) +static int net_ads_gpo_usage(struct net_context *c, int argc, const char **argv) { d_printf( "net ads gpo \n"\ @@ -41,7 +41,7 @@ static int net_ads_gpo_usage(int argc, const char **argv) return -1; } -static int net_ads_gpo_refresh(int argc, const char **argv) +static int net_ads_gpo_refresh(struct net_context *c, int argc, const char **argv) { TALLOC_CTX *mem_ctx; ADS_STRUCT *ads; @@ -65,7 +65,7 @@ static int net_ads_gpo_refresh(int argc, const char **argv) return -1; } - status = ads_startup(False, &ads); + status = ads_startup(c, false, &ads); if (!ADS_ERR_OK(status)) { printf("failed to connect AD server: %s\n", ads_errstr(status)); goto out; @@ -128,7 +128,7 @@ static int net_ads_gpo_refresh(int argc, const char **argv) printf("finished\n"); - if (opt_verbose) { + if (c->opt_verbose) { printf("* dumping GPO list\n"); @@ -173,7 +173,7 @@ static int net_ads_gpo_refresh(int argc, const char **argv) printf("finished\n"); - if (opt_verbose) { + if (c->opt_verbose) { printf("* dumping GPO list from registry\n"); @@ -211,7 +211,7 @@ static int net_ads_gpo_refresh(int argc, const char **argv) return 0; } -static int net_ads_gpo_list_all(int argc, const char **argv) +static int net_ads_gpo_list_all(struct net_context *c, int argc, const char **argv) { ADS_STRUCT *ads; ADS_STATUS status; @@ -238,7 +238,7 @@ static int net_ads_gpo_list_all(int argc, const char **argv) return -1; } - status = ads_startup(False, &ads); + status = ads_startup(c, false, &ads); if (!ADS_ERR_OK(status)) { goto out; } @@ -290,7 +290,7 @@ out: return 0; } -static int net_ads_gpo_list(int argc, const char **argv) +static int net_ads_gpo_list(struct net_context *c, int argc, const char **argv) { ADS_STRUCT *ads; ADS_STATUS status; @@ -312,7 +312,7 @@ static int net_ads_gpo_list(int argc, const char **argv) goto out; } - status = ads_startup(False, &ads); + status = ads_startup(c, false, &ads); if (!ADS_ERR_OK(status)) { goto out; } @@ -357,7 +357,7 @@ out: } #if 0 -static int net_ads_gpo_apply(int argc, const char **argv) +static int net_ads_gpo_apply(struct net_context *c, int argc, const char **argv) { TALLOC_CTX *mem_ctx; ADS_STRUCT *ads; @@ -383,7 +383,7 @@ static int net_ads_gpo_apply(int argc, const char **argv) filter = cse_gpo_name_to_guid_string(argv[1]); } - status = ads_startup(False, &ads); + status = ads_startup(c, false, &ads); if (!ADS_ERR_OK(status)) { printf("got: %s\n", ads_errstr(status)); goto out; @@ -438,7 +438,7 @@ out: } #endif -static int net_ads_gpo_link_get(int argc, const char **argv) +static int net_ads_gpo_link_get(struct net_context *c, int argc, const char **argv) { ADS_STRUCT *ads; ADS_STATUS status; @@ -455,7 +455,7 @@ static int net_ads_gpo_link_get(int argc, const char **argv) return -1; } - status = ads_startup(False, &ads); + status = ads_startup(c, false, &ads); if (!ADS_ERR_OK(status)) { goto out; } @@ -476,7 +476,7 @@ out: return 0; } -static int net_ads_gpo_link_add(int argc, const char **argv) +static int net_ads_gpo_link_add(struct net_context *c, int argc, const char **argv) { ADS_STRUCT *ads; ADS_STATUS status; @@ -499,7 +499,7 @@ static int net_ads_gpo_link_add(int argc, const char **argv) gpo_opt = atoi(argv[2]); } - status = ads_startup(False, &ads); + status = ads_startup(c, false, &ads); if (!ADS_ERR_OK(status)) { goto out; } @@ -519,7 +519,7 @@ out: #if 0 /* broken */ -static int net_ads_gpo_link_delete(int argc, const char **argv) +static int net_ads_gpo_link_delete(struct net_context *c, int argc, const char **argv) { ADS_STRUCT *ads; ADS_STATUS status; @@ -534,7 +534,7 @@ static int net_ads_gpo_link_delete(int argc, const char **argv) return -1; } - status = ads_startup(False, &ads); + status = ads_startup(c, false, &ads); if (!ADS_ERR_OK(status)) { goto out; } @@ -554,7 +554,7 @@ out: #endif -static int net_ads_gpo_get_gpo(int argc, const char **argv) +static int net_ads_gpo_get_gpo(struct net_context *c, int argc, const char **argv) { ADS_STRUCT *ads; ADS_STATUS status; @@ -571,7 +571,7 @@ static int net_ads_gpo_get_gpo(int argc, const char **argv) return -1; } - status = ads_startup(False, &ads); + status = ads_startup(c, false, &ads); if (!ADS_ERR_OK(status)) { goto out; } @@ -597,7 +597,7 @@ out: return 0; } -int net_ads_gpo(int argc, const char **argv) +int net_ads_gpo(struct net_context *c, int argc, const char **argv) { struct functable func[] = { /* {"APPLY", net_ads_gpo_apply}, */ @@ -612,7 +612,7 @@ int net_ads_gpo(int argc, const char **argv) {NULL, NULL} }; - return net_run_function(argc, argv, func, net_ads_gpo_usage); + return net_run_function(c, argc, argv, func, net_ads_gpo_usage); } #endif /* HAVE_ADS */ diff --git a/source3/utils/net_cache.c b/source3/utils/net_cache.c index 8e0f98ef7e..e59a534e4a 100644 --- a/source3/utils/net_cache.c +++ b/source3/utils/net_cache.c @@ -14,8 +14,8 @@ 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, see . */ - + along with this program. If not, see . +*/ #include "includes.h" #include "net.h" @@ -145,10 +145,11 @@ static time_t parse_timeout(const char* timeout_str) /** * Add an entry to the cache. If it does exist, then set it. * + * @param c A net_context structure * @param argv key, value and timeout are passed in command line * @return 0 on success, otherwise failure **/ -static int net_cache_add(int argc, const char **argv) +static int net_cache_add(struct net_context *c, int argc, const char **argv) { const char *keystr, *datastr, *timeout_str; time_t timeout; @@ -183,10 +184,11 @@ static int net_cache_add(int argc, const char **argv) /** * Delete an entry in the cache * + * @param c A net_context structure * @param argv key to delete an entry of * @return 0 on success, otherwise failure **/ -static int net_cache_del(int argc, const char **argv) +static int net_cache_del(struct net_context *c, int argc, const char **argv) { const char *keystr = argv[0]; @@ -208,10 +210,11 @@ static int net_cache_del(int argc, const char **argv) /** * Get and display an entry from the cache * + * @param c A net_context structure * @param argv key to search an entry of * @return 0 on success, otherwise failure **/ -static int net_cache_get(int argc, const char **argv) +static int net_cache_get(struct net_context *c, int argc, const char **argv) { const char* keystr = argv[0]; char* valuestr; @@ -235,10 +238,11 @@ static int net_cache_get(int argc, const char **argv) /** * Search an entry/entries in the cache * + * @param c A net_context structure * @param argv key pattern to match the entries to * @return 0 on success, otherwise failure **/ -static int net_cache_search(int argc, const char **argv) +static int net_cache_search(struct net_context *c, int argc, const char **argv) { const char* pattern; @@ -256,10 +260,11 @@ static int net_cache_search(int argc, const char **argv) /** * List the contents of the cache * + * @param c A net_context structure * @param argv ignored in this functionailty * @return always returns 0 **/ -static int net_cache_list(int argc, const char **argv) +static int net_cache_list(struct net_context *c, int argc, const char **argv) { const char* pattern = "*"; gencache_iterate(print_cache_entry, NULL, pattern); @@ -271,10 +276,11 @@ static int net_cache_list(int argc, const char **argv) /** * Flush the whole cache * + * @param c A net_context structure * @param argv ignored in this functionality * @return always returns 0 **/ -static int net_cache_flush(int argc, const char **argv) +static int net_cache_flush(struct net_context *c, int argc, const char **argv) { const char* pattern = "*"; gencache_iterate(delete_cache_entry, NULL, pattern); @@ -286,10 +292,11 @@ static int net_cache_flush(int argc, const char **argv) /** * Short help * + * @param c A net_context structure * @param argv ignored in this functionality * @return always returns -1 **/ -static int net_cache_usage(int argc, const char **argv) +static int net_cache_usage(struct net_context *c, int argc, const char **argv) { d_printf(" net cache add \t add add new cache entry\n"); d_printf(" net cache del \t delete existing cache entry by key\n"); @@ -304,10 +311,11 @@ static int net_cache_usage(int argc, const char **argv) /** * Entry point to 'net cache' subfunctionality * + * @param c A net_context structure * @param argv arguments passed to further called functions * @return whatever further functions return **/ -int net_cache(int argc, const char **argv) +int net_cache(struct net_context *c, int argc, const char **argv) { struct functable func[] = { {"add", net_cache_add}, @@ -319,5 +327,5 @@ int net_cache(int argc, const char **argv) {NULL, NULL} }; - return net_run_function(argc, argv, func, net_cache_usage); + return net_run_function(c, argc, argv, func, net_cache_usage); } diff --git a/source3/utils/net_conf.c b/source3/utils/net_conf.c index 08a06eabd4..a922e13583 100644 --- a/source3/utils/net_conf.c +++ b/source3/utils/net_conf.c @@ -36,13 +36,15 @@ * **********************************************************************/ -static int net_conf_list_usage(int argc, const char **argv) +static int net_conf_list_usage(struct net_context *c, int argc, + const char **argv) { d_printf("USAGE: net conf list\n"); return -1; } -static int net_conf_import_usage(int argc, const char**argv) +static int net_conf_import_usage(struct net_context *c, int argc, + const char**argv) { d_printf("USAGE: net conf import [--test|-T] " "[]\n" @@ -53,25 +55,29 @@ static int net_conf_import_usage(int argc, const char**argv) return -1; } -static int net_conf_listshares_usage(int argc, const char **argv) +static int net_conf_listshares_usage(struct net_context *c, int argc, + const char **argv) { d_printf("USAGE: net conf listshares\n"); return -1; } -static int net_conf_drop_usage(int argc, const char **argv) +static int net_conf_drop_usage(struct net_context *c, int argc, + const char **argv) { d_printf("USAGE: net conf drop\n"); return -1; } -static int net_conf_showshare_usage(int argc, const char **argv) +static int net_conf_showshare_usage(struct net_context *c, int argc, + const char **argv) { d_printf("USAGE: net conf showshare \n"); return -1; } -static int net_conf_addshare_usage(int argc, const char **argv) +static int net_conf_addshare_usage(struct net_context *c, int argc, + const char **argv) { d_printf("USAGE: net conf addshare " "[writeable={y|N} [guest_ok={y|N} []]\n" @@ -85,43 +91,50 @@ static int net_conf_addshare_usage(int argc, const char **argv) return -1; } -static int net_conf_delshare_usage(int argc, const char **argv) +static int net_conf_delshare_usage(struct net_context *c, int argc, + const char **argv) { d_printf("USAGE: net conf delshare \n"); return -1; } -static int net_conf_setparm_usage(int argc, const char **argv) +static int net_conf_setparm_usage(struct net_context *c, int argc, + const char **argv) { d_printf("USAGE: net conf setparm
\n"); return -1; } -static int net_conf_getparm_usage(int argc, const char **argv) +static int net_conf_getparm_usage(struct net_context *c, int argc, + const char **argv) { d_printf("USAGE: net conf getparm
\n"); return -1; } -static int net_conf_delparm_usage(int argc, const char **argv) +static int net_conf_delparm_usage(struct net_context *c, int argc, + const char **argv) { d_printf("USAGE: net conf delparm
\n"); return -1; } -static int net_conf_getincludes_usage(int argc, const char **argv) +static int net_conf_getincludes_usage(struct net_context *c, int argc, + const char **argv) { d_printf("USAGE: net conf getincludes
\n"); return -1; } -static int net_conf_setincludes_usage(int argc, const char **argv) +static int net_conf_setincludes_usage(struct net_context *c, int argc, + const char **argv) { d_printf("USAGE: net conf setincludes
[]*\n"); return -1; } -static int net_conf_delincludes_usage(int argc, const char **argv) +static int net_conf_delincludes_usage(struct net_context *c, int argc, + const char **argv) { d_printf("USAGE: net conf delincludes
\n"); return -1; @@ -137,7 +150,8 @@ static int net_conf_delincludes_usage(int argc, const char **argv) /** * This functions process a service previously loaded with libsmbconf. */ -static WERROR import_process_service(struct smbconf_ctx *conf_ctx, +static WERROR import_process_service(struct net_context *c, + struct smbconf_ctx *conf_ctx, struct smbconf_service *service) { uint32_t idx; @@ -146,7 +160,7 @@ static WERROR import_process_service(struct smbconf_ctx *conf_ctx, char **includes = NULL; TALLOC_CTX *mem_ctx = talloc_stackframe(); - if (opt_testmode) { + if (c->opt_testmode) { const char *indent = ""; if (service->name != NULL) { d_printf("[%s]\n", service->name); @@ -215,7 +229,7 @@ done: * **********************************************************************/ -static int net_conf_list(struct smbconf_ctx *conf_ctx, +static int net_conf_list(struct net_context *c, struct smbconf_ctx *conf_ctx, int argc, const char **argv) { WERROR werr = WERR_OK; @@ -228,7 +242,7 @@ static int net_conf_list(struct smbconf_ctx *conf_ctx, mem_ctx = talloc_stackframe(); if (argc != 0) { - net_conf_list_usage(argc, argv); + net_conf_list_usage(c, argc, argv); goto done; } @@ -264,7 +278,7 @@ done: return ret; } -static int net_conf_import(struct smbconf_ctx *conf_ctx, +static int net_conf_import(struct net_context *c, struct smbconf_ctx *conf_ctx, int argc, const char **argv) { int ret = -1; @@ -280,7 +294,7 @@ static int net_conf_import(struct smbconf_ctx *conf_ctx, switch (argc) { case 0: default: - net_conf_import_usage(argc, argv); + net_conf_import_usage(c, argc, argv); goto done; case 2: servicename = talloc_strdup_lower(mem_ctx, argv[1]); @@ -309,7 +323,7 @@ static int net_conf_import(struct smbconf_ctx *conf_ctx, goto done; } - if (opt_testmode) { + if (c->opt_testmode) { d_printf("\nTEST MODE - " "would import the following configuration:\n\n"); } @@ -323,7 +337,7 @@ static int net_conf_import(struct smbconf_ctx *conf_ctx, if (!W_ERROR_IS_OK(werr)) { goto done; } - werr = import_process_service(conf_ctx, service); + werr = import_process_service(c, conf_ctx, service); if (!W_ERROR_IS_OK(werr)) { goto done; } @@ -337,14 +351,15 @@ static int net_conf_import(struct smbconf_ctx *conf_ctx, if (!W_ERROR_IS_OK(werr)) { goto done; } - if (!opt_testmode) { + if (!c->opt_testmode) { werr = smbconf_drop(conf_ctx); if (!W_ERROR_IS_OK(werr)) { goto done; } } for (sidx = 0; sidx < num_shares; sidx++) { - werr = import_process_service(conf_ctx, services[sidx]); + werr = import_process_service(c, conf_ctx, + services[sidx]); if (!W_ERROR_IS_OK(werr)) { goto done; } @@ -358,8 +373,9 @@ done: return ret; } -static int net_conf_listshares(struct smbconf_ctx *conf_ctx, - int argc, const char **argv) +static int net_conf_listshares(struct net_context *c, + struct smbconf_ctx *conf_ctx, int argc, + const char **argv) { WERROR werr = WERR_OK; int ret = -1; @@ -370,7 +386,7 @@ static int net_conf_listshares(struct smbconf_ctx *conf_ctx, mem_ctx = talloc_stackframe(); if (argc != 0) { - net_conf_listshares_usage(argc, argv); + net_conf_listshares_usage(c, argc, argv); goto done; } @@ -392,14 +408,14 @@ done: return ret; } -static int net_conf_drop(struct smbconf_ctx *conf_ctx, +static int net_conf_drop(struct net_context *c, struct smbconf_ctx *conf_ctx, int argc, const char **argv) { int ret = -1; WERROR werr; if (argc != 0) { - net_conf_drop_usage(argc, argv); + net_conf_drop_usage(c, argc, argv); goto done; } @@ -416,8 +432,9 @@ done: return ret; } -static int net_conf_showshare(struct smbconf_ctx *conf_ctx, - int argc, const char **argv) +static int net_conf_showshare(struct net_context *c, + struct smbconf_ctx *conf_ctx, int argc, + const char **argv) { int ret = -1; WERROR werr = WERR_OK; @@ -429,7 +446,7 @@ static int net_conf_showshare(struct smbconf_ctx *conf_ctx, mem_ctx = talloc_stackframe(); if (argc != 1) { - net_conf_showshare_usage(argc, argv); + net_conf_showshare_usage(c, argc, argv); goto done; } @@ -466,8 +483,9 @@ done: * This is a high level utility function of the net conf utility, * not a direct frontend to the smbconf API. */ -static int net_conf_addshare(struct smbconf_ctx *conf_ctx, - int argc, const char **argv) +static int net_conf_addshare(struct net_context *c, + struct smbconf_ctx *conf_ctx, int argc, + const char **argv) { int ret = -1; WERROR werr = WERR_OK; @@ -483,13 +501,13 @@ static int net_conf_addshare(struct smbconf_ctx *conf_ctx, case 0: case 1: default: - net_conf_addshare_usage(argc, argv); + net_conf_addshare_usage(c, argc, argv); goto done; case 5: comment = argv[4]; case 4: if (!strnequal(argv[3], "guest_ok=", 9)) { - net_conf_addshare_usage(argc, argv); + net_conf_addshare_usage(c, argc, argv); goto done; } switch (argv[3][9]) { @@ -502,12 +520,12 @@ static int net_conf_addshare(struct smbconf_ctx *conf_ctx, guest_ok = "no"; break; default: - net_conf_addshare_usage(argc, argv); + net_conf_addshare_usage(c, argc, argv); goto done; } case 3: if (!strnequal(argv[2], "writeable=", 10)) { - net_conf_addshare_usage(argc, argv); + net_conf_addshare_usage(c, argc, argv); goto done; } switch (argv[2][10]) { @@ -520,7 +538,7 @@ static int net_conf_addshare(struct smbconf_ctx *conf_ctx, writeable = "no"; break; default: - net_conf_addshare_usage(argc, argv); + net_conf_addshare_usage(c, argc, argv); goto done; } case 2: @@ -646,8 +664,9 @@ done: return ret; } -static int net_conf_delshare(struct smbconf_ctx *conf_ctx, - int argc, const char **argv) +static int net_conf_delshare(struct net_context *c, + struct smbconf_ctx *conf_ctx, int argc, + const char **argv) { int ret = -1; const char *sharename = NULL; @@ -655,7 +674,7 @@ static int net_conf_delshare(struct smbconf_ctx *conf_ctx, TALLOC_CTX *mem_ctx = talloc_stackframe(); if (argc != 1) { - net_conf_delshare_usage(argc, argv); + net_conf_delshare_usage(c, argc, argv); goto done; } sharename = talloc_strdup_lower(mem_ctx, argv[0]); @@ -677,7 +696,7 @@ done: return ret; } -static int net_conf_setparm(struct smbconf_ctx *conf_ctx, +static int net_conf_setparm(struct net_context *c, struct smbconf_ctx *conf_ctx, int argc, const char **argv) { int ret = -1; @@ -688,7 +707,7 @@ static int net_conf_setparm(struct smbconf_ctx *conf_ctx, TALLOC_CTX *mem_ctx = talloc_stackframe(); if (argc != 3) { - net_conf_setparm_usage(argc, argv); + net_conf_setparm_usage(c, argc, argv); goto done; } service = talloc_strdup_lower(mem_ctx, argv[0]); @@ -727,7 +746,7 @@ done: return ret; } -static int net_conf_getparm(struct smbconf_ctx *conf_ctx, +static int net_conf_getparm(struct net_context *c, struct smbconf_ctx *conf_ctx, int argc, const char **argv) { int ret = -1; @@ -740,7 +759,7 @@ static int net_conf_getparm(struct smbconf_ctx *conf_ctx, mem_ctx = talloc_stackframe(); if (argc != 2) { - net_conf_getparm_usage(argc, argv); + net_conf_getparm_usage(c, argc, argv); goto done; } service = talloc_strdup_lower(mem_ctx, argv[0]); @@ -780,7 +799,7 @@ done: return ret; } -static int net_conf_delparm(struct smbconf_ctx *conf_ctx, +static int net_conf_delparm(struct net_context *c, struct smbconf_ctx *conf_ctx, int argc, const char **argv) { int ret = -1; @@ -790,7 +809,7 @@ static int net_conf_delparm(struct smbconf_ctx *conf_ctx, TALLOC_CTX *mem_ctx = talloc_stackframe(); if (argc != 2) { - net_conf_delparm_usage(argc, argv); + net_conf_delparm_usage(c, argc, argv); goto done; } service = talloc_strdup_lower(mem_ctx, argv[0]); @@ -829,7 +848,8 @@ done: return ret; } -static int net_conf_getincludes(struct smbconf_ctx *conf_ctx, +static int net_conf_getincludes(struct net_context *c, + struct smbconf_ctx *conf_ctx, int argc, const char **argv) { WERROR werr; @@ -841,7 +861,7 @@ static int net_conf_getincludes(struct smbconf_ctx *conf_ctx, TALLOC_CTX *mem_ctx = talloc_stackframe(); if (argc != 1) { - net_conf_getincludes_usage(argc, argv); + net_conf_getincludes_usage(c, argc, argv); goto done; } @@ -869,7 +889,8 @@ done: return ret; } -static int net_conf_setincludes(struct smbconf_ctx *conf_ctx, +static int net_conf_setincludes(struct net_context *c, + struct smbconf_ctx *conf_ctx, int argc, const char **argv) { WERROR werr; @@ -880,7 +901,7 @@ static int net_conf_setincludes(struct smbconf_ctx *conf_ctx, TALLOC_CTX *mem_ctx = talloc_stackframe(); if (argc < 1) { - net_conf_setincludes_usage(argc, argv); + net_conf_setincludes_usage(c, argc, argv); goto done; } @@ -910,7 +931,8 @@ done: return ret; } -static int net_conf_delincludes(struct smbconf_ctx *conf_ctx, +static int net_conf_delincludes(struct net_context *c, + struct smbconf_ctx *conf_ctx, int argc, const char **argv) { WERROR werr; @@ -919,7 +941,7 @@ static int net_conf_delincludes(struct smbconf_ctx *conf_ctx, TALLOC_CTX *mem_ctx = talloc_stackframe(); if (argc != 1) { - net_conf_delincludes_usage(argc, argv); + net_conf_delincludes_usage(c, argc, argv); goto done; } @@ -954,7 +976,9 @@ done: * The wrapper calls handles opening and closing of the * configuration. */ -static int net_conf_wrap_function(int (*fn)(struct smbconf_ctx *, +static int net_conf_wrap_function(struct net_context *c, + int (*fn)(struct net_context *, + struct smbconf_ctx *, int, const char **), int argc, const char **argv) { @@ -969,7 +993,7 @@ static int net_conf_wrap_function(int (*fn)(struct smbconf_ctx *, return -1; } - ret = fn(conf_ctx, argc, argv); + ret = fn(c, conf_ctx, argc, argv); smbconf_shutdown(conf_ctx); @@ -983,7 +1007,8 @@ static int net_conf_wrap_function(int (*fn)(struct smbconf_ctx *, */ struct conf_functable { const char *funcname; - int (*fn)(struct smbconf_ctx *ctx, int argc, const char **argv); + int (*fn)(struct net_context *c, struct smbconf_ctx *ctx, int argc, + const char **argv); const char *helptext; }; @@ -991,8 +1016,8 @@ struct conf_functable { * This imitates net_run_function2 but calls the main functions * through the wrapper net_conf_wrap_function(). */ -static int net_conf_run_function(int argc, const char **argv, - const char *whoami, +static int net_conf_run_function(struct net_context *c, int argc, + const char **argv, const char *whoami, struct conf_functable *table) { int i; @@ -1000,7 +1025,7 @@ static int net_conf_run_function(int argc, const char **argv, if (argc != 0) { for (i=0; table[i].funcname; i++) { if (StrCaseCmp(argv[0], table[i].funcname) == 0) - return net_conf_wrap_function(table[i].fn, + return net_conf_wrap_function(c, table[i].fn, argc-1, argv+1); } @@ -1018,7 +1043,7 @@ static int net_conf_run_function(int argc, const char **argv, * Entry-point for all the CONF functions. */ -int net_conf(int argc, const char **argv) +int net_conf(struct net_context *c, int argc, const char **argv) { int ret = -1; struct conf_functable func_table[] = { @@ -1051,7 +1076,7 @@ int net_conf(int argc, const char **argv) {NULL, NULL, NULL} }; - ret = net_conf_run_function(argc, argv, "net conf", func_table); + ret = net_conf_run_function(c, argc, argv, "net conf", func_table); return ret; } diff --git a/source3/utils/net_dom.c b/source3/utils/net_dom.c index 6e4bf14c84..86dad658d6 100644 --- a/source3/utils/net_dom.c +++ b/source3/utils/net_dom.c @@ -20,7 +20,7 @@ #include "includes.h" #include "utils/net.h" -static int net_dom_usage(int argc, const char **argv) +static int net_dom_usage(struct net_context *c, int argc, const char **argv) { d_printf("usage: net dom join " " \n"); @@ -30,7 +30,7 @@ static int net_dom_usage(int argc, const char **argv) return -1; } -int net_help_dom(int argc, const char **argv) +int net_help_dom(struct net_context *c, int argc, const char **argv) { d_printf("net dom join"\ "\n Join a remote machine\n"); @@ -40,7 +40,7 @@ int net_help_dom(int argc, const char **argv) return -1; } -static int net_dom_unjoin(int argc, const char **argv) +static int net_dom_unjoin(struct net_context *c, int argc, const char **argv) { struct libnetapi_ctx *ctx = NULL; const char *server_name = NULL; @@ -56,11 +56,11 @@ static int net_dom_unjoin(int argc, const char **argv) int i; if (argc < 1) { - return net_dom_usage(argc, argv); + return net_dom_usage(c, argc, argv); } - if (opt_host) { - server_name = opt_host; + if (c->opt_host) { + server_name = c->opt_host; } for (i=0; iopt_workgroup, + server_name, NULL, 0, + &cli); if (!NT_STATUS_IS_OK(ntstatus)) { return -1; } @@ -94,8 +95,8 @@ static int net_dom_unjoin(int argc, const char **argv) return -1; } - libnetapi_set_username(ctx, opt_user_name); - libnetapi_set_password(ctx, opt_password); + libnetapi_set_username(ctx, c->opt_user_name); + libnetapi_set_password(ctx, c->opt_password); status = NetUnjoinDomain(server_name, account, password, unjoin_flags); if (status != 0) { @@ -105,18 +106,19 @@ static int net_dom_unjoin(int argc, const char **argv) } if (reboot) { - opt_comment = "Shutting down due to a domain membership change"; - opt_reboot = true; - opt_timeout = 30; + c->opt_comment = "Shutting down due to a domain membership " + "change"; + c->opt_reboot = true; + c->opt_timeout = 30; - ret = run_rpc_command(cli, PI_INITSHUTDOWN, 0, + ret = run_rpc_command(c, cli, PI_INITSHUTDOWN, 0, rpc_init_shutdown_internals, argc, argv); if (ret == 0) { goto done; } - ret = run_rpc_command(cli, PI_WINREG, 0, + ret = run_rpc_command(c, cli, PI_WINREG, 0, rpc_reg_shutdown_internals, argc, argv); goto done; @@ -132,7 +134,7 @@ static int net_dom_unjoin(int argc, const char **argv) return ret; } -static int net_dom_join(int argc, const char **argv) +static int net_dom_join(struct net_context *c, int argc, const char **argv) { struct libnetapi_ctx *ctx = NULL; const char *server_name = NULL; @@ -150,14 +152,14 @@ static int net_dom_join(int argc, const char **argv) int i; if (argc < 1) { - return net_dom_usage(argc, argv); + return net_dom_usage(c, argc, argv); } - if (opt_host) { - server_name = opt_host; + if (c->opt_host) { + server_name = c->opt_host; } - if (opt_force) { + if (c->opt_force) { join_flags |= WKSSVC_JOIN_FLAGS_DOMAIN_JOIN_IF_JOINED; } @@ -192,8 +194,9 @@ static int net_dom_join(int argc, const char **argv) } if (reboot) { - ntstatus = net_make_ipc_connection_ex(opt_workgroup, server_name, - NULL, 0, &cli); + ntstatus = net_make_ipc_connection_ex(c, c->opt_workgroup, + server_name, NULL, 0, + &cli); if (!NT_STATUS_IS_OK(ntstatus)) { return -1; } @@ -206,8 +209,8 @@ static int net_dom_join(int argc, const char **argv) return -1; } - libnetapi_set_username(ctx, opt_user_name); - libnetapi_set_password(ctx, opt_password); + libnetapi_set_username(ctx, c->opt_user_name); + libnetapi_set_password(ctx, c->opt_password); status = NetJoinDomain(server_name, domain_name, account_ou, Account, password, join_flags); @@ -218,18 +221,19 @@ static int net_dom_join(int argc, const char **argv) } if (reboot) { - opt_comment = "Shutting down due to a domain membership change"; - opt_reboot = true; - opt_timeout = 30; + c->opt_comment = "Shutting down due to a domain membership " + "change"; + c->opt_reboot = true; + c->opt_timeout = 30; - ret = run_rpc_command(cli, PI_INITSHUTDOWN, 0, + ret = run_rpc_command(c, cli, PI_INITSHUTDOWN, 0, rpc_init_shutdown_internals, argc, argv); if (ret == 0) { goto done; } - ret = run_rpc_command(cli, PI_WINREG, 0, + ret = run_rpc_command(c, cli, PI_WINREG, 0, rpc_reg_shutdown_internals, argc, argv); goto done; @@ -245,7 +249,7 @@ static int net_dom_join(int argc, const char **argv) return ret; } -int net_dom(int argc, const char **argv) +int net_dom(struct net_context *c, int argc, const char **argv) { struct functable func[] = { {"JOIN", net_dom_join}, @@ -254,5 +258,5 @@ int net_dom(int argc, const char **argv) {NULL, NULL} }; - return net_run_function(argc, argv, func, net_dom_usage); + return net_run_function(c, argc, argv, func, net_dom_usage); } diff --git a/source3/utils/net_groupmap.c b/source3/utils/net_groupmap.c index b0e3d60a24..0fdebcc912 100644 --- a/source3/utils/net_groupmap.c +++ b/source3/utils/net_groupmap.c @@ -72,7 +72,7 @@ static void print_map_entry ( GROUP_MAP map, bool long_list ) /********************************************************* List the groups. **********************************************************/ -static int net_groupmap_list(int argc, const char **argv) +static int net_groupmap_list(struct net_context *c, int argc, const char **argv) { size_t entries; bool long_list = False; @@ -80,7 +80,7 @@ static int net_groupmap_list(int argc, const char **argv) fstring ntgroup = ""; fstring sid_string = ""; - if (opt_verbose || opt_long_list_entries) + if (c->opt_verbose || c->opt_long_list_entries) long_list = True; /* get the options */ @@ -148,7 +148,7 @@ static int net_groupmap_list(int argc, const char **argv) Add a new group mapping entry **********************************************************/ -static int net_groupmap_add(int argc, const char **argv) +static int net_groupmap_add(struct net_context *c, int argc, const char **argv) { DOM_SID sid; fstring ntgroup = ""; @@ -293,7 +293,6 @@ static int net_groupmap_add(int argc, const char **argv) if (!ntgroup[0] ) fstrcpy( ntgroup, unixgrp ); - if (!NT_STATUS_IS_OK(add_initial_entry(gid, string_sid, sid_type, ntgroup, ntcomment))) { d_fprintf(stderr, "adding entry for group %s failed!\n", ntgroup); return -1; @@ -304,7 +303,7 @@ static int net_groupmap_add(int argc, const char **argv) return 0; } -static int net_groupmap_modify(int argc, const char **argv) +static int net_groupmap_modify(struct net_context *c, int argc, const char **argv) { DOM_SID sid; GROUP_MAP map; @@ -436,7 +435,7 @@ static int net_groupmap_modify(int argc, const char **argv) return 0; } -static int net_groupmap_delete(int argc, const char **argv) +static int net_groupmap_delete(struct net_context *c, int argc, const char **argv) { DOM_SID sid; fstring ntgroup = ""; @@ -490,7 +489,7 @@ static int net_groupmap_delete(int argc, const char **argv) return 0; } -static int net_groupmap_set(int argc, const char **argv) +static int net_groupmap_set(struct net_context *c, int argc, const char **argv) { const char *ntgroup = NULL; struct group *grp = NULL; @@ -503,7 +502,7 @@ static int net_groupmap_set(int argc, const char **argv) return -1; } - if ( opt_localgroup && opt_domaingroup ) { + if ( c->opt_localgroup && c->opt_domaingroup ) { d_printf("Can only specify -L or -D, not both\n"); return -1; } @@ -540,11 +539,11 @@ static int net_groupmap_set(int argc, const char **argv) map.gid = grp->gr_gid; - if (opt_rid == 0) { + if (c->opt_rid == 0) { if ( pdb_rid_algorithm() ) - opt_rid = algorithmic_pdb_gid_to_group_rid(map.gid); + c->opt_rid = algorithmic_pdb_gid_to_group_rid(map.gid); else { - if ( !pdb_new_rid((uint32*)&opt_rid) ) { + if ( !pdb_new_rid((uint32*)&c->opt_rid) ) { d_fprintf( stderr, "Could not allocate new RID\n"); return -1; } @@ -552,7 +551,7 @@ static int net_groupmap_set(int argc, const char **argv) } sid_copy(&map.sid, get_global_sam_sid()); - sid_append_rid(&map.sid, opt_rid); + sid_append_rid(&map.sid, c->opt_rid); map.sid_name_use = SID_NAME_DOM_GRP; fstrcpy(map.nt_name, ntgroup); @@ -567,7 +566,7 @@ static int net_groupmap_set(int argc, const char **argv) /* Now we have a mapping entry, update that stuff */ - if ( opt_localgroup || opt_domaingroup ) { + if ( c->opt_localgroup || c->opt_domaingroup ) { if (map.sid_name_use == SID_NAME_WKN_GRP) { d_fprintf(stderr, "Can't change type of the BUILTIN group %s\n", map.nt_name); @@ -575,19 +574,19 @@ static int net_groupmap_set(int argc, const char **argv) } } - if (opt_localgroup) + if (c->opt_localgroup) map.sid_name_use = SID_NAME_ALIAS; - if (opt_domaingroup) + if (c->opt_domaingroup) map.sid_name_use = SID_NAME_DOM_GRP; /* The case (opt_domaingroup && opt_localgroup) was tested for above */ - if (strlen(opt_comment) > 0) - fstrcpy(map.comment, opt_comment); + if (strlen(c->opt_comment) > 0) + fstrcpy(map.comment, c->opt_comment); - if (strlen(opt_newntname) > 0) - fstrcpy(map.nt_name, opt_newntname); + if (strlen(c->opt_newntname) > 0) + fstrcpy(map.nt_name, c->opt_newntname); if (grp != NULL) map.gid = grp->gr_gid; @@ -600,7 +599,7 @@ static int net_groupmap_set(int argc, const char **argv) return 0; } -static int net_groupmap_cleanup(int argc, const char **argv) +static int net_groupmap_cleanup(struct net_context *c, int argc, const char **argv) { GROUP_MAP *map = NULL; size_t i, entries; @@ -629,7 +628,7 @@ static int net_groupmap_cleanup(int argc, const char **argv) return 0; } -static int net_groupmap_addmem(int argc, const char **argv) +static int net_groupmap_addmem(struct net_context *c, int argc, const char **argv) { DOM_SID alias, member; @@ -649,7 +648,7 @@ static int net_groupmap_addmem(int argc, const char **argv) return 0; } -static int net_groupmap_delmem(int argc, const char **argv) +static int net_groupmap_delmem(struct net_context *c, int argc, const char **argv) { DOM_SID alias, member; @@ -669,7 +668,7 @@ static int net_groupmap_delmem(int argc, const char **argv) return 0; } -static int net_groupmap_listmem(int argc, const char **argv) +static int net_groupmap_listmem(struct net_context *c, int argc, const char **argv) { DOM_SID alias; DOM_SID *members; @@ -726,7 +725,7 @@ static bool print_alias_memberships(TALLOC_CTX *mem_ctx, return True; } -static int net_groupmap_memberships(int argc, const char **argv) +static int net_groupmap_memberships(struct net_context *c, int argc, const char **argv) { TALLOC_CTX *mem_ctx; DOM_SID *domain_sid, *builtin_sid, member; @@ -759,7 +758,7 @@ static int net_groupmap_memberships(int argc, const char **argv) return 0; } -int net_help_groupmap(int argc, const char **argv) +int net_help_groupmap(struct net_context *c, int argc, const char **argv) { d_printf("net groupmap add"\ "\n Create a new group mapping\n"); @@ -789,7 +788,7 @@ int net_help_groupmap(int argc, const char **argv) /*********************************************************** migrated functionality from smbgroupedit **********************************************************/ -int net_groupmap(int argc, const char **argv) +int net_groupmap(struct net_context *c, int argc, const char **argv) { struct functable func[] = { {"add", net_groupmap_add}, @@ -813,8 +812,8 @@ int net_groupmap(int argc, const char **argv) } if ( argc ) - return net_run_function(argc, argv, func, net_help_groupmap); + return net_run_function(c, argc, argv, func, net_help_groupmap); - return net_help_groupmap( argc, argv ); + return net_help_groupmap(c, argc, argv ); } diff --git a/source3/utils/net_help.c b/source3/utils/net_help.c index 908be0512a..61d4167019 100644 --- a/source3/utils/net_help.c +++ b/source3/utils/net_help.c @@ -20,7 +20,7 @@ #include "includes.h" #include "utils/net.h" -int net_common_methods_usage(int argc, const char**argv) +int net_common_methods_usage(struct net_context *c, int argc, const char**argv) { d_printf("Valid methods: (auto-detected if not specified)\n"); d_printf("\tads\t\t\t\tActive Directory (LDAP/Kerberos)\n"); @@ -30,7 +30,7 @@ int net_common_methods_usage(int argc, const char**argv) return 0; } -int net_common_flags_usage(int argc, const char **argv) +int net_common_flags_usage(struct net_context *c, int argc, const char **argv) { d_printf("Valid targets: choose one (none defaults to localhost)\n"); d_printf("\t-S or --server=\t\tserver name\n"); @@ -52,7 +52,7 @@ int net_common_flags_usage(int argc, const char **argv) return -1; } -static int help_usage(int argc, const char **argv) +static int help_usage(struct net_context *c, int argc, const char **argv) { d_printf( "\n"\ @@ -65,7 +65,7 @@ static int help_usage(int argc, const char **argv) return -1; } -int net_help_user(int argc, const char **argv) +int net_help_user(struct net_context *c, int argc, const char **argv) { d_printf("\nnet [] user [misc. options] [targets]"\ "\n\tList users\n\n"); @@ -80,14 +80,14 @@ int net_help_user(int argc, const char **argv) " [targets]\n\tRename specified user\n\n"); - net_common_methods_usage(argc, argv); - net_common_flags_usage(argc, argv); + net_common_methods_usage(c, argc, argv); + net_common_flags_usage(c, argc, argv); d_printf("\t-C or --comment=\tdescriptive comment (for add only)\n"); d_printf("\t-c or --container=\tLDAP container, defaults to cn=Users (for add in ADS only)\n"); return -1; } -int net_help_group(int argc, const char **argv) +int net_help_group(struct net_context *c, int argc, const char **argv) { d_printf("net [] group [misc. options] [targets]"\ "\n\tList user groups\n\n"); @@ -101,26 +101,26 @@ int net_help_group(int argc, const char **argv) d_printf("\nnet rpc group MEMBERS \n\tList Group Members\n\n"); d_printf("\nnet rpc group ADDMEM \n\tAdd Group Members\n\n"); d_printf("\nnet rpc group DELMEM \n\tDelete Group Members\n\n"); - net_common_methods_usage(argc, argv); - net_common_flags_usage(argc, argv); + net_common_methods_usage(c, argc, argv); + net_common_flags_usage(c, argc, argv); d_printf("\t-C or --comment=\tdescriptive comment (for add only)\n"); d_printf("\t-c or --container=\tLDAP container, defaults to cn=Users (for add in ADS only)\n"); d_printf("\t-L or --localgroup\t\tWhen adding groups, create a local group (alias)\n"); return -1; } -int net_help_join(int argc, const char **argv) +int net_help_join(struct net_context *c, int argc, const char **argv) { d_printf("\nnet [] join [misc. options]\n" "\tjoins this server to a domain\n"); d_printf("Valid methods: (auto-detected if not specified)\n"); d_printf("\tads\t\t\t\tActive Directory (LDAP/Kerberos)\n"); d_printf("\trpc\t\t\t\tDCE-RPC\n"); - net_common_flags_usage(argc, argv); + net_common_flags_usage(c, argc, argv); return -1; } -int net_help_share(int argc, const char **argv) +int net_help_share(struct net_context *c, int argc, const char **argv) { d_printf( "\nnet [] share [misc. options] [targets] \n" @@ -145,8 +145,8 @@ int net_help_share(int argc, const char **argv) "\n\tMigrates shares (including directories, files) from remote\n" "\tto local server\n\n" ); - net_common_methods_usage(argc, argv); - net_common_flags_usage(argc, argv); + net_common_methods_usage(c, argc, argv); + net_common_flags_usage(c, argc, argv); d_printf( "\t-C or --comment=\tdescriptive comment (for add only)\n" "\t-M or --maxusers=\t\tmax users allowed for share\n" @@ -159,7 +159,7 @@ int net_help_share(int argc, const char **argv) return -1; } -int net_help_file(int argc, const char **argv) +int net_help_file(struct net_context *c, int argc, const char **argv) { d_printf("net [] file [misc. options] [targets]\n"\ "\tlists all open files on file server\n\n"); @@ -171,12 +171,12 @@ int net_help_file(int argc, const char **argv) d_printf("net [rap] file INFO [misc. options] [targets]\n"\ "\tdisplays information about the specified open file\n"); - net_common_methods_usage(argc, argv); - net_common_flags_usage(argc, argv); + net_common_methods_usage(c, argc, argv); + net_common_flags_usage(c, argc, argv); return -1; } -int net_help_printer(int argc, const char **argv) +int net_help_printer(struct net_context *c, int argc, const char **argv) { d_printf("net rpc printer LIST [printer] [misc. options] [targets]\n"\ "\tlists all printers on print-server\n\n"); @@ -198,8 +198,8 @@ int net_help_printer(int argc, const char **argv) d_printf("net rpc printer MIGRATE ALL [printer] [misc. options] [targets]"\ "\n\tmigrates drivers, forms, queues, settings and acls from\n"\ "\tremote to local print-server\n\n"); - net_common_methods_usage(argc, argv); - net_common_flags_usage(argc, argv); + net_common_methods_usage(c, argc, argv); + net_common_flags_usage(c, argc, argv); d_printf( "\t-v or --verbose\t\t\tgive verbose output\n" "\t --destination\t\tmigration target server (default: localhost)\n"); @@ -208,7 +208,7 @@ int net_help_printer(int argc, const char **argv) } -int net_help_status(int argc, const char **argv) +int net_help_status(struct net_context *c, int argc, const char **argv) { d_printf(" net status sessions [parseable] " "Show list of open sessions\n"); @@ -217,7 +217,7 @@ int net_help_status(int argc, const char **argv) return -1; } -static int net_usage(int argc, const char **argv) +static int net_usage(struct net_context *c, int argc, const char **argv) { d_printf(" net time\t\tto view or set time information\n"\ " net lookup\t\tto lookup host name or ip address\n"\ @@ -243,14 +243,14 @@ static int net_usage(int argc, const char **argv) " net rpc \tto run RPC commands\n"\ "\n"\ "Type \"net help