diff options
author | Artur Grabowski <art@cvs.openbsd.org> | 1997-12-12 10:02:48 +0000 |
---|---|---|
committer | Artur Grabowski <art@cvs.openbsd.org> | 1997-12-12 10:02:48 +0000 |
commit | e9661eae9354189ee0fd73e835fb8243ebc1b6db (patch) | |
tree | 1c5d304e1e3f211a69365a8327c9b1ff466739b3 /kerberosIV/kadm | |
parent | c2e173d16ac5aa279c3b4432abe23c6fb9a948ef (diff) |
Clean up, check pointers, etc.
Diffstat (limited to 'kerberosIV/kadm')
-rw-r--r-- | kerberosIV/kadm/kadm_stream.c | 316 | ||||
-rw-r--r-- | kerberosIV/kadm/kadm_supp.c | 112 |
2 files changed, 236 insertions, 192 deletions
diff --git a/kerberosIV/kadm/kadm_stream.c b/kerberosIV/kadm/kadm_stream.c index 58f53cce124..9f10aa45e1b 100644 --- a/kerberosIV/kadm/kadm_stream.c +++ b/kerberosIV/kadm/kadm_stream.c @@ -1,3 +1,4 @@ +/* $OpenBSD: kadm_stream.c,v 1.4 1997/12/12 10:02:47 art Exp $ */ /* $KTH: kadm_stream.c,v 1.11 1997/05/02 10:28:05 joda Exp $ */ /* @@ -26,16 +27,17 @@ or implied warranty. */ /* - kadm_stream.c - this holds the stream support routines for the kerberos administration server - - vals_to_stream: converts a vals struct to a stream for transmission - internals build_field_header, vts_[string, char, long, short] - stream_to_vals: converts a stream to a vals struct - internals check_field_header, stv_[string, char, long, short] - error: prints out a kadm error message, returns - fatal: prints out a kadm fatal error message, exits -*/ + * kadm_stream.c + * this holds the stream support routines for the kerberos administration + * server + * + * vals_to_stream: converts a vals struct to a stream for transmission + * internals build_field_header, vts_[string, char, long, short] + * stream_to_vals: converts a stream to a vals struct + * internals check_field_header, stv_[string, char, long, short] + * error: prints out a kadm error message, returns + * fatal: prints out a kadm fatal error message, exits + */ #include "kadm_locl.h" @@ -44,9 +46,11 @@ build_field_header(u_char *cont, u_char **st) /* container for fields data */ /* stream */ { - *st = (u_char *) malloc (4); - memcpy(*st, cont, 4); - return 4; /* return pointer to current stream location */ + *st = (u_char *) malloc (4); + if (st == NULL) + return -1; + memcpy(*st, cont, 4); + return 4; /* return pointer to current stream location */ } static int @@ -55,10 +59,10 @@ check_field_header(u_char *st, u_char *cont, int maxlen) /* container for fields data */ { - if (4 > maxlen) - return(-1); - memcpy(cont, st, 4); - return 4; /* return pointer to current stream location */ + if (maxlen < 4 || cont == NULL || st == NULL) + return(-1); + memcpy(cont, st, 4); + return 4; /* return pointer to current stream location */ } int @@ -67,9 +71,11 @@ vts_string(char *dat, u_char **st, int loc) /* base pointer to the stream */ /* offset into the stream for current data */ { - *st = (u_char *) realloc (*st, (unsigned) (loc + strlen(dat) + 1)); - memcpy(*st + loc, dat, strlen(dat)+1); - return strlen(dat)+1; + *st = (u_char *) realloc (*st, (unsigned) (loc + strlen(dat) + 1)); + if (*st == NULL) + return -1; + memcpy(*st + loc, dat, strlen(dat)+1); + return strlen(dat)+1; } @@ -134,18 +140,18 @@ stv_string(u_char *st, /* base pointer to the stream */ int stlen, /* max length of string to copy in */ int maxlen) /* max length of input stream */ { - int maxcount; /* max count of chars to copy */ - - maxcount = min(maxlen - loc, stlen); - - if(maxcount <= 0) - return -1; - - strncpy(dat, (char *)st + loc, maxcount); - - if (dat[maxcount-1]) /* not null-term --> not enuf room */ - return(-1); - return strlen(dat)+1; + int maxcount; /* max count of chars to copy */ + + maxcount = min(maxlen - loc, stlen); + + if(maxcount <= 0) + return -1; + + strncpy(dat, (char *)st + loc, maxcount); + + if (dat[maxcount - 1]) /* not null-term --> not enough room */ + return -1; + return strlen(dat)+1; } static int @@ -155,11 +161,11 @@ stv_short(u_char *st, u_int16_t *dat, int loc, int maxlen) /* offset into the stream for current data */ { - if (maxlen - loc < 2) - return -1; - - *dat = (st[loc] << 8) | st[loc + 1]; - return 2; + if (maxlen - loc < 2) + return -1; + + *dat = (st[loc] << 8) | st[loc + 1]; + return 2; } int @@ -169,11 +175,11 @@ stv_long(u_char *st, u_int32_t *dat, int loc, int maxlen) /* offset into the stream for current data */ /* maximum length of st */ { - if (maxlen - loc < 4) - return -1; + if (maxlen - loc < 4) + return -1; - *dat = (st[loc] << 24) | (st[loc+1] << 16) | (st[loc+2] << 8) | st[loc+3]; - return 4; + *dat = (st[loc] << 24) | (st[loc+1] << 16) | (st[loc+2] << 8) | st[loc+3]; + return 4; } static int @@ -183,121 +189,147 @@ stv_char(u_char *st, u_char *dat, int loc, int maxlen) /* offset into the stream for current data */ { - if (maxlen - loc < 1) - return -1; + if (maxlen - loc < 1) + return -1; - *dat = st[loc]; - return 1; + *dat = st[loc]; + return 1; } /* -vals_to_stream - recieves : kadm_vals *, u_char * - returns : a realloced and filled in u_char * - -this function creates a byte-stream representation of the kadm_vals structure -*/ + * vals_to_stream + * recieves : kadm_vals *, u_char * + * returns : a realloced and filled in u_char * + * + * this function creates a byte-stream representation of the kadm_vals + * structure + */ + int vals_to_stream(Kadm_vals *dt_in, u_char **dt_out) { - int vsloop, stsize; /* loop counter, stream size */ - - stsize = build_field_header(dt_in->fields, dt_out); - for (vsloop=31; vsloop>=0; vsloop--) - if (IS_FIELD(vsloop,dt_in->fields)) { - switch (vsloop) { - case KADM_NAME: - stsize+=vts_string(dt_in->name, dt_out, stsize); - break; - case KADM_INST: - stsize+=vts_string(dt_in->instance, dt_out, stsize); - break; - case KADM_EXPDATE: - stsize+=vts_long(dt_in->exp_date, dt_out, stsize); - break; - case KADM_ATTR: - stsize+=vts_short(dt_in->attributes, dt_out, stsize); - break; - case KADM_MAXLIFE: - stsize+=vts_char(dt_in->max_life, dt_out, stsize); - break; - case KADM_DESKEY: - stsize+=vts_long(dt_in->key_high, dt_out, stsize); - stsize+=vts_long(dt_in->key_low, dt_out, stsize); - break; - default: - break; - } -} - return(stsize); + int vsloop, stsize, stsizetemp; /* loop counter, stream size */ + + stsize = build_field_header(dt_in->fields, dt_out); + if (stsize < 0) + return -1; + + for (vsloop=31; vsloop>=0; vsloop--) + if (IS_FIELD(vsloop, dt_in->fields)) { + switch (vsloop) { + case KADM_NAME: + stsizetemp = vts_string(dt_in->name, dt_out, stsize); + if (stsizetemp < 0) + return -1; + stsize += stsizetemp; + break; + case KADM_INST: + stsizetemp = vts_string(dt_in->instance, dt_out, stsize); + if (stsizetemp < 0) + return -1; + stsize += stsizetemp; + break; + case KADM_EXPDATE: + stsizetemp = vts_long(dt_in->exp_date, dt_out, stsize); + if (stsizetemp < 0) + return -1; + stsize += stsizetemp; + break; + case KADM_ATTR: + stsizetemp = vts_short(dt_in->attributes, dt_out, stsize); + if (stsizetemp < 0) + return -1; + stsize += stsizetemp; + break; + case KADM_MAXLIFE: + stsizetemp = vts_char(dt_in->max_life, dt_out, stsize); + if (stsizetemp < 0) + return -1; + stsize += stsizetemp; + break; + case KADM_DESKEY: + stsizetemp = vts_long(dt_in->key_high, dt_out, stsize); + if (stsizetemp < 0) + return -1; + stsize += stsizetemp; + stsizetemp = vts_long(dt_in->key_low, dt_out, stsize); + if (stsizetemp < 0) + return -1; + stsize += stsizetemp; + break; + default: + break; + } + } + return(stsize); } /* -stream_to_vals - recieves : u_char *, kadm_vals * - returns : a kadm_vals filled in according to u_char * - -this decodes a byte stream represntation of a vals struct into kadm_vals -*/ + * stream_to_vals + * recieves : u_char *, kadm_vals * + * returns : a kadm_vals filled in according to u_char * + * + * this decodes a byte stream represntation of a vals struct into kadm_vals + */ int stream_to_vals(u_char *dt_in, Kadm_vals *dt_out, int maxlen) /* max length to use */ { - int vsloop, stsize; /* loop counter, stream size */ - int status; - - memset(dt_out, 0, sizeof(*dt_out)); - - stsize = check_field_header(dt_in, dt_out->fields, maxlen); - if (stsize < 0) - return(-1); - for (vsloop=31; vsloop>=0; vsloop--) - if (IS_FIELD(vsloop,dt_out->fields)) - switch (vsloop) { - case KADM_NAME: - if ((status = stv_string(dt_in, dt_out->name, stsize, - sizeof(dt_out->name), maxlen)) < 0) - return(-1); - stsize += status; - break; - case KADM_INST: - if ((status = stv_string(dt_in, dt_out->instance, stsize, - sizeof(dt_out->instance), maxlen)) < 0) - return(-1); - stsize += status; - break; - case KADM_EXPDATE: - if ((status = stv_long(dt_in, &dt_out->exp_date, stsize, - maxlen)) < 0) - return(-1); - stsize += status; - break; - case KADM_ATTR: - if ((status = stv_short(dt_in, &dt_out->attributes, stsize, - maxlen)) < 0) - return(-1); - stsize += status; - break; - case KADM_MAXLIFE: - if ((status = stv_char(dt_in, &dt_out->max_life, stsize, - maxlen)) < 0) - return(-1); - stsize += status; - break; - case KADM_DESKEY: - if ((status = stv_long(dt_in, &dt_out->key_high, stsize, - maxlen)) < 0) - return(-1); - stsize += status; - if ((status = stv_long(dt_in, &dt_out->key_low, stsize, - maxlen)) < 0) - return(-1); - stsize += status; - break; - default: - break; - } - return stsize; + int vsloop, stsize; /* loop counter, stream size */ + int status; + + memset(dt_out, 0, sizeof(*dt_out)); + + stsize = check_field_header(dt_in, dt_out->fields, maxlen); + if (stsize < 0) + return(-1); + for (vsloop=31; vsloop>=0; vsloop--) + if (IS_FIELD(vsloop,dt_out->fields)) + switch (vsloop) { + case KADM_NAME: + if ((status = stv_string(dt_in, dt_out->name, stsize, + sizeof(dt_out->name), maxlen)) < 0) + return(-1); + stsize += status; + break; + case KADM_INST: + if ((status = stv_string(dt_in, dt_out->instance, stsize, + sizeof(dt_out->instance), maxlen)) < 0) + return(-1); + stsize += status; + break; + case KADM_EXPDATE: + if ((status = stv_long(dt_in, &dt_out->exp_date, stsize, + maxlen)) < 0) + return(-1); + stsize += status; + break; + case KADM_ATTR: + if ((status = stv_short(dt_in, &dt_out->attributes, stsize, + maxlen)) < 0) + return(-1); + stsize += status; + break; + case KADM_MAXLIFE: + if ((status = stv_char(dt_in, &dt_out->max_life, stsize, + maxlen)) < 0) + return(-1); + stsize += status; + break; + case KADM_DESKEY: + if ((status = stv_long(dt_in, &dt_out->key_high, stsize, + maxlen)) < 0) + return(-1); + stsize += status; + if ((status = stv_long(dt_in, &dt_out->key_low, stsize, + maxlen)) < 0) + return(-1); + stsize += status; + break; + default: + break; + } + return stsize; } diff --git a/kerberosIV/kadm/kadm_supp.c b/kerberosIV/kadm/kadm_supp.c index 4a771ff5fca..f3ff2fca573 100644 --- a/kerberosIV/kadm/kadm_supp.c +++ b/kerberosIV/kadm/kadm_supp.c @@ -1,3 +1,4 @@ +/* $OpenBSD: kadm_supp.c,v 1.3 1997/12/12 10:02:46 art Exp $ */ /* $KTH: kadm_supp.c,v 1.8 1997/05/02 10:27:58 joda Exp $ */ /* @@ -44,14 +45,14 @@ prin_vals: void prin_vals(Kadm_vals *vals) { - printf("Info in Database for %s.%s:\n", vals->name, vals->instance); - printf(" Max Life: %d (%s) Exp Date: %s\n", - vals->max_life, - krb_life_to_atime(vals->max_life), - asctime(k_localtime(&vals->exp_date))); - printf(" Attribs: %.2x key: %#lx %#lx\n", - vals->attributes, - (long)vals->key_low, (long)vals->key_high); + printf("Info in Database for %s.%s:\n", vals->name, vals->instance); + printf(" Max Life: %d (%s) Exp Date: %s\n", + vals->max_life, + krb_life_to_atime(vals->max_life), + asctime(k_localtime(&vals->exp_date))); + printf(" Attribs: %.2x key: %#lx %#lx\n", + vals->attributes, + (long)vals->key_low, (long)vals->key_high); } /* kadm_prin_to_vals takes a fields arguments, a Kadm_vals and a Principal, @@ -61,51 +62,62 @@ prin_vals(Kadm_vals *vals) void kadm_prin_to_vals(u_char *fields, Kadm_vals *new, Principal *old) { - memset(new, 0, sizeof(*new)); - if (IS_FIELD(KADM_NAME,fields)) { - strncpy(new->name, old->name, ANAME_SZ); - SET_FIELD(KADM_NAME, new->fields); - } - if (IS_FIELD(KADM_INST,fields)) { - strncpy(new->instance, old->instance, INST_SZ); - SET_FIELD(KADM_INST, new->fields); - } - if (IS_FIELD(KADM_EXPDATE,fields)) { - new->exp_date = old->exp_date; - SET_FIELD(KADM_EXPDATE, new->fields); - } - if (IS_FIELD(KADM_ATTR,fields)) { - new->attributes = old->attributes; - SET_FIELD(KADM_ATTR, new->fields); - } - if (IS_FIELD(KADM_MAXLIFE,fields)) { - new->max_life = old->max_life; - SET_FIELD(KADM_MAXLIFE, new->fields); - } - if (IS_FIELD(KADM_DESKEY,fields)) { - new->key_low = old->key_low; - new->key_high = old->key_high; - SET_FIELD(KADM_DESKEY, new->fields); - } + if (new == NULL) + return; + + memset(new, 0, sizeof(*new)); + if (IS_FIELD(KADM_NAME,fields)) { + strncpy(new->name, old->name, ANAME_SZ - 1); + new->name[ANAME_SZ - 1] = '\0'; + SET_FIELD(KADM_NAME, new->fields); + } + if (IS_FIELD(KADM_INST,fields)) { + strncpy(new->instance, old->instance, INST_SZ - 1); + new->instance[INST_SZ - 1] = '\0'; + SET_FIELD(KADM_INST, new->fields); + } + if (IS_FIELD(KADM_EXPDATE,fields)) { + new->exp_date = old->exp_date; + SET_FIELD(KADM_EXPDATE, new->fields); + } + if (IS_FIELD(KADM_ATTR,fields)) { + new->attributes = old->attributes; + SET_FIELD(KADM_ATTR, new->fields); + } + if (IS_FIELD(KADM_MAXLIFE,fields)) { + new->max_life = old->max_life; + SET_FIELD(KADM_MAXLIFE, new->fields); + } + if (IS_FIELD(KADM_DESKEY,fields)) { + new->key_low = old->key_low; + new->key_high = old->key_high; + SET_FIELD(KADM_DESKEY, new->fields); + } } void kadm_vals_to_prin(u_char *fields, Principal *new, Kadm_vals *old) { - - memset(new, 0, sizeof(*new)); - if (IS_FIELD(KADM_NAME,fields)) - strncpy(new->name, old->name, ANAME_SZ); - if (IS_FIELD(KADM_INST,fields)) - strncpy(new->instance, old->instance, INST_SZ); - if (IS_FIELD(KADM_EXPDATE,fields)) - new->exp_date = old->exp_date; - if (IS_FIELD(KADM_ATTR,fields)) - new->attributes = old->attributes; - if (IS_FIELD(KADM_MAXLIFE,fields)) - new->max_life = old->max_life; - if (IS_FIELD(KADM_DESKEY,fields)) { - new->key_low = old->key_low; - new->key_high = old->key_high; - } + if (new == NULL) + return; + + memset(new, 0, sizeof(*new)); + if (IS_FIELD(KADM_NAME,fields)) { + strncpy(new->name, old->name, ANAME_SZ); + new->name[ANAME_SZ - 1] = '\0'; + } + if (IS_FIELD(KADM_INST,fields)) { + strncpy(new->instance, old->instance, INST_SZ); + new->instance[KADM_INST - 1] = '\0'; + } + if (IS_FIELD(KADM_EXPDATE,fields)) + new->exp_date = old->exp_date; + if (IS_FIELD(KADM_ATTR,fields)) + new->attributes = old->attributes; + if (IS_FIELD(KADM_MAXLIFE,fields)) + new->max_life = old->max_life; + if (IS_FIELD(KADM_DESKEY,fields)) { + new->key_low = old->key_low; + new->key_high = old->key_high; + } } |