1 /*
2    Samba Unix/Linux SMB client library
3    Distributed SMB/CIFS Server Management Utility
4    Copyright (C) 2001 Andrew Bartlett (abartlet@samba.org)
5 
6    This program is free software; you can redistribute it and/or modify
7    it under the terms of the GNU General Public License as published by
8    the Free Software Foundation; either version 3 of the License, or
9    (at your option) any later version.
10 
11    This program is distributed in the hope that it will be useful,
12    but WITHOUT ANY WARRANTY; without even the implied warranty of
13    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14    GNU General Public License for more details.
15 
16    You should have received a copy of the GNU General Public License
17    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
18 
19 /*
20  * A function of this type is passed to the '
21  * run_rpc_command' wrapper.  Must go before the net_proto.h
22  * include
23  */
24 
25 struct cli_state;
26 
27 #include "../librpc/gen_ndr/lsa.h"
28 
29 #include "intl.h"
30 #ifdef HAVE_LIBINTL_H
31 #include <libintl.h>
32 #endif
33 
34 #if defined(HAVE_GETTEXT) && !defined(__LCLINT__)
35 #define _(foo) gettext(foo)
36 #else
37 #define _(foo) foo
38 #endif
39 
40 #define MODULE_NAME "net"
41 
42 struct net_context {
43 	const char *opt_requester_name;
44 	const char *opt_host;
45 	const char *opt_password;
46 	const char *opt_user_name;
47 	bool opt_user_specified;
48 	const char *opt_workgroup;
49 	int opt_long_list_entries;
50 	int opt_reboot;
51 	int opt_force;
52 	int opt_stdin;
53 	int opt_port;
54 	int opt_verbose;
55 	int opt_maxusers;
56 	const char *opt_comment;
57 	const char *opt_container;
58 	int opt_flags;
59 	int opt_timeout;
60 	int opt_request_timeout;
61 	const char *opt_target_workgroup;
62 	int opt_machine_pass;
63 	int opt_localgroup;
64 	int opt_domaingroup;
65 	int do_talloc_report;
66 	const char *opt_newntname;
67 	int opt_rid;
68 	int opt_acls;
69 	int opt_attrs;
70 	int opt_timestamps;
71 	const char *opt_exclude;
72 	const char *opt_destination;
73 	int opt_testmode;
74 	int opt_kerberos;
75 	int opt_force_full_repl;
76 	int opt_ccache;
77 	int opt_single_obj_repl;
78 	int opt_clean_old_entries;
79 	const char *opt_db;
80 	int opt_lock;
81 	int opt_auto;
82 	int opt_repair;
83 	int opt_reg_version;
84 	const char *opt_output;
85 	int opt_wipe;
86 	const char *opt_precheck;
87 	int opt_no_dns_updates;
88 	int opt_keep_account;
89 	int opt_json;
90 	int opt_continue_on_error;
91 	int opt_recursive;
92 	int opt_follow_symlink;
93 
94 	int opt_have_ip;
95 	struct sockaddr_storage opt_dest_ip;
96 	bool smb_encrypt;
97 	struct libnetapi_ctx *netapi_ctx;
98 	struct messaging_context *msg_ctx;
99 	struct netlogon_creds_cli_context *netlogon_creds;
100 
101 	bool display_usage;
102 	void *private_data;
103 };
104 
105 struct net_dc_info {
106 	bool is_dc;
107 	bool is_pdc;
108 	bool is_ad;
109 	bool is_mixed_mode;
110 	const char *netbios_domain_name;
111 	const char *dns_domain_name;
112 	const char *forest_name;
113 };
114 
115 #define NET_TRANSPORT_LOCAL 0x01
116 #define NET_TRANSPORT_RAP   0x02
117 #define NET_TRANSPORT_RPC   0x04
118 #define NET_TRANSPORT_ADS   0x08
119 
120 struct functable {
121 	const char *funcname;
122 	int (*fn)(struct net_context *c, int argc, const char **argv);
123 	int valid_transports;
124 	const char *description;
125 	const char *usage;
126 };
127 
128 typedef NTSTATUS (*rpc_command_fn)(struct net_context *c,
129 				const struct dom_sid *,
130 				const char *,
131 				struct cli_state *cli,
132 				struct rpc_pipe_client *,
133 				TALLOC_CTX *,
134 				int,
135 				const char **);
136 
137 typedef struct copy_clistate {
138 	TALLOC_CTX *mem_ctx;
139 	struct cli_state *cli_share_src;
140 	struct cli_state *cli_share_dst;
141 	char *cwd;
142 	uint16_t attribute;
143 	struct net_context *c;
144 }copy_clistate;
145 
146 struct rpc_sh_ctx {
147 	struct cli_state *cli;
148 
149 	struct dom_sid *domain_sid;
150 	const char *domain_name;
151 
152 	const char *whoami;
153 	const char *thiscmd;
154 	struct rpc_sh_cmd *cmds;
155 	struct rpc_sh_ctx *parent;
156 };
157 
158 struct rpc_sh_cmd {
159 	const char *name;
160 	struct rpc_sh_cmd *(*sub)(struct net_context *c,
161 				  TALLOC_CTX *mem_ctx,
162 				  struct rpc_sh_ctx *ctx);
163 	const struct ndr_interface_table *table;
164 	NTSTATUS (*fn)(struct net_context *c, TALLOC_CTX *mem_ctx,
165 		       struct rpc_sh_ctx *ctx,
166 		       struct rpc_pipe_client *pipe_hnd,
167 		       int argc, const char **argv);
168 	const char *help;
169 };
170 
171 enum netdom_domain_t { ND_TYPE_NT4, ND_TYPE_AD };
172 
173 /* INCLUDE FILES */
174 
175 #include "utils/net_proto.h"
176 #include "utils/net_help_common.h"
177 
178 /* MACROS & DEFINES */
179 
180 #define NET_FLAGS_MASTER 			0x00000001
181 #define NET_FLAGS_DMB 				0x00000002
182 #define NET_FLAGS_LOCALHOST_DEFAULT_INSANE 	0x00000004 	/* Would it be insane to set 'localhost'
183 								   as the default remote host for this
184 								   operation?  For example, localhost
185 								   is insane for a 'join' operation.  */
186 #define NET_FLAGS_PDC 				0x00000008	/* PDC only */
187 #define NET_FLAGS_ANONYMOUS 			0x00000010	/* use an anonymous connection */
188 #define NET_FLAGS_NO_PIPE 			0x00000020	/* don't open an RPC pipe */
189 #define NET_FLAGS_SIGN				0x00000040	/* sign RPC connection */
190 #define NET_FLAGS_SEAL				0x00000080	/* seal RPC connection */
191 #define NET_FLAGS_TCP				0x00000100	/* use ncacn_ip_tcp */
192 #define NET_FLAGS_EXPECT_FALLBACK		0x00000200	/* the caller will fallback */
193 
194 /* net share operation modes */
195 #define NET_MODE_SHARE_MIGRATE 1
196 
197