mirror of
https://github.com/samba-team/samba.git
synced 2025-02-04 17:47:26 +03:00
Merge of get_dc_list() api change. This was slightly more intrusive
than the version in APPLIANCE so watch out for boogs.
This commit is contained in:
parent
b195b1fa15
commit
1e054e3db6
@ -288,8 +288,23 @@ static NTSTATUS find_connect_pdc(struct cli_state **cli,
|
|||||||
if (time_now - last_change_time < 3600)
|
if (time_now - last_change_time < 3600)
|
||||||
use_pdc_only = True;
|
use_pdc_only = True;
|
||||||
|
|
||||||
if (!get_dc_list(use_pdc_only, domain, &ip_list, &count))
|
if (use_pdc_only) {
|
||||||
return NT_STATUS_NO_LOGON_SERVERS;
|
struct in_addr pdc_ip;
|
||||||
|
|
||||||
|
if (!get_pdc_ip(domain, &pdc_ip))
|
||||||
|
return NT_STATUS_NO_LOGON_SERVERS;
|
||||||
|
|
||||||
|
if ((ip_list = (struct in_addr *)
|
||||||
|
malloc(sizeof(struct in_addr))) == NULL)
|
||||||
|
return NT_STATUS_NO_MEMORY;
|
||||||
|
|
||||||
|
ip_list[0] = pdc_ip;
|
||||||
|
count = 1;
|
||||||
|
|
||||||
|
} else {
|
||||||
|
if (!get_dc_list(domain, &ip_list, &count))
|
||||||
|
return NT_STATUS_NO_LOGON_SERVERS;
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Firstly try and contact a PDC/BDC who has the same
|
* Firstly try and contact a PDC/BDC who has the same
|
||||||
|
@ -180,7 +180,7 @@ static BOOL ads_try_dns(ADS_STRUCT *ads)
|
|||||||
/* try connecting to a ldap server via netbios */
|
/* try connecting to a ldap server via netbios */
|
||||||
static BOOL ads_try_netbios(ADS_STRUCT *ads)
|
static BOOL ads_try_netbios(ADS_STRUCT *ads)
|
||||||
{
|
{
|
||||||
struct in_addr *ip_list;
|
struct in_addr *ip_list, pdc_ip;
|
||||||
int count;
|
int count;
|
||||||
int i;
|
int i;
|
||||||
char *workgroup = ads->server.workgroup;
|
char *workgroup = ads->server.workgroup;
|
||||||
@ -192,20 +192,15 @@ static BOOL ads_try_netbios(ADS_STRUCT *ads)
|
|||||||
DEBUG(6,("ads_try_netbios: looking for workgroup '%s'\n", workgroup));
|
DEBUG(6,("ads_try_netbios: looking for workgroup '%s'\n", workgroup));
|
||||||
|
|
||||||
/* try the PDC first */
|
/* try the PDC first */
|
||||||
if (get_dc_list(True, workgroup, &ip_list, &count)) {
|
if (get_pdc_ip(workgroup, &pdc_ip)) {
|
||||||
for (i=0;i<count;i++) {
|
DEBUG(6,("ads_try_netbios: trying server '%s'\n",
|
||||||
DEBUG(6,("ads_try_netbios: trying server '%s'\n",
|
inet_ntoa(pdc_ip)));
|
||||||
inet_ntoa(ip_list[i])));
|
if (ads_try_connect(ads, inet_ntoa(pdc_ip), LDAP_PORT))
|
||||||
if (ads_try_connect(ads, inet_ntoa(ip_list[i]), LDAP_PORT)) {
|
return True;
|
||||||
free(ip_list);
|
|
||||||
return True;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
free(ip_list);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* now any DC, including backups */
|
/* now any DC, including backups */
|
||||||
if (get_dc_list(False, workgroup, &ip_list, &count)) {
|
if (get_dc_list(workgroup, &ip_list, &count)) {
|
||||||
for (i=0;i<count;i++) {
|
for (i=0;i<count;i++) {
|
||||||
DEBUG(6,("ads_try_netbios: trying server '%s'\n",
|
DEBUG(6,("ads_try_netbios: trying server '%s'\n",
|
||||||
inet_ntoa(ip_list[i])));
|
inet_ntoa(ip_list[i])));
|
||||||
|
@ -1206,54 +1206,87 @@ NT GETDC call, UNICODE, NT domain SID and uncle tom cobbley and all...
|
|||||||
#endif /* defined(I_HATE_WINDOWS_REPLY_CODE) */
|
#endif /* defined(I_HATE_WINDOWS_REPLY_CODE) */
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/********************************************************
|
/********************************************************
|
||||||
Get the IP address list of the PDC/BDC's of a Domain.
|
Get the IP address list of the primary domain controller
|
||||||
|
for a domain.
|
||||||
*********************************************************/
|
*********************************************************/
|
||||||
|
|
||||||
BOOL get_dc_list(BOOL pdc_only, const char *group, struct in_addr **ip_list, int *count)
|
BOOL get_pdc_ip(const char *domain, struct in_addr *ip)
|
||||||
{
|
{
|
||||||
int name_type = pdc_only ? 0x1B : 0x1C;
|
struct in_addr *ip_list;
|
||||||
|
int count;
|
||||||
|
|
||||||
|
/* Look up #1B name */
|
||||||
|
|
||||||
|
if (!internal_resolve_name(domain, 0x1b, &ip_list, &count))
|
||||||
|
return False;
|
||||||
|
|
||||||
|
SMB_ASSERT(count == 1);
|
||||||
|
|
||||||
|
*ip = ip_list[0];
|
||||||
|
SAFE_FREE(ip_list);
|
||||||
|
|
||||||
|
return True;
|
||||||
|
}
|
||||||
|
|
||||||
|
/********************************************************
|
||||||
|
Get the IP address list of the domain controllers for
|
||||||
|
a domain.
|
||||||
|
*********************************************************/
|
||||||
|
|
||||||
|
BOOL get_dc_list(const char *domain, struct in_addr **ip_list, int *count)
|
||||||
|
{
|
||||||
/*
|
/*
|
||||||
* If it's our domain then
|
* If it's our domain then
|
||||||
* use the 'password server' parameter.
|
* use the 'password server' parameter.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
if (strequal(group, lp_workgroup())) {
|
if (strequal(domain, lp_workgroup())) {
|
||||||
char *p;
|
char *p;
|
||||||
char *pserver = lp_passwordserver();
|
char *pserver = lp_passwordserver();
|
||||||
fstring name;
|
fstring name;
|
||||||
int num_adresses = 0;
|
int num_adresses = 0;
|
||||||
struct in_addr *return_iplist = NULL;
|
struct in_addr *return_iplist = NULL;
|
||||||
|
|
||||||
if (! *pserver)
|
if (!*pserver)
|
||||||
return internal_resolve_name(group, name_type, ip_list, count);
|
return internal_resolve_name(
|
||||||
|
domain, 0x1C, ip_list, count);
|
||||||
|
|
||||||
p = pserver;
|
p = pserver;
|
||||||
|
|
||||||
while (next_token(&p,name,LIST_SEP,sizeof(name))) {
|
while (next_token(&p,name,LIST_SEP,sizeof(name))) {
|
||||||
if (strequal(name, "*"))
|
if (strequal(name, "*"))
|
||||||
return internal_resolve_name(group, name_type, ip_list, count);
|
return internal_resolve_name(
|
||||||
|
domain, 0x1C, ip_list, count);
|
||||||
num_adresses++;
|
num_adresses++;
|
||||||
}
|
}
|
||||||
if (num_adresses == 0)
|
|
||||||
return internal_resolve_name(group, name_type, ip_list, count);
|
|
||||||
|
|
||||||
return_iplist = (struct in_addr *)malloc(num_adresses * sizeof(struct in_addr));
|
if (num_adresses == 0)
|
||||||
if(return_iplist == NULL) {
|
return internal_resolve_name(
|
||||||
|
domain, 0x1C, ip_list, count);
|
||||||
|
|
||||||
|
return_iplist = (struct in_addr *)malloc(
|
||||||
|
num_adresses * sizeof(struct in_addr));
|
||||||
|
|
||||||
|
if (return_iplist == NULL) {
|
||||||
DEBUG(3,("get_dc_list: malloc fail !\n"));
|
DEBUG(3,("get_dc_list: malloc fail !\n"));
|
||||||
return False;
|
return False;
|
||||||
}
|
}
|
||||||
|
|
||||||
p = pserver;
|
p = pserver;
|
||||||
*count = 0;
|
*count = 0;
|
||||||
|
|
||||||
while (next_token(&p,name,LIST_SEP,sizeof(name))) {
|
while (next_token(&p,name,LIST_SEP,sizeof(name))) {
|
||||||
struct in_addr name_ip;
|
struct in_addr name_ip;
|
||||||
if (resolve_name( name, &name_ip, 0x20) == False)
|
if (resolve_name( name, &name_ip, 0x20) == False)
|
||||||
continue;
|
continue;
|
||||||
return_iplist[(*count)++] = name_ip;
|
return_iplist[(*count)++] = name_ip;
|
||||||
}
|
}
|
||||||
|
|
||||||
*ip_list = return_iplist;
|
*ip_list = return_iplist;
|
||||||
|
|
||||||
return (*count != 0);
|
return (*count != 0);
|
||||||
} else
|
}
|
||||||
return internal_resolve_name(group, name_type, ip_list, count);
|
|
||||||
|
return internal_resolve_name(domain, 0x1C, ip_list, count);
|
||||||
}
|
}
|
||||||
|
@ -143,10 +143,22 @@ static BOOL cm_rpc_find_dc(const char *domain, struct in_addr *dc_ip, fstring sr
|
|||||||
struct in_addr *ip_list = NULL;
|
struct in_addr *ip_list = NULL;
|
||||||
int count, i;
|
int count, i;
|
||||||
|
|
||||||
if (!get_dc_list(False, domain, &ip_list, &count) &&
|
if (!get_dc_list(domain, &ip_list, &count)) {
|
||||||
!get_dc_list(True, domain, &ip_list, &count)) {
|
struct in_addr pdc_ip;
|
||||||
DEBUG(3, ("Could not look up dc's for domain %s\n", domain));
|
|
||||||
return False;
|
if (!get_pdc_ip(domain, &pdc_ip)) {
|
||||||
|
DEBUG(3, ("Could not look up any DCs for domain %s\n",
|
||||||
|
domain));
|
||||||
|
return False;
|
||||||
|
}
|
||||||
|
|
||||||
|
ip_list = (struct in_addr *)malloc(sizeof(struct in_addr));
|
||||||
|
|
||||||
|
if (!ip_list)
|
||||||
|
return False;
|
||||||
|
|
||||||
|
ip_list[0] = pdc_ip;
|
||||||
|
count = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Pick a nice close server */
|
/* Pick a nice close server */
|
||||||
|
@ -494,8 +494,7 @@ static struct cli_state *init_connection(struct cli_state **cli,
|
|||||||
char *password)
|
char *password)
|
||||||
{
|
{
|
||||||
extern pstring global_myname;
|
extern pstring global_myname;
|
||||||
struct in_addr *dest_ip;
|
struct in_addr pdc_ip;
|
||||||
int count;
|
|
||||||
fstring dest_host;
|
fstring dest_host;
|
||||||
|
|
||||||
/* Initialise myname */
|
/* Initialise myname */
|
||||||
@ -511,13 +510,13 @@ static struct cli_state *init_connection(struct cli_state **cli,
|
|||||||
|
|
||||||
/* Look up name of PDC controller */
|
/* Look up name of PDC controller */
|
||||||
|
|
||||||
if (!get_dc_list(True, lp_workgroup(), &dest_ip, &count)) {
|
if (!get_pdc_ip(lp_workgroup(), &pdc_ip)) {
|
||||||
DEBUG(0, ("Cannot find domain controller for domain %s\n",
|
DEBUG(0, ("Cannot find domain controller for domain %s\n",
|
||||||
lp_workgroup()));
|
lp_workgroup()));
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!lookup_dc_name(global_myname, lp_workgroup(), dest_ip,
|
if (!lookup_dc_name(global_myname, lp_workgroup(), pdc_ip,
|
||||||
dest_host)) {
|
dest_host)) {
|
||||||
DEBUG(0, ("Could not lookup up PDC name for domain %s\n",
|
DEBUG(0, ("Could not lookup up PDC name for domain %s\n",
|
||||||
lp_workgroup()));
|
lp_workgroup()));
|
||||||
@ -525,7 +524,7 @@ static struct cli_state *init_connection(struct cli_state **cli,
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (NT_STATUS_IS_OK(cli_full_connection(cli, global_myname, dest_host,
|
if (NT_STATUS_IS_OK(cli_full_connection(cli, global_myname, dest_host,
|
||||||
dest_ip, 0,
|
pdc_ip, 0,
|
||||||
"IPC$", "IPC",
|
"IPC$", "IPC",
|
||||||
username, domain,
|
username, domain,
|
||||||
password, 0))) {
|
password, 0))) {
|
||||||
|
@ -105,12 +105,11 @@ account password for domain %s.\n", domain));
|
|||||||
* We have been asked to dynamcially determine the IP addresses of the PDC.
|
* We have been asked to dynamcially determine the IP addresses of the PDC.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
struct in_addr *ip_list = NULL;
|
struct in_addr pdc_ip;
|
||||||
int count = 0;
|
fstring dc_name;
|
||||||
int i;
|
|
||||||
|
|
||||||
/* Use the PDC *only* for this. */
|
/* Use the PDC *only* for this. */
|
||||||
if(!get_dc_list(True, domain, &ip_list, &count))
|
if(!get_pdc_ip(domain, &pdc_ip))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -118,17 +117,11 @@ account password for domain %s.\n", domain));
|
|||||||
* address used as a string.
|
* address used as a string.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
for(i = 0; i < count; i++) {
|
if(!lookup_dc_name(global_myname, domain, &pdc_ip, dc_name))
|
||||||
fstring dc_name;
|
|
||||||
if(!lookup_dc_name(global_myname, domain, &ip_list[i], dc_name))
|
|
||||||
continue;
|
continue;
|
||||||
if(NT_STATUS_IS_OK(res = modify_trust_password( domain, dc_name,
|
if(NT_STATUS_IS_OK(res = modify_trust_password( domain, dc_name,
|
||||||
old_trust_passwd_hash)))
|
old_trust_passwd_hash)))
|
||||||
break;
|
break;
|
||||||
}
|
|
||||||
|
|
||||||
SAFE_FREE(ip_list);
|
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
res = modify_trust_password( domain, remote_machine,
|
res = modify_trust_password( domain, remote_machine,
|
||||||
old_trust_passwd_hash);
|
old_trust_passwd_hash);
|
||||||
|
@ -180,20 +180,15 @@ BOOL net_find_server(unsigned flags, struct in_addr *server_ip, char **server_na
|
|||||||
return False;
|
return False;
|
||||||
}
|
}
|
||||||
} else if (flags & NET_FLAGS_PDC) {
|
} else if (flags & NET_FLAGS_PDC) {
|
||||||
struct in_addr *ip_list;
|
struct in_addr pdc_ip;
|
||||||
int addr_count;
|
|
||||||
if (get_dc_list(True /* PDC only*/, opt_target_workgroup, &ip_list, &addr_count)) {
|
if (get_pdc_ip(opt_target_workgroup, &pdc_ip)) {
|
||||||
fstring dc_name;
|
fstring dc_name;
|
||||||
if (addr_count < 1) {
|
|
||||||
return False;
|
|
||||||
}
|
|
||||||
|
|
||||||
*server_ip = *ip_list;
|
if (is_zero_ip(pdc_ip))
|
||||||
|
|
||||||
if (is_zero_ip(*server_ip))
|
|
||||||
return False;
|
return False;
|
||||||
|
|
||||||
if (!lookup_dc_name(global_myname, opt_target_workgroup, server_ip, dc_name))
|
if (!lookup_dc_name(global_myname, opt_target_workgroup, &pdc_ip, dc_name))
|
||||||
return False;
|
return False;
|
||||||
|
|
||||||
*server_name = strdup(dc_name);
|
*server_name = strdup(dc_name);
|
||||||
@ -236,17 +231,9 @@ BOOL net_find_server(unsigned flags, struct in_addr *server_ip, char **server_na
|
|||||||
|
|
||||||
BOOL net_find_dc(struct in_addr *server_ip, fstring server_name, const char *domain_name)
|
BOOL net_find_dc(struct in_addr *server_ip, fstring server_name, const char *domain_name)
|
||||||
{
|
{
|
||||||
struct in_addr *ip_list;
|
if (get_pdc_ip(domain_name, server_ip)) {
|
||||||
int addr_count;
|
|
||||||
|
|
||||||
if (get_dc_list(True /* PDC only*/, domain_name, &ip_list, &addr_count)) {
|
|
||||||
fstring dc_name;
|
fstring dc_name;
|
||||||
if (addr_count < 1) {
|
|
||||||
return False;
|
|
||||||
}
|
|
||||||
|
|
||||||
*server_ip = *ip_list;
|
|
||||||
|
|
||||||
if (is_zero_ip(*server_ip))
|
if (is_zero_ip(*server_ip))
|
||||||
return False;
|
return False;
|
||||||
|
|
||||||
|
@ -79,8 +79,8 @@ static int net_lookup_ldap(int argc, const char **argv)
|
|||||||
#ifdef HAVE_LDAP
|
#ifdef HAVE_LDAP
|
||||||
char *srvlist;
|
char *srvlist;
|
||||||
const char *domain;
|
const char *domain;
|
||||||
int rc, count;
|
int rc;
|
||||||
struct in_addr *addr;
|
struct in_addr addr;
|
||||||
struct hostent *hostent;
|
struct hostent *hostent;
|
||||||
|
|
||||||
if (argc > 0)
|
if (argc > 0)
|
||||||
@ -96,10 +96,10 @@ static int net_lookup_ldap(int argc, const char **argv)
|
|||||||
}
|
}
|
||||||
|
|
||||||
DEBUG(9, ("Looking up DC for domain %s\n", domain));
|
DEBUG(9, ("Looking up DC for domain %s\n", domain));
|
||||||
if (!get_dc_list(True, domain, &addr, &count))
|
if (!get_pdc_ip(domain, &addr))
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
hostent = gethostbyaddr((char *) &addr->s_addr, sizeof(addr->s_addr),
|
hostent = gethostbyaddr((char *) &addr.s_addr, sizeof(addr.s_addr),
|
||||||
AF_INET);
|
AF_INET);
|
||||||
if (!hostent)
|
if (!hostent)
|
||||||
return -1;
|
return -1;
|
||||||
@ -124,7 +124,7 @@ static int net_lookup_ldap(int argc, const char **argv)
|
|||||||
|
|
||||||
static int net_lookup_dc(int argc, const char **argv)
|
static int net_lookup_dc(int argc, const char **argv)
|
||||||
{
|
{
|
||||||
struct in_addr *ip_list;
|
struct in_addr *ip_list, addr;
|
||||||
char *pdc_str = NULL;
|
char *pdc_str = NULL;
|
||||||
const char *domain=opt_target_workgroup;
|
const char *domain=opt_target_workgroup;
|
||||||
int count, i;
|
int count, i;
|
||||||
@ -133,13 +133,13 @@ static int net_lookup_dc(int argc, const char **argv)
|
|||||||
domain=argv[0];
|
domain=argv[0];
|
||||||
|
|
||||||
/* first get PDC */
|
/* first get PDC */
|
||||||
if (!get_dc_list(True, domain, &ip_list, &count))
|
if (!get_pdc_ip(domain, &addr))
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
asprintf(&pdc_str, "%s", inet_ntoa(*ip_list));
|
asprintf(&pdc_str, "%s", inet_ntoa(addr));
|
||||||
d_printf("%s\n", pdc_str);
|
d_printf("%s\n", pdc_str);
|
||||||
|
|
||||||
if (!get_dc_list(False, domain, &ip_list, &count)) {
|
if (!get_dc_list(domain, &ip_list, &count)) {
|
||||||
SAFE_FREE(pdc_str);
|
SAFE_FREE(pdc_str);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user