diff options
Diffstat (limited to 'kadmin/get.c')
| -rw-r--r-- | kadmin/get.c | 142 | 
1 files changed, 84 insertions, 58 deletions
| diff --git a/kadmin/get.c b/kadmin/get.c index 6e09f916d4f9..0895b53ccba2 100644 --- a/kadmin/get.c +++ b/kadmin/get.c @@ -1,34 +1,34 @@  /* - * Copyright (c) 1997-2006 Kungliga Tekniska Högskolan - * (Royal Institute of Technology, Stockholm, Sweden).  - * All rights reserved.  + * Copyright (c) 1997-2006 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" @@ -36,8 +36,6 @@  #include <parse_units.h>  #include <rtbl.h> -RCSID("$Id: get.c 21745 2007-07-31 16:11:25Z lha $"); -  static struct field_name {      const char *fieldname;      unsigned int fieldvalue; @@ -100,7 +98,7 @@ add_column(struct get_entry_data *data, struct field_name *ff, const char *heade      data->mask |= ff->fieldvalue;      data->extra_mask |= ff->extra_mask;      if(data->table != NULL) -	rtbl_add_column_by_id(data->table, ff->fieldvalue,  +	rtbl_add_column_by_id(data->table, ff->fieldvalue,  			      header ? header : ff->default_header, ff->flags);      return 0;  } @@ -112,9 +110,9 @@ add_column(struct get_entry_data *data, struct field_name *ff, const char *heade  static int  cmp_salt (const krb5_salt *salt, const krb5_key_data *k)  { -    if (salt->salttype != k->key_data_type[1]) +    if (salt->salttype != (size_t)k->key_data_type[1])  	return 1; -    if (salt->saltvalue.length != k->key_data_length[1]) +    if (salt->saltvalue.length != (size_t)k->key_data_length[1])  	return 1;      return memcmp (salt->saltvalue.data, k->key_data_contents[1],  		   salt->saltvalue.length); @@ -159,7 +157,7 @@ format_keytype(krb5_key_data *k, krb5_salt *def_salt, char *buf, size_t buf_len)  }  static void -format_field(kadm5_principal_ent_t princ, unsigned int field,  +format_field(kadm5_principal_ent_t princ, unsigned int field,  	     unsigned int subfield, char *buf, size_t buf_len, int condensed)  {      switch(field) { @@ -169,27 +167,27 @@ format_field(kadm5_principal_ent_t princ, unsigned int field,  	else  	    krb5_unparse_name_fixed(context, princ->principal, buf, buf_len);  	break; -     +      case KADM5_PRINC_EXPIRE_TIME:  	time_t2str(princ->princ_expire_time, buf, buf_len, !condensed);  	break; -	     +      case KADM5_PW_EXPIRATION:  	time_t2str(princ->pw_expiration, buf, buf_len, !condensed);  	break; -	     +      case KADM5_LAST_PWD_CHANGE:  	time_t2str(princ->last_pwd_change, buf, buf_len, !condensed);  	break; -	     +      case KADM5_MAX_LIFE:  	deltat2str(princ->max_life, buf, buf_len);  	break; -	     +      case KADM5_MAX_RLIFE:  	deltat2str(princ->max_renewable_life, buf, buf_len);  	break; -	     +      case KADM5_MOD_TIME:  	time_t2str(princ->mod_date, buf, buf_len, !condensed);  	break; @@ -209,7 +207,8 @@ format_field(kadm5_principal_ent_t princ, unsigned int field,  	snprintf(buf, buf_len, "%d", princ->kvno);  	break;      case KADM5_MKVNO: -	snprintf(buf, buf_len, "%d", princ->mkvno); +	/* XXX libkadm5srv decrypts the keys, so mkvno is always 0. */ +	strlcpy(buf, "unknown", buf_len);  	break;      case KADM5_LAST_SUCCESS:  	time_t2str(princ->last_success, buf, buf_len, !condensed); @@ -246,7 +245,7 @@ format_field(kadm5_principal_ent_t princ, unsigned int field,  	krb5_tl_data *tl;  	for (tl = princ->tl_data; tl != NULL; tl = tl->tl_data_next) -	    if (tl->tl_data_type == subfield) +	    if ((unsigned)tl->tl_data_type == subfield)  		break;  	if (tl == NULL) {  	    strlcpy(buf, "", buf_len); @@ -262,7 +261,8 @@ format_field(kadm5_principal_ent_t princ, unsigned int field,  	case KRB5_TL_PKINIT_ACL: {  	    HDB_Ext_PKINIT_acl acl;  	    size_t size; -	    int i, ret; +	    int ret; +	    size_t i;  	    ret = decode_HDB_Ext_PKINIT_acl(tl->tl_data_contents,  					    tl->tl_data_length, @@ -294,7 +294,8 @@ format_field(kadm5_principal_ent_t princ, unsigned int field,  	case KRB5_TL_ALIASES: {  	    HDB_Ext_Aliases alias;  	    size_t size; -	    int i, ret; +	    int ret; +	    size_t i;  	    ret = decode_HDB_Ext_Aliases(tl->tl_data_contents,  					 tl->tl_data_length, @@ -310,7 +311,7 @@ format_field(kadm5_principal_ent_t princ, unsigned int field,  		ret = krb5_unparse_name(context, &alias.aliases.val[i], &p);  		if (ret)  		    break; -		if (i < 0) +		if (i > 0)  		    strlcat(buf, " ", buf_len);  		strlcat(buf, p, buf_len);  		free(p); @@ -335,7 +336,7 @@ print_entry_short(struct get_entry_data *data, kadm5_principal_ent_t princ)  {      char buf[1024];      struct field_info *f; -     +      for(f = data->chead; f != NULL; f = f->next) {  	format_field(princ, f->ff->fieldvalue, f->ff->subvalue, buf, sizeof(buf), 1);  	rtbl_add_column_entry_by_id(data->table, f->ff->fieldvalue, buf); @@ -348,7 +349,7 @@ print_entry_long(struct get_entry_data *data, kadm5_principal_ent_t princ)      char buf[1024];      struct field_info *f;      int width = 0; -     +      for(f = data->chead; f != NULL; f = f->next) {  	int w = strlen(f->header ? f->header : f->ff->def_longheader);  	if(w > width) @@ -367,9 +368,9 @@ do_get_entry(krb5_principal principal, void *data)      kadm5_principal_ent_rec princ;      krb5_error_code ret;      struct get_entry_data *e = data; -     +      memset(&princ, 0, sizeof(princ)); -    ret = kadm5_get_principal(kadm_handle, principal,  +    ret = kadm5_get_principal(kadm_handle, principal,  			      &princ,  			      e->mask | e->extra_mask);      if(ret) @@ -420,9 +421,35 @@ setup_columns(struct get_entry_data *data, const char *column_info)      return 0;  } +static int +do_list_entry(krb5_principal principal, void *data) +{ +    char buf[1024]; +    krb5_error_code ret; + +    ret = krb5_unparse_name_fixed_short(context, principal, buf, sizeof(buf)); +    if (ret != 0) +        return ret; +    printf("%s\n", buf); +    return 0; +} + +static int +listit(const char *funcname, int argc, char **argv) +{ +    int i; +    krb5_error_code ret, saved_ret = 0; + +    for (i = 0; i < argc; i++) { +	ret = foreach_principal(argv[i], do_list_entry, funcname, NULL); +        if (saved_ret == 0 && ret != 0) +            saved_ret = ret; +    } +    return saved_ret != 0; +} +  #define DEFAULT_COLUMNS_SHORT "principal,princ_expire_time,pw_expiration,last_pwd_change,max_life,max_rlife"  #define DEFAULT_COLUMNS_LONG "principal,princ_expire_time,pw_expiration,last_pwd_change,max_life,max_rlife,kvno,mkvno,last_success,last_failed,fail_auth_count,mod_time,mod_name,attributes,keytypes,pkinit-acl,aliases" -#define DEFAULT_COLUMNS_TERSE "principal="  static int  getit(struct get_options *opt, const char *name, int argc, char **argv) @@ -430,7 +457,7 @@ getit(struct get_options *opt, const char *name, int argc, char **argv)      int i;      krb5_error_code ret;      struct get_entry_data data; -     +      if(opt->long_flag == -1 && (opt->short_flag == 1 || opt->terse_flag == 1))  	opt->long_flag = 0;      if(opt->short_flag == -1 && (opt->long_flag == 1 || opt->terse_flag == 1)) @@ -440,13 +467,16 @@ getit(struct get_options *opt, const char *name, int argc, char **argv)      if(opt->long_flag == 0 && opt->short_flag == 0 && opt->terse_flag == 0)  	opt->short_flag = 1; +    if (opt->terse_flag) +        return listit(name, argc, argv); +      data.table = NULL;      data.chead = NULL;      data.ctail = &data.chead;      data.mask = 0;      data.extra_mask = 0; -    if(opt->short_flag || opt->terse_flag) { +    if(opt->short_flag) {  	data.table = rtbl_create();  	rtbl_set_separator(data.table, "  ");  	data.format = print_entry_short; @@ -455,24 +485,20 @@ getit(struct get_options *opt, const char *name, int argc, char **argv)      if(opt->column_info_string == NULL) {  	if(opt->long_flag)  	    ret = setup_columns(&data, DEFAULT_COLUMNS_LONG); -	else if(opt->short_flag) +	else  	    ret = setup_columns(&data, DEFAULT_COLUMNS_SHORT); -	else { -	    ret = setup_columns(&data, DEFAULT_COLUMNS_TERSE); -	    rtbl_set_flags(data.table, RTBL_HEADER_STYLE_NONE); -	}      } else  	ret = setup_columns(&data, opt->column_info_string); -	 +      if(ret != 0) {  	if(data.table != NULL)  	    rtbl_destroy(data.table);  	return 0;      } -     +      for(i = 0; i < argc; i++) -	ret = foreach_principal(argv[i], do_get_entry, "get", &data); -     +	ret = foreach_principal(argv[i], do_get_entry, name, &data); +      if(data.table != NULL) {  	rtbl_format(data.table, stdout);  	rtbl_destroy(data.table); | 
