summaryrefslogtreecommitdiffstats
path: root/src/lib/krb5/krb/str_conv.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/krb5/krb/str_conv.c')
-rw-r--r--src/lib/krb5/krb/str_conv.c219
1 files changed, 110 insertions, 109 deletions
diff --git a/src/lib/krb5/krb/str_conv.c b/src/lib/krb5/krb/str_conv.c
index 531eba1264..1f2edcc66f 100644
--- a/src/lib/krb5/krb/str_conv.c
+++ b/src/lib/krb5/krb/str_conv.c
@@ -1,3 +1,4 @@
+/* -*- mode: c; c-basic-offset: 4; indent-tabs-mode: nil -*- */
/*
* lib/kadm/str_conv.c
*
@@ -34,16 +35,16 @@
*
* String decoding:
* ----------------
- * krb5_string_to_salttype() - Convert string to salttype (krb5_int32)
- * krb5_string_to_timestamp() - Convert string to krb5_timestamp.
- * krb5_string_to_deltat() - Convert string to krb5_deltat.
+ * krb5_string_to_salttype() - Convert string to salttype (krb5_int32)
+ * krb5_string_to_timestamp() - Convert string to krb5_timestamp.
+ * krb5_string_to_deltat() - Convert string to krb5_deltat.
*
* String encoding:
* ----------------
- * krb5_salttype_to_string() - Convert salttype (krb5_int32) to string.
- * krb5_timestamp_to_string() - Convert krb5_timestamp to string.
- * krb5_timestamp_to_sfstring() - Convert krb5_timestamp to short filled string
- * krb5_deltat_to_string() - Convert krb5_deltat to string.
+ * krb5_salttype_to_string() - Convert salttype (krb5_int32) to string.
+ * krb5_timestamp_to_string() - Convert krb5_timestamp to string.
+ * krb5_timestamp_to_sfstring() - Convert krb5_timestamp to short filled string
+ * krb5_deltat_to_string() - Convert krb5_deltat to string.
*/
#include "k5-int.h"
@@ -55,9 +56,9 @@
* Local data structures.
*/
struct salttype_lookup_entry {
- krb5_int32 stt_enctype; /* Salt type */
- const char * stt_specifier; /* How to recognize it */
- const char * stt_output; /* How to spit it out */
+ krb5_int32 stt_enctype; /* Salt type */
+ const char * stt_specifier; /* How to recognize it */
+ const char * stt_output; /* How to spit it out */
};
/*
@@ -66,20 +67,20 @@ struct salttype_lookup_entry {
#include "kdb.h"
static const struct salttype_lookup_entry salttype_table[] = {
-/* salt type input specifier output string */
-/*----------------------------- --------------- ---------------*/
-{ KRB5_KDB_SALTTYPE_NORMAL, "normal", "Version 5" },
-{ KRB5_KDB_SALTTYPE_V4, "v4", "Version 4" },
-{ KRB5_KDB_SALTTYPE_NOREALM, "norealm", "Version 5 - No Realm" },
-{ KRB5_KDB_SALTTYPE_ONLYREALM, "onlyrealm", "Version 5 - Realm Only" },
-{ KRB5_KDB_SALTTYPE_SPECIAL, "special", "Special" },
-{ KRB5_KDB_SALTTYPE_AFS3, "afs3", "AFS version 3" },
+/* salt type input specifier output string */
+/*----------------------------- --------------- ---------------*/
+ { KRB5_KDB_SALTTYPE_NORMAL, "normal", "Version 5" },
+ { KRB5_KDB_SALTTYPE_V4, "v4", "Version 4" },
+ { KRB5_KDB_SALTTYPE_NOREALM, "norealm", "Version 5 - No Realm" },
+ { KRB5_KDB_SALTTYPE_ONLYREALM, "onlyrealm", "Version 5 - Realm Only" },
+ { KRB5_KDB_SALTTYPE_SPECIAL, "special", "Special" },
+ { KRB5_KDB_SALTTYPE_AFS3, "afs3", "AFS version 3" },
#if PKINIT_APPLE
-{ KRB5_KDB_SALTTYPE_CERTHASH, "certhash", "PKINIT Cert Hash" }
+ { KRB5_KDB_SALTTYPE_CERTHASH, "certhash", "PKINIT Cert Hash" }
#endif /* PKINIT_APPLE */
};
static const int salttype_table_nents = sizeof(salttype_table)/
- sizeof(salttype_table[0]);
+ sizeof(salttype_table[0]);
krb5_error_code KRB5_CALLCONV
krb5_string_to_salttype(char *string, krb5_int32 *salttypep)
@@ -89,11 +90,11 @@ krb5_string_to_salttype(char *string, krb5_int32 *salttypep)
found = 0;
for (i=0; i<salttype_table_nents; i++) {
- if (!strcasecmp(string, salttype_table[i].stt_specifier)) {
- found = 1;
- *salttypep = salttype_table[i].stt_enctype;
- break;
- }
+ if (!strcasecmp(string, salttype_table[i].stt_specifier)) {
+ found = 1;
+ *salttypep = salttype_table[i].stt_enctype;
+ break;
+ }
}
return((found) ? 0 : EINVAL);
}
@@ -112,18 +113,18 @@ krb5_salttype_to_string(krb5_int32 salttype, char *buffer, size_t buflen)
out = (char *) NULL;
for (i=0; i<salttype_table_nents; i++) {
- if (salttype == salttype_table[i].stt_enctype) {
- out = salttype_table[i].stt_output;
- break;
- }
+ if (salttype == salttype_table[i].stt_enctype) {
+ out = salttype_table[i].stt_output;
+ break;
+ }
}
if (out) {
- if (strlcpy(buffer, out, buflen) >= buflen)
- return(ENOMEM);
- return(0);
+ if (strlcpy(buffer, out, buflen) >= buflen)
+ return(ENOMEM);
+ return(0);
}
else
- return(EINVAL);
+ return(EINVAL);
}
/* (absolute) time conversions */
@@ -137,7 +138,7 @@ static size_t strftime (char *, size_t, const char *, const struct tm *);
#ifdef HAVE_STRPTIME
#ifdef NEED_STRPTIME_PROTO
extern char *strptime (const char *, const char *,
- struct tm *)
+ struct tm *)
#ifdef __cplusplus
throw()
#endif
@@ -155,7 +156,7 @@ localtime_r(const time_t *t, struct tm *buf)
{
struct tm *tm = localtime(t);
if (tm == NULL)
- return NULL;
+ return NULL;
*buf = *tm;
return buf;
}
@@ -169,47 +170,47 @@ krb5_string_to_timestamp(char *string, krb5_timestamp *timestampp)
time_t now, ret_time;
char *s;
static const char * const atime_format_table[] = {
- "%Y%m%d%H%M%S", /* yyyymmddhhmmss */
- "%Y.%m.%d.%H.%M.%S", /* yyyy.mm.dd.hh.mm.ss */
- "%y%m%d%H%M%S", /* yymmddhhmmss */
- "%y.%m.%d.%H.%M.%S", /* yy.mm.dd.hh.mm.ss */
- "%y%m%d%H%M", /* yymmddhhmm */
- "%H%M%S", /* hhmmss */
- "%H%M", /* hhmm */
- "%T", /* hh:mm:ss */
- "%R", /* hh:mm */
- /* The following not really supported unless native strptime present */
- "%x:%X", /* locale-dependent short format */
- "%d-%b-%Y:%T", /* dd-month-yyyy:hh:mm:ss */
- "%d-%b-%Y:%R" /* dd-month-yyyy:hh:mm */
+ "%Y%m%d%H%M%S", /* yyyymmddhhmmss */
+ "%Y.%m.%d.%H.%M.%S", /* yyyy.mm.dd.hh.mm.ss */
+ "%y%m%d%H%M%S", /* yymmddhhmmss */
+ "%y.%m.%d.%H.%M.%S", /* yy.mm.dd.hh.mm.ss */
+ "%y%m%d%H%M", /* yymmddhhmm */
+ "%H%M%S", /* hhmmss */
+ "%H%M", /* hhmm */
+ "%T", /* hh:mm:ss */
+ "%R", /* hh:mm */
+ /* The following not really supported unless native strptime present */
+ "%x:%X", /* locale-dependent short format */
+ "%d-%b-%Y:%T", /* dd-month-yyyy:hh:mm:ss */
+ "%d-%b-%Y:%R" /* dd-month-yyyy:hh:mm */
};
static const int atime_format_table_nents =
- sizeof(atime_format_table)/sizeof(atime_format_table[0]);
+ sizeof(atime_format_table)/sizeof(atime_format_table[0]);
now = time((time_t *) NULL);
if (localtime_r(&now, &timebuf2) == NULL)
- return EINVAL;
+ return EINVAL;
for (i=0; i<atime_format_table_nents; i++) {
/* We reset every time throughout the loop as the manual page
- * indicated that no guarantees are made as to preserving timebuf
- * when parsing fails
- */
- timebuf = timebuf2;
- if ((s = strptime(string, atime_format_table[i], &timebuf))
- && (s != string)) {
- /* See if at end of buffer - otherwise partial processing */
- while(*s != 0 && isspace((int) *s)) s++;
- if (*s != 0)
- continue;
- if (timebuf.tm_year <= 0)
- continue; /* clearly confused */
- ret_time = mktime(&timebuf);
- if (ret_time == (time_t) -1)
- continue; /* clearly confused */
- *timestampp = (krb5_timestamp) ret_time;
- return 0;
- }
+ * indicated that no guarantees are made as to preserving timebuf
+ * when parsing fails
+ */
+ timebuf = timebuf2;
+ if ((s = strptime(string, atime_format_table[i], &timebuf))
+ && (s != string)) {
+ /* See if at end of buffer - otherwise partial processing */
+ while(*s != 0 && isspace((int) *s)) s++;
+ if (*s != 0)
+ continue;
+ if (timebuf.tm_year <= 0)
+ continue; /* clearly confused */
+ ret_time = mktime(&timebuf);
+ if (ret_time == (time_t) -1)
+ continue; /* clearly confused */
+ *timestampp = (krb5_timestamp) ret_time;
+ return 0;
+ }
}
return(EINVAL);
}
@@ -220,8 +221,8 @@ krb5_timestamp_to_string(krb5_timestamp timestamp, char *buffer, size_t buflen)
size_t ret;
time_t timestamp2 = timestamp;
struct tm tmbuf;
- const char *fmt = "%c"; /* This is to get around gcc -Wall warning that
- the year returned might be two digits */
+ const char *fmt = "%c"; /* This is to get around gcc -Wall warning that
+ the year returned might be two digits */
#ifdef HAVE_LOCALTIME_R
(void) localtime_r(&timestamp2, &tmbuf);
@@ -230,27 +231,27 @@ krb5_timestamp_to_string(krb5_timestamp timestamp, char *buffer, size_t buflen)
#endif
ret = strftime(buffer, buflen, fmt, &tmbuf);
if (ret == 0 || ret == buflen)
- return(ENOMEM);
+ return(ENOMEM);
return(0);
}
krb5_error_code KRB5_CALLCONV
krb5_timestamp_to_sfstring(krb5_timestamp timestamp, char *buffer, size_t buflen, char *pad)
{
- struct tm *tmp;
+ struct tm *tmp;
size_t i;
- size_t ndone;
+ size_t ndone;
time_t timestamp2 = timestamp;
struct tm tmbuf;
static const char * const sftime_format_table[] = {
- "%c", /* Default locale-dependent date and time */
- "%d %b %Y %T", /* dd mon yyyy hh:mm:ss */
- "%x %X", /* locale-dependent short format */
- "%d/%m/%Y %R" /* dd/mm/yyyy hh:mm */
+ "%c", /* Default locale-dependent date and time */
+ "%d %b %Y %T", /* dd mon yyyy hh:mm:ss */
+ "%x %X", /* locale-dependent short format */
+ "%d/%m/%Y %R" /* dd/mm/yyyy hh:mm */
};
static const unsigned int sftime_format_table_nents =
- sizeof(sftime_format_table)/sizeof(sftime_format_table[0]);
+ sizeof(sftime_format_table)/sizeof(sftime_format_table[0]);
#ifdef HAVE_LOCALTIME_R
tmp = localtime_r(&timestamp2, &tmbuf);
@@ -259,22 +260,22 @@ krb5_timestamp_to_sfstring(krb5_timestamp timestamp, char *buffer, size_t buflen
#endif
ndone = 0;
for (i=0; i<sftime_format_table_nents; i++) {
- if ((ndone = strftime(buffer, buflen, sftime_format_table[i], tmp)))
- break;
+ if ((ndone = strftime(buffer, buflen, sftime_format_table[i], tmp)))
+ break;
}
if (!ndone) {
-#define sftime_default_len 2+1+2+1+4+1+2+1+2+1
- if (buflen >= sftime_default_len) {
- snprintf(buffer, buflen, "%02d/%02d/%4d %02d:%02d",
- tmp->tm_mday, tmp->tm_mon+1, 1900+tmp->tm_year,
- tmp->tm_hour, tmp->tm_min);
- ndone = strlen(buffer);
- }
+#define sftime_default_len 2+1+2+1+4+1+2+1+2+1
+ if (buflen >= sftime_default_len) {
+ snprintf(buffer, buflen, "%02d/%02d/%4d %02d:%02d",
+ tmp->tm_mday, tmp->tm_mon+1, 1900+tmp->tm_year,
+ tmp->tm_hour, tmp->tm_min);
+ ndone = strlen(buffer);
+ }
}
if (ndone && pad) {
- for (i=ndone; i<buflen-1; i++)
- buffer[i] = *pad;
- buffer[buflen-1] = '\0';
+ for (i=ndone; i<buflen-1; i++)
+ buffer[i] = *pad;
+ buffer[buflen-1] = '\0';
}
return((ndone) ? 0 : ENOMEM);
}
@@ -286,8 +287,8 @@ krb5_timestamp_to_sfstring(krb5_timestamp timestamp, char *buffer, size_t buflen
krb5_error_code KRB5_CALLCONV
krb5_deltat_to_string(krb5_deltat deltat, char *buffer, size_t buflen)
{
- int days, hours, minutes, seconds;
- krb5_deltat dt;
+ int days, hours, minutes, seconds;
+ krb5_deltat dt;
/*
* We want something like ceil(log10(2**(nbits-1))) + 1. That log
@@ -298,7 +299,7 @@ krb5_deltat_to_string(krb5_deltat deltat, char *buffer, size_t buflen)
*
* This will break if bytes are more than 8 bits.
*/
-#define MAX_CHARS_FOR_INT_TYPE(TYPE) ((int) (2 + 2.408241 * sizeof (TYPE)))
+#define MAX_CHARS_FOR_INT_TYPE(TYPE) ((int) (2 + 2.408241 * sizeof (TYPE)))
char tmpbuf[MAX_CHARS_FOR_INT_TYPE(int) * 4 + 8];
days = (int) (deltat / (24*3600L));
@@ -310,22 +311,22 @@ krb5_deltat_to_string(krb5_deltat deltat, char *buffer, size_t buflen)
memset (tmpbuf, 0, sizeof (tmpbuf));
if (days == 0)
- snprintf(buffer, buflen, "%d:%02d:%02d", hours, minutes, seconds);
+ snprintf(buffer, buflen, "%d:%02d:%02d", hours, minutes, seconds);
else if (hours || minutes || seconds)
- snprintf(buffer, buflen, "%d %s %02d:%02d:%02d", days,
- (days > 1) ? "days" : "day",
- hours, minutes, seconds);
+ snprintf(buffer, buflen, "%d %s %02d:%02d:%02d", days,
+ (days > 1) ? "days" : "day",
+ hours, minutes, seconds);
else
- snprintf(buffer, buflen, "%d %s", days,
- (days > 1) ? "days" : "day");
+ snprintf(buffer, buflen, "%d %s", days,
+ (days > 1) ? "days" : "day");
if (tmpbuf[sizeof(tmpbuf)-1] != 0)
- /* Something must be very wrong with my math above, or the
- assumptions going into it... */
- abort ();
+ /* Something must be very wrong with my math above, or the
+ assumptions going into it... */
+ abort ();
if (strlen (tmpbuf) > buflen)
- return ENOMEM;
+ return ENOMEM;
else
- strncpy (buffer, tmpbuf, buflen);
+ strncpy (buffer, tmpbuf, buflen);
return 0;
}
@@ -348,10 +349,10 @@ struct dummy_locale_info_t {
char am_pm[2][3];
};
static const struct dummy_locale_info_t dummy_locale_info = {
- "%a %b %d %X %Y", /* %c */
- "%I:%M:%S %p", /* %r */
- "%H:%M:%S", /* %X */
- "%m/%d/%y", /* %x */
+ "%a %b %d %X %Y", /* %c */
+ "%I:%M:%S %p", /* %r */
+ "%H:%M:%S", /* %X */
+ "%m/%d/%y", /* %x */
{ "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday",
"Saturday" },
{ "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat" },
@@ -373,7 +374,7 @@ static const struct dummy_locale_info_t dummy_locale_info = {
#undef DAYSPERWEEK
#define DAYSPERWEEK 7
#undef isleap
-#define isleap(N) ((N % 4) == 0 && (N % 100 != 0 || N % 400 == 0))
+#define isleap(N) ((N % 4) == 0 && (N % 100 != 0 || N % 400 == 0))
#undef tzname
#define tzname my_tzname
static const char *const tzname[2] = { 0, 0 };