kadmin: Fix warnings

This commit is contained in:
Nicolas Williams
2021-03-27 23:24:24 -05:00
parent 69eee19541
commit b7bf5ca6e8
9 changed files with 40 additions and 18 deletions

View File

@@ -46,7 +46,7 @@ add_enctype(struct add_enctype_options*opt, int argc, char **argv)
krb5_error_code ret;
const char *princ_name;
int i, j;
krb5_key_data *new_key_data;
krb5_key_data *new_key_data = NULL;
int n_etypes;
krb5_enctype *etypes;
@@ -108,7 +108,6 @@ add_enctype(struct add_enctype_options*opt, int argc, char **argv)
/* XXX Should this be an error? The admin can del_enctype... */
krb5_warnx(context, "enctype %d already exists",
(int)etypes[j]);
free(new_key_data);
goto out;
}
}
@@ -163,6 +162,7 @@ add_enctype(struct add_enctype_options*opt, int argc, char **argv)
if (ret)
krb5_warn(context, ret, "kadm5_modify_principal");
out:
free(new_key_data);
krb5_free_principal (context, princ_ent);
kadm5_free_principal_ent(kadm_handle, &princ);
out2:

View File

@@ -464,10 +464,12 @@ add_one_namespace(const char *name,
/* XXX Shouldn't need a password for this */
random_password(pwbuf, sizeof(pwbuf));
ret = kadm5_create_principal_3(kadm_handle, &princ, mask,
nkstuple, kstuple, pwbuf);
if (ret)
krb5_warn(context, ret, "kadm5_create_principal_3");
if (ret == 0) {
ret = kadm5_create_principal_3(kadm_handle, &princ, mask,
nkstuple, kstuple, pwbuf);
if (ret)
krb5_warn(context, ret, "kadm5_create_principal_3");
}
kadm5_free_principal_ent(kadm_handle, &princ); /* frees princ_ent */
if (default_ent)

View File

@@ -61,12 +61,15 @@ do_del_ns_entry(krb5_principal nsp, void *data)
krb5_principal p = NULL;
const char *comp0 = krb5_principal_get_comp_string(context, nsp, 0);
const char *comp1 = krb5_principal_get_comp_string(context, nsp, 1);
char *unsp = NULL;
if (krb5_principal_get_num_comp(context, nsp) != 2) {
(void) krb5_unparse_name(context, nsp, &unsp);
krb5_warn(context, ret = EINVAL, "Not a valid namespace name %s",
unsp ? unsp : "<Out of memory>");
char *unsp = NULL;
ret = krb5_unparse_name(context, nsp, &unsp);
krb5_warn(context, ret,
"Not a valid namespace name (component count is not 2): %s",
unsp ? unsp : "<out of memory>");
free(unsp);
return EINVAL;
}
@@ -80,7 +83,6 @@ do_del_ns_entry(krb5_principal nsp, void *data)
if (ret == 0)
ret = kadm5_delete_principal(kadm_handle, p);
krb5_free_principal(context, p);
free(unsp);
return ret;
}

View File

@@ -148,7 +148,7 @@ do_ext_keytab(krb5_principal principal, void *data)
}
free(unparsed);
free(keys);
return 0;
return ret;
}
int

View File

@@ -134,6 +134,8 @@ main(int argc, char **argv)
argc -= optidx;
argv += optidx;
if (argc != 0)
usage(1);
if (config_file == NULL) {
int aret;

View File

@@ -367,7 +367,7 @@ my_fgetln(FILE *f, char **bufp, size_t *szp, size_t *lenp)
size_t len;
size_t sz = *szp;
char *buf = *bufp;
char *p, *n;
char *n;
if (!buf) {
buf = malloc(sz ? sz : 8192);
@@ -378,7 +378,7 @@ my_fgetln(FILE *f, char **bufp, size_t *szp, size_t *lenp)
}
len = 0;
while ((p = fgets(&buf[len], sz-len, f)) != NULL) {
while (fgets(&buf[len], sz-len, f) != NULL) {
len += strlen(&buf[len]);
if (buf[len-1] == '\n')
break;

View File

@@ -123,7 +123,7 @@ static void
add_aliases(krb5_context contextp, kadm5_principal_ent_rec *princ,
struct getarg_strings *strings)
{
krb5_error_code ret;
krb5_error_code ret = 0;
HDB_extension ext;
krb5_data buf;
krb5_principal p;
@@ -144,9 +144,16 @@ add_aliases(krb5_context contextp, kadm5_principal_ent_rec *princ,
sizeof(ext.data.u.aliases.aliases.val[0]));
ext.data.u.aliases.aliases.len = strings->num_strings;
for (i = 0; i < strings->num_strings; i++) {
for (i = 0; ret == 0 && i < strings->num_strings; i++) {
ret = krb5_parse_name(contextp, strings->strings[i], &p);
ret = copy_Principal(p, &ext.data.u.aliases.aliases.val[i]);
if (ret)
krb5_err(contextp, 1, ret, "Could not parse alias %s",
strings->strings[i]);
if (ret == 0)
ret = copy_Principal(p, &ext.data.u.aliases.aliases.val[i]);
if (ret)
krb5_err(contextp, 1, ret, "Could not copy parsed alias %s",
strings->strings[i]);
krb5_free_principal(contextp, p);
}
}
@@ -224,6 +231,7 @@ add_etypes(krb5_context contextp,
if (ret) {
krb5_warn(contextp, ret, "Could not parse enctype %s",
strings->strings[i]);
free(etypes.val);
return ret;
}
etypes.val[i] = etype;
@@ -236,6 +244,7 @@ add_etypes(krb5_context contextp,
if (ret || buf.length != size)
abort();
add_tl(princ, KRB5_TL_ETYPES, &buf);
free(etypes.val);
return 0;
}

View File

@@ -691,6 +691,10 @@ iter_aliases(kadm5_principal_ent_rec *from,
if (ctx->done > 0)
return 0;
if (from == NULL) {
ctx->done = 1;
return 0;
}
if (ctx->done == 0) {
if (ctx->alias_idx < ctx->aliases.aliases.len) {

View File

@@ -106,7 +106,10 @@ stash(struct stash_options *opt, int argc, char **argv)
}
}
ret = krb5_string_to_key_salt(context, enctype, buf, salt, &key);
ret = hdb_add_master_key(context, &key, &mkey);
if (ret == 0)
ret = hdb_add_master_key(context, &key, &mkey);
if (ret)
krb5_warn(context, errno, "setting master key");
krb5_free_keyblock_contents(context, &key);
}