aboutsummaryrefslogtreecommitdiff
path: root/src/kdc/kdc_util.c
diff options
context:
space:
mode:
authorTom Yu <tlyu@mit.edu>2001-06-19 20:32:12 +0000
committerTom Yu <tlyu@mit.edu>2001-06-19 20:32:12 +0000
commit26444a8941bed940c588602eb9371825b2fa58eb (patch)
treecb35c7d89162c12cfd3ec662e44b8b39eb5c0314 /src/kdc/kdc_util.c
parent8e366ad4fec486419e594db80c84b113eba499dd (diff)
downloadkrb5-26444a8941bed940c588602eb9371825b2fa58eb.zip
krb5-26444a8941bed940c588602eb9371825b2fa58eb.tar.gz
krb5-26444a8941bed940c588602eb9371825b2fa58eb.tar.bz2
* kdc_util.c (ktypes2str): New function; construct a string
containing a list of enctypes, given a number and list of enctypes. (rep_etypes2str): New function; construct a string indicating all three enctypes associated with a KDC reply. * kdc_util.h: Add prototypes for ktypes2str() and rep_etypes2str(). * do_as_req.c (process_as_req): Call ktypes2str() and rep_etypes2str() as appropriate. * do_tgs_req.c (process_tgs_req): Call ktypes2str() and rep_etypes2str() as appropriate. git-svn-id: svn://anonsvn.mit.edu/krb5/trunk@13389 dc483132-0cff-0310-8789-dd5450dbe970
Diffstat (limited to 'src/kdc/kdc_util.c')
-rw-r--r--src/kdc/kdc_util.c66
1 files changed, 66 insertions, 0 deletions
diff --git a/src/kdc/kdc_util.c b/src/kdc/kdc_util.c
index 6d25764..f1bf943 100644
--- a/src/kdc/kdc_util.c
+++ b/src/kdc/kdc_util.c
@@ -31,6 +31,7 @@
#include "kdc_util.h"
#include "extern.h"
#include <stdio.h>
+#include <ctype.h>
#include <syslog.h>
#include "adm.h"
#include "adm_proto.h"
@@ -1537,3 +1538,68 @@ void limit_string(char *name)
name[i] = '\0';
return;
}
+
+/*
+ * L10_256 = log10(256**x), rounded up.
+ */
+#define L10_256(x) ((int)((x) * 2.41 + 0.5))
+
+void
+ktypes2str(char *s, size_t len, int nktypes, krb5_enctype *ktype)
+{
+ int i;
+ char stmp[L10_256(sizeof(krb5_enctype)) + 3];
+
+ if (nktypes < 0
+ || len < sizeof(" etypes {}") + L10_256(sizeof(krb5_enctype)))
+ return;
+
+ sprintf(s, "%d etypes {", nktypes);
+ for (i = 0; i < nktypes; i++) {
+ sprintf(stmp, "%s%d", i ? " " : "", ktype[i]);
+ if (strlen(s) + strlen(stmp) + 2 > len)
+ break;
+ strcat(s, stmp);
+ }
+ if (i < nktypes) {
+ /*
+ * We broke out of the loop. Try to truncate the list.
+ */
+ for (i = strlen(s); i > 0; i--) {
+ if (!isdigit((int)s[i]) && len - i > sizeof("...}")) {
+ s[i] = '\0';
+ strcat(s, "...");
+ break;
+ }
+ }
+ }
+ strcat(s, "}");
+ return;
+}
+
+void
+rep_etypes2str(char *s, size_t len, krb5_kdc_rep *rep)
+{
+ char stmp[sizeof("skey=") + L10_256(sizeof(krb5_enctype)) + 1];
+
+ if (len < (3 * (L10_256(sizeof(krb5_enctype)) + 3)
+ + sizeof("etypes {rep= tkt= skey=}")))
+ return;
+
+ sprintf(s, "etypes {rep=%ld", (long)rep->enc_part.enctype);
+
+ if (rep->ticket != NULL) {
+ sprintf(stmp, " tkt=%ld", (long)rep->ticket->enc_part.enctype);
+ strcat(s, stmp);
+ }
+
+ if (rep->ticket != NULL
+ && rep->ticket->enc_part2 != NULL
+ && rep->ticket->enc_part2->session != NULL) {
+ sprintf(stmp, " skey=%ld",
+ (long)rep->ticket->enc_part2->session->enctype);
+ strcat(s, stmp);
+ }
+ strcat(s, "}");
+ return;
+}