-NTSTATUS cli_credentials_update_all_keytabs(TALLOC_CTX *parent_ctx)
-{
- TALLOC_CTX *mem_ctx;
- int ldb_ret;
- struct ldb_context *ldb;
- struct ldb_message **msgs;
- const char *attrs[] = { NULL };
- struct cli_credentials *creds;
- const char *filter;
- NTSTATUS status;
- int i, ret;
-
- mem_ctx = talloc_new(parent_ctx);
- if (!mem_ctx) {
- return NT_STATUS_NO_MEMORY;
- }
-
- /* Local secrets are stored in secrets.ldb */
- ldb = secrets_db_connect(mem_ctx);
- if (!ldb) {
- DEBUG(1, ("Could not open secrets.ldb\n"));
- talloc_free(mem_ctx);
- return NT_STATUS_ACCESS_DENIED;
- }
-
- /* search for the secret record, but only of things we can
- * actually update */
- ldb_ret = gendb_search(ldb,
- mem_ctx, NULL,
- &msgs, attrs,
- "(&(objectClass=kerberosSecret)(|(secret=*)(ntPwdHash=*)))");
- if (ldb_ret == -1) {
- DEBUG(1, ("Error looking for kerberos type secrets to push into a keytab:: %s", ldb_errstring(ldb)));
- talloc_free(mem_ctx);
- return NT_STATUS_INTERNAL_DB_CORRUPTION;
- }
-
- for (i=0; i < ldb_ret; i++) {
- /* Make a credentials structure from it */
- creds = cli_credentials_init(mem_ctx);
- if (!creds) {
- DEBUG(1, ("cli_credentials_init failed!"));
- talloc_free(mem_ctx);
- return NT_STATUS_NO_MEMORY;
- }
- cli_credentials_set_conf(creds);
- filter = talloc_asprintf(mem_ctx, "dn=%s", ldb_dn_get_linearized(msgs[i]->dn));
- status = cli_credentials_set_secrets(creds, NULL, filter);
- if (!NT_STATUS_IS_OK(status)) {
- DEBUG(1, ("Failed to read secrets for keytab update for %s\n",
- filter));
- continue;
- }
- ret = cli_credentials_update_keytab(creds);
- if (ret != 0) {
- DEBUG(1, ("Failed to update keytab for %s\n",
- filter));
- continue;
- }
- }
- return NT_STATUS_OK;
-}
-