in ad-joining/ksetpwd/ksetpwd.c [165:235]
int main(
/* [IN] */ int argc,
/* [IN] */ char *argv[])
{
int result;
krb5_context context = NULL;
krb5_principal agent_principal = NULL;
krb5_principal target_principal = NULL;
// Parse command line
setlocale(LC_ALL, "");
if (argc < 3)
{
fprintf(stderr, "usage: %s [agent principal] [principal]\n", NAME);
result = 1;
goto cleanup;
}
// Initialize Kerberos.
result = krb5_init_context(&context);
if (result != 0)
{
com_err(NAME, result, "Initializing Kerberos failed");
result = 1;
goto cleanup;
}
// Parse principal names.
result = krb5_parse_name(context, argv[1], &agent_principal);
if (result != 0)
{
com_err(NAME, result, "Parsing agent principal name failed");
result = 1;
goto cleanup;
}
result = krb5_parse_name(context, argv[2], &target_principal);
if (result != 0)
{
com_err(NAME, result, "Parsing target principal name failed");
result = 1;
goto cleanup;
}
fprintf(stderr, "Resetting password for %s\n", argv[2]);
result = reset_password(
context,
agent_principal,
getenv("KSETPWD_AGENT_PASSWORD"),
target_principal,
getenv("KSETPWD_TARGET_PASSWORD"));
cleanup:
if (target_principal != NULL)
{
krb5_free_principal(context, target_principal);
}
if (agent_principal != NULL)
{
krb5_free_principal(context, agent_principal);
}
if (context != NULL)
{
krb5_free_context(context);
}
exit(result);
}