aboutsummaryrefslogtreecommitdiff
path: root/kadmin/load.c
diff options
context:
space:
mode:
Diffstat (limited to 'kadmin/load.c')
-rw-r--r--kadmin/load.c92
1 files changed, 45 insertions, 47 deletions
diff --git a/kadmin/load.c b/kadmin/load.c
index 30e6d93c0898..eb33be77ac5f 100644
--- a/kadmin/load.c
+++ b/kadmin/load.c
@@ -1,42 +1,40 @@
/*
- * Copyright (c) 1997-2005 Kungliga Tekniska Högskolan
- * (Royal Institute of Technology, Stockholm, Sweden).
- * All rights reserved.
+ * Copyright (c) 1997-2005 Kungliga Tekniska Högskolan
+ * (Royal Institute of Technology, Stockholm, Sweden).
+ * All rights reserved.
*
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
*
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
*
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
*
- * 3. Neither the name of the Institute nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
+ * 3. Neither the name of the Institute nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
*
- * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
+ * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
*/
#include "kadmin_locl.h"
#include "kadmin-commands.h"
#include <kadm5/private.h>
-RCSID("$Id: load.c 16658 2006-01-25 12:29:46Z lha $");
-
struct entry {
char *principal;
char *key;
@@ -55,7 +53,7 @@ struct entry {
static char *
skip_next(char *p)
{
- while(*p && !isspace((unsigned char)*p))
+ while(*p && !isspace((unsigned char)*p))
p++;
*p++ = 0;
while(*p && isspace((unsigned char)*p))
@@ -78,7 +76,7 @@ parse_time_string(time_t *t, const char *s)
if(strcmp(s, "-") == 0)
return 0;
- if(sscanf(s, "%04d%02d%02d%02d%02d%02d",
+ if(sscanf(s, "%04d%02d%02d%02d%02d%02d",
&year, &month, &date, &hour, &minute, &second) != 6)
return -1;
tm.tm_year = year - 1900;
@@ -155,8 +153,8 @@ parse_keys(hdb_entry *ent, char *str)
krb5_error_code ret;
int tmp;
char *p;
- int i;
-
+ size_t i;
+
p = strsep(&str, ":");
if (sscanf(p, "%d", &tmp) != 1)
return 1;
@@ -164,7 +162,7 @@ parse_keys(hdb_entry *ent, char *str)
p = strsep(&str, ":");
while(p){
Key *key;
- key = realloc(ent->keys.val,
+ key = realloc(ent->keys.val,
(ent->keys.len + 1) * sizeof(*ent->keys.val));
if(key == NULL)
krb5_errx (context, 1, "realloc: out of memory");
@@ -203,11 +201,11 @@ parse_keys(hdb_entry *ent, char *str)
p++;
p_len = strlen(p);
- key->salt = malloc(sizeof(*key->salt));
+ key->salt = calloc(1, sizeof(*key->salt));
if (key->salt == NULL)
krb5_errx (context, 1, "malloc: out of memory");
key->salt->type = type;
-
+
if (p_len) {
if(*p == '\"') {
ret = krb5_data_copy(&key->salt->salt, p + 1, p_len - 2);
@@ -333,8 +331,10 @@ parse_extensions(char *str, HDB_extensions **e)
d = malloc(len);
len = hex_decode(p, d, len);
- if (len < 0)
+ if (len < 0) {
+ free(d);
return -1;
+ }
ret = decode_HDB_extension(d, len, &ext, NULL);
free(d);
@@ -395,7 +395,6 @@ doit(const char *filename, int mergep)
line = 0;
ret = 0;
while(fgets(s, sizeof(s), f) != NULL) {
- ret = 0;
line++;
p = s;
@@ -412,7 +411,7 @@ doit(const char *filename, int mergep)
}
}
p = skip_next(p);
-
+
e.key = p;
p = skip_next(p);
@@ -444,26 +443,25 @@ doit(const char *filename, int mergep)
p = skip_next(p);
e.extensions = p;
- p = skip_next(p);
+ skip_next(p);
memset(&ent, 0, sizeof(ent));
ret = krb5_parse_name(context, e.principal, &ent.entry.principal);
if(ret) {
- fprintf(stderr, "%s:%d:%s (%s)\n",
- filename,
- line,
- krb5_get_err_text(context, ret),
- e.principal);
+ const char *msg = krb5_get_error_message(context, ret);
+ fprintf(stderr, "%s:%d:%s (%s)\n",
+ filename, line, msg, e.principal);
+ krb5_free_error_message(context, msg);
continue;
}
-
+
if (parse_keys(&ent.entry, e.key)) {
fprintf (stderr, "%s:%d:error parsing keys (%s)\n",
filename, line, e.key);
hdb_free_entry (context, &ent);
continue;
}
-
+
if (parse_event(&ent.entry.created_by, e.created) == -1) {
fprintf (stderr, "%s:%d:error parsing created event (%s)\n",
filename, line, e.created);
@@ -555,13 +553,13 @@ loadit(int mergep, const char *name, int argc, char **argv)
return doit(argv[0], mergep);
}
-
+
int
load(void *opt, int argc, char **argv)
{
return loadit(0, "load", argc, argv);
}
-
+
int
merge(void *opt, int argc, char **argv)
{