msktconf.cpp (msktutil-1.1.tar.bz2) | : | msktconf.cpp (msktutil-1.2.1) | ||
---|---|---|---|---|
skipping to change at line 151 | skipping to change at line 151 | |||
if (ret) { | if (ret) { | |||
error_exit("setenv failed"); | error_exit("setenv failed"); | |||
} | } | |||
#else | #else | |||
int ret = putenv(strdup((std::string("KRB5_CONFIG=") + g_config_filename).c _str())); | int ret = putenv(strdup((std::string("KRB5_CONFIG=") + g_config_filename).c _str())); | |||
if (ret) { | if (ret) { | |||
error_exit("putenv failed"); | error_exit("putenv failed"); | |||
} | } | |||
#endif | #endif | |||
VERBOSE("Created a fake krb5.conf file: %s", g_config_filename.c_str()); | VERBOSE("Created fake krb5.conf file: %s", g_config_filename.c_str()); | |||
destroy_g_context(); | destroy_g_context(); | |||
initialize_g_context(); | initialize_g_context(); | |||
} | } | |||
void remove_fake_krb5_conf() | void remove_fake_krb5_conf() | |||
{ | { | |||
if (!g_config_filename.empty()) { | if (!g_config_filename.empty()) { | |||
unlink(g_config_filename.c_str()); | unlink(g_config_filename.c_str()); | |||
g_config_filename.clear(); | g_config_filename.clear(); | |||
skipping to change at line 198 | skipping to change at line 198 | |||
} | } | |||
#endif | #endif | |||
krb5_cc_set_default_name(g_context, ccache_name); | krb5_cc_set_default_name(g_context, ccache_name); | |||
} | } | |||
bool try_machine_keytab_princ(msktutil_flags *flags, | bool try_machine_keytab_princ(msktutil_flags *flags, | |||
const std::string &principal_name, | const std::string &principal_name, | |||
const char *ccache_name) | const char *ccache_name) | |||
{ | { | |||
try { | try { | |||
VERBOSE("Trying to authenticate for %s from local keytab", | VERBOSE("Trying to authenticate %s from local keytab", | |||
principal_name.c_str()); | principal_name.c_str()); | |||
KRB5Keytab keytab(flags->keytab_readname); | KRB5Keytab keytab(flags->keytab_readname); | |||
KRB5Principal principal(principal_name); | KRB5Principal principal(principal_name); | |||
KRB5Creds creds(principal, keytab); | KRB5Creds creds(principal, keytab); | |||
KRB5CCache ccache(ccache_name); | KRB5CCache ccache(ccache_name); | |||
ccache.initialize(principal); | ccache.initialize(principal); | |||
ccache.store(creds); | ccache.store(creds); | |||
switch_default_ccache(ccache_name); | switch_default_ccache(ccache_name); | |||
return true; | return true; | |||
} catch (KRB5Exception &e) { | } catch (KRB5Exception &e) { | |||
VERBOSE("%s", e.what()); | VERBOSE("%s", e.what()); | |||
VERBOSE("Authentication with keytab failed"); | VERBOSE("Authentication with keytab failed"); | |||
return false; | return false; | |||
} | } | |||
} | } | |||
bool try_machine_password(msktutil_flags *flags, const char *ccache_name) | bool try_machine_password(msktutil_flags *flags, const char *ccache_name) | |||
{ | { | |||
try { | try { | |||
VERBOSE("Trying to authenticate for %s with password", | VERBOSE("Trying to authenticate %s with password", | |||
flags->sAMAccountName.c_str()); | flags->sAMAccountName.c_str()); | |||
KRB5Principal principal(flags->sAMAccountName); | KRB5Principal principal(flags->sAMAccountName); | |||
KRB5Creds creds(principal, | KRB5Creds creds(principal, | |||
/*password:*/ | /*password:*/ | |||
create_default_machine_password(flags->sAMAccountName)); | create_default_machine_password(flags->sAMAccountName)); | |||
KRB5CCache ccache(ccache_name); | KRB5CCache ccache(ccache_name); | |||
ccache.initialize(principal); | ccache.initialize(principal); | |||
ccache.store(creds); | ccache.store(creds); | |||
switch_default_ccache(ccache_name); | switch_default_ccache(ccache_name); | |||
return true; | return true; | |||
skipping to change at line 240 | skipping to change at line 240 | |||
VERBOSE("%s", e.what()); | VERBOSE("%s", e.what()); | |||
VERBOSE("Authentication with password failed"); | VERBOSE("Authentication with password failed"); | |||
return false; | return false; | |||
} | } | |||
} | } | |||
bool try_machine_supplied_password(msktutil_flags *flags, | bool try_machine_supplied_password(msktutil_flags *flags, | |||
const char *ccache_name) | const char *ccache_name) | |||
{ | { | |||
try { | try { | |||
VERBOSE("Trying to authenticate for %s with supplied password", | VERBOSE("Trying to authenticate %s with supplied password", | |||
flags->sAMAccountName.c_str()); | flags->sAMAccountName.c_str()); | |||
KRB5Principal principal(flags->sAMAccountName); | KRB5Principal principal(flags->sAMAccountName); | |||
KRB5Creds creds(principal, /*password:*/ flags->old_account_password); | KRB5Creds creds(principal, /*password:*/ flags->old_account_password); | |||
KRB5CCache ccache(ccache_name); | KRB5CCache ccache(ccache_name); | |||
ccache.initialize(principal); | ccache.initialize(principal); | |||
ccache.store(creds); | ccache.store(creds); | |||
switch_default_ccache(ccache_name); | switch_default_ccache(ccache_name); | |||
return true; | return true; | |||
} catch (KRB5Exception &e) { | } catch (KRB5Exception &e) { | |||
VERBOSE("%s", e.what()); | VERBOSE("%s", e.what()); | |||
skipping to change at line 293 | skipping to change at line 293 | |||
try { | try { | |||
VERBOSE("Checking if default ticket cache has tickets"); | VERBOSE("Checking if default ticket cache has tickets"); | |||
/* The following is for the side effect of throwing an | /* The following is for the side effect of throwing an | |||
* exception or not. */ | * exception or not. */ | |||
KRB5CCache ccache(KRB5CCache::defaultName()); | KRB5CCache ccache(KRB5CCache::defaultName()); | |||
KRB5Principal princ(ccache); | KRB5Principal princ(ccache); | |||
return true; | return true; | |||
} catch(KRB5Exception &e) { | } catch(KRB5Exception &e) { | |||
VERBOSE("%s", e.what()); | VERBOSE("%s", e.what()); | |||
VERBOSE("User ticket cache was not valid"); | VERBOSE("Default ticket cache was not valid"); | |||
return false; | return false; | |||
} | } | |||
} | } | |||
int find_working_creds(msktutil_flags *flags) | int find_working_creds(msktutil_flags *flags) | |||
{ | { | |||
/* We try some different ways, in order: | /* We try some different ways, in order: | |||
* 1) Use principal from keytab. Try both: | * 1) Use principal from keytab. Try both: | |||
* a) sAMAccountName | * a) sAMAccountName | |||
* b) host/full-hostname (for compat with older msktutil which | * b) host/full-hostname (for compat with older msktutil which | |||
End of changes. 5 change blocks. | ||||
5 lines changed or deleted | 5 lines changed or added |