From 2e50959a9b09db65e1402d34a3c95d23fbd9055b Mon Sep 17 00:00:00 2001 From: Ken Raeburn Date: Sat, 7 Oct 2006 01:02:08 +0000 Subject: [PATCH] Eliminate some warnings and non-gcc build problems: - nested function - bogus pointer casts - C++-style comments - unused variables - variables of same name in nested scopes - if condition syntax - unused function - use of GNU-only strndup() function git-svn-id: svn://anonsvn.mit.edu/krb5/trunk@18659 dc483132-0cff-0310-8789-dd5450dbe970 --- .../kdb/ldap/libkdb_ldap/ldap_create.c | 3 +- src/plugins/kdb/ldap/libkdb_ldap/ldap_misc.c | 25 +++++++++++-- .../kdb/ldap/libkdb_ldap/ldap_principal.c | 2 +- .../kdb/ldap/libkdb_ldap/ldap_principal2.c | 37 ++++++++----------- src/plugins/kdb/ldap/libkdb_ldap/ldap_realm.c | 24 ++++++------ .../libkdb_ldap/princ_key_encode_decode.c | 25 +++++++++---- 6 files changed, 68 insertions(+), 48 deletions(-) diff --git a/src/plugins/kdb/ldap/libkdb_ldap/ldap_create.c b/src/plugins/kdb/ldap/libkdb_ldap/ldap_create.c index 989dea7b9..d4b73c37b 100644 --- a/src/plugins/kdb/ldap/libkdb_ldap/ldap_create.c +++ b/src/plugins/kdb/ldap/libkdb_ldap/ldap_create.c @@ -243,7 +243,8 @@ krb5_ldap_create (krb5_context context, char *conf_section, char **db_args) prepend_err_str (context, "Error reading LDAP server params: ", status, status); goto cleanup; } - if (status = krb5_ldap_db_init(context, ldap_context)) { + status = krb5_ldap_db_init(context, ldap_context); + if (status) { goto cleanup; } diff --git a/src/plugins/kdb/ldap/libkdb_ldap/ldap_misc.c b/src/plugins/kdb/ldap/libkdb_ldap/ldap_misc.c index e37295b84..ed82132b5 100644 --- a/src/plugins/kdb/ldap/libkdb_ldap/ldap_misc.c +++ b/src/plugins/kdb/ldap/libkdb_ldap/ldap_misc.c @@ -37,6 +37,25 @@ extern char *strptime (const char *, const char *, struct tm *); #endif +/* Linux (GNU Libc) provides a length-limited variant of strdup. + But all the world's not Linux. */ +#undef strndup +#define strndup my_strndup +static char *my_strndup (const char *input, size_t limit) +{ + size_t len = strlen(input); + char *result; + if (len > limit) { + result = malloc(1 + limit); + if (result != NULL) { + memcpy(result, input, limit); + result[limit] = 0; + } + return result; + } else + return strdup(input); +} + /* Get integer or string values from the config section, falling back to the default section, then to hard-coded values. */ static errcode_t @@ -250,7 +269,7 @@ krb5_ldap_read_server_params(context, conf_section, srv_type) } (*server_info)[ele]->server_status = NOTSET; } else { - char *server=NULL, *item=NULL; + char *item=NULL; item = strtok_r(tempval,delims,&save_ptr); while (item != NULL && elemask has KRB_PRINCIPAL flag set * then it is a add operation */ - if (entries->mask & KDB_PRINCIPAL == 1) + if (entries->mask & KDB_PRINCIPAL) optype = ADD_PRINCIPAL; else optype = MODIFY_PRINCIPAL; @@ -971,9 +970,6 @@ krb5_ldap_put_principal(context, entries, nentries, db_args) } if (entries->mask & KDB_KEY_DATA || entries->mask & KDB_KVNO) { - int kcount=0, zero=0, salttype=0, totalkeys=0; - char *currpos=NULL, *krbsecretkey=NULL; - bersecretkey = krb5_encode_krbsecretkey (entries->key_data, entries->n_key_data); @@ -1015,7 +1011,7 @@ krb5_ldap_put_principal(context, entries, nentries, db_args) } /* Modify Key data ends here */ - // Set tl_data + /* Set tl_data */ if (entries->tl_data != NULL) { int count = 0; struct berval **ber_tl_data = NULL; @@ -1028,13 +1024,13 @@ krb5_ldap_put_principal(context, entries, nentries, db_args) || ptr->tl_data_type == KRB5_TL_KADM_DATA || ptr->tl_data_type == KDB_TL_USER_INFO) continue; - count ++; + count++; } if (count != 0) { - int i; + int j; ber_tl_data = (struct berval **) calloc (count, sizeof (struct berval*)); - for (i = 0, ptr = entries->tl_data; ptr != NULL; ptr = ptr->tl_data_next) { + for (j = 0, ptr = entries->tl_data; ptr != NULL; ptr = ptr->tl_data_next) { /* Ignore tl_data that are stored in separate directory * attributes */ if (ptr->tl_data_type == KRB5_TL_LAST_PWD_CHANGE @@ -1044,14 +1040,14 @@ krb5_ldap_put_principal(context, entries, nentries, db_args) || ptr->tl_data_type == KRB5_TL_KADM_DATA || ptr->tl_data_type == KDB_TL_USER_INFO) continue; - if ((st = tl_data2berval (ptr, &ber_tl_data[i])) != 0) + if ((st = tl_data2berval (ptr, &ber_tl_data[j])) != 0) break; - i++; + j++; } if (st != 0) { - for (i = 0; ber_tl_data[i] != NULL; i++) { - free (ber_tl_data[i]->bv_val); - free (ber_tl_data[i]); + for (j = 0; ber_tl_data[j] != NULL; j++) { + free (ber_tl_data[j]->bv_val); + free (ber_tl_data[j]); } free (ber_tl_data); goto cleanup; @@ -1065,10 +1061,7 @@ krb5_ldap_put_principal(context, entries, nentries, db_args) /* Directory specific attribute */ if (xargs.tktpolicydn != NULL) { - int tmask=0, tkttree = 0, subtreednlen = 0, ntre = 0, tktdnlen = 0; - - char **subtreednlist=NULL; - krb5_boolean dnoutofsubtree=TRUE; + int tmask=0; if (strlen(xargs.tktpolicydn) != 0) { st = checkattributevalue(ld, xargs.tktpolicydn, "objectclass", policyclass, &tmask); @@ -1289,7 +1282,7 @@ krb5_decode_krbsecretkey(context, entries, bvalues, userinfo_tl_data) &mkvno); if (st != 0) { - char *msg = error_message(st); + const char *msg = error_message(st); st = -1; /* Something more appropriate ? */ krb5_set_error_message (context, st, "unable to decode stored principal key data (%s)", msg); diff --git a/src/plugins/kdb/ldap/libkdb_ldap/ldap_realm.c b/src/plugins/kdb/ldap/libkdb_ldap/ldap_realm.c index eac20a4c9..0d5357e00 100644 --- a/src/plugins/kdb/ldap/libkdb_ldap/ldap_realm.c +++ b/src/plugins/kdb/ldap/libkdb_ldap/ldap_realm.c @@ -266,6 +266,12 @@ cleanup: * Delete the realm along with the principals belonging to the realm in the Directory. */ +static void +delete_password_policy (krb5_pointer ptr, osa_policy_ent_t pol) +{ + krb5_ldap_delete_password_policy ((krb5_context)ptr, pol->name); +} + krb5_error_code krb5_ldap_delete_realm (context, lrealm) krb5_context context; @@ -353,15 +359,7 @@ krb5_ldap_delete_realm (context, lrealm) } /* Delete all password policies */ - { - char *attr[] = {NULL}, filter[256]; - - void delete_password_policy (krb5_pointer ptr, osa_policy_ent_t pol) { - krb5_ldap_delete_password_policy (context, pol->name); - } - - krb5_ldap_iterate_password_policy (context, "*", delete_password_policy, NULL); - } + krb5_ldap_iterate_password_policy (context, "*", delete_password_policy, context); /* Delete all ticket policies */ { @@ -424,7 +422,7 @@ krb5_ldap_modify_realm(context, rparams, mask) int mask; { LDAP *ld=NULL; - krb5_error_code st=0, retval=0; + krb5_error_code st=0; char **strval=NULL, *strvalprc[5]={NULL}; #ifdef HAVE_EDIRECTORY char **values=NULL; @@ -434,7 +432,7 @@ krb5_ldap_modify_realm(context, rparams, mask) char errbuf[1024]; #endif LDAPMod **mods = NULL; - int i=0, oldmask=0, objectmask=0,k=0,part_of_subtree=0; + int i=0, oldmask=0, objectmask=0,k=0; kdb5_dal_handle *dal_handle=NULL; krb5_ldap_context *ldap_context=NULL; krb5_ldap_server_handle *ldap_server_handle=NULL; @@ -1076,7 +1074,7 @@ krb5_ldap_create_realm(context, rparams, mask) char *strval[4]={NULL}; char *contref[2]={NULL}; LDAPMod **mods = NULL; - int i=0, objectmask=0, subtreecount=0,k=0, part_of_subtree=0; + int i=0, objectmask=0, subtreecount=0; kdb5_dal_handle *dal_handle=NULL; krb5_ldap_context *ldap_context=NULL; krb5_ldap_server_handle *ldap_server_handle=NULL; @@ -1320,7 +1318,7 @@ krb5_ldap_read_realm_params(context, lrealm, rlparamp, mask) kdb5_dal_handle *dal_handle=NULL; krb5_ldap_context *ldap_context=NULL; krb5_ldap_server_handle *ldap_server_handle=NULL; - int valcount=0, x=0; + int x=0; SETUP_CONTEXT (); diff --git a/src/plugins/kdb/ldap/libkdb_ldap/princ_key_encode_decode.c b/src/plugins/kdb/ldap/libkdb_ldap/princ_key_encode_decode.c index f84c1bb8e..bde22e409 100644 --- a/src/plugins/kdb/ldap/libkdb_ldap/princ_key_encode_decode.c +++ b/src/plugins/kdb/ldap/libkdb_ldap/princ_key_encode_decode.c @@ -240,6 +240,7 @@ last: return ret; } +#if 0 /* not currently used */ static asn1_error_code decode_tagged_unsigned_integer (asn1buf *buf, int expectedtag, unsigned long *val) { @@ -264,6 +265,7 @@ decode_tagged_unsigned_integer (asn1buf *buf, int expectedtag, unsigned long *va last: return ret; } +#endif static asn1_error_code decode_tagged_octetstring (asn1buf *buf, int expectedtag, int *len, @@ -340,6 +342,9 @@ static asn1_error_code asn1_decode_key(asn1buf *buf, krb5_key_data *key) { int buflen; asn1buf kbuf; + long lval; + int ival; + if (t.tagnum != 1) cleanup (ASN1_MISSING_FIELD); @@ -347,12 +352,13 @@ static asn1_error_code asn1_decode_key(asn1buf *buf, krb5_key_data *key) buflen = length; ret = asn1buf_imbed(&kbuf, &subbuf, length, seqindef); checkerr; - ret = decode_tagged_integer (&kbuf, 0, (int *)&key->key_data_type[0]); + ret = decode_tagged_integer (&kbuf, 0, &lval); checkerr; + key->key_data_type[0] = lval; /* XXX range check? */ - ret = decode_tagged_octetstring (&kbuf, 1, - (int *)&key->key_data_length[0], + ret = decode_tagged_octetstring (&kbuf, 1, &ival, &key->key_data_contents[0]); checkerr; + key->key_data_length[0] = ival; safe_syncbuf (&subbuf, &kbuf); } @@ -385,6 +391,7 @@ krb5_error_code asn1_decode_sequence_of_keys (krb5_data *in, unsigned int length; taginfo t; int kvno, maj, min; + long lval; *n_key_data = 0; *out = NULL; @@ -395,19 +402,23 @@ krb5_error_code asn1_decode_sequence_of_keys (krb5_data *in, ret = asn1buf_imbed(&subbuf, &buf, length, seqindef); checkerr; /* attribute-major-vno */ - ret = decode_tagged_integer (&subbuf, 0, &maj); checkerr; + ret = decode_tagged_integer (&subbuf, 0, &lval); checkerr; + maj = lval; /* XXX range check? */ /* attribute-minor-vno */ - ret = decode_tagged_integer (&subbuf, 1, &min); checkerr; + ret = decode_tagged_integer (&subbuf, 1, &lval); checkerr; + min = lval; /* XXX range check? */ if (maj != 1 || min != 1) cleanup (ASN1_BAD_FORMAT); /* kvno (assuming all keys in array have same version) */ - ret = decode_tagged_integer (&subbuf, 2, &kvno); checkerr; + ret = decode_tagged_integer (&subbuf, 2, &lval); checkerr; + kvno = lval; /* XXX range check? */ /* mkvno (optional) */ - ret = decode_tagged_integer (&subbuf, 3, mkvno); checkerr; + ret = decode_tagged_integer (&subbuf, 3, &lval); checkerr; + *mkvno = lval; /* XXX range check? */ ret = asn1_get_tag_2(&subbuf, &t); checkerr; -- 2.26.2