From e65e16fdf60819a45d03862579e69be3b11d9118 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Wed, 27 Nov 2002 19:09:48 +0000 Subject: Test was reversed for ERRmoredata in cli_read. Jeremy. (This used to be commit 1a36ac60bef8de5368860478c268ba1671bb4825) --- source3/libsmb/clireadwrite.c | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'source3/libsmb') diff --git a/source3/libsmb/clireadwrite.c b/source3/libsmb/clireadwrite.c index 875df11dca..38e8aac42a 100644 --- a/source3/libsmb/clireadwrite.c +++ b/source3/libsmb/clireadwrite.c @@ -84,6 +84,7 @@ ssize_t cli_read(struct cli_state *cli, int fnum, char *buf, off_t offset, size_ errors. */ if (cli_is_error(cli)) { + BOOL recoverable_error = False; NTSTATUS status = NT_STATUS_OK; uint8 eclass = 0; uint32 ecode = 0; @@ -93,8 +94,17 @@ ssize_t cli_read(struct cli_state *cli, int fnum, char *buf, off_t offset, size_ else cli_dos_error(cli, &eclass, &ecode); + /* + * ERRDOS ERRmoredata or STATUS_MORE_ENRTIES is a + * recoverable error, plus we have valid data in the + * packet so don't error out here. + */ + if ((eclass == ERRDOS && ecode == ERRmoredata) || NT_STATUS_V(status) == NT_STATUS_V(STATUS_MORE_ENTRIES)) + recoverable_error = True; + + if (!recoverable_error) return -1; } -- cgit From fe768c331533898989ae422d0b42a3ef9af3262e Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Sun, 1 Dec 2002 00:46:50 +0000 Subject: Fixup of ordered cleanup of get_dc_list - bug found by Dominik 'Aeneas' Schnitzer Jeremy. (This used to be commit 7ba051a830a7dc96e3860a87643a3ac99cdf5836) --- source3/libsmb/namequery.c | 37 ++++++++++--------------------------- 1 file changed, 10 insertions(+), 27 deletions(-) (limited to 'source3/libsmb') diff --git a/source3/libsmb/namequery.c b/source3/libsmb/namequery.c index 1c5af8bff0..6a59b73db2 100644 --- a/source3/libsmb/namequery.c +++ b/source3/libsmb/namequery.c @@ -1294,8 +1294,7 @@ BOOL get_dc_list(const char *domain, struct in_addr **ip_list, int *count, int * /* fill in the return list now with real IP's */ - while ( (local_count Date: Sun, 1 Dec 2002 03:12:50 +0000 Subject: Dereference the correct thing here, so we don't segfault (This used to be commit ea18d02036b4e0502e5ecb057c9fe381709a07d8) --- source3/libsmb/namequery.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/libsmb') diff --git a/source3/libsmb/namequery.c b/source3/libsmb/namequery.c index 6a59b73db2..c781e98365 100644 --- a/source3/libsmb/namequery.c +++ b/source3/libsmb/namequery.c @@ -913,7 +913,7 @@ static BOOL internal_resolve_name(const char *name, int name_type, /* Save in name cache */ for (i = 0; i < *return_count && DEBUGLEVEL == 100; i++) DEBUG(100, ("Storing name %s of type %d (ip: %s)\n", name, - name_type, inet_ntoa(*return_iplist[i]))); + name_type, inet_ntoa((*return_iplist)[i]))); namecache_store(name, name_type, *return_count, *return_iplist); -- cgit From db9686ff893c5a47249610e494a6bfad1168caf2 Mon Sep 17 00:00:00 2001 From: Herb Lewis Date: Tue, 3 Dec 2002 20:00:31 +0000 Subject: use the new IVAL_TO_SMB_OFF_T for file_info size member dir now shows correct size on large files (This used to be commit ce7d421ba9cfa65e3ed404f18e8b3b4cf4730593) --- source3/libsmb/clilist.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'source3/libsmb') diff --git a/source3/libsmb/clilist.c b/source3/libsmb/clilist.c index 3eacc25380..1616d46bf1 100644 --- a/source3/libsmb/clilist.c +++ b/source3/libsmb/clilist.c @@ -48,7 +48,7 @@ static int interpret_long_filename(struct cli_state *cli, finfo->ctime = make_unix_date2(p+4); finfo->atime = make_unix_date2(p+8); finfo->mtime = make_unix_date2(p+12); - finfo->size = IVAL(p,16); + finfo->size = IVAL_TO_SMB_OFF_T(p,16); finfo->mode = CVAL(p,24); len = CVAL(p, 26); p += 27; @@ -69,7 +69,7 @@ static int interpret_long_filename(struct cli_state *cli, finfo->ctime = make_unix_date2(p+4); finfo->atime = make_unix_date2(p+8); finfo->mtime = make_unix_date2(p+12); - finfo->size = IVAL(p,16); + finfo->size = IVAL_TO_SMB_OFF_T(p,16); finfo->mode = CVAL(p,24); len = CVAL(p, 30); p += 31; @@ -104,7 +104,7 @@ static int interpret_long_filename(struct cli_state *cli, finfo->ctime = interpret_long_date(p); p += 8; finfo->atime = interpret_long_date(p); p += 8; finfo->mtime = interpret_long_date(p); p += 8; p += 8; - finfo->size = IVAL(p,0); p += 8; + finfo->size = IVAL_TO_SMB_OFF_T(p,0); p += 8; p += 8; /* alloc size */ finfo->mode = CVAL(p,0); p += 4; namelen = IVAL(p,0); p += 4; @@ -322,7 +322,7 @@ static int interpret_short_filename(struct cli_state *cli, char *p,file_info *fi /* this date is converted to GMT by make_unix_date */ finfo->ctime = make_unix_date(p+22); finfo->mtime = finfo->atime = finfo->ctime; - finfo->size = IVAL(p,26); + finfo->size = IVAL_TO_SMB_OFF_T(p,26); clistr_pull(cli, finfo->name, p+30, sizeof(finfo->name), 12, STR_ASCII); if (strcmp(finfo->name, "..") && strcmp(finfo->name, ".")) fstrcpy(finfo->short_name,finfo->name); -- cgit From 64c967919145209a81863b425d3b66b636283c0c Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Wed, 4 Dec 2002 18:40:01 +0000 Subject: Doing janitorial duty for tpot - memory leak fix. Jeremy. (This used to be commit c6da50def80e64226c7e5b310dce30d0490512cb) --- source3/libsmb/namequery.c | 2 ++ 1 file changed, 2 insertions(+) (limited to 'source3/libsmb') diff --git a/source3/libsmb/namequery.c b/source3/libsmb/namequery.c index c781e98365..7aaa7d5908 100644 --- a/source3/libsmb/namequery.c +++ b/source3/libsmb/namequery.c @@ -1314,6 +1314,8 @@ BOOL get_dc_list(const char *domain, struct in_addr **ip_list, int *count, int * } + SAFE_FREE(auto_ip_list); + /* need to remove duplicates in the list if we have any explicit password servers */ -- cgit From c73c3e1daa9449eb6abab182b2d41bb945ada8c9 Mon Sep 17 00:00:00 2001 From: Gerald Carter Date: Wed, 4 Dec 2002 19:00:29 +0000 Subject: [merge] remove assert(count ==1) for multi-homed PDCs; CR 1277 (This used to be commit 157b5ab198670c6999f22d6b49072fdebc84be0d) --- source3/libsmb/namequery.c | 204 +++++---------------------------------------- 1 file changed, 22 insertions(+), 182 deletions(-) (limited to 'source3/libsmb') diff --git a/source3/libsmb/namequery.c b/source3/libsmb/namequery.c index 7aaa7d5908..f446453b9a 100644 --- a/source3/libsmb/namequery.c +++ b/source3/libsmb/namequery.c @@ -1001,7 +1001,6 @@ BOOL find_master_ip(const char *group, struct in_addr *master_ip) BOOL lookup_dc_name(const char *srcname, const char *domain, struct in_addr *dc_ip, char *ret_name) { -#if !defined(I_HATE_WINDOWS_REPLY_CODE) fstring dc_name; BOOL ret; @@ -1025,184 +1024,6 @@ BOOL lookup_dc_name(const char *srcname, const char *domain, } return False; - -#else /* defined(I_HATE_WINDOWS_REPLY_CODE) */ - -JRA - This code is broken with BDC rollover - we need to do a full -NT GETDC call, UNICODE, NT domain SID and uncle tom cobbley and all... - - int retries = 3; - int retry_time = 2000; - struct timeval tval; - struct packet_struct p; - struct dgram_packet *dgram = &p.packet.dgram; - char *ptr,*p2; - char tmp[4]; - int len; - struct sockaddr_in sock_name; - int sock_len = sizeof(sock_name); - const char *mailslot = NET_LOGON_MAILSLOT; - char *mailslot_name; - char buffer[1024]; - char *bufp; - int dgm_id = generate_trn_id(); - int sock = open_socket_in(SOCK_DGRAM, 0, 3, interpret_addr(lp_socket_address()), True ); - - if(sock == -1) - return False; - - /* Find out the transient UDP port we have been allocated. */ - if(getsockname(sock, (struct sockaddr *)&sock_name, &sock_len)<0) { - DEBUG(0,("lookup_pdc_name: Failed to get local UDP port. Error was %s\n", - strerror(errno))); - close(sock); - return False; - } - - /* - * Create the request data. - */ - - memset(buffer,'\0',sizeof(buffer)); - bufp = buffer; - SSVAL(bufp,0,QUERYFORPDC); - bufp += 2; - fstrcpy(bufp,srcname); - bufp += (strlen(bufp) + 1); - slprintf(bufp, sizeof(fstring)-1, "\\MAILSLOT\\NET\\GETDC%d", dgm_id); - mailslot_name = bufp; - bufp += (strlen(bufp) + 1); - bufp = ALIGN2(bufp, buffer); - bufp += push_ucs2(NULL, bufp, srcname, sizeof(buffer) - (bufp - buffer), STR_TERMINATE); - - SIVAL(bufp,0,1); - SSVAL(bufp,4,0xFFFF); - SSVAL(bufp,6,0xFFFF); - bufp += 8; - len = PTR_DIFF(bufp,buffer); - - memset((char *)&p,'\0',sizeof(p)); - - /* DIRECT GROUP or UNIQUE datagram. */ - dgram->header.msg_type = 0x10; - dgram->header.flags.node_type = M_NODE; - dgram->header.flags.first = True; - dgram->header.flags.more = False; - dgram->header.dgm_id = dgm_id; - dgram->header.source_ip = *iface_ip(*pdc_ip); - dgram->header.source_port = ntohs(sock_name.sin_port); - dgram->header.dgm_length = 0; /* Let build_dgram() handle this. */ - dgram->header.packet_offset = 0; - - make_nmb_name(&dgram->source_name,srcname,0); - make_nmb_name(&dgram->dest_name,domain,0x1C); - - 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,17 + len,True); - memcpy(ptr,tmp,4); - - CVAL(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); - pstrcpy(p2,mailslot); - p2 = skip_string(p2,1); - - memcpy(p2,buffer,len); - p2 += len; - - dgram->datasize = PTR_DIFF(p2,ptr+4); /* +4 for tcp length. */ - - p.ip = *pdc_ip; - p.port = DGRAM_PORT; - p.fd = sock; - p.timestamp = time(NULL); - p.packet_type = DGRAM_PACKET; - - GetTimeOfDay(&tval); - - if (!send_packet(&p)) { - DEBUG(0,("lookup_pdc_name: send_packet failed.\n")); - close(sock); - return False; - } - - retries--; - - while (1) { - struct timeval tval2; - struct packet_struct *p_ret; - - GetTimeOfDay(&tval2); - if (TvalDiff(&tval,&tval2) > retry_time) { - if (!retries) - break; - if (!send_packet(&p)) { - DEBUG(0,("lookup_pdc_name: send_packet failed.\n")); - close(sock); - return False; - } - GetTimeOfDay(&tval); - retries--; - } - - if ((p_ret = receive_dgram_packet(sock,90,mailslot_name))) { - struct dgram_packet *dgram2 = &p_ret->packet.dgram; - char *buf; - char *buf2; - - buf = &dgram2->data[0]; - buf -= 4; - - if (CVAL(buf,smb_com) != SMBtrans) { - DEBUG(0,("lookup_pdc_name: datagram type %u != SMBtrans(%u)\n", (unsigned int) - CVAL(buf,smb_com), (unsigned int)SMBtrans )); - free_packet(p_ret); - continue; - } - - len = SVAL(buf,smb_vwv11); - buf2 = smb_base(buf) + SVAL(buf,smb_vwv12); - - if (len <= 0) { - DEBUG(0,("lookup_pdc_name: datagram len < 0 (%d)\n", len )); - free_packet(p_ret); - continue; - } - - DEBUG(4,("lookup_pdc_name: datagram reply from %s to %s IP %s for %s of type %d len=%d\n", - nmb_namestr(&dgram2->source_name),nmb_namestr(&dgram2->dest_name), - inet_ntoa(p_ret->ip), smb_buf(buf),SVAL(buf2,0),len)); - - if(SVAL(buf2,0) != QUERYFORPDC_R) { - DEBUG(0,("lookup_pdc_name: datagram type (%u) != QUERYFORPDC_R(%u)\n", - (unsigned int)SVAL(buf,0), (unsigned int)QUERYFORPDC_R )); - free_packet(p_ret); - continue; - } - - buf2 += 2; - /* Note this is safe as it is a bounded strcpy. */ - fstrcpy(ret_name, buf2); - ret_name[sizeof(fstring)-1] = '\0'; - close(sock); - free_packet(p_ret); - return True; - } - } - - close(sock); - return False; -#endif /* defined(I_HATE_WINDOWS_REPLY_CODE) */ } /******************************************************** @@ -1214,15 +1035,34 @@ BOOL get_pdc_ip(const char *domain, struct in_addr *ip) { struct in_addr *ip_list; int count; + int i = 0; /* Look up #1B name */ if (!internal_resolve_name(domain, 0x1b, &ip_list, &count)) return False; - SMB_ASSERT(count == 1); + /* if we get more than 1 IP back we have to assume it is a + multi-homed PDC and not a mess up */ + + if ( count > 1 ) { + DEBUG(6,("get_pdc_ip: PDC has %d IP addresses!\n", count)); + + /* look for a local net */ + for ( i=0; i Date: Wed, 4 Dec 2002 19:03:32 +0000 Subject: cleaning up some friendly error messages (This used to be commit f978387e789eeaf9b53a21231d4cdc7cf3ea6db3) --- source3/libsmb/nterr.c | 48 ++++++++++++++++++++++++++---------------------- 1 file changed, 26 insertions(+), 22 deletions(-) (limited to 'source3/libsmb') diff --git a/source3/libsmb/nterr.c b/source3/libsmb/nterr.c index 89ad58b26f..4bb21efaa7 100644 --- a/source3/libsmb/nterr.c +++ b/source3/libsmb/nterr.c @@ -542,28 +542,32 @@ static nt_err_code_struct nt_errs[] = nt_err_code_struct nt_err_desc[] = { { "Success", NT_STATUS_OK }, - { "Undetermined error", NT_STATUS_UNSUCCESSFUL }, - { "Access denied", NT_STATUS_ACCESS_DENIED }, - { "Account locked out", NT_STATUS_ACCOUNT_LOCKED_OUT }, - { "Password is too short", NT_STATUS_PWD_TOO_SHORT }, - { "Password is too recent", NT_STATUS_PWD_TOO_RECENT }, - { "Password history conflict", NT_STATUS_PWD_HISTORY_CONFLICT }, - { "No logon servers", NT_STATUS_NO_LOGON_SERVERS }, - { "Invalid account name", NT_STATUS_INVALID_ACCOUNT_NAME }, - { "User exists", NT_STATUS_USER_EXISTS }, - { "No such user", NT_STATUS_NO_SUCH_USER }, - { "Group exists", NT_STATUS_GROUP_EXISTS }, - { "No such group", NT_STATUS_NO_SUCH_GROUP }, - { "Member not in group", NT_STATUS_MEMBER_NOT_IN_GROUP }, - { "Wrong Password", NT_STATUS_WRONG_PASSWORD }, - { "Ill formed password", NT_STATUS_ILL_FORMED_PASSWORD }, - { "Password restriction", NT_STATUS_PASSWORD_RESTRICTION }, - { "Logon failure", NT_STATUS_LOGON_FAILURE }, - { "Account restruction", NT_STATUS_ACCOUNT_RESTRICTION }, - { "Invalid logon hours", NT_STATUS_INVALID_LOGON_HOURS }, - { "Invalid workstation", NT_STATUS_INVALID_WORKSTATION }, - { "Password expired", NT_STATUS_PASSWORD_EXPIRED }, - { "Account Disabled", NT_STATUS_ACCOUNT_DISABLED }, + { "Undetermined error", NT_STATUS_UNSUCCESSFUL }, + { "Access denied", NT_STATUS_ACCESS_DENIED }, + { "Account locked out", NT_STATUS_ACCOUNT_LOCKED_OUT }, + { "Password is too short", NT_STATUS_PWD_TOO_SHORT }, + { "Password is too recent", NT_STATUS_PWD_TOO_RECENT }, + { "Password history conflict", NT_STATUS_PWD_HISTORY_CONFLICT }, + { "No logon servers", NT_STATUS_NO_LOGON_SERVERS }, + { "Improperly formed account name", NT_STATUS_INVALID_ACCOUNT_NAME }, + { "User exists", NT_STATUS_USER_EXISTS }, + { "No such user", NT_STATUS_NO_SUCH_USER }, + { "Group exists", NT_STATUS_GROUP_EXISTS }, + { "No such group", NT_STATUS_NO_SUCH_GROUP }, + { "Member not in group", NT_STATUS_MEMBER_NOT_IN_GROUP }, + { "Wrong Password", NT_STATUS_WRONG_PASSWORD }, + { "Ill formed password", NT_STATUS_ILL_FORMED_PASSWORD }, + { "Password restriction", NT_STATUS_PASSWORD_RESTRICTION }, + { "Logon failure", NT_STATUS_LOGON_FAILURE }, + { "Account restriction", NT_STATUS_ACCOUNT_RESTRICTION }, + { "Invalid logon hours", NT_STATUS_INVALID_LOGON_HOURS }, + { "Invalid workstation", NT_STATUS_INVALID_WORKSTATION }, + { "Password expired", NT_STATUS_PASSWORD_EXPIRED }, + { "Account disabled", NT_STATUS_ACCOUNT_DISABLED }, + { "Unexpected information received", NT_STATUS_INVALID_PARAMETER }, + { "Memory allocation error", NT_STATUS_NO_MEMORY }, + { "No domain controllers located", NT_STATUS_DOMAIN_CONTROLLER_NOT_FOUND }, + { "Account locked out", NT_STATUS_ACCOUNT_LOCKED_OUT }, { NULL, NT_STATUS(0) } }; -- cgit From 8c13b09b9d8dc8f4d7d3515f35dbd2fb58ff3e0e Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Fri, 6 Dec 2002 19:58:27 +0000 Subject: Ensure global_scope() returns "", not the NULL string. Froma tpot fix. Jeremy. (This used to be commit 7185b846e41da2bf7edaa7f3edeff1cc1486d28b) --- source3/libsmb/nmblib.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/libsmb') diff --git a/source3/libsmb/nmblib.c b/source3/libsmb/nmblib.c index 43e32aebbd..d38e2ff0ec 100644 --- a/source3/libsmb/nmblib.c +++ b/source3/libsmb/nmblib.c @@ -1203,7 +1203,7 @@ int name_mangle( char *In, char *Out, char name_type ) p[0] = '\0'; /* Add the scope string. */ - for( i = 0, len = 0; NULL != global_scope(); i++, len++ ) + for( i = 0, len = 0; *(global_scope()) != '\0'; i++, len++ ) { switch( (global_scope())[i] ) { -- cgit From 89ef861b4b7530a8a9a157b2e9e253a2e5716738 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Tue, 10 Dec 2002 23:27:12 +0000 Subject: Fix client large file reporting. Jeremy (This used to be commit 185804ac945e717a5e3d3602e8118b35080f6251) --- source3/libsmb/clilist.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'source3/libsmb') diff --git a/source3/libsmb/clilist.c b/source3/libsmb/clilist.c index 1616d46bf1..4a1737af49 100644 --- a/source3/libsmb/clilist.c +++ b/source3/libsmb/clilist.c @@ -48,7 +48,7 @@ static int interpret_long_filename(struct cli_state *cli, finfo->ctime = make_unix_date2(p+4); finfo->atime = make_unix_date2(p+8); finfo->mtime = make_unix_date2(p+12); - finfo->size = IVAL_TO_SMB_OFF_T(p,16); + finfo->size = IVAL(p,16); finfo->mode = CVAL(p,24); len = CVAL(p, 26); p += 27; @@ -69,7 +69,7 @@ static int interpret_long_filename(struct cli_state *cli, finfo->ctime = make_unix_date2(p+4); finfo->atime = make_unix_date2(p+8); finfo->mtime = make_unix_date2(p+12); - finfo->size = IVAL_TO_SMB_OFF_T(p,16); + finfo->size = IVAL(p,16); finfo->mode = CVAL(p,24); len = CVAL(p, 30); p += 31; @@ -104,7 +104,7 @@ static int interpret_long_filename(struct cli_state *cli, finfo->ctime = interpret_long_date(p); p += 8; finfo->atime = interpret_long_date(p); p += 8; finfo->mtime = interpret_long_date(p); p += 8; p += 8; - finfo->size = IVAL_TO_SMB_OFF_T(p,0); p += 8; + finfo->size = IVAL2_TO_SMB_BIG_UINT(p,0); p += 8; p += 8; /* alloc size */ finfo->mode = CVAL(p,0); p += 4; namelen = IVAL(p,0); p += 4; @@ -322,7 +322,7 @@ static int interpret_short_filename(struct cli_state *cli, char *p,file_info *fi /* this date is converted to GMT by make_unix_date */ finfo->ctime = make_unix_date(p+22); finfo->mtime = finfo->atime = finfo->ctime; - finfo->size = IVAL_TO_SMB_OFF_T(p,26); + finfo->size = IVAL(p,26); clistr_pull(cli, finfo->name, p+30, sizeof(finfo->name), 12, STR_ASCII); if (strcmp(finfo->name, "..") && strcmp(finfo->name, ".")) fstrcpy(finfo->short_name,finfo->name); -- cgit From f7267c1235ae1b8c6a7324d508f5d435ff18de50 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Wed, 11 Dec 2002 18:52:32 +0000 Subject: Fix write error returning EFBIG - found by Conrad. Jeremy. (This used to be commit 2d63fc7760634308cc280e4d745a6f7398f75d20) --- source3/libsmb/errormap.c | 3 +++ 1 file changed, 3 insertions(+) (limited to 'source3/libsmb') diff --git a/source3/libsmb/errormap.c b/source3/libsmb/errormap.c index 7c28c7e8aa..8bd29b55c0 100644 --- a/source3/libsmb/errormap.c +++ b/source3/libsmb/errormap.c @@ -1512,6 +1512,9 @@ const struct unix_error_map unix_dos_nt_errmap[] = { #endif #ifdef ENAMETOOLONG { ENAMETOOLONG, ERRDOS, 206, NT_STATUS_OBJECT_NAME_INVALID }, +#endif +#ifdef EFBIG + { EFBIG, ERRHRD, ERRdiskfull, NT_STATUS_DISK_FULL }, #endif { 0, 0, 0, NT_STATUS_OK } }; -- cgit From f6c4f25e4319b47ac6c8dbf67a4b1c513148384c Mon Sep 17 00:00:00 2001 From: Gerald Carter Date: Thu, 12 Dec 2002 23:35:55 +0000 Subject: merge of get_dc_name()-like code from APP_HEAD; better support password server = DC1 * (This used to be commit 6b18ca9511ddcf1718f222af3f61491d1e5f3b60) --- source3/libsmb/namequery_dc.c | 104 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 104 insertions(+) create mode 100644 source3/libsmb/namequery_dc.c (limited to 'source3/libsmb') diff --git a/source3/libsmb/namequery_dc.c b/source3/libsmb/namequery_dc.c new file mode 100644 index 0000000000..ffc64139e9 --- /dev/null +++ b/source3/libsmb/namequery_dc.c @@ -0,0 +1,104 @@ +/* + Unix SMB/CIFS implementation. + + Winbind daemon connection manager + + Copyright (C) Tim Potter 2001 + Copyright (C) Andrew Bartlett 2002 + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +*/ + + +#include "includes.h" + + +/* + find the DC for a domain using methods appropriate for a RPC domain +*/ +BOOL rpc_find_dc(const char *domain, fstring srv_name, struct in_addr *ip_out) +{ + struct in_addr *ip_list = NULL, dc_ip, exclude_ip; + int count, i; + BOOL list_ordered; + BOOL use_pdc_only; + + zero_ip(&exclude_ip); + + use_pdc_only = must_use_pdc(domain); + + /* Lookup domain controller name */ + + if ( use_pdc_only && get_pdc_ip(domain, &dc_ip) ) { + DEBUG(10,("rpc_find_dc: Atempting to lookup PDC to avoid sam sync delays\n")); + + if (name_status_find(domain, 0x1c, 0x20, dc_ip, srv_name)) { + goto done; + } + /* Didn't get name, remember not to talk to this DC. */ + exclude_ip = dc_ip; + } + + /* get a list of all domain controllers */ + + if (!get_dc_list( domain, &ip_list, &count, &list_ordered) ) { + DEBUG(3, ("Could not look up dc's for domain %s\n", domain)); + return False; + } + + /* Remove the entry we've already failed with (should be the PDC). */ + + if ( use_pdc_only ) { + for (i = 0; i < count; i++) { + if (ip_equal( exclude_ip, ip_list[i])) + zero_ip(&ip_list[i]); + } + } + + /* Pick a nice close server, but only if the list was not ordered */ + if (!list_ordered && (count > 1) ) { + qsort(ip_list, count, sizeof(struct in_addr), QSORT_CAST ip_compare); + } + + for (i = 0; i < count; i++) { + if (is_zero_ip(ip_list[i])) + continue; + + if (name_status_find(domain, 0x1c, 0x20, ip_list[i], srv_name)) { + dc_ip = ip_list[i]; + goto done; + } + } + + + SAFE_FREE(ip_list); + + return False; +done: + /* We have the netbios name and IP address of a domain controller. + Ideally we should sent a SAMLOGON request to determine whether + the DC is alive and kicking. If we can catch a dead DC before + performing a cli_connect() we can avoid a 30-second timeout. */ + + DEBUG(3, ("rpc_find_dc: Returning DC %s (%s) for domain %s\n", srv_name, + inet_ntoa(dc_ip), domain)); + + *ip_out = dc_ip; + + SAFE_FREE(ip_list); + + return True; +} + -- cgit