#include <ctype.h>
#include <stdlib.h>
#include <string.h>
+#include <k5-buf.h>
#include "ftpd_var.h"
if (s == 0) {
register int i, j, w;
int columns, lines;
+ struct k5buf buf;
lreply(214, "The following %scommands are recognized %s.",
ftype, "(* =>'s unimplemented)");
columns = 1;
lines = (NCMDS + columns - 1) / columns;
for (i = 0; i < lines; i++) {
- strcpy(str, " ");
+ krb5int_buf_init_fixed(&buf, str, sizeof(str));
+ krb5int_buf_add(&buf, " ");
for (j = 0; j < columns; j++) {
c = ctab + j * lines + i;
- sprintf(&str[strlen(str)], "%s%c", c->name,
- c->implemented ? ' ' : '*');
+ krb5int_buf_add_fmt(&buf, "%s%c", c->name,
+ c->implemented ? ' '
+ : '*');
if (c + lines >= &ctab[NCMDS])
break;
w = strlen(c->name) + 1;
while (w < width) {
- strcat(str, " ");
+ krb5int_buf_add(&buf, " ");
w++;
}
}
int i = 0;
krb5_boolean retbool= FALSE;
int j =0;
- char * err;
- unsigned int max_ln=0;
- unsigned int tln=0;
+ struct k5buf buf;
while(fcmd_arr[i]){
- tln = strlen(fcmd_arr[i]);
- if ( tln > max_ln) max_ln = tln;
if (!stat (fcmd_arr[i], &st_temp )){
*cmd_out = xstrdup(fcmd_arr[i]);
retbool = TRUE;
}
if (retbool == FALSE ){
- err = (char *) xcalloc((80 + (max_ln+2)*i) ,sizeof(char));
- strcpy(err,"Error: not found -> ");
- for(j= 0; j < i; j ++){
- strcat(err, " ");
- strcat(err, fcmd_arr[j]);
- strcat(err, " ");
+ krb5int_buf_init_dynamic(&buf);
+ krb5int_buf_add(&buf, "Error: not found -> ");
+ for(j= 0; j < i; j ++)
+ krb5int_buf_add_fmt(&buf, " %s ", fcmd_arr[j]);
+ krb5int_buf_add(&buf, "\n");
+ *err_out = krb5int_buf_cstr(&buf);
+ if (*err_out == NULL) {
+ perror(prog_name);
+ exit(1);
}
- strcat(err, "\n");
- *err_out = err;
}
krb5_error_code err;
int i, j;
int lose = 0;
+ struct k5buf buf;
/* RFC 2202 test vector. */
static const struct hmac_test md5tests[] = {
exit(1);
}
- if (sizeof(stroutbuf) - 3 < 2 * out.length)
- abort();
- strcpy(stroutbuf, "0x");
+ krb5int_buf_init_fixed(&buf, stroutbuf, sizeof(stroutbuf));
+ krb5int_buf_add(&buf, "0x");
for (j = 0; j < out.length; j++)
- sprintf(stroutbuf + strlen(stroutbuf), "%02x", 0xff & outbuf[j]);
+ krb5int_buf_add_fmt(&buf, "%02x", 0xff & outbuf[j]);
+ if (krb5int_buf_cstr(&buf) == NULL)
+ abort();
if (strcmp(stroutbuf, md5tests[i].hexdigest)) {
printf("*** CHECK FAILED!\n"
"\tReturned: %s.\n"
#include <errno.h>
#include "k5-platform.h"
+#include "k5-buf.h"
typedef UINT64_TYPE gssint_uint64;
/** helper macros **/
const gss_OID_desc * const oid;
gss_buffer_t oid_str;
{
- char numstr[128];
OM_uint32 number;
- int numshift;
- OM_uint32 string_length;
OM_uint32 i;
unsigned char *cp;
char *bp;
+ struct k5buf buf;
if (minor_status != NULL)
*minor_status = 0;
/* Decoded according to krb5/gssapi_krb5.c */
- /* First determine the size of the string */
- string_length = 0;
- number = 0;
- numshift = 0;
cp = (unsigned char *) oid->elements;
number = (unsigned long) cp[0];
- snprintf(numstr, sizeof(numstr), "%lu ", (unsigned long)number/40);
- string_length += strlen(numstr);
- snprintf(numstr, sizeof(numstr), "%lu ", (unsigned long)number%40);
- string_length += strlen(numstr);
+ krb5int_buf_init_dynamic(&buf);
+ krb5int_buf_add_fmt(&buf, "{ %lu %lu ", (unsigned long)number/40,
+ (unsigned long)number%40);
+ number = 0;
+ cp = (unsigned char *) oid->elements;
for (i=1; i<oid->length; i++) {
- if ((OM_uint32) (numshift+7) < (sizeof (OM_uint32)*8)) {/* XXX */
- number = (number << 7) | (cp[i] & 0x7f);
- numshift += 7;
- }
- else {
- return(GSS_S_FAILURE);
- }
+ number = (number << 7) | (cp[i] & 0x7f);
if ((cp[i] & 0x80) == 0) {
- snprintf(numstr, sizeof(numstr), "%lu ", (unsigned long)number);
- string_length += strlen(numstr);
+ krb5int_buf_add_fmt(&buf, "%lu ", (unsigned long)number);
number = 0;
- numshift = 0;
}
}
- /*
- * If we get here, we've calculated the length of "n n n ... n ". Add 4
- * here for "{ " and "}\0".
- */
- string_length += 4;
- if ((bp = (char *) malloc(string_length))) {
- strcpy(bp, "{ ");
- number = (OM_uint32) cp[0];
- snprintf(numstr, sizeof(numstr), "%lu ", (unsigned long)number/40);
- strcat(bp, numstr);
- snprintf(numstr, sizeof(numstr), "%lu ", (unsigned long)number%40);
- strcat(bp, numstr);
- number = 0;
- cp = (unsigned char *) oid->elements;
- for (i=1; i<oid->length; i++) {
- number = (number << 7) | (cp[i] & 0x7f);
- if ((cp[i] & 0x80) == 0) {
- snprintf(numstr, sizeof(numstr), "%lu ", (unsigned long)number);
- strcat(bp, numstr);
- number = 0;
- }
- }
- strcat(bp, "}");
- oid_str->length = strlen(bp)+1;
- oid_str->value = (void *) bp;
- return(GSS_S_COMPLETE);
+ krb5int_buf_add(&buf, "}");
+ bp = krb5int_buf_cstr(&buf);
+ if (bp == NULL) {
+ *minor_status = ENOMEM;
+ return(GSS_S_FAILURE);
}
- *minor_status = ENOMEM;
- return(GSS_S_FAILURE);
+ oid_str->length = krb5int_buf_len(&buf)+1;
+ oid_str->value = (void *) bp;
+ return(GSS_S_COMPLETE);
}
OM_uint32
krb5_error_code kret;
profile_t profile;
const char *kdc_config;
- size_t krb5_config_len, kdc_config_len;
char *profile_path;
char **filenames;
int i;
+ struct k5buf buf;
kret = krb5_get_default_config_files (&filenames);
if (kret)
return kret;
- krb5_config_len = 0;
- for (i = 0; filenames[i] != NULL; i++)
- krb5_config_len += strlen(filenames[i]) + 1;
- if (i > 0)
- krb5_config_len--;
- if (envname == NULL
- || (kdc_config = getenv(envname)) == NULL)
+ if (envname == NULL || (kdc_config = getenv(envname)) == NULL)
kdc_config = fname;
- if (kdc_config == NULL)
- kdc_config_len = 0;
- else
- kdc_config_len = strlen(kdc_config);
- profile_path = malloc(2 + krb5_config_len + kdc_config_len);
- if (profile_path == NULL) {
- krb5_free_config_files(filenames);
- return ENOMEM;
+ krb5int_buf_init_dynamic(&buf);
+ if (kdc_config)
+ krb5int_buf_add(&buf, kdc_config);
+ for (i = 0; filenames[i] != NULL; i++) {
+ if (krb5int_buf_len(&buf) > 0)
+ krb5int_buf_add(&buf, ":");
+ krb5int_buf_add(&buf, filenames[i]);
}
- if (kdc_config_len)
- strcpy(profile_path, kdc_config);
- else
- profile_path[0] = 0;
- if (krb5_config_len)
- for (i = 0; filenames[i] != NULL; i++) {
- if (kdc_config_len || i)
- strcat(profile_path, ":");
- strcat(profile_path, filenames[i]);
- }
krb5_free_config_files(filenames);
+ profile_path = krb5int_buf_cstr(&buf);
+ if (profile_path == NULL)
+ return ENOMEM;
profile = (profile_t) NULL;
kret = profile_init_path(profile_path, &profile);
free(profile_path);
int i;
krb5_flags pflags;
const char *sepstring;
- char *op;
- int initial;
- krb5_error_code retval;
+ struct k5buf buf;
- retval = 0;
- op = buffer;
pflags = 0;
- initial = 1;
sepstring = (sep) ? sep : flags_default_sep;
+ krb5int_buf_init_fixed(&buf, buffer, buflen);
/* Blast through the table matching all we can */
for (i=0; i<flags_table_nents; i++) {
if (flags & flags_table[i].fl_flags) {
- /* Found a match, see if it'll fit into the output buffer */
- if ((op+strlen(flags_table[i].fl_output)+strlen(sepstring)) <
- (buffer + buflen)) {
- if (!initial) {
- strcpy(op, sep);
- op += strlen(sep);
- }
- initial = 0;
- strcpy(op, flags_table[i].fl_output);
- op += strlen(flags_table[i].fl_output);
- }
- else {
- retval = ENOMEM;
- break;
- }
+ if (krb5int_buf_len(&buf) > 0)
+ krb5int_buf_add(&buf, sepstring);
+ krb5int_buf_add(&buf, flags_table[i].fl_output);
/* Keep track of what we matched */
pflags |= flags_table[i].fl_flags;
}
}
- if (!retval) {
- /* See if there's any leftovers */
- if (flags & ~pflags)
- retval = EINVAL;
- else if (initial)
- *buffer = '\0';
- }
- return(retval);
+ if (krb5int_buf_cstr(&buf) == NULL)
+ return(ENOMEM);
+
+ /* See if there's any leftovers */
+ if (flags & ~pflags)
+ return(EINVAL);
+
+ return(0);
}
krb5_error_code
unsigned int prompt_len = sc->sam_response_prompt.length;
char *challenge = sc->sam_challenge.data;
unsigned int challenge_len = sc->sam_challenge.length;
- char *prompt1, *p;
- char *sep1 = ": [";
- char *sep2 = "]\n";
- char *sep3 = ": ";
+ struct k5buf buf;
if (sc->sam_cksum.length == 0) {
/* or invalid -- but lets just handle presence now XXX */
Challenge for Digital Pathways mechanism: [134591]
Passcode:
*/
- p = prompt1 = malloc(label_len + strlen(sep1) +
- challenge_len + strlen(sep2) +
- prompt_len+ strlen(sep3) + 1);
- if (p == NULL)
- return NULL;
+ krb5int_buf_init_dynamic(&buf);
if (challenge_len) {
- strncpy(p, label, label_len); p += label_len;
- strcpy(p, sep1); p += strlen(sep1);
- strncpy(p, challenge, challenge_len); p += challenge_len;
- strcpy(p, sep2); p += strlen(sep2);
+ krb5int_buf_add_len(&buf, label, label_len);
+ krb5int_buf_add(&buf, ": [");
+ krb5int_buf_add_len(&buf, challenge, challenge_len);
+ krb5int_buf_add(&buf, "]\n");
}
- strncpy(p, prompt, prompt_len); p += prompt_len;
- strcpy(p, sep3); /* p += strlen(sep3); */
- return prompt1;
+ krb5int_buf_add_len(&buf, prompt, prompt_len);
+ krb5int_buf_add(&buf, ": ");
+ return krb5int_buf_cstr(&buf);
}
/*
{
krb5_rcache rcache = 0;
char *cachename = 0, *cachetype;
- char tmp[4];
krb5_error_code retval;
- unsigned int p, i;
- unsigned int len;
-
+ unsigned int i;
+ struct k5buf buf;
#ifdef HAVE_GETEUID
- unsigned long tens;
unsigned long uid = geteuid();
#endif
cachetype = krb5_rc_default_type(context);
- len = piece->length + 3 + 1;
+ krb5int_buf_init_dynamic(&buf);
+ krb5int_buf_add(&buf, cachetype);
+ krb5int_buf_add(&buf, ":");
for (i = 0; i < piece->length; i++) {
if (piece->data[i] == '-')
- len++;
+ krb5int_buf_add(&buf, "--");
else if (!isvalidrcname((int) piece->data[i]))
- len += 3;
+ krb5int_buf_add_fmt(&buf, "-%03o", piece->data[i]);
+ else
+ krb5int_buf_add_len(&buf, &piece->data[i], 1);
}
-
#ifdef HAVE_GETEUID
- len += 2; /* _<uid> */
- for (tens = 1; (uid / tens) > 9 ; tens *= 10)
- len++;
+ krb5int_buf_add_fmt(&buf, "_%lu", uid);
#endif
-
- cachename = malloc(strlen(cachetype) + 5 + len);
- if (!cachename) {
- retval = ENOMEM;
- goto cleanup;
- }
- strcpy(cachename, cachetype);
- p = strlen(cachename);
- cachename[p++] = ':';
- for (i = 0; i < piece->length; i++) {
- if (piece->data[i] == '-') {
- cachename[p++] = '-';
- cachename[p++] = '-';
- continue;
- }
- if (!isvalidrcname((int) piece->data[i])) {
- snprintf(tmp, sizeof(tmp), "%03o", piece->data[i]);
- cachename[p++] = '-';
- cachename[p++] = tmp[0];
- cachename[p++] = tmp[1];
- cachename[p++] = tmp[2];
- continue;
- }
- cachename[p++] = piece->data[i];
- }
-
-#ifdef HAVE_GETEUID
- cachename[p++] = '_';
- while (tens) {
- cachename[p++] = '0' + ((uid / tens) % 10);
- tens /= 10;
- }
-#endif
-
- cachename[p++] = '\0';
+ cachename = krb5int_buf_cstr(&buf);
+ if (cachename == NULL)
+ return ENOMEM;
retval = krb5_rc_resolve_full(context, &rcache, cachename);
if (retval) {
#define max(a,b) ((a) > (b) ? (a) : (b))
#endif
char tmpbuf[max(NI_MAXHOST + NI_MAXSERV + 30, 200)];
+ struct k5buf buf;
if (!krb5int_debug_sendto_kdc)
return;
case 'A':
/* %A => addrinfo */
ai = va_arg(args, struct addrinfo *);
+ krb5int_buf_init_dynamic(&buf);
if (ai->ai_socktype == SOCK_DGRAM)
- strlcpy(tmpbuf, "dgram", sizeof(tmpbuf));
+ krb5int_buf_add(&buf, "dgram");
else if (ai->ai_socktype == SOCK_STREAM)
- strlcpy(tmpbuf, "stream", sizeof(tmpbuf));
+ krb5int_buf_add(&buf, "stream");
else
- snprintf(tmpbuf, sizeof(tmpbuf), "socktype%d", ai->ai_socktype);
+ krb5int_buf_add_fmt(&buf, "socktype%d", ai->ai_socktype);
+
if (0 != getnameinfo (ai->ai_addr, ai->ai_addrlen,
addrbuf, sizeof (addrbuf),
portbuf, sizeof (portbuf),
NI_NUMERICHOST | NI_NUMERICSERV)) {
if (ai->ai_addr->sa_family == AF_UNSPEC)
- strcpy(tmpbuf + strlen(tmpbuf), " AF_UNSPEC");
+ krb5int_buf_add(&buf, " AF_UNSPEC");
else
- snprintf(tmpbuf + strlen(tmpbuf),
- sizeof(tmpbuf)-strlen(tmpbuf),
- " af%d", ai->ai_addr->sa_family);
+ krb5int_buf_add_fmt(&buf, " af%d", ai->ai_addr->sa_family);
} else
- snprintf(tmpbuf + strlen(tmpbuf), sizeof(tmpbuf)-strlen(tmpbuf),
- " %s.%s", addrbuf, portbuf);
- putstr(tmpbuf);
+ krb5int_buf_add_fmt(&buf, " %s.%s", addrbuf, portbuf);
+ if (krb5int_buf_cstr(&buf))
+ putstr(krb5int_buf_cstr(&buf));
+ krb5int_free_buf(&buf);
break;
case 'D':
/* %D => krb5_data * */
char *i_princ_name;
char **o_princ_name;
{
- char *tmp_princ_name = NULL, *princ_name = NULL, *at_rlm_name = NULL;
- int l = 0, m = 0, tmp_princ_name_len = 0, princ_name_len = 0, at_count = 0;
- krb5_error_code st = 0;
+ const char *at_rlm_name, *p;
+ struct k5buf buf;
at_rlm_name = strrchr(i_princ_name, '@');
-
if (!at_rlm_name) {
*o_princ_name = strdup(i_princ_name);
- if (!o_princ_name) {
- st = ENOMEM;
- goto cleanup;
- }
+ if (!o_princ_name)
+ return ENOMEM;
} else {
- tmp_princ_name_len = at_rlm_name - i_princ_name;
-
- tmp_princ_name = (char *) malloc ((unsigned) tmp_princ_name_len + 1);
- if (!tmp_princ_name) {
- st = ENOMEM;
- goto cleanup;
- }
- memset(tmp_princ_name, 0, (unsigned) tmp_princ_name_len + 1);
- memcpy(tmp_princ_name, i_princ_name, (unsigned) tmp_princ_name_len);
-
- l = 0;
- while (tmp_princ_name[l]) {
- if (tmp_princ_name[l++] == '@')
- at_count++;
- }
-
- princ_name_len = strlen(i_princ_name) + at_count + 1;
- princ_name = (char *) malloc ((unsigned) princ_name_len);
- if (!princ_name) {
- st = ENOMEM;
- goto cleanup;
+ krb5int_buf_init_dynamic(&buf);
+ for (p = i_princ_name; p < at_rlm_name; p++) {
+ if (*p == '@')
+ krb5int_buf_add(&buf, "\\");
+ krb5int_buf_add_len(&buf, p, 1);
}
- memset(princ_name, 0, (unsigned) princ_name_len);
-
- l = 0;
- m = 0;
- while (tmp_princ_name[l]) {
- if (tmp_princ_name[l] == '@') {
- princ_name[m++]='\\';
- }
- princ_name[m++]=tmp_princ_name[l++];
- }
- strcat(princ_name, at_rlm_name);
-
- *o_princ_name = princ_name;
+ krb5int_buf_add(&buf, at_rlm_name);
+ *o_princ_name = krb5int_buf_cstr(&buf);
+ if (!*o_princ_name)
+ return ENOMEM;
}
-
-cleanup:
-
- if (tmp_princ_name) {
- free(tmp_princ_name);
- tmp_princ_name = NULL;
- }
-
- return st;
+ return 0;
}