int edit_deltat (const char *prompt, krb5_deltat *value, int *mask, int bit) { char buf[1024], resp[1024]; if (mask && (*mask & bit)) return 0; deltat2str(*value, buf, sizeof(buf)); for (;;) { if(get_response(prompt, buf, resp, sizeof(resp)) != 0) return 1; if (parse_deltat (resp, value, mask, bit) == 0) break; } return 0; }
static void format_field(kadm5_principal_ent_t princ, unsigned int field, unsigned int subfield, char *buf, size_t buf_len, int condensed) { switch(field) { case KADM5_PRINCIPAL: if(condensed) krb5_unparse_name_fixed_short(context, princ->principal, buf, buf_len); else krb5_unparse_name_fixed(context, princ->principal, buf, buf_len); break; case KADM5_PRINC_EXPIRE_TIME: time_t2str(princ->princ_expire_time, buf, buf_len, !condensed); break; case KADM5_PW_EXPIRATION: time_t2str(princ->pw_expiration, buf, buf_len, !condensed); break; case KADM5_LAST_PWD_CHANGE: time_t2str(princ->last_pwd_change, buf, buf_len, !condensed); break; case KADM5_MAX_LIFE: deltat2str(princ->max_life, buf, buf_len); break; case KADM5_MAX_RLIFE: deltat2str(princ->max_renewable_life, buf, buf_len); break; case KADM5_MOD_TIME: time_t2str(princ->mod_date, buf, buf_len, !condensed); break; case KADM5_MOD_NAME: if (princ->mod_name == NULL) strlcpy(buf, "unknown", buf_len); else if(condensed) krb5_unparse_name_fixed_short(context, princ->mod_name, buf, buf_len); else krb5_unparse_name_fixed(context, princ->mod_name, buf, buf_len); break; case KADM5_ATTRIBUTES: attributes2str (princ->attributes, buf, buf_len); break; case KADM5_KVNO: snprintf(buf, buf_len, "%d", princ->kvno); break; case KADM5_MKVNO: /* XXX libkadm5srv decrypts the keys, so mkvno is always 0. */ strlcpy(buf, "unknown", buf_len); break; case KADM5_LAST_SUCCESS: time_t2str(princ->last_success, buf, buf_len, !condensed); break; case KADM5_LAST_FAILED: time_t2str(princ->last_failed, buf, buf_len, !condensed); break; case KADM5_FAIL_AUTH_COUNT: snprintf(buf, buf_len, "%d", princ->fail_auth_count); break; case KADM5_POLICY: if(princ->policy != NULL) strlcpy(buf, princ->policy, buf_len); else strlcpy(buf, "none", buf_len); break; case KADM5_KEY_DATA:{ krb5_salt def_salt; int i; char buf2[1024]; krb5_get_pw_salt (context, princ->principal, &def_salt); *buf = '\0'; for (i = 0; i < princ->n_key_data; ++i) { format_keytype(&princ->key_data[i], &def_salt, buf2, sizeof(buf2)); if(i > 0) strlcat(buf, ", ", buf_len); strlcat(buf, buf2, buf_len); } krb5_free_salt (context, def_salt); break; } case KADM5_TL_DATA: { krb5_tl_data *tl; for (tl = princ->tl_data; tl != NULL; tl = tl->tl_data_next) if ((unsigned)tl->tl_data_type == subfield) break; if (tl == NULL) { strlcpy(buf, "", buf_len); break; } switch (subfield) { case KRB5_TL_PASSWORD: snprintf(buf, buf_len, "\"%.*s\"", (int)tl->tl_data_length, (const char *)tl->tl_data_contents); break; case KRB5_TL_PKINIT_ACL: { HDB_Ext_PKINIT_acl acl; size_t size; int ret; size_t i; ret = decode_HDB_Ext_PKINIT_acl(tl->tl_data_contents, tl->tl_data_length, &acl, &size); if (ret) { snprintf(buf, buf_len, "failed to decode ACL"); break; } buf[0] = '\0'; for (i = 0; i < acl.len; i++) { strlcat(buf, "subject: ", buf_len); strlcat(buf, acl.val[i].subject, buf_len); if (acl.val[i].issuer) { strlcat(buf, " issuer:", buf_len); strlcat(buf, *acl.val[i].issuer, buf_len); } if (acl.val[i].anchor) { strlcat(buf, " anchor:", buf_len); strlcat(buf, *acl.val[i].anchor, buf_len); } if (i + 1 < acl.len) strlcat(buf, ", ", buf_len); } free_HDB_Ext_PKINIT_acl(&acl); break; } case KRB5_TL_ALIASES: { HDB_Ext_Aliases alias; size_t size; int ret; size_t i; ret = decode_HDB_Ext_Aliases(tl->tl_data_contents, tl->tl_data_length, &alias, &size); if (ret) { snprintf(buf, buf_len, "failed to decode alias"); break; } buf[0] = '\0'; for (i = 0; i < alias.aliases.len; i++) { char *p; ret = krb5_unparse_name(context, &alias.aliases.val[i], &p); if (ret) break; if (i > 0) strlcat(buf, " ", buf_len); strlcat(buf, p, buf_len); free(p); } free_HDB_Ext_Aliases(&alias); break; } default: snprintf(buf, buf_len, "unknown type %d", subfield); break; } break; } default: strlcpy(buf, "<unknown>", buf_len); break; } }