summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLuke Leighton <lkcl@samba.org>1999-11-27 00:02:03 +0000
committerLuke Leighton <lkcl@samba.org>1999-11-27 00:02:03 +0000
commit4c92992b4e9797f34113251c00a99eafa97958bf (patch)
treef0f8a527679e926dd39c0e54384bafe2962058d8
parent9b683054751866af4fb2ac79c092392e31effaff (diff)
downloadsamba-4c92992b4e9797f34113251c00a99eafa97958bf.tar.gz
samba-4c92992b4e9797f34113251c00a99eafa97958bf.tar.bz2
samba-4c92992b4e9797f34113251c00a99eafa97958bf.zip
bug-fixing registry commands and the rpcclient "rpcclient" command.
the rpcclient "rpcclient" command allows user options to be reset (e.g the username / password) _without_ terminating rpcclient. try this: rpcclient -S srv1 -U% -l log srv1$ rpcclient -S srv2 srv2$ :-) (This used to be commit c049865782d87ca09744ecdefb387b7852ec2ae7)
-rw-r--r--source3/include/proto.h1
-rw-r--r--source3/rpcclient/cmd_reg.c77
-rw-r--r--source3/rpcclient/rpcclient.c109
3 files changed, 122 insertions, 65 deletions
diff --git a/source3/include/proto.h b/source3/include/proto.h
index ec340ec1d6..3380bc4e63 100644
--- a/source3/include/proto.h
+++ b/source3/include/proto.h
@@ -3571,6 +3571,7 @@ void cmd_sam_sync(struct client_info *info, int argc, char *argv[]);
/*The following definitions come from rpcclient/cmd_reg.c */
+void split_server_keyname(char *srv_name, char *key, const char* arg);
BOOL msrpc_reg_enum_key(const char* srv_name, const char* full_keyname,
REG_FN(reg_fn),
REG_KEY_FN(reg_key_fn),
diff --git a/source3/rpcclient/cmd_reg.c b/source3/rpcclient/cmd_reg.c
index 38c14ea96b..8d8d8f0167 100644
--- a/source3/rpcclient/cmd_reg.c
+++ b/source3/rpcclient/cmd_reg.c
@@ -37,15 +37,16 @@ extern FILE* out_hnd;
* keys. of the form:
* ----
*
- * [HKLM]|[HKU]\[parent_keyname_components]\[subkey]|[value]
+ * [HKLM]|[HKU]|[HKCR]\[parent_keyname]\[subkey]|[value]
*
* reg_getsubkey() splits this down into:
- * [HKLM]|[HKU]\[parent_keyname_components] and [subkey]|[value]
+ * [HKLM]|[HKU]|[HKCR]\[parent_keyname_components] and [subkey]|[value]
*
* reg_connect() splits the left side down further into:
- * [HKLM]|[HKU] and [parent_keyname_components].
+ * [HKLM]|[HKU]|[HKCR] and [parent_keyname_components].
*
* HKLM is short for HKEY_LOCAL_MACHINE
+ * HKCR is short for HKEY_CLASSES_ROOT
* HKU is short for HKEY_USERS
*
* oh, and HKEY stands for "Hive Key".
@@ -94,6 +95,25 @@ static void reg_display_key(int val, const char *full_keyname, int num)
}
}
+void split_server_keyname(char *srv_name, char *key, const char* arg)
+{
+ pstrcpy(key, arg);
+
+ if (strnequal("\\\\", key, 2))
+ {
+ char *p = strchr(&key[2], '\\');
+ if (p == NULL)
+ {
+ key[0] = 0;
+ return;
+ }
+
+ *p = 0;
+
+ fstrcpy(srv_name, key);
+ pstrcpy(key, &arg[strlen(srv_name)+1]);
+ }
+}
/****************************************************************************
nt registry enum
@@ -150,8 +170,7 @@ BOOL msrpc_reg_enum_key(const char* srv_name, const char* full_keyname,
memcpy(&key_pol, &pol_con, sizeof(key_pol));
}
- res1 = res1 ? reg_query_key(
- &key_pol,
+ res1 = res1 ? reg_query_key(&key_pol,
key_class, &max_class_len,
&num_subkeys, &max_subkeylen, &max_subkeysize,
&num_values, &max_valnamelen, &max_valbufsize,
@@ -278,7 +297,7 @@ nt registry enum
****************************************************************************/
void cmd_reg_enum(struct client_info *info, int argc, char *argv[])
{
- char *full_keyname;
+ pstring full_keyname;
fstring srv_name;
@@ -292,7 +311,7 @@ void cmd_reg_enum(struct client_info *info, int argc, char *argv[])
return;
}
- full_keyname = argv[1];
+ split_server_keyname(srv_name, full_keyname, argv[1]);
(void)(msrpc_reg_enum_key(srv_name, full_keyname,
reg_display_key,
@@ -310,7 +329,7 @@ void cmd_reg_query_info(struct client_info *info, int argc, char *argv[])
POLICY_HND key_pol;
POLICY_HND pol_con;
- char *full_keyname;
+ pstring full_keyname;
fstring key_name;
fstring keyname;
fstring val_name;
@@ -334,7 +353,7 @@ void cmd_reg_query_info(struct client_info *info, int argc, char *argv[])
return;
}
- full_keyname = argv[1];
+ split_server_keyname(srv_name, full_keyname, argv[1]);
reg_get_subkey(full_keyname, keyname, val_name);
@@ -395,7 +414,7 @@ void cmd_reg_query_key(struct client_info *info, int argc, char *argv[])
POLICY_HND key_pol;
POLICY_HND pol_con;
- char *full_keyname;
+ pstring full_keyname;
fstring key_name;
/*
@@ -425,7 +444,7 @@ void cmd_reg_query_key(struct client_info *info, int argc, char *argv[])
return;
}
- full_keyname = argv[1];
+ split_server_keyname(srv_name, full_keyname, argv[1]);
/* open registry receive a policy handle */
res = res ? reg_connect(srv_name, full_keyname, key_name,
@@ -442,8 +461,7 @@ void cmd_reg_query_key(struct client_info *info, int argc, char *argv[])
memcpy(&key_pol, &pol_con, sizeof(key_pol));
}
- res1 = res1 ? reg_query_key(
- &key_pol,
+ res1 = res1 ? reg_query_key(&key_pol,
key_class, &key_class_len,
&num_subkeys, &max_subkeylen, &max_subkeysize,
&num_values, &max_valnamelen, &max_valbufsize,
@@ -451,8 +469,7 @@ void cmd_reg_query_key(struct client_info *info, int argc, char *argv[])
if (res1 && key_class_len != 0)
{
- res1 = res1 ? reg_query_key(
- &key_pol,
+ res1 = res1 ? reg_query_key(&key_pol,
key_class, &key_class_len,
&num_subkeys, &max_subkeylen, &max_subkeysize,
&num_values, &max_valnamelen, &max_valbufsize,
@@ -497,7 +514,7 @@ void cmd_reg_create_val(struct client_info *info, int argc, char *argv[])
POLICY_HND parent_pol;
POLICY_HND pol_con;
- char *full_keyname;
+ pstring full_keyname;
fstring keyname;
fstring parent_name;
fstring val_name;
@@ -525,13 +542,13 @@ void cmd_reg_create_val(struct client_info *info, int argc, char *argv[])
return;
}
- argc--;
- argv++;
-
- full_keyname = argv[0];
+ split_server_keyname(srv_name, full_keyname, argv[1]);
reg_get_subkey(full_keyname, keyname, val_name);
+ argc--;
+ argv++;
+
if (keyname[0] == 0 || val_name[0] == 0)
{
report(out_hnd, "invalid key name\n");
@@ -637,7 +654,7 @@ void cmd_reg_delete_val(struct client_info *info, int argc, char *argv[])
POLICY_HND parent_pol;
POLICY_HND pol_con;
- char *full_keyname;
+ pstring full_keyname;
fstring keyname;
fstring parent_name;
fstring val_name;
@@ -654,7 +671,7 @@ void cmd_reg_delete_val(struct client_info *info, int argc, char *argv[])
return;
}
- full_keyname = argv[1];
+ split_server_keyname(srv_name, full_keyname, argv[1]);
reg_get_subkey(full_keyname, keyname, val_name);
@@ -713,7 +730,7 @@ void cmd_reg_delete_key(struct client_info *info, int argc, char *argv[])
POLICY_HND parent_pol;
POLICY_HND pol_con;
- char *full_keyname;
+ pstring full_keyname;
fstring parent_name;
fstring key_name;
fstring subkey_name;
@@ -730,7 +747,7 @@ void cmd_reg_delete_key(struct client_info *info, int argc, char *argv[])
return;
}
- full_keyname = argv[1];
+ split_server_keyname(srv_name, full_keyname, argv[1]);
reg_get_subkey(full_keyname, parent_name, subkey_name);
@@ -793,7 +810,7 @@ void cmd_reg_create_key(struct client_info *info, int argc, char *argv[])
POLICY_HND parent_pol;
POLICY_HND key_pol;
POLICY_HND pol_con;
- char *full_keyname;
+ pstring full_keyname;
fstring parent_key;
fstring parent_name;
fstring key_name;
@@ -812,7 +829,7 @@ void cmd_reg_create_key(struct client_info *info, int argc, char *argv[])
return;
}
- full_keyname = argv[1];
+ split_server_keyname(srv_name, full_keyname, argv[1]);
reg_get_subkey(full_keyname, parent_key, key_name);
@@ -890,7 +907,7 @@ void cmd_reg_test_key_sec(struct client_info *info, int argc, char *argv[])
POLICY_HND key_pol;
POLICY_HND pol_con;
- char *full_keyname;
+ pstring full_keyname;
fstring key_name;
/*
@@ -913,7 +930,7 @@ void cmd_reg_test_key_sec(struct client_info *info, int argc, char *argv[])
return;
}
- full_keyname = argv[1];
+ split_server_keyname(srv_name, full_keyname, argv[1]);
/* open registry receive a policy handle */
res = res ? reg_connect(srv_name, full_keyname, key_name,
@@ -994,7 +1011,7 @@ void cmd_reg_get_key_sec(struct client_info *info, int argc, char *argv[])
POLICY_HND key_pol;
POLICY_HND pol_con;
- char *full_keyname;
+ pstring full_keyname;
fstring key_name;
/*
@@ -1017,7 +1034,7 @@ void cmd_reg_get_key_sec(struct client_info *info, int argc, char *argv[])
return;
}
- full_keyname = argv[1];
+ split_server_keyname(srv_name, full_keyname, argv[1]);
/* open registry receive a policy handle */
res = res ? reg_connect(srv_name, full_keyname, key_name,
diff --git a/source3/rpcclient/rpcclient.c b/source3/rpcclient/rpcclient.c
index 70f7d0d87e..f0f4a6de5c 100644
--- a/source3/rpcclient/rpcclient.c
+++ b/source3/rpcclient/rpcclient.c
@@ -649,18 +649,13 @@ static int process_tok(char *tok)
return(-2);
}
-/* command options mask */
-static uint32 cmd_set_options = 0xffffffff;
-
/****************************************************************************
- process commands from the client
+ turn command line into command argument array
****************************************************************************/
-static BOOL do_command(struct client_info *info, char *line)
+static BOOL get_cmd_args(char *line)
{
- int i;
char *ptr = line;
pstring tok;
-
cmd_argc = 0;
cmd_argv = NULL;
@@ -676,6 +671,21 @@ static BOOL do_command(struct client_info *info, char *line)
} while (next_token(NULL, tok, NULL, sizeof(tok)));
+ return True;
+}
+
+/* command options mask */
+static uint32 cmd_set_options = 0xffffffff;
+
+/****************************************************************************
+ process commands from the client
+****************************************************************************/
+static BOOL do_command(struct client_info *info, char *line)
+{
+ int i;
+
+ if (!get_cmd_args(line)) return False;
+
if (cmd_argc == 0)
{
return False;
@@ -693,11 +703,13 @@ static BOOL do_command(struct client_info *info, char *line)
}
else if (i == -2)
{
- fprintf(out_hnd, "%s: command abbreviation ambiguous\n", CNV_LANG(tok));
+ fprintf(out_hnd, "%s: command abbreviation ambiguous\n",
+ CNV_LANG(cmd_argv[0]));
}
else
{
- fprintf(out_hnd, "%s: command not found\n", CNV_LANG(tok));
+ fprintf(out_hnd, "%s: command not found\n",
+ CNV_LANG(cmd_argv[0]));
}
free_char_array(cmd_argc, cmd_argv);
@@ -916,10 +928,16 @@ static char *complete_regenum(char *text, int state)
if (state == 0)
{
fstring srv_name;
+ fstrcpy(srv_name, "\\\\");
+ fstrcat(srv_name, cli_info.dest_host);
+ strupper(srv_name);
+
if (cmd_argc >= 2 && cmd_argv != NULL && cmd_argv[1] != NULL)
{
char *sep;
- pstrcpy(full_keyname, cmd_argv[1]);
+ split_server_keyname(srv_name, full_keyname,
+ cmd_argv[1]);
+
sep = strrchr(full_keyname, '\\');
if (sep != NULL)
{
@@ -927,10 +945,6 @@ static char *complete_regenum(char *text, int state)
}
}
- fstrcpy(srv_name, "\\\\");
- fstrcat(srv_name, cli_info.dest_host);
- strupper(srv_name);
-
/* Iterate all keys / values */
if (!msrpc_reg_enum_key(srv_name, full_keyname,
reg_init, reg_key_list, reg_val_list))
@@ -1249,6 +1263,8 @@ static char **completion_fn(char *text, int start, int end)
int i;
char lastch = ' ';
+ (void)get_cmd_args(rl_line_buffer);
+
safe_strcpy(cmd_partial, rl_line_buffer,
MAX(sizeof(cmd_partial),end)-1);
@@ -1354,7 +1370,6 @@ static void set_user_password(struct user_credentials *u,
}
}
-#define CMD_INTER 0x0
#define CMD_STR 0x1
#define CMD_DBF 0x2
#define CMD_SVC 0x4
@@ -1372,6 +1387,7 @@ static void set_user_password(struct user_credentials *u,
#define CMD_NAME 0x4000
#define CMD_DBG 0x8000
#define CMD_SCOPE 0x10000
+#define CMD_INTER 0x20000
static void cmd_set(struct client_info *info, int argc, char *argv[])
{
@@ -1390,7 +1406,7 @@ static void cmd_set(struct client_info *info, int argc, char *argv[])
*term_code = 0;
#endif /* KANJI */
- if (*argv[1] != '-')
+ if (argc > 1 && *argv[1] != '-')
{
if (argc > 1 && (*argv[1] != '-'))
{
@@ -1457,6 +1473,10 @@ static void cmd_set(struct client_info *info, int argc, char *argv[])
cmd_set_options |= CMD_PASS;
memset(strchr(optarg,'%')+1,'X',strlen(password));
}
+ if (usr.user_name[0] == 0 && password[0] == 0)
+ {
+ cmd_set_options |= CMD_NOPW;
+ }
break;
}
@@ -1554,13 +1574,18 @@ static void cmd_set(struct client_info *info, int argc, char *argv[])
}
}
+ DEBUG(10,("cmd_set: options: %x\n", cmd_set_options));
+
if (IS_BITS_SET_ALL(cmd_set_options, CMD_HELP))
{
return;
}
- setup_logging(debugf, interactive);
- reopen_logs();
+ if (IS_BITS_SET_ALL(cmd_set_options, CMD_INTER))
+ {
+ setup_logging(debugf, interactive);
+ reopen_logs();
+ }
if (IS_BITS_SET_ALL(cmd_set_options, CMD_NOPW))
{
@@ -1577,12 +1602,19 @@ static void cmd_set(struct client_info *info, int argc, char *argv[])
strupper(global_myname);
fstrcpy(cli_info.myhostname, global_myname);
- if (!lp_load(servicesf,True, False, False))
+ if (IS_BITS_SET_ALL(cmd_set_options, CMD_SVC))
{
- fprintf(stderr, "Can't load %s - run testparm to debug it\n", servicesf);
+ if (!lp_load(servicesf,True, False, False))
+ {
+ fprintf(stderr, "Can't load %s - run testparm to debug it\n", servicesf);
+ }
+
}
- load_interfaces();
+ if (IS_BITS_SET_ALL(cmd_set_options, CMD_INTER))
+ {
+ load_interfaces();
+ }
fstrcpy(cli_info.mach_acct, cli_info.myhostname);
strupper(cli_info.mach_acct);
@@ -1636,6 +1668,26 @@ static void read_user_env(struct user_credentials *u)
bzero(password, sizeof(password));
}
+void readline_init(void)
+{
+#ifdef HAVE_LIBREADLINE
+
+ /* Initialise GNU Readline */
+
+ rl_readline_name = "rpcclient";
+ rl_attempted_completion_function = completion_fn;
+ rl_completion_entry_function = (Function *)complete_cmd_null;
+
+ /* Initialise history list */
+
+ using_history();
+
+#else
+ int x;
+ x = 0; /* stop compiler warnings */
+#endif /* HAVE_LIBREADLINE */
+}
+
/****************************************************************************
main program
****************************************************************************/
@@ -1666,20 +1718,7 @@ static void read_user_env(struct user_credentials *u)
fstrcpy(cli_info.dom.level3_dom, "");
fstrcpy(cli_info.dom.level5_dom, "");
-#ifdef HAVE_LIBREADLINE
-
- /* Initialise GNU Readline */
-
- rl_readline_name = "rpcclient";
- rl_attempted_completion_function = completion_fn;
- rl_completion_entry_function = (Function *)complete_cmd_null;
-
- /* Initialise history list */
-
- using_history();
-
-#endif /* HAVE_LIBREADLINE */
-
+ readline_init();
TimeInit();
charset_initialise();