summaryrefslogtreecommitdiff
path: root/source3/lib
diff options
context:
space:
mode:
authorGerald Carter <jerry@samba.org>2000-07-07 06:20:46 +0000
committerGerald Carter <jerry@samba.org>2000-07-07 06:20:46 +0000
commitd2b40a7de259377d937492acedd39988ddd108a4 (patch)
treef0849ba6679575e80500b43b8989b3dddf16e2a4 /source3/lib
parent9de93aa8188293671a92e84b2b9dc104cc7eb64c (diff)
downloadsamba-d2b40a7de259377d937492acedd39988ddd108a4.tar.gz
samba-d2b40a7de259377d937492acedd39988ddd108a4.tar.bz2
samba-d2b40a7de259377d937492acedd39988ddd108a4.zip
More rpcclient merge issues:
* fixes some readline bugs from the merge * first attempt at commands (spoolenum almost works) * no changes to existing functions in HEAD; only additions of new functions. I'll weed out what I can as I go. --jerry (This used to be commit 61d2aad5dc2b212b11c981f1eca47efa627e9fc8)
Diffstat (limited to 'source3/lib')
-rw-r--r--source3/lib/cmd_interp.c20
-rw-r--r--source3/lib/msrpc-client.c164
-rw-r--r--source3/lib/util_unistr.c46
3 files changed, 221 insertions, 9 deletions
diff --git a/source3/lib/cmd_interp.c b/source3/lib/cmd_interp.c
index 7b90daa06f..f952a57e57 100644
--- a/source3/lib/cmd_interp.c
+++ b/source3/lib/cmd_interp.c
@@ -348,8 +348,9 @@ static uint32 do_command(struct client_info *info, char *line)
{
return False;
}
-
- if ((i = process_tok(cmd_argv[0])) >= 0)
+
+ i = process_tok(cmd_argv[0]);
+ if (i >= 0)
{
int argc = ((int)cmd_argc)-1;
char **argv = cmd_argv;
@@ -418,7 +419,7 @@ static uint32 process(struct client_info *info, char *cmd_str)
{
while (!feof(stdin))
{
-#ifdef HAVE_READLINE
+#ifdef HAVE_LIBREADLINE
char *ret_line;
#endif
pstring pline;
@@ -447,7 +448,7 @@ static uint32 process(struct client_info *info, char *cmd_str)
sizeof(pline) - 1);
safe_strcat(pline, "]$ ", sizeof(pline) - 1);
-#ifndef HAVE_READLINE
+#ifndef HAVE_LIBREADLINE
/* display a prompt */
fprintf(out_hnd, "%s", CNV_LANG(pline));
@@ -461,7 +462,7 @@ static uint32 process(struct client_info *info, char *cmd_str)
break;
}
-#else /* HAVE_READLINE */
+#else /* HAVE_LIBREADLINE */
if (!(ret_line = readline(pline)))
break;
@@ -535,7 +536,7 @@ static void usage(char *pname)
fprintf(out_hnd, "\n");
}
-#ifdef HAVE_READLINE
+#ifdef HAVE_LIBREADLINE
/****************************************************************************
GNU readline completion functions
@@ -648,7 +649,7 @@ static char *complete_cmd_null(char *text, int state)
return NULL;
}
-#endif /* HAVE_READLINE */
+#endif /* HAVE_LIBREADLINE */
static void set_user_password(struct ntuser_creds *u,
BOOL got_pass, char *password)
@@ -708,6 +709,7 @@ static uint32 cmd_use(struct client_info *info, int argc, char *argv[])
report(out_hnd, " -d Deletes a connection\n");
report(out_hnd, " -f Forcibly deletes a connection\n");
report(out_hnd, "net -u Shows all connections\n");
+ return 0;
}
if (argc > 1 && (*argv[1] != '-'))
@@ -1248,7 +1250,7 @@ static void read_user_env(struct ntuser_creds *u)
static void readline_init(void)
{
-#ifdef HAVE_READLINE
+#ifdef HAVE_LIBREADLINE
/* Initialise GNU Readline */ rl_readline_name = "rpcclient";
rl_attempted_completion_function = completion_fn;
rl_completion_entry_function = (Function *) complete_cmd_null;
@@ -1260,7 +1262,7 @@ static void readline_init(void)
#else
int x;
x = 0; /* stop compiler warnings */
-#endif /* HAVE_READLINE */
+#endif /* HAVE_LIBREADLINE */
}
/****************************************************************************
diff --git a/source3/lib/msrpc-client.c b/source3/lib/msrpc-client.c
index 696413b4f9..9b9350cb7e 100644
--- a/source3/lib/msrpc-client.c
+++ b/source3/lib/msrpc-client.c
@@ -27,6 +27,29 @@
extern int DEBUGLEVEL;
/****************************************************************************
+open the msrpcent sockets
+****************************************************************************/
+static BOOL ncalrpc_l_connect(struct msrpc_local *msrpc, const char *pipe_name)
+{
+ fstring path;
+ fstring pname;
+ fstrcpy(pname, pipe_name);
+ strlower(pname);
+ slprintf(path, sizeof(path) - 1, "%s/.msrpc/%s", LOCKDIR, pname);
+
+ fstrcpy(msrpc->pipe_name, pipe_name);
+
+ msrpc->fd = open_pipe_sock(path);
+
+ if (msrpc->fd == -1)
+ {
+ return False;
+ }
+
+ return True;
+}
+
+/****************************************************************************
read an msrpc pdu from a fd.
The timeout is in milliseconds.
****************************************************************************/
@@ -141,6 +164,46 @@ static void ncalrpc_l_close_socket(struct msrpc_local *msrpc)
msrpc->fd = -1;
}
+static BOOL ncalrpc_l_authenticate(struct msrpc_local *msrpc)
+{
+ int sock = msrpc->fd;
+ uint32 len;
+ char *data;
+ prs_struct ps;
+ uint32 status;
+
+ uint16 command;
+
+ command = AGENT_CMD_CON;
+
+ if (!create_user_creds(&ps, msrpc->pipe_name, 0x0, command,
+ msrpc->nt.key.pid, NULL))
+ {
+ DEBUG(0, ("could not parse credentials\n"));
+ close(sock);
+ return False;
+ }
+
+ len = ps.data_offset;
+ data = prs_data(&ps, 0);
+
+ SIVAL(data, 0, len);
+
+#ifdef DEBUG_PASSWORD
+ DEBUG(100, ("data len: %d\n", len));
+ dump_data(100, data, len);
+#endif
+
+ if (write_socket(sock, data, len) <= 0)
+ {
+ DEBUG(0, ("write failed\n"));
+ return False;
+ }
+ len = read_data(sock, (char*)&status, sizeof(status));
+
+ return len == sizeof(status) && status == 0x0;
+}
+
/****************************************************************************
shutdown a msrpcent structure
@@ -160,6 +223,62 @@ void ncalrpc_l_shutdown(struct msrpc_local *msrpc)
memset(msrpc, 0, sizeof(*msrpc));
}
+/****************************************************************************
+initialise a msrpcent structure
+****************************************************************************/
+struct msrpc_local *ncalrpc_l_initialise(struct msrpc_local *msrpc,
+ const vuser_key * key)
+{
+ if (!msrpc)
+ {
+ msrpc = (struct msrpc_local *)malloc(sizeof(*msrpc));
+ if (!msrpc)
+ return NULL;
+ ZERO_STRUCTP(msrpc);
+ }
+
+ if (msrpc->initialised)
+ {
+ ncalrpc_l_shutdown(msrpc);
+ }
+
+ ZERO_STRUCTP(msrpc);
+
+ msrpc->fd = -1;
+ msrpc->outbuf = (char *)malloc(CLI_BUFFER_SIZE + 4);
+ msrpc->inbuf = (char *)malloc(CLI_BUFFER_SIZE + 4);
+ if (!msrpc->outbuf || !msrpc->inbuf)
+ {
+ return False;
+ }
+
+ msrpc->initialised = 1;
+
+ if (key != NULL)
+ {
+ msrpc->nt.key = *key;
+ }
+ else
+ {
+ NET_USER_INFO_3 usr;
+ uid_t uid = getuid();
+ gid_t gid = getgid();
+ char *name = uidtoname(uid);
+
+ ZERO_STRUCT(usr);
+
+ msrpc->nt.key.pid = sys_getpid();
+
+#if 0 /* comment ou by JERRY */
+ msrpc->nt.key.vuid = register_vuid(msrpc->nt.key.pid,
+ uid, gid,
+ name, name, False, &usr);
+#endif /* comment ou by JERRY */
+ }
+
+ return msrpc;
+}
+
/****************************************************************************
open the msrpcent sockets
@@ -433,3 +552,48 @@ BOOL msrpc_establish_connection(struct msrpc_state *msrpc,
return True;
}
+/****************************************************************************
+establishes a connection right up to doing tconX, reading in a password.
+****************************************************************************/
+BOOL ncalrpc_l_establish_connection(struct msrpc_local *msrpc,
+ const char *pipe_name)
+{
+ if (strnequal("\\PIPE\\", pipe_name, 6))
+ {
+ pipe_name = &pipe_name[6];
+ }
+
+ DEBUG(5, ("ncalrpc_l_establish_connection: connecting to %s\n",
+ pipe_name));
+
+ /* establish connection */
+
+ if (!msrpc->initialised)
+ {
+ return False;
+ }
+
+ if (msrpc->fd == -1)
+ {
+ if (!ncalrpc_l_connect(msrpc, pipe_name))
+ {
+ DEBUG(1,
+ ("ncalrpc_l_establish_connection: failed %s)\n",
+ pipe_name));
+
+ return False;
+ }
+ }
+
+ if (!ncalrpc_l_authenticate(msrpc))
+ {
+ DEBUG(0, ("authenticate failed\n"));
+ close(msrpc->fd);
+ msrpc->fd = -1;
+ return False;
+ }
+
+ return True;
+}
+
+
diff --git a/source3/lib/util_unistr.c b/source3/lib/util_unistr.c
index 1c13ff2758..42f1dc0644 100644
--- a/source3/lib/util_unistr.c
+++ b/source3/lib/util_unistr.c
@@ -222,6 +222,52 @@ char *dos_unistr2_to_str(UNISTR2 *str)
}
/*******************************************************************
+ Put an ASCII string into a UNICODE array (uint16's).
+ ********************************************************************/
+void ascii_to_unistr(uint16 *dest, const char *src, int maxlen)
+{
+ uint16 *destend = dest + maxlen;
+ register char c;
+
+ while (dest < destend)
+ {
+ c = *(src++);
+ if (c == 0)
+ {
+ break;
+ }
+
+ *(dest++) = (uint16)c;
+ }
+
+ *dest = 0;
+}
+
+
+/*******************************************************************
+ Pull an ASCII string out of a UNICODE array (uint16's).
+ ********************************************************************/
+
+void unistr_to_ascii(char *dest, const uint16 *src, int len)
+{
+ char *destend = dest + len;
+ register uint16 c;
+
+ while (dest < destend)
+ {
+ c = *(src++);
+ if (c == 0)
+ {
+ break;
+ }
+
+ *(dest++) = (char)c;
+ }
+
+ *dest = 0;
+}
+
+/*******************************************************************
Convert a UNISTR2 structure to an ASCII string
Warning: this version does DOS codepage.
********************************************************************/