From 5e22394654eba2ed5d01e81b165a044a59dd65ab Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Fri, 10 Mar 2000 19:50:03 +0000 Subject: Fixups for compiles with gcc flags -Wall -Wshadow -Wstrict-prototypes -Wpointer-arith -Wcast-qual Partially implemented rpc daemon redirect (needs more work). Jeremy. (This used to be commit a462191698fa589ceac4afd14c652adf699eccad) --- source3/include/ntdomain.h | 17 +++++ source3/include/proto.h | 5 +- source3/include/smb.h | 33 +------- source3/lib/util.c | 10 +-- source3/msdfs/msdfs.c | 4 +- source3/rpc_server/srv_pipe.c | 27 ------- source3/rpc_server/srv_pipe_hnd.c | 148 ++++++++++++++++++++++++++++-------- source3/rpc_server/srv_spoolss_nt.c | 3 + source3/smbd/trans2.c | 2 + 9 files changed, 149 insertions(+), 100 deletions(-) diff --git a/source3/include/ntdomain.h b/source3/include/ntdomain.h index 46be965d70..b754dd8525 100644 --- a/source3/include/ntdomain.h +++ b/source3/include/ntdomain.h @@ -31,6 +31,8 @@ /* miscellaneous structures / defines */ #include "rpc_misc.h" +#include "rpc_creds.h" + /* * A bunch of stuff that was put into smb.h * in the NTDOM branch - it didn't belong there. @@ -114,6 +116,21 @@ typedef struct _input_data { prs_struct data; } input_data; +struct msrpc_state +{ + fstring pipe_name; + struct user_creds usr; + struct ntdom_info nt; + + int fd; + BOOL redirect; + BOOL initialised; + char *inbuf; + char *outbuf; + + uint32 pid; +}; + typedef struct pipes_struct { struct pipes_struct *next, *prev; diff --git a/source3/include/proto.h b/source3/include/proto.h index 6a09935226..d65c5a5d64 100644 --- a/source3/include/proto.h +++ b/source3/include/proto.h @@ -812,7 +812,7 @@ int setup_dfs_referral(char* pathname, int max_referral_level, int dfs_path_error(char* inbuf, char* outbuf); int setup_dfs_referral(char* pathname, int max_referral_level, char** ppdata); -int unistr_to_dos(char* dst,uint16* src) ; +void unistr_to_dos(char* dst,uint16* src) ; /*The following definitions come from msdfs/msdfs_tdb.c */ @@ -2609,11 +2609,10 @@ BOOL api_rpcTNP(pipes_struct *p, char *rpc_name, struct api_struct *api_rpc_cmds void set_pipe_handle_offset(int max_open_files); void reset_chain_p(void); void init_rpc_pipe_hnd(void); -BOOL pipe_init_outgoing_data(output_data *o_data); pipes_struct *open_rpc_pipe_p(char *pipe_name, connection_struct *conn, uint16 vuid); ssize_t write_to_pipe(pipes_struct *p, char *data, size_t n); -int read_from_pipe(pipes_struct *p, char *data, int n); +ssize_t read_from_pipe(pipes_struct *p, char *data, size_t n); BOOL wait_rpc_pipe_hnd_state(pipes_struct *p, uint16 priority); BOOL set_rpc_pipe_hnd_state(pipes_struct *p, uint16 device_state); BOOL close_rpc_pipe_hnd(pipes_struct *p, connection_struct *conn); diff --git a/source3/include/smb.h b/source3/include/smb.h index 15b491239c..a179a7808e 100644 --- a/source3/include/smb.h +++ b/source3/include/smb.h @@ -171,8 +171,6 @@ implemented */ #define ERRbaddirectory 267 /* Invalid directory name in a path. */ #define ERRunknownipc 2142 -#define ERROR_ACCESS_DENIED (5) -#define ERROR_INVALID_HANDLE (6) #define ERROR_INVALID_PARAMETER (87) #define ERROR_INSUFFICIENT_BUFFER (122) #define ERROR_INVALID_NAME (123) @@ -618,9 +616,6 @@ struct dcinfo uchar md4pw[16]; /* md4(machine password) */ }; -#include "nt_printing.h" - -#include "ntdomain.h" typedef struct { @@ -640,18 +635,8 @@ typedef struct /* per-user authentication information on NT RPCs */ /* lkclXXXX - THIS SHOULD NOT BE HERE! */ struct dcinfo dc; - - NET_USER_INFO_3 usr; - } user_struct; -typedef struct -{ - uint32 pid; - uint16 vuid; - -} vuser_key; - enum {LPQ_QUEUED,LPQ_PAUSED,LPQ_SPOOLING,LPQ_PRINTING}; typedef struct _print_queue_struct @@ -1679,8 +1664,6 @@ struct pwd_info uchar sess_key[16]; }; -#include "rpc_creds.h" - struct ntdom_info { unsigned char sess_key[16]; /* Current session key. */ @@ -1694,20 +1677,10 @@ struct ntdom_info int max_xmit_frag; }; -struct msrpc_state -{ - fstring pipe_name; - struct user_creds usr; - struct ntdom_info nt; - - int fd; - BOOL redirect; - BOOL initialised; - char *inbuf; - char *outbuf; +#include "nt_printing.h" +#include "rpc_creds.h" +#include "ntdomain.h" - uint32 pid; -}; #include "client.h" #include "rpcclient.h" diff --git a/source3/lib/util.c b/source3/lib/util.c index 772ac2f9ef..3c86570af1 100644 --- a/source3/lib/util.c +++ b/source3/lib/util.c @@ -1028,10 +1028,6 @@ BOOL unix_do_match(char *str, char *regexp, BOOL case_sig) { char *p; - - while(*str && (case_sig ? (*p != *str) : (toupper(*p)!=toupper(*str)))) - str++; - for( p = regexp; *p && *str; ) { switch(*p) { case '?': @@ -1047,6 +1043,10 @@ BOOL unix_do_match(char *str, char *regexp, BOOL case_sig) if(!*p) return True; /* Automatic match */ while(*str) { + + while(*str && (case_sig ? (*p != *str) : (toupper(*p)!=toupper(*str)))) + str++; + /* * Patch from weidel@multichart.de. In the case of the regexp * '*XX*' we want to ensure there are at least 2 'X' characters @@ -1130,7 +1130,7 @@ static BOOL unix_mask_match(char *str, char *regexp, BOOL case_sig) { char *p; pstring p1, p2; - fstring ebase,eext,sbase,sext; + fstring ebase,sbase; BOOL matched; /* Make local copies of str and regexp */ diff --git a/source3/msdfs/msdfs.c b/source3/msdfs/msdfs.c index adb968db81..efc5b47ad7 100644 --- a/source3/msdfs/msdfs.c +++ b/source3/msdfs/msdfs.c @@ -23,7 +23,7 @@ extern int DEBUGLEVEL; extern pstring global_myname; -extern global_client_caps; +extern uint32 global_client_caps; #ifdef MS_DFS @@ -442,7 +442,7 @@ int setup_dfs_referral(char* pathname, int max_referral_level, #endif /* Trivial fn that chops off upper bytes to convert unicode to dos */ -int unistr_to_dos(char* dst,uint16* src) +void unistr_to_dos(char* dst,uint16* src) { pstring s; int i=0; diff --git a/source3/rpc_server/srv_pipe.c b/source3/rpc_server/srv_pipe.c index 9079590f31..9a17862bd5 100644 --- a/source3/rpc_server/srv_pipe.c +++ b/source3/rpc_server/srv_pipe.c @@ -492,15 +492,6 @@ BOOL api_pipe_bind_auth_resp(pipes_struct *p, prs_struct *rpc_in_p) DEBUG(5,("api_pipe_bind_auth_resp: decode request. %d\n", __LINE__)); - /* - * Create the response data buffer. - */ - - if(!pipe_init_outgoing_data(&p->out_data)) { - DEBUG(0,("api_pipe_bind_auth_resp: failed to create outgoing buffer.\n")); - return False; - } - if (p->hdr.auth_len == 0) { DEBUG(0,("api_pipe_bind_auth_resp: No auth field sent !\n")); return False; @@ -695,15 +686,6 @@ BOOL api_pipe_bind_req(pipes_struct *p, prs_struct *rpc_in_p) DEBUG(5,("api_pipe_bind_req: decode request. %d\n", __LINE__)); - /* - * Create the response data buffer. - */ - - if(!pipe_init_outgoing_data(&p->out_data)) { - DEBUG(0,("api_pipe_bind_req: failed to create outgoing buffer.\n")); - return False; - } - /* * Try and find the correct pipe name to ensure * that this is a pipe name we support. @@ -1062,15 +1044,6 @@ BOOL api_pipe_request(pipes_struct *p) BOOL ret = False; BOOL changed_user_id = False; - /* - * Create the response data buffer. - */ - - if(!pipe_init_outgoing_data(&p->out_data)) { - DEBUG(0,("api_pipe_request: failed to create outgoing buffer.\n")); - return False; - } - if (p->ntlmssp_auth_validated) { if(!become_authenticated_pipe_user(p)) { diff --git a/source3/rpc_server/srv_pipe_hnd.c b/source3/rpc_server/srv_pipe_hnd.c index 4c71433c2a..fdee90e8ae 100644 --- a/source3/rpc_server/srv_pipe_hnd.c +++ b/source3/rpc_server/srv_pipe_hnd.c @@ -77,8 +77,12 @@ void init_rpc_pipe_hnd(void) Initialise an outgoing packet. ****************************************************************************/ -BOOL pipe_init_outgoing_data(output_data *o_data) +static BOOL pipe_init_outgoing_data(output_data *o_data, uint32 len) { + /* Reset the offset counters. */ + o_data->data_sent_length = 0; + o_data->current_pdu_len = 0; + o_data->current_pdu_sent = 0; memset(o_data->current_pdu, '\0', sizeof(o_data->current_pdu)); @@ -89,21 +93,16 @@ BOOL pipe_init_outgoing_data(output_data *o_data) * Initialize the outgoing RPC data buffer. * we will use this as the raw data area for replying to rpc requests. */ - if(!prs_init(&o_data->rdata, MAX_PDU_FRAG_LEN, 4, MARSHALL)) { + if(!prs_init(&o_data->rdata, len, 4, MARSHALL)) { DEBUG(0,("pipe_init_outgoing_data: malloc fail.\n")); return False; } - /* Reset the offset counters. */ - o_data->data_sent_length = 0; - o_data->current_pdu_len = 0; - o_data->current_pdu_sent = 0; - return True; } /**************************************************************************** - HACK !!! Attempt to find a remote process to communicate RPC's with. + Attempt to find a remote process to communicate RPC's with. ****************************************************************************/ static void attempt_remote_rpc_connect(pipes_struct *p) @@ -254,7 +253,7 @@ pipes_struct *open_rpc_pipe_p(char *pipe_name, fstrcpy(p->name, pipe_name); /* - * HACK !!! For Luke - attempt to connect to RPC redirect process. + * For Luke - attempt to connect to RPC redirect process. */ attempt_remote_rpc_connect(p); @@ -464,7 +463,7 @@ authentication failed. Denying the request.\n", p->name)); } if(p->hdr.flags & RPC_FLG_LAST) { - BOOL ret; + BOOL ret = False; /* * Ok - we finally have a complete RPC stream. * Call the rpc command to process it. @@ -482,7 +481,8 @@ authentication failed. Denying the request.\n", p->name)); * Process the complete data stream here. */ - ret = api_pipe_request(p); + if(pipe_init_outgoing_data(&p->out_data, MAX_PDU_FRAG_LEN)) + ret = api_pipe_request(p); /* * We have consumed the whole data stream. Set back to @@ -532,13 +532,15 @@ static ssize_t process_complete_pdu(pipes_struct *p) /* * We assume that a pipe bind is only in one pdu. */ - reply = api_pipe_bind_req(p, &rpc_in); + if(pipe_init_outgoing_data(&p->out_data, MAX_PDU_FRAG_LEN)) + reply = api_pipe_bind_req(p, &rpc_in); break; case RPC_BINDRESP: /* * We assume that a pipe bind_resp is only in one pdu. */ - reply = api_pipe_bind_auth_resp(p, &rpc_in); + if(pipe_init_outgoing_data(&p->out_data, MAX_PDU_FRAG_LEN)) + reply = api_pipe_bind_auth_resp(p, &rpc_in); break; case RPC_REQUEST: reply = process_request_pdu(p, &rpc_in); @@ -661,7 +663,14 @@ ssize_t write_to_pipe(pipes_struct *p, char *data, size_t n) DEBUG(10,("write_to_pipe: data_left = %u\n", (unsigned int)data_left )); - data_used = process_incoming_data(p, data, data_left); + /* + * Deal with the redirect to the remote RPC daemon. + */ + + if(p->m) + data_used = write(p->m->fd, data, data_left); + else + data_used = process_incoming_data(p, data, data_left); DEBUG(10,("write_to_pipe: data_used = %d\n", (int)data_used )); @@ -675,9 +684,72 @@ ssize_t write_to_pipe(pipes_struct *p, char *data, size_t n) return n; } +/**************************************************************************** + Gets data from a remote TNG daemon. Gets data from the remote daemon into + the outgoing prs_struct. + + NB. Note to Luke : This code will be broken until Luke implements a length + field before reply data... + +****************************************************************************/ + +static BOOL read_from_remote(pipes_struct *p) +{ + uint32 data_len; + uint32 data_len_left; + + if(prs_offset(&p->out_data.rdata) == 0) { + + ssize_t len = 0; + + /* + * Read all the reply data as a stream of pre-created + * PDU's from the remote deamon into the rdata struct. + */ + + /* + * Create the response data buffer. + */ + + if(!pipe_init_outgoing_data(&p->out_data, 65536)) { + DEBUG(0,("read_from_remote: failed to create outgoing buffer.\n")); + return False; + } + + /* Read from remote here. */ + if((len = read_with_timeout(p->m->fd, prs_data_p(&p->out_data.rdata), 1, 65536, 10000)) < 0) { + DEBUG(0,("read_from_remote: failed to read from external daemon.\n")); + prs_mem_free(&p->out_data.rdata); + return False; + } + + /* Set the length we got. */ + prs_set_offset(&p->out_data.rdata, (uint32)len); + } + + /* + * The amount we send is the minimum of the available + * space and the amount left to send. + */ + + data_len_left = prs_offset(&p->out_data.rdata) - p->out_data.data_sent_length; + + /* + * Ensure there really is data left to send. + */ + + if(!data_len_left) { + DEBUG(0,("read_from_remote: no data left to send !\n")); + return False; + } + + data_len = MIN(data_len_left, MAX_PDU_FRAG_LEN); + + return False; /* Notfinished... */ +} /**************************************************************************** - Replyies to a request to read data from a pipe. + Replies to a request to read data from a pipe. Headers are interspersed with the data at PDU intervals. By the time this function is called, the start of the data could possibly have been @@ -685,13 +757,12 @@ ssize_t write_to_pipe(pipes_struct *p, char *data, size_t n) Calling create_rpc_reply() here is a hack. The data should already have been prepared into arrays of headers + data stream sections. +****************************************************************************/ - ****************************************************************************/ - -int read_from_pipe(pipes_struct *p, char *data, int n) +ssize_t read_from_pipe(pipes_struct *p, char *data, size_t n) { uint32 pdu_remaining = 0; - int data_returned = 0; + ssize_t data_returned = 0; if (!p || !p->open) { DEBUG(0,("read_from_pipe: pipe not open\n")); @@ -700,7 +771,7 @@ int read_from_pipe(pipes_struct *p, char *data, int n) DEBUG(6,("read_from_pipe: %x", p->pnum)); - DEBUG(6,(" name: %s len: %d\n", p->name, n)); + DEBUG(6,(" name: %s len: %u\n", p->name, (unsigned int)n)); /* * We cannot return more than one PDU length per @@ -708,8 +779,8 @@ int read_from_pipe(pipes_struct *p, char *data, int n) */ if(n > MAX_PDU_FRAG_LEN) { - DEBUG(0,("read_from_pipe: loo large read (%d) requested on pipe %s. We can \ -only service %d sized reads.\n", n, p->name, MAX_PDU_FRAG_LEN )); + DEBUG(0,("read_from_pipe: loo large read (%u) requested on pipe %s. We can \ +only service %d sized reads.\n", (unsigned int)n, p->name, MAX_PDU_FRAG_LEN )); return -1; } @@ -722,7 +793,7 @@ only service %d sized reads.\n", n, p->name, MAX_PDU_FRAG_LEN )); */ if((pdu_remaining = p->out_data.current_pdu_len - p->out_data.current_pdu_sent) > 0) { - data_returned = MIN(n, pdu_remaining); + data_returned = (ssize_t)MIN(n, pdu_remaining); DEBUG(10,("read_from_pipe: %s: current_pdu_len = %u, current_pdu_sent = %u \ returning %d bytes.\n", p->name, (unsigned int)p->out_data.current_pdu_len, @@ -749,17 +820,28 @@ returning %d bytes.\n", p->name, (unsigned int)p->out_data.current_pdu_len, return 0; } - /* - * We need to create a new PDU from the data left in p->rdata. - * Create the header/data/footers. This also sets up the fields - * p->current_pdu_len, p->current_pdu_sent, p->data_sent_length - * and stores the outgoing PDU in p->current_pdu. - */ + if(p->m) { + /* + * Remote to the RPC daemon. + */ + if(!read_from_remote(p)) { + DEBUG(0,("read_from_pipe: %s: read_from_remote failed.\n", p->name )); + return -1; + } - if(!create_next_pdu(p)) { - DEBUG(0,("read_from_pipe: %s: create_next_pdu failed.\n", - p->name)); - return -1; + } else { + + /* + * We need to create a new PDU from the data left in p->rdata. + * Create the header/data/footers. This also sets up the fields + * p->current_pdu_len, p->current_pdu_sent, p->data_sent_length + * and stores the outgoing PDU in p->current_pdu. + */ + + if(!create_next_pdu(p)) { + DEBUG(0,("read_from_pipe: %s: create_next_pdu failed.\n", p->name)); + return -1; + } } data_returned = MIN(n, p->out_data.current_pdu_len); diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index 9170b8afdd..b4aefe44c1 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -4140,6 +4140,8 @@ static uint32 getjob_level_1(print_queue_struct *queue, int count, int snum, uin /**************************************************************************** ****************************************************************************/ +#if 0 +... Not yet used... static uint32 getjob_level_2(print_queue_struct *queue, int count, int snum, uint32 jobid, NEW_BUFFER *buffer, uint32 offered, uint32 *needed) { int i=0; @@ -4179,6 +4181,7 @@ static uint32 getjob_level_2(print_queue_struct *queue, int count, int snum, uin else return NT_STATUS_NO_PROBLEMO; } +#endif /**************************************************************************** ****************************************************************************/ diff --git a/source3/smbd/trans2.c b/source3/smbd/trans2.c index 21fa9b5cc5..3135079514 100644 --- a/source3/smbd/trans2.c +++ b/source3/smbd/trans2.c @@ -2132,6 +2132,7 @@ static int call_trans2getdfsreferral(connection_struct *conn, char* inbuf, char* outbuf, int length, int bufsize, char** pparams, char** ppdata) { +#ifdef MS_DFS char *params = *pparams; enum remote_arch_types ra_type = get_remote_arch(); BOOL NT_arch = ((ra_type == RA_WINNT) || (ra_type == RA_WIN2K)); @@ -2139,6 +2140,7 @@ static int call_trans2getdfsreferral(connection_struct *conn, char* inbuf, int reply_size = 0; char* dfs_referral = NULL; int max_referral_level = SVAL(params,0); +#endif DEBUG(10,("call_trans2getdfsreferral\n")); #ifdef MS_DFS -- cgit