mirror of
https://github.com/samba-team/samba.git
synced 2025-11-09 20:23:51 +03:00
libads: add ads_get_machine_kvno() to make ads_get_kvno() a bit more generic.
Guenther
This commit is contained in:
@@ -2081,7 +2081,8 @@ char *ads_ou_string(ADS_STRUCT *ads, const char *org_unit);
|
|||||||
char *ads_default_ou_string(ADS_STRUCT *ads, const char *wknguid);
|
char *ads_default_ou_string(ADS_STRUCT *ads, const char *wknguid);
|
||||||
ADS_STATUS ads_add_strlist(TALLOC_CTX *ctx, ADS_MODLIST *mods,
|
ADS_STATUS ads_add_strlist(TALLOC_CTX *ctx, ADS_MODLIST *mods,
|
||||||
const char *name, const char **vals);
|
const char *name, const char **vals);
|
||||||
uint32 ads_get_kvno(ADS_STRUCT *ads, const char *machine_name);
|
uint32 ads_get_kvno(ADS_STRUCT *ads, const char *account_name);
|
||||||
|
uint32_t ads_get_machine_kvno(ADS_STRUCT *ads, const char *machine_name);
|
||||||
ADS_STATUS ads_clear_service_principal_names(ADS_STRUCT *ads, const char *machine_name);
|
ADS_STATUS ads_clear_service_principal_names(ADS_STRUCT *ads, const char *machine_name);
|
||||||
ADS_STATUS ads_add_service_principal_name(ADS_STRUCT *ads, const char *machine_name,
|
ADS_STATUS ads_add_service_principal_name(ADS_STRUCT *ads, const char *machine_name,
|
||||||
const char *my_fqdn, const char *spn);
|
const char *my_fqdn, const char *spn);
|
||||||
|
|||||||
@@ -312,9 +312,9 @@ int ads_keytab_add_entry(ADS_STRUCT *ads, const char *srvPrinc)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
kvno = (krb5_kvno) ads_get_kvno(ads, global_myname());
|
kvno = (krb5_kvno) ads_get_machine_kvno(ads, global_myname());
|
||||||
if (kvno == -1) { /* -1 indicates failure, everything else is OK */
|
if (kvno == -1) { /* -1 indicates failure, everything else is OK */
|
||||||
DEBUG(1,("ads_keytab_add_entry: ads_get_kvno failed to determine the system's kvno.\n"));
|
DEBUG(1,("ads_keytab_add_entry: ads_get_machine_kvno failed to determine the system's kvno.\n"));
|
||||||
ret = -1;
|
ret = -1;
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
@@ -380,7 +380,7 @@ int ads_keytab_flush(ADS_STRUCT *ads)
|
|||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
||||||
kvno = (krb5_kvno) ads_get_kvno(ads, global_myname());
|
kvno = (krb5_kvno) ads_get_machine_kvno(ads, global_myname());
|
||||||
if (kvno == -1) { /* -1 indicates a failure */
|
if (kvno == -1) { /* -1 indicates a failure */
|
||||||
DEBUG(1,("ads_keytab_flush: Error determining the system's kvno.\n"));
|
DEBUG(1,("ads_keytab_flush: Error determining the system's kvno.\n"));
|
||||||
goto out;
|
goto out;
|
||||||
@@ -527,9 +527,9 @@ int ads_keytab_create_default(ADS_STRUCT *ads)
|
|||||||
|
|
||||||
/* Now loop through the keytab and update any other existing entries... */
|
/* Now loop through the keytab and update any other existing entries... */
|
||||||
|
|
||||||
kvno = (krb5_kvno) ads_get_kvno(ads, machine_name);
|
kvno = (krb5_kvno) ads_get_machine_kvno(ads, machine_name);
|
||||||
if (kvno == -1) {
|
if (kvno == -1) {
|
||||||
DEBUG(1,("ads_keytab_create_default: ads_get_kvno failed to determine the system's kvno.\n"));
|
DEBUG(1,("ads_keytab_create_default: ads_get_machine_kvno failed to determine the system's kvno.\n"));
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1516,13 +1516,13 @@ ADS_STATUS ads_add_strlist(TALLOC_CTX *ctx, ADS_MODLIST *mods,
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Determines the computer account's current KVNO via an LDAP lookup
|
* Determines the an account's current KVNO via an LDAP lookup
|
||||||
* @param ads An initialized ADS_STRUCT
|
* @param ads An initialized ADS_STRUCT
|
||||||
* @param machine_name the NetBIOS name of the computer, which is used to identify the computer account.
|
* @param account_name the NT samaccountname.
|
||||||
* @return the kvno for the computer account, or -1 in case of a failure.
|
* @return the kvno for the account, or -1 in case of a failure.
|
||||||
**/
|
**/
|
||||||
|
|
||||||
uint32 ads_get_kvno(ADS_STRUCT *ads, const char *machine_name)
|
uint32 ads_get_kvno(ADS_STRUCT *ads, const char *account_name)
|
||||||
{
|
{
|
||||||
LDAPMessage *res = NULL;
|
LDAPMessage *res = NULL;
|
||||||
uint32 kvno = (uint32)-1; /* -1 indicates a failure */
|
uint32 kvno = (uint32)-1; /* -1 indicates a failure */
|
||||||
@@ -1531,14 +1531,14 @@ uint32 ads_get_kvno(ADS_STRUCT *ads, const char *machine_name)
|
|||||||
char *dn_string = NULL;
|
char *dn_string = NULL;
|
||||||
ADS_STATUS ret = ADS_ERROR(LDAP_SUCCESS);
|
ADS_STATUS ret = ADS_ERROR(LDAP_SUCCESS);
|
||||||
|
|
||||||
DEBUG(5,("ads_get_kvno: Searching for host %s\n", machine_name));
|
DEBUG(5,("ads_get_kvno: Searching for account %s\n", account_name));
|
||||||
if (asprintf(&filter, "(samAccountName=%s$)", machine_name) == -1) {
|
if (asprintf(&filter, "(samAccountName=%s)", account_name) == -1) {
|
||||||
return kvno;
|
return kvno;
|
||||||
}
|
}
|
||||||
ret = ads_search(ads, &res, filter, attrs);
|
ret = ads_search(ads, &res, filter, attrs);
|
||||||
SAFE_FREE(filter);
|
SAFE_FREE(filter);
|
||||||
if (!ADS_ERR_OK(ret) || (ads_count_replies(ads, res) != 1)) {
|
if (!ADS_ERR_OK(ret) || (ads_count_replies(ads, res) != 1)) {
|
||||||
DEBUG(1,("ads_get_kvno: Computer Account For %s not found.\n", machine_name));
|
DEBUG(1,("ads_get_kvno: Account for %s not found.\n", account_name));
|
||||||
ads_msgfree(ads, res);
|
ads_msgfree(ads, res);
|
||||||
return kvno;
|
return kvno;
|
||||||
}
|
}
|
||||||
@@ -1573,6 +1573,28 @@ uint32 ads_get_kvno(ADS_STRUCT *ads, const char *machine_name)
|
|||||||
return kvno;
|
return kvno;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Determines the computer account's current KVNO via an LDAP lookup
|
||||||
|
* @param ads An initialized ADS_STRUCT
|
||||||
|
* @param machine_name the NetBIOS name of the computer, which is used to identify the computer account.
|
||||||
|
* @return the kvno for the computer account, or -1 in case of a failure.
|
||||||
|
**/
|
||||||
|
|
||||||
|
uint32_t ads_get_machine_kvno(ADS_STRUCT *ads, const char *machine_name)
|
||||||
|
{
|
||||||
|
char *computer_account = NULL;
|
||||||
|
uint32_t kvno = -1;
|
||||||
|
|
||||||
|
if (asprintf(&computer_account, "%s$", machine_name) < 0) {
|
||||||
|
return kvno;
|
||||||
|
}
|
||||||
|
|
||||||
|
kvno = ads_get_kvno(ads, computer_account);
|
||||||
|
free(computer_account);
|
||||||
|
|
||||||
|
return kvno;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This clears out all registered spn's for a given hostname
|
* This clears out all registered spn's for a given hostname
|
||||||
* @param ads An initilaized ADS_STRUCT
|
* @param ads An initilaized ADS_STRUCT
|
||||||
|
|||||||
Reference in New Issue
Block a user