/* -*- mode: c; c-basic-offset: 4; indent-tabs-mode: nil -*- */
/*
*
* Copyright 1995, 1999, 2007 by the Massachusetts Institute of Technology.
* All Rights Reserved.
*
* Export of this software from the United States of America may
* require a specific license from the United States Government.
* It is the responsibility of any person or organization contemplating
* export to obtain such a license before exporting.
*
* WITHIN THAT CONSTRAINT, permission to use, copy, modify, and
* distribute this software and its documentation for any purpose and
* without fee is hereby granted, provided that the above copyright
* notice appear in all copies and that both that copyright notice and
* this permission notice appear in supporting documentation, and that
* the name of M.I.T. not be used in advertising or publicity pertaining
* to distribution of the software without specific, written prior
* permission. Furthermore if you modify this software you must label
* your software as modified software and not distribute it in such a
* fashion that it might be confused with the original M.I.T. software.
* M.I.T. makes no representations about the suitability of
* this software for any purpose. It is provided "as is" without express
* or implied warranty.
*
*/
/*
* str_conv.c - Convert between strings and Kerberos internal data.
*/
/*
* Table of contents:
*
* 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.
*
* 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.
*/
#include "k5-int.h"
#include <ctype.h>
/* Salt type conversions */
/*
* Local data structures.
*/
struct salttype_lookup_entry {
};
/*
* Lookup tables.
*/
#include "kdb.h"
/* salt type input specifier output string */
/*----------------------------- --------------- ---------------*/
#if PKINIT_APPLE
#endif /* PKINIT_APPLE */
};
sizeof(salttype_table[0]);
{
int i;
int found;
found = 0;
for (i=0; i<salttype_table_nents; i++) {
found = 1;
break;
}
}
}
/*
* Internal datatype to string routines.
*
* These routines return 0 for success, EINVAL for invalid parameter, ENOMEM
*/
{
int i;
const char *out;
for (i=0; i<salttype_table_nents; i++) {
break;
}
}
if (out) {
return(ENOMEM);
return(0);
}
else
return(EINVAL);
}
/* (absolute) time conversions */
#ifndef HAVE_STRFTIME
#endif
#ifdef HAVE_STRPTIME
#ifdef NEED_STRPTIME_PROTO
extern char *strptime (const char *, const char *,
struct tm *)
#ifdef __cplusplus
throw()
#endif
;
#endif
#else /* HAVE_STRPTIME */
#endif
#ifndef HAVE_LOCALTIME_R
static inline struct tm *
{
return NULL;
return buf;
}
#endif
{
int i;
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 */
};
static const int atime_format_table_nents =
sizeof(atime_format_table)/sizeof(atime_format_table[0]);
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
*/
&& (s != string)) {
/* See if at end of buffer - otherwise partial processing */
while(*s != 0 && isspace((int) *s)) s++;
if (*s != 0)
continue;
continue; /* clearly confused */
continue; /* clearly confused */
return 0;
}
}
return(EINVAL);
}
{
the year returned might be two digits */
#ifdef HAVE_LOCALTIME_R
#else
#endif
return(ENOMEM);
return(0);
}
{
size_t i;
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 */
};
static const unsigned int sftime_format_table_nents =
sizeof(sftime_format_table)/sizeof(sftime_format_table[0]);
#ifdef HAVE_LOCALTIME_R
#else
#endif
ndone = 0;
for (i=0; i<sftime_format_table_nents; i++) {
break;
}
if (!ndone) {
if (buflen >= sftime_default_len) {
}
}
}
}
/* relative time (delta-t) conversions */
/* string->deltat is in deltat.y */
{
/*
* We want something like ceil(log10(2**(nbits-1))) + 1. That log
* value is log10(2)*(nbits-1) or log10(2**8)*(nbits-1)/8. So,
* 2.4... is log10(256), rounded up. Add one to handle leading
* minus, and one more to force int cast to round the value up.
* This doesn't include room for a trailing nul.
*
* This will break if bytes are more than 8 bits.
*/
dt %= 3600;
if (days == 0)
else
return 0;
}
#define __P(X) X
#if !defined (HAVE_STRFTIME) || !defined (HAVE_STRPTIME)
struct dummy_locale_info_t {
};
"%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" },
{ "January", "February", "March", "April", "May", "June",
"July", "August", "September", "October", "November", "December" },
{ "Jan", "Feb", "Mar", "Apr", "May", "Jun",
"Jul", "Aug", "Sep", "Oct", "Nov", "Dec" },
{ "AM", "PM" },
};
#endif
#ifndef HAVE_STRFTIME
#define tzset()
#include "strftime.c"
#endif
#ifndef HAVE_STRPTIME
#include "strptime.c"
#endif