diff options
author | Gerald Carter <jerry@samba.org> | 2005-06-08 22:10:34 +0000 |
---|---|---|
committer | Gerald (Jerry) Carter <jerry@samba.org> | 2007-10-10 10:57:08 -0500 |
commit | fed660877c16562265327c6093ea645cf4176b5c (patch) | |
tree | e92ae1356542ba095d806bbe1093fa56fbc8ddcc /source3/libsmb | |
parent | 66bb4f03c3466205488f72e4878e8801c5bbb295 (diff) | |
download | samba-fed660877c16562265327c6093ea645cf4176b5c.tar.gz samba-fed660877c16562265327c6093ea645cf4176b5c.tar.bz2 samba-fed660877c16562265327c6093ea645cf4176b5c.zip |
r7415: * big change -- volker's new async winbindd from trunk
(This used to be commit a0ac9a8ffd4af31a0ebc423b4acbb2f043d865b8)
Diffstat (limited to 'source3/libsmb')
-rw-r--r-- | source3/libsmb/clidgram.c | 283 | ||||
-rw-r--r-- | source3/libsmb/clientgen.c | 31 | ||||
-rw-r--r-- | source3/libsmb/clitrans.c | 4 |
3 files changed, 124 insertions, 194 deletions
diff --git a/source3/libsmb/clidgram.c b/source3/libsmb/clidgram.c index ba65c46d16..819616105e 100644 --- a/source3/libsmb/clidgram.c +++ b/source3/libsmb/clidgram.c @@ -26,105 +26,101 @@ * cli_send_mailslot, send a mailslot for client code ... */ -int cli_send_mailslot(int dgram_sock, BOOL unique, const char *mailslot, - char *buf, int len, - const char *srcname, int src_type, - const char *dstname, int dest_type, - struct in_addr dest_ip, struct in_addr src_ip, - int dest_port, int src_port) +BOOL cli_send_mailslot(BOOL unique, const char *mailslot, + uint16 priority, + char *buf, int len, + const char *srcname, int src_type, + const char *dstname, int dest_type, + struct in_addr dest_ip) { - struct packet_struct p; - struct dgram_packet *dgram = &p.packet.dgram; - char *ptr, *p2; - char tmp[4]; - - memset((char *)&p, '\0', sizeof(p)); - - /* - * Next, build the DGRAM ... - */ - - /* DIRECT GROUP or UNIQUE datagram. */ - dgram->header.msg_type = unique ? 0x10 : 0x11; - dgram->header.flags.node_type = M_NODE; - dgram->header.flags.first = True; - dgram->header.flags.more = False; - dgram->header.dgm_id = ((unsigned)time(NULL)%(unsigned)0x7FFF) + ((unsigned)sys_getpid()%(unsigned)100); - dgram->header.source_ip.s_addr = src_ip.s_addr; - dgram->header.source_port = ntohs(src_port); - dgram->header.dgm_length = 0; /* Let build_dgram() handle this. */ - dgram->header.packet_offset = 0; + struct packet_struct p; + struct dgram_packet *dgram = &p.packet.dgram; + char *ptr, *p2; + char tmp[4]; + pid_t nmbd_pid; + + if ((nmbd_pid = pidfile_pid("nmbd")) == 0) { + DEBUG(3, ("No nmbd found\n")); + return False; + } + + if (!message_init()) + return False; + + memset((char *)&p, '\0', sizeof(p)); + + /* + * Next, build the DGRAM ... + */ + + /* DIRECT GROUP or UNIQUE datagram. */ + dgram->header.msg_type = unique ? 0x10 : 0x11; + dgram->header.flags.node_type = M_NODE; + dgram->header.flags.first = True; + dgram->header.flags.more = False; + dgram->header.dgm_id = ((unsigned)time(NULL)%(unsigned)0x7FFF) + + ((unsigned)sys_getpid()%(unsigned)100); + /* source ip is filled by nmbd */ + dgram->header.dgm_length = 0; /* Let build_dgram() handle this. */ + dgram->header.packet_offset = 0; - make_nmb_name(&dgram->source_name,srcname,src_type); - make_nmb_name(&dgram->dest_name,dstname,dest_type); - - ptr = &dgram->data[0]; - - /* Setup the smb part. */ - ptr -= 4; /* XXX Ugliness because of handling of tcp SMB length. */ - memcpy(tmp,ptr,4); - set_message(ptr,17,strlen(mailslot) + 1 + len,True); - memcpy(ptr,tmp,4); - - SCVAL(ptr,smb_com,SMBtrans); - SSVAL(ptr,smb_vwv1,len); - SSVAL(ptr,smb_vwv11,len); - SSVAL(ptr,smb_vwv12,70 + strlen(mailslot)); - SSVAL(ptr,smb_vwv13,3); - SSVAL(ptr,smb_vwv14,1); - SSVAL(ptr,smb_vwv15,1); - SSVAL(ptr,smb_vwv16,2); - p2 = smb_buf(ptr); - fstrcpy(p2,mailslot); - p2 = skip_string(p2,1); - - memcpy(p2,buf,len); - p2 += len; - - dgram->datasize = PTR_DIFF(p2,ptr+4); /* +4 for tcp length. */ - - p.ip = dest_ip; - p.port = dest_port; - p.fd = dgram_sock; - p.timestamp = time(NULL); - p.packet_type = DGRAM_PACKET; - - DEBUG(4,("send_mailslot: Sending to mailslot %s from %s IP %s ", mailslot, - nmb_namestr(&dgram->source_name), inet_ntoa(src_ip))); - DEBUG(4,("to %s IP %s\n", nmb_namestr(&dgram->dest_name), inet_ntoa(dest_ip))); - - return send_packet(&p); - + make_nmb_name(&dgram->source_name,srcname,src_type); + make_nmb_name(&dgram->dest_name,dstname,dest_type); + + ptr = &dgram->data[0]; + + /* Setup the smb part. */ + ptr -= 4; /* XXX Ugliness because of handling of tcp SMB length. */ + memcpy(tmp,ptr,4); + set_message(ptr,17,strlen(mailslot) + 1 + len,True); + memcpy(ptr,tmp,4); + + SCVAL(ptr,smb_com,SMBtrans); + SSVAL(ptr,smb_vwv1,len); + SSVAL(ptr,smb_vwv11,len); + SSVAL(ptr,smb_vwv12,70 + strlen(mailslot)); + SSVAL(ptr,smb_vwv13,3); + SSVAL(ptr,smb_vwv14,1); + SSVAL(ptr,smb_vwv15,priority); + SSVAL(ptr,smb_vwv16,2); + p2 = smb_buf(ptr); + fstrcpy(p2,mailslot); + p2 = skip_string(p2,1); + + memcpy(p2,buf,len); + p2 += len; + + dgram->datasize = PTR_DIFF(p2,ptr+4); /* +4 for tcp length. */ + + p.packet_type = DGRAM_PACKET; + p.ip = dest_ip; + p.timestamp = time(NULL); + + DEBUG(4,("send_mailslot: Sending to mailslot %s from %s ", + mailslot, nmb_namestr(&dgram->source_name))); + DEBUGADD(4,("to %s IP %s\n", nmb_namestr(&dgram->dest_name), + inet_ntoa(dest_ip))); + + return message_send_pid(nmbd_pid, MSG_SEND_PACKET, &p, sizeof(p), + False); } /* * cli_get_response: Get a response ... */ -int cli_get_response(int dgram_sock, BOOL unique, const char *mailslot, char *buf, int bufsiz) +BOOL cli_get_response(const char *mailslot, char *buf, int bufsiz) { - struct packet_struct *packet; - - packet = receive_dgram_packet(dgram_sock, 5, mailslot); - - if (packet) { /* We got one, pull what we want out of the SMB data ... */ - - struct dgram_packet *dgram = &packet->packet.dgram; - - /* - * We should probably parse the SMB, but for now, we will pull what - * from fixed, known locations ... - */ + struct packet_struct *p; - /* Copy the data to buffer, respecting sizes ... */ + p = receive_unexpected(DGRAM_PACKET, 0, mailslot); - memcpy(buf, &dgram->data[92], MIN(bufsiz, (dgram->datasize - 92))); + if (p == NULL) + return False; - } - else - return -1; - - return 0; + memcpy(buf, &p->packet.dgram.data[92], + MIN(bufsiz, p->packet.dgram.datasize-92)); + return True; } /* @@ -135,108 +131,43 @@ static char cli_backup_list[1024]; int cli_get_backup_list(const char *myname, const char *send_to_name) { - pstring outbuf; - char *p; - struct in_addr sendto_ip, my_ip; - int dgram_sock; - struct sockaddr_in sock_out; - socklen_t name_size; - - if (!resolve_name(send_to_name, &sendto_ip, 0x1d)) { - - DEBUG(0, ("Could not resolve name: %s<1D>\n", send_to_name)); - return False; - - } - - my_ip.s_addr = inet_addr("0.0.0.0"); - - if (!resolve_name(myname, &my_ip, 0x00)) { /* FIXME: Call others here */ - - DEBUG(0, ("Could not resolve name: %s<00>\n", myname)); - - } - - if ((dgram_sock = open_socket_out(SOCK_DGRAM, &sendto_ip, 138, LONG_CONNECT_TIMEOUT)) < 0) { - - DEBUG(4, ("open_sock_out failed ...")); - return False; - - } - - /* Make it a broadcast socket ... */ + pstring outbuf; + char *p; + struct in_addr sendto_ip; - set_socket_options(dgram_sock, "SO_BROADCAST"); + if (!resolve_name(send_to_name, &sendto_ip, 0x1d)) { - /* Make it non-blocking??? */ + DEBUG(0, ("Could not resolve name: %s<1D>\n", send_to_name)); + return False; - if (fcntl(dgram_sock, F_SETFL, O_NONBLOCK) < 0) { + } - DEBUG(0, ("Unable to set non blocking on dgram sock\n")); + memset(cli_backup_list, '\0', sizeof(cli_backup_list)); + memset(outbuf, '\0', sizeof(outbuf)); - } - - /* Now, bind a local addr to it ... Try port 138 first ... */ - - memset((char *)&sock_out, '\0', sizeof(sock_out)); - sock_out.sin_addr.s_addr = INADDR_ANY; - sock_out.sin_port = htons(138); - sock_out.sin_family = AF_INET; - - if (bind(dgram_sock, (struct sockaddr *)&sock_out, sizeof(sock_out)) < 0) { - - /* Try again on any port ... */ - - sock_out.sin_port = INADDR_ANY; - - if (bind(dgram_sock, (struct sockaddr *)&sock_out, sizeof(sock_out)) < 0) { - - DEBUG(4, ("failed to bind socket to address ...\n")); - return False; - - } - - } + p = outbuf; - /* Now, figure out what socket name we were bound to. We want the port */ + SCVAL(p, 0, ANN_GetBackupListReq); + p++; - name_size = sizeof(sock_out); + SCVAL(p, 0, 1); /* Count pointer ... */ + p++; - getsockname(dgram_sock, (struct sockaddr *)&sock_out, &name_size); + SIVAL(p, 0, 1); /* The sender's token ... */ + p += 4; - DEBUG(5, ("Socket bound to IP:%s, port: %d\n", inet_ntoa(sock_out.sin_addr), ntohs(sock_out.sin_port))); + cli_send_mailslot(True, "\\MAILSLOT\\BROWSE", 1, outbuf, + PTR_DIFF(p, outbuf), myname, 0, send_to_name, + 0x1d, sendto_ip); - /* Now, build the request */ + /* We should check the error and return if we got one */ - memset(cli_backup_list, '\0', sizeof(cli_backup_list)); - memset(outbuf, '\0', sizeof(outbuf)); + /* Now, get the response ... */ - p = outbuf; + cli_get_response("\\MAILSLOT\\BROWSE", + cli_backup_list, sizeof(cli_backup_list)); - SCVAL(p, 0, ANN_GetBackupListReq); - p++; - - SCVAL(p, 0, 1); /* Count pointer ... */ - p++; - - SIVAL(p, 0, 1); /* The sender's token ... */ - p += 4; - - cli_send_mailslot(dgram_sock, True, "\\MAILSLOT\\BROWSE", outbuf, - PTR_DIFF(p, outbuf), myname, 0, send_to_name, - 0x1d, sendto_ip, my_ip, 138, sock_out.sin_port); - - /* We should check the error and return if we got one */ - - /* Now, get the response ... */ - - cli_get_response(dgram_sock, True, "\\MAILSLOT\\BROWSE", cli_backup_list, sizeof(cli_backup_list)); - - /* Should check the response here ... FIXME */ - - close(dgram_sock); - - return True; + return True; } diff --git a/source3/libsmb/clientgen.c b/source3/libsmb/clientgen.c index e787650c2f..2977099f7d 100644 --- a/source3/libsmb/clientgen.c +++ b/source3/libsmb/clientgen.c @@ -22,8 +22,6 @@ #include "includes.h" -extern int smb_read_error; - /**************************************************************************** Change the timeout (in milliseconds). ****************************************************************************/ @@ -83,6 +81,7 @@ static BOOL client_receive_smb(int fd,char *buffer, unsigned int timeout) BOOL cli_receive_smb(struct cli_state *cli) { + extern int smb_read_error; BOOL ret; /* fd == -1 causes segfaults -- Tom (tom@ninja.nl) */ @@ -321,9 +320,9 @@ struct cli_state *cli_initialise(struct cli_state *cli) cli_null_set_signing(cli); for (i=0; i<PI_MAX_PIPES; i++) - cli->nt_pipe_fnum[i] = 0; + cli->pipes[i].fnum = 0; - cli->saved_netlogon_pipe_fnum = 0; + cli->netlogon_pipe.fnum = 0; cli->initialised = 1; cli->allocated = alloced_cli; @@ -353,14 +352,14 @@ void cli_nt_session_close(struct cli_state *cli) { int i; - if (cli->ntlmssp_pipe_state) { - ntlmssp_end(&cli->ntlmssp_pipe_state); - } - for (i=0; i<PI_MAX_PIPES; i++) { - if (cli->nt_pipe_fnum[i] != 0) - cli_close(cli, cli->nt_pipe_fnum[i]); - cli->nt_pipe_fnum[i] = 0; + if (cli->pipes[i].pipe_auth_flags & AUTH_PIPE_NTLMSSP) { + ntlmssp_end(&cli->pipes[i].ntlmssp_pipe_state); + } + + if (cli->pipes[i].fnum != 0) + cli_close(cli, cli->pipes[i].fnum); + cli->pipes[i].fnum = 0; } cli->pipe_idx = -1; } @@ -371,9 +370,9 @@ close the NETLOGON session holding the session key for NETSEC void cli_nt_netlogon_netsec_session_close(struct cli_state *cli) { - if (cli->saved_netlogon_pipe_fnum != 0) { - cli_close(cli, cli->saved_netlogon_pipe_fnum); - cli->saved_netlogon_pipe_fnum = 0; + if (cli->netlogon_pipe.fnum != 0) { + cli_close(cli, cli->netlogon_pipe.fnum); + cli->netlogon_pipe.fnum = 0; } } @@ -408,8 +407,8 @@ void cli_close_connection(struct cli_state *cli) data_blob_free(&cli->secblob); data_blob_free(&cli->user_session_key); - if (cli->ntlmssp_pipe_state) - ntlmssp_end(&cli->ntlmssp_pipe_state); + if (cli->pipes[cli->pipe_idx].pipe_auth_flags & AUTH_PIPE_NTLMSSP) + ntlmssp_end(&cli->pipes[cli->pipe_idx].ntlmssp_pipe_state); if (cli->mem_ctx) { talloc_destroy(cli->mem_ctx); diff --git a/source3/libsmb/clitrans.c b/source3/libsmb/clitrans.c index 27da63ccda..75afe5195e 100644 --- a/source3/libsmb/clitrans.c +++ b/source3/libsmb/clitrans.c @@ -505,7 +505,7 @@ BOOL cli_receive_nt_trans(struct cli_state *cli, */ if (cli_is_dos_error(cli)) { cli_dos_error(cli, &eclass, &ecode); - if (cli->nt_pipe_fnum[cli->pipe_idx] == 0 || !(eclass == ERRDOS && ecode == ERRmoredata)) { + if (cli->pipes[cli->pipe_idx].fnum == 0 || !(eclass == ERRDOS && ecode == ERRmoredata)) { cli_signing_trans_stop(cli); return(False); } @@ -639,7 +639,7 @@ BOOL cli_receive_nt_trans(struct cli_state *cli, } if (cli_is_dos_error(cli)) { cli_dos_error(cli, &eclass, &ecode); - if(cli->nt_pipe_fnum[cli->pipe_idx] == 0 || !(eclass == ERRDOS && ecode == ERRmoredata)) { + if(cli->pipes[cli->pipe_idx].fnum == 0 || !(eclass == ERRDOS && ecode == ERRmoredata)) { cli_signing_trans_stop(cli); return(False); } |