summaryrefslogtreecommitdiff
path: root/source3
diff options
context:
space:
mode:
authorLuke Leighton <lkcl@samba.org>1999-11-29 21:16:12 +0000
committerLuke Leighton <lkcl@samba.org>1999-11-29 21:16:12 +0000
commit44334ace985b55295dfc1c93e92d46e01d39fb97 (patch)
treec5fea98bba79a19cda1226954794a3407be93c71 /source3
parente302cb2b189f679bcf7efe60d5ae9fb4218c1411 (diff)
downloadsamba-44334ace985b55295dfc1c93e92d46e01d39fb97.tar.gz
samba-44334ace985b55295dfc1c93e92d46e01d39fb97.tar.bz2
samba-44334ace985b55295dfc1c93e92d46e01d39fb97.zip
ok. got ntlogin command working. argh, it maintains a connection to
the remote machine, because i don't know what to _do_ with it!!!! argh!!! (This used to be commit 85cc680736f17e3f879895be5dac8f1427653919)
Diffstat (limited to 'source3')
-rw-r--r--source3/include/proto.h7
-rw-r--r--source3/lib/util_array.c57
-rw-r--r--source3/rpc_client/cli_connect.c131
-rw-r--r--source3/rpcclient/cmd_netlogon.c2
-rw-r--r--source3/rpcclient/rpcclient.c7
5 files changed, 151 insertions, 53 deletions
diff --git a/source3/include/proto.h b/source3/include/proto.h
index 1ffe32f314..8a0fb3d083 100644
--- a/source3/include/proto.h
+++ b/source3/include/proto.h
@@ -486,10 +486,13 @@ BOOL become_user_permanently(uid_t uid, gid_t gid);
void free_void_array(uint32 num_entries, void **entries,
void(free_item)(void*));
-void* add_item_to_array(uint32 *len, void ***array, const void *item,
+void* add_copy_to_array(uint32 *len, void ***array, const void *item,
void*(item_dup)(const void*), BOOL alloc_anyway);
+void* add_item_to_array(uint32 *len, void ***array, void *item);
void free_char_array(uint32 num_entries, char **entries);
char* add_chars_to_array(uint32 *len, char ***array, const char *name);
+void free_con_array(uint32 num_entries, struct cli_connection **entries);
+struct cli_connection* add_con_to_array(uint32 *len, struct cli_connection ***array, struct cli_connection *con);
void free_uint32_array(uint32 num_entries, uint32 **entries);
uint32* add_uint32s_to_array(uint32 *len, uint32 ***array, const uint32 *name);
void free_unistr_array(uint32 num_entries, UNISTR2 **entries);
@@ -1785,6 +1788,8 @@ BOOL brs_query_info( const char *srv_name, uint32 switch_value,
/*The following definitions come from rpc_client/cli_connect.c */
+void init_connections(void);
+void free_connections(void);
void cli_connection_free(struct cli_connection *con);
void cli_connection_unlink(struct cli_connection *con);
BOOL cli_connection_init_list(char* servers, const char* pipe_name,
diff --git a/source3/lib/util_array.c b/source3/lib/util_array.c
index 5edb6ebf32..71f7046d62 100644
--- a/source3/lib/util_array.c
+++ b/source3/lib/util_array.c
@@ -39,26 +39,40 @@ void free_void_array(uint32 num_entries, void **entries,
}
}
-void* add_item_to_array(uint32 *len, void ***array, const void *item,
+void* add_copy_to_array(uint32 *len, void ***array, const void *item,
void*(item_dup)(const void*), BOOL alloc_anyway)
{
- if (len == NULL || array == NULL || item_dup == NULL)
+ if (len == NULL || array == NULL)
{
return NULL;
}
- (*array) = (void**)Realloc((*array), ((*len)+1)*sizeof((*array)[0]));
-
- if ((*array) != NULL)
+ if (item != NULL || alloc_anyway)
{
void* copy = NULL;
if (item != NULL || alloc_anyway)
{
copy = item_dup(item);
}
- (*array)[(*len)] = copy;
+ add_item_to_array(len, array, copy);
+ }
+ return NULL;
+}
+
+void* add_item_to_array(uint32 *len, void ***array, void *item)
+{
+ if (len == NULL || array == NULL)
+ {
+ return NULL;
+ }
+
+ (*array) = (void**)Realloc((*array), ((*len)+1)*sizeof((*array)[0]));
+
+ if ((*array) != NULL)
+ {
+ (*array)[(*len)] = item;
(*len)++;
- return copy;
+ return item;
}
return NULL;
}
@@ -72,11 +86,24 @@ void free_char_array(uint32 num_entries, char **entries)
char* add_chars_to_array(uint32 *len, char ***array, const char *name)
{
void*(*fn)(const void*) = (void*(*)(const void*))&strdup;
- return (char*)add_item_to_array(len,
+ return (char*)add_copy_to_array(len,
(void***)array, (const void*)name, *fn, False);
}
+void free_con_array(uint32 num_entries, struct cli_connection **entries)
+{
+ void(*fn)(void*) = (void(*)(void*))&cli_connection_free;
+ free_void_array(num_entries, (void**)entries, *fn);
+}
+
+struct cli_connection* add_con_to_array(uint32 *len, struct cli_connection ***array, struct cli_connection *con)
+{
+ return (struct cli_connection*)add_item_to_array(len,
+ (void***)array, (void*)con);
+
+}
+
static uint32 *uint32_dup(const uint32* from)
{
if (from != NULL)
@@ -100,7 +127,7 @@ void free_uint32_array(uint32 num_entries, uint32 **entries)
uint32* add_uint32s_to_array(uint32 *len, uint32 ***array, const uint32 *name)
{
void*(*fn)(const void*) = (void*(*)(const void*))&uint32_dup;
- return (uint32*)add_item_to_array(len,
+ return (uint32*)add_copy_to_array(len,
(void***)array, (const void*)name, *fn, False);
}
@@ -114,7 +141,7 @@ void free_unistr_array(uint32 num_entries, UNISTR2 **entries)
UNISTR2* add_unistr_to_array(uint32 *len, UNISTR2 ***array, UNISTR2 *name)
{
void*(*fn)(const void*) = (void*(*)(const void*))&unistr2_dup;
- return (UNISTR2*)add_item_to_array(len,
+ return (UNISTR2*)add_copy_to_array(len,
(void***)array, (const void*)name, *fn, False);
}
@@ -127,7 +154,7 @@ void free_sid_array(uint32 num_entries, DOM_SID **entries)
DOM_SID* add_sid_to_array(uint32 *len, DOM_SID ***array, const DOM_SID *sid)
{
void*(*fn)(const void*) = (void*(*)(const void*))&sid_dup;
- return (DOM_SID*)add_item_to_array(len,
+ return (DOM_SID*)add_copy_to_array(len,
(void***)array, (const void*)sid, *fn, False);
}
@@ -177,7 +204,7 @@ PRINTER_INFO_2 *add_print2_to_array(uint32 *len, PRINTER_INFO_2 ***array,
const PRINTER_INFO_2 *prt)
{
void*(*fn)(const void*) = (void*(*)(const void*))&prt2_dup;
- return (PRINTER_INFO_2*)add_item_to_array(len,
+ return (PRINTER_INFO_2*)add_copy_to_array(len,
(void***)array, (const void*)prt, *fn, True);
}
@@ -208,7 +235,7 @@ PRINTER_INFO_1 *add_print1_to_array(uint32 *len, PRINTER_INFO_1 ***array,
const PRINTER_INFO_1 *prt)
{
void*(*fn)(const void*) = (void*(*)(const void*))&prt1_dup;
- return (PRINTER_INFO_1*)add_item_to_array(len,
+ return (PRINTER_INFO_1*)add_copy_to_array(len,
(void***)array, (const void*)prt, *fn, True);
}
@@ -239,7 +266,7 @@ JOB_INFO_1 *add_job1_to_array(uint32 *len, JOB_INFO_1 ***array,
const JOB_INFO_1 *job)
{
void*(*fn)(const void*) = (void*(*)(const void*))&job1_dup;
- return (JOB_INFO_1*)add_item_to_array(len,
+ return (JOB_INFO_1*)add_copy_to_array(len,
(void***)array, (const void*)job, *fn, True);
}
@@ -270,7 +297,7 @@ JOB_INFO_2 *add_job2_to_array(uint32 *len, JOB_INFO_2 ***array,
const JOB_INFO_2 *job)
{
void*(*fn)(const void*) = (void*(*)(const void*))&job2_dup;
- return (JOB_INFO_2*)add_item_to_array(len,
+ return (JOB_INFO_2*)add_copy_to_array(len,
(void***)array, (const void*)job, *fn, True);
}
diff --git a/source3/rpc_client/cli_connect.c b/source3/rpc_client/cli_connect.c
index bca539c396..fc6f5c8c44 100644
--- a/source3/rpc_client/cli_connect.c
+++ b/source3/rpc_client/cli_connect.c
@@ -33,10 +33,75 @@ extern pstring global_myname;
struct cli_connection
{
+ uint32 num_connections;
+ char *srv_name;
+ char *pipe_name;
+ struct user_credentials usr_creds;
struct cli_state *cli;
uint16 fnum;
};
+static struct cli_connection **con_list = NULL;
+uint32 num_cons = 0;
+
+void init_connections(void)
+{
+ con_list = NULL;
+ num_cons = 0;
+}
+
+void free_connections(void)
+{
+ free_con_array(num_cons, con_list);
+}
+
+static struct cli_connection *cli_con_get(const char* srv_name,
+ const char* pipe_name)
+{
+ struct cli_connection *con = NULL;
+
+ con = (struct cli_connection*)malloc(sizeof(*con));
+
+ if (con == NULL)
+ {
+ return NULL;
+ }
+
+ memset(con, 0, sizeof(*con));
+
+ if (srv_name != NULL)
+ {
+ con->srv_name = strdup(srv_name);
+ }
+ if (pipe_name != NULL)
+ {
+ con->pipe_name = strdup(pipe_name);
+ }
+
+ con->cli = cli_initialise(NULL);
+ con->fnum = 0xffff;
+
+ memcpy(&con->usr_creds, usr_creds, sizeof(*usr_creds));
+
+ if (con->cli == NULL)
+ {
+ cli_connection_free(con);
+ return NULL;
+ }
+
+ /*
+ * initialise
+ */
+
+ con->cli->capabilities |= CAP_NT_SMBS | CAP_STATUS32;
+ cli_init_creds(con->cli, usr_creds);
+
+ con->cli->use_ntlmv2 = lp_client_ntlmv2();
+
+ add_con_to_array(&num_cons, &con_list, con);
+
+ return con;
+}
/****************************************************************************
terminate client connection
@@ -46,6 +111,18 @@ void cli_connection_free(struct cli_connection *con)
cli_nt_session_close(con->cli, con->fnum);
cli_shutdown(con->cli);
free(con->cli);
+
+ if (con->srv_name != NULL)
+ {
+ free(con->srv_name);
+ }
+ if (con->pipe_name != NULL)
+ {
+ free(con->pipe_name);
+ }
+
+ memset(&con->usr_creds, 0, sizeof(con->usr_creds));
+
free(con);
}
@@ -73,30 +150,13 @@ BOOL cli_connection_init_list(char* servers, const char* pipe_name,
* allocate
*/
- (*con) = (struct cli_connection*)malloc(sizeof(**con));
+ *con = cli_con_get(servers, pipe_name);
if ((*con) == NULL)
{
return False;
}
- (*con)->cli = cli_initialise(NULL);
- (*con)->fnum = 0xffff;
-
- if ((*con)->cli == NULL)
- {
- return False;
- }
-
- /*
- * initialise
- */
-
- (*con)->cli->capabilities |= CAP_NT_SMBS | CAP_STATUS32;
- cli_init_creds((*con)->cli, usr_creds);
-
- (*con)->cli->use_ntlmv2 = lp_client_ntlmv2();
-
if (!cli_connect_serverlist((*con)->cli, servers))
{
DEBUG(0,("cli_state_init: connection failed\n"));
@@ -130,30 +190,13 @@ BOOL cli_connection_init(const char* server_name, const char* pipe_name,
* allocate
*/
- (*con) = (struct cli_connection*)malloc(sizeof(**con));
+ *con = cli_con_get(server_name, pipe_name);
if ((*con) == NULL)
{
return False;
}
- (*con)->cli = cli_initialise(NULL);
- (*con)->fnum = 0xffff;
-
- if ((*con)->cli == NULL)
- {
- return False;
- }
-
- /*
- * initialise
- */
-
- (*con)->cli->capabilities |= CAP_NT_SMBS | CAP_STATUS32;
- cli_init_creds((*con)->cli, usr_creds);
-
- (*con)->cli->use_ntlmv2 = lp_client_ntlmv2();
-
if (resolve_srv_name(server_name, dest_host, &ip))
{
dest_ip = &ip;
@@ -195,6 +238,22 @@ obtain client state
BOOL cli_connection_getsrv(const char* srv_name, const char* pipe_name,
struct cli_connection **con)
{
+ int i;
+ if (con_list == NULL || num_cons == 0)
+ {
+ return False;
+ }
+
+ for (i = 0; i < num_cons; i++)
+ {
+ if (con_list[i] != NULL &&
+ strequal(con_list[i]->srv_name , srv_name ) &&
+ strequal(con_list[i]->pipe_name, pipe_name))
+ {
+ (*con) = con_list[i];
+ return True;
+ }
+ }
return False;
}
diff --git a/source3/rpcclient/cmd_netlogon.c b/source3/rpcclient/cmd_netlogon.c
index 3010ed5297..4933501b7a 100644
--- a/source3/rpcclient/cmd_netlogon.c
+++ b/source3/rpcclient/cmd_netlogon.c
@@ -87,7 +87,7 @@ void cmd_netlogon_login_test(struct client_info *info, int argc, char *argv[])
argc--;
argv++;
- if (argc < 2)
+ if (argc > 0)
{
nt_password = argv[0];
}
diff --git a/source3/rpcclient/rpcclient.c b/source3/rpcclient/rpcclient.c
index 3951b8e564..c55f99fcaf 100644
--- a/source3/rpcclient/rpcclient.c
+++ b/source3/rpcclient/rpcclient.c
@@ -579,6 +579,7 @@ static void cmd_quit(struct client_info *info, int argc, char *argv[])
dbgflush();
}
#endif
+ free_connections();
exit(0);
}
@@ -1490,6 +1491,7 @@ static void cmd_set(struct client_info *info, int argc, char *argv[])
cli_info.dest_ip = *interpret_addr2(optarg);
if (zero_ip(cli_info.dest_ip))
{
+ free_connections();
exit(1);
}
break;
@@ -1707,6 +1709,7 @@ void readline_init(void)
readline_init();
TimeInit();
charset_initialise();
+ init_connections();
myumask = umask(0);
umask(myumask);
@@ -1719,6 +1722,7 @@ void readline_init(void)
if (argc < 2)
{
usage(argv[0]);
+ free_connections();
exit(1);
}
@@ -1731,6 +1735,7 @@ void readline_init(void)
if (IS_BITS_SET_ALL(cmd_set_options, CMD_HELP))
{
+ free_connections();
exit(0);
}
@@ -1740,5 +1745,7 @@ void readline_init(void)
process(&cli_info, NULL);
+ free_connections();
+
return(0);
}