17c478bd9Sstevel@tonic-gate /* 27c478bd9Sstevel@tonic-gate * CDDL HEADER START 37c478bd9Sstevel@tonic-gate * 47c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the 5*013a79b2SRameshkumar Ramasamy * Common Development and Distribution License (the "License"). 6*013a79b2SRameshkumar Ramasamy * You may not use this file except in compliance with the License. 77c478bd9Sstevel@tonic-gate * 87c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 97c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 107c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions 117c478bd9Sstevel@tonic-gate * and limitations under the License. 127c478bd9Sstevel@tonic-gate * 137c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 147c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 157c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 167c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 177c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 187c478bd9Sstevel@tonic-gate * 197c478bd9Sstevel@tonic-gate * CDDL HEADER END 207c478bd9Sstevel@tonic-gate */ 21*013a79b2SRameshkumar Ramasamy 227c478bd9Sstevel@tonic-gate /* 23*013a79b2SRameshkumar Ramasamy * Copyright 2008 Sun Microsystems, Inc. All rights reserved. 247c478bd9Sstevel@tonic-gate * Use is subject to license terms. 257c478bd9Sstevel@tonic-gate */ 267c478bd9Sstevel@tonic-gate 277c478bd9Sstevel@tonic-gate /* 287c478bd9Sstevel@tonic-gate * This is the main program file for the configuration administration 297c478bd9Sstevel@tonic-gate * command as set out in manual page cfgadm(1M). It uses the configuration 307c478bd9Sstevel@tonic-gate * administration library interface, libcfgadm, as set out in manual 317c478bd9Sstevel@tonic-gate * page config_admin(3X). 327c478bd9Sstevel@tonic-gate */ 337c478bd9Sstevel@tonic-gate 347c478bd9Sstevel@tonic-gate #include <stdio.h> 357c478bd9Sstevel@tonic-gate #include <stdlib.h> 367c478bd9Sstevel@tonic-gate #include <string.h> 377c478bd9Sstevel@tonic-gate #include <locale.h> 387c478bd9Sstevel@tonic-gate #include <langinfo.h> 397c478bd9Sstevel@tonic-gate #include <time.h> 407c478bd9Sstevel@tonic-gate #include <assert.h> 417c478bd9Sstevel@tonic-gate #include <sys/types.h> 427c478bd9Sstevel@tonic-gate #include <sys/stat.h> 437c478bd9Sstevel@tonic-gate #include <sys/param.h> 447c478bd9Sstevel@tonic-gate #include <sys/sunddi.h> 457c478bd9Sstevel@tonic-gate #include <sys/openpromio.h> 467c478bd9Sstevel@tonic-gate #include <sys/ddi_impldefs.h> 477c478bd9Sstevel@tonic-gate #include <sys/systeminfo.h> 487c478bd9Sstevel@tonic-gate #include <ctype.h> 497c478bd9Sstevel@tonic-gate 507c478bd9Sstevel@tonic-gate #include <config_admin.h> 517c478bd9Sstevel@tonic-gate #include "cfgadm.h" 527c478bd9Sstevel@tonic-gate 537c478bd9Sstevel@tonic-gate #define S_FREE(x) (((x) != NULL) ? (free(x), (x) = NULL) : (void *)0) 547c478bd9Sstevel@tonic-gate #define GET_DYN(a) (strstr((a), CFGA_DYN_SEP)) 557c478bd9Sstevel@tonic-gate /* 567c478bd9Sstevel@tonic-gate * forward declarations 577c478bd9Sstevel@tonic-gate */ 587c478bd9Sstevel@tonic-gate static char *basename(char *); 597c478bd9Sstevel@tonic-gate static void cfgadm_error(int, char *); 607c478bd9Sstevel@tonic-gate static int confirm_interactive(void *, const char *); 617c478bd9Sstevel@tonic-gate static int confirm_no(void *, const char *); 627c478bd9Sstevel@tonic-gate static int confirm_yes(void *, const char *); 637c478bd9Sstevel@tonic-gate static void usage(void); 647c478bd9Sstevel@tonic-gate static void usage_field(void); 657c478bd9Sstevel@tonic-gate static int extract_list_suboptions(char *, char **, char **, char **, 667c478bd9Sstevel@tonic-gate int *, char **, char **, char **); 677c478bd9Sstevel@tonic-gate static int message_output(void *appdata_ptr, const char *message); 687c478bd9Sstevel@tonic-gate static void *config_calloc_check(size_t, size_t); 697c478bd9Sstevel@tonic-gate static cfga_ap_types_t find_arg_type(const char *); 707c478bd9Sstevel@tonic-gate static int yesno(char *, char *); 717c478bd9Sstevel@tonic-gate 727c478bd9Sstevel@tonic-gate 737c478bd9Sstevel@tonic-gate static int compare_ap_id(cfga_list_data_t *, cfga_list_data_t *, match_type_t); 747c478bd9Sstevel@tonic-gate static int compare_r_state(cfga_list_data_t *, cfga_list_data_t *, 757c478bd9Sstevel@tonic-gate match_type_t); 767c478bd9Sstevel@tonic-gate static int compare_o_state(cfga_list_data_t *, cfga_list_data_t *, 777c478bd9Sstevel@tonic-gate match_type_t); 787c478bd9Sstevel@tonic-gate static int compare_cond(cfga_list_data_t *, cfga_list_data_t *, match_type_t); 797c478bd9Sstevel@tonic-gate static int compare_time(cfga_list_data_t *, cfga_list_data_t *, match_type_t); 807c478bd9Sstevel@tonic-gate static int compare_info(cfga_list_data_t *, cfga_list_data_t *, match_type_t); 817c478bd9Sstevel@tonic-gate static int compare_type(cfga_list_data_t *, cfga_list_data_t *, match_type_t); 827c478bd9Sstevel@tonic-gate static int compare_busy(cfga_list_data_t *, cfga_list_data_t *, match_type_t); 837c478bd9Sstevel@tonic-gate static int compare_class(cfga_list_data_t *, cfga_list_data_t *, match_type_t); 847c478bd9Sstevel@tonic-gate static int compare_null(cfga_list_data_t *, cfga_list_data_t *, match_type_t); 857c478bd9Sstevel@tonic-gate static void print_log_id(cfga_list_data_t *, int, char *); 867c478bd9Sstevel@tonic-gate static void print_r_state(cfga_list_data_t *, int, char *); 877c478bd9Sstevel@tonic-gate static void print_o_state(cfga_list_data_t *, int, char *); 887c478bd9Sstevel@tonic-gate static void print_cond(cfga_list_data_t *, int, char *); 897c478bd9Sstevel@tonic-gate static void print_time(cfga_list_data_t *, int, char *); 907c478bd9Sstevel@tonic-gate static void print_time_p(cfga_list_data_t *, int, char *); 917c478bd9Sstevel@tonic-gate static void print_info(cfga_list_data_t *, int, char *); 927c478bd9Sstevel@tonic-gate static void print_type(cfga_list_data_t *, int, char *); 937c478bd9Sstevel@tonic-gate static void print_busy(cfga_list_data_t *, int, char *); 947c478bd9Sstevel@tonic-gate static void print_phys_id(cfga_list_data_t *, int, char *); 957c478bd9Sstevel@tonic-gate static void print_class(cfga_list_data_t *, int, char *); 967c478bd9Sstevel@tonic-gate static void print_null(cfga_list_data_t *, int, char *); 977c478bd9Sstevel@tonic-gate static int count_fields(char *, char); 987c478bd9Sstevel@tonic-gate static int process_sort_fields(int, struct sort_el *, char *); 997c478bd9Sstevel@tonic-gate static int process_fields(int, struct print_col *, int, char *); 1007c478bd9Sstevel@tonic-gate static cfga_err_t print_fields(int, struct print_col *, int, int, char *, 1017c478bd9Sstevel@tonic-gate cfga_list_data_t *, FILE *); 1027c478bd9Sstevel@tonic-gate static int ldata_compare(const void *, const void *); 1037c478bd9Sstevel@tonic-gate 1047c478bd9Sstevel@tonic-gate static void arg_got_resp(ap_arg_t *inp, ap_out_t *out_array, int nouts, 1057c478bd9Sstevel@tonic-gate int dyn_exp); 1067c478bd9Sstevel@tonic-gate static void out_was_req(ap_out_t *outp, ap_arg_t *in_array, int nargs, 1077c478bd9Sstevel@tonic-gate int no_dyn); 1087c478bd9Sstevel@tonic-gate static void report_no_response(ap_arg_t *arg_array, int napids_to_list); 1097c478bd9Sstevel@tonic-gate 1107c478bd9Sstevel@tonic-gate static cfga_err_t set_log_flt(cfga_list_data_t *p, const char *val); 1117c478bd9Sstevel@tonic-gate static cfga_err_t set_type_flt(cfga_list_data_t *p, const char *val); 1127c478bd9Sstevel@tonic-gate static cfga_err_t set_class_flt(cfga_list_data_t *p, const char *val); 1137c478bd9Sstevel@tonic-gate 1147c478bd9Sstevel@tonic-gate static char *get_dyn(const char *ap_id); 1157c478bd9Sstevel@tonic-gate static void remove_dyn(char *ap_id); 1163977d6cdSvikram static char *s_strdup(char *str); 1177c478bd9Sstevel@tonic-gate 1187c478bd9Sstevel@tonic-gate /* 1197c478bd9Sstevel@tonic-gate * global data 1207c478bd9Sstevel@tonic-gate */ 1217c478bd9Sstevel@tonic-gate /* command name for messages */ 1227c478bd9Sstevel@tonic-gate static char *cmdname; 1237c478bd9Sstevel@tonic-gate 1247c478bd9Sstevel@tonic-gate /* 1257c478bd9Sstevel@tonic-gate * control for comparing, printing and filtering cfga_list_data 1267c478bd9Sstevel@tonic-gate * NOTE:Field names (i.e. member 0 of field_info struct) may not contain '('. 1277c478bd9Sstevel@tonic-gate * The post filtering code depends on it. 1287c478bd9Sstevel@tonic-gate * NOTE:A NULL value for the set_filter member indicates that filtering based 1297c478bd9Sstevel@tonic-gate * on that field is currently not supported. 1307c478bd9Sstevel@tonic-gate */ 1317c478bd9Sstevel@tonic-gate static struct field_info all_fields[] = { 1327c478bd9Sstevel@tonic-gate {"ap_id", "Ap_Id", SZ_EL(ap_log_id), compare_ap_id, print_log_id, set_log_flt}, 1337c478bd9Sstevel@tonic-gate {"r_state", "Receptacle", STATE_WIDTH, compare_r_state, print_r_state, NULL}, 1347c478bd9Sstevel@tonic-gate {"o_state", "Occupant", STATE_WIDTH, compare_o_state, print_o_state, NULL}, 1357c478bd9Sstevel@tonic-gate {"condition", "Condition", COND_WIDTH, compare_cond, print_cond, NULL}, 1367c478bd9Sstevel@tonic-gate {"status_time", "When", TIME_WIDTH, compare_time, print_time, NULL}, 1377c478bd9Sstevel@tonic-gate {"status_time_p", "When", TIME_P_WIDTH, compare_time, print_time_p, NULL}, 1387c478bd9Sstevel@tonic-gate {"info", "Information", SZ_EL(ap_info), compare_info, print_info, NULL}, 1397c478bd9Sstevel@tonic-gate {"type", "Type", SZ_EL(ap_type), compare_type, print_type, set_type_flt}, 1407c478bd9Sstevel@tonic-gate {"busy", "Busy", 8, compare_busy, print_busy, NULL}, 1417c478bd9Sstevel@tonic-gate {"physid", "Phys_Id", SZ_EL(ap_phys_id), compare_ap_id, print_phys_id, NULL}, 1427c478bd9Sstevel@tonic-gate {"class", "Class", SZ_EL(ap_class), compare_class, print_class, set_class_flt} 1437c478bd9Sstevel@tonic-gate }; 1447c478bd9Sstevel@tonic-gate 1457c478bd9Sstevel@tonic-gate #define PREFILT_CLASS_STR "class=" 1467c478bd9Sstevel@tonic-gate 1477c478bd9Sstevel@tonic-gate typedef struct { 1487c478bd9Sstevel@tonic-gate cfga_list_data_t ldata; /* Selection criteria */ 1497c478bd9Sstevel@tonic-gate match_type_t match_type_p[N_FIELDS]; /* Type of match */ 1507c478bd9Sstevel@tonic-gate } post_filter_t; 1517c478bd9Sstevel@tonic-gate 1527c478bd9Sstevel@tonic-gate static struct field_info null_field = 1537c478bd9Sstevel@tonic-gate {"null", "", 0, compare_null, print_null, NULL}; 1547c478bd9Sstevel@tonic-gate 1557c478bd9Sstevel@tonic-gate static struct sort_el *sort_list; /* Used in ldata_compare() */ 1567c478bd9Sstevel@tonic-gate static int nsort_list; 1577c478bd9Sstevel@tonic-gate static char unk_field[] = "%s: field \"%s\" unknown\n"; 1587c478bd9Sstevel@tonic-gate 1597c478bd9Sstevel@tonic-gate static char aptype_no_dyn[] = "%s: Invalid ap_id: %s\n"; 1607c478bd9Sstevel@tonic-gate 1617c478bd9Sstevel@tonic-gate /* strings that make up the usage message */ 1627c478bd9Sstevel@tonic-gate static char *usage_tab[] = { 1637c478bd9Sstevel@tonic-gate " %s [-f] [-y|-n] [-v] [-o hardware_opts ] -c function ap_id [ap_id...]\n", 1647c478bd9Sstevel@tonic-gate " %s [-f] [-y|-n] [-v] [-o hardware_opts ] -x function ap_id [ap_id...]\n", 1657c478bd9Sstevel@tonic-gate " %s [-v] [-s listing_options ] [-o hardware_opts ] [-a]\n" 1667c478bd9Sstevel@tonic-gate "\t[-l [ap_id|ap_type...]]\n", 1677c478bd9Sstevel@tonic-gate " %s [-v] [-o hardware_opts ] -t ap_id [ap_id...]\n", 1687c478bd9Sstevel@tonic-gate " %s [-v] [-o hardware_opts ] -h [ap_id|ap_type...]\n", 1697c478bd9Sstevel@tonic-gate }; 1707c478bd9Sstevel@tonic-gate 1717c478bd9Sstevel@tonic-gate /* Type of matches currently supported by the select sub-option */ 1727c478bd9Sstevel@tonic-gate static match_cvt_t match_type_array[] = { 1737c478bd9Sstevel@tonic-gate {"partial", CFGA_MATCH_PARTIAL}, 1747c478bd9Sstevel@tonic-gate {"exact", CFGA_MATCH_EXACT} 1757c478bd9Sstevel@tonic-gate }; 1767c478bd9Sstevel@tonic-gate 1777c478bd9Sstevel@tonic-gate #define N_MATCH_TYPES (sizeof (match_type_array)/sizeof (match_type_array[0])) 1787c478bd9Sstevel@tonic-gate 1797c478bd9Sstevel@tonic-gate static cfga_err_t setup_filter(const char *selectp, const char *matchp, 1807c478bd9Sstevel@tonic-gate post_filter_t *post_filtp, char **prefilt_optpp); 1817c478bd9Sstevel@tonic-gate static cfga_err_t parse_select_opt(const char *selectp, 1827c478bd9Sstevel@tonic-gate post_filter_t *post_filtp, match_type_t match_type); 1837c478bd9Sstevel@tonic-gate static int do_config_list(int, char *[], cfga_list_data_t *, int, char *, 1847c478bd9Sstevel@tonic-gate char *, char *, int, char *, post_filter_t *, int); 1857c478bd9Sstevel@tonic-gate static void do_post_filter(ap_out_t *outp, post_filter_t *post_filtp, int *jp); 1867c478bd9Sstevel@tonic-gate 1877c478bd9Sstevel@tonic-gate 1887c478bd9Sstevel@tonic-gate /* 1897c478bd9Sstevel@tonic-gate * main - the main routine of cfgadm, processes the command line 1907c478bd9Sstevel@tonic-gate * and dispatches functions off to libraries. 1917c478bd9Sstevel@tonic-gate */ 1923977d6cdSvikram int 1937c478bd9Sstevel@tonic-gate main( 1947c478bd9Sstevel@tonic-gate int argc, 1957c478bd9Sstevel@tonic-gate char *argv[]) 1967c478bd9Sstevel@tonic-gate { 1977c478bd9Sstevel@tonic-gate extern char *optarg; 1987c478bd9Sstevel@tonic-gate extern int optind; 1997c478bd9Sstevel@tonic-gate int c; 2007c478bd9Sstevel@tonic-gate char *subopts; 2017c478bd9Sstevel@tonic-gate char *subvalue; 2027c478bd9Sstevel@tonic-gate char *const *ap_args = NULL; 2037c478bd9Sstevel@tonic-gate cfga_cmd_t sc_opt = NULL; 2047c478bd9Sstevel@tonic-gate struct cfga_confirm confirm; 2057c478bd9Sstevel@tonic-gate struct cfga_msg message; 2067c478bd9Sstevel@tonic-gate int ret = CFGA_ERROR; 2077c478bd9Sstevel@tonic-gate int i; 2087c478bd9Sstevel@tonic-gate char *estrp = NULL; 2097c478bd9Sstevel@tonic-gate cfga_op_t action = CFGA_OP_NONE; 2107c478bd9Sstevel@tonic-gate char *plat_opts = NULL; 2117c478bd9Sstevel@tonic-gate char *act_arg = NULL; 2127c478bd9Sstevel@tonic-gate enum confirm confarg = CONFIRM_DEFAULT; 2137c478bd9Sstevel@tonic-gate char *list_opts = NULL; 2147c478bd9Sstevel@tonic-gate cfga_flags_t flags = 0; 2157c478bd9Sstevel@tonic-gate int arg_error = 0; 2167c478bd9Sstevel@tonic-gate int dyn_exp = 0; 2177c478bd9Sstevel@tonic-gate 2187c478bd9Sstevel@tonic-gate estrp = NULL; 2197c478bd9Sstevel@tonic-gate if (argc > 0) 2207c478bd9Sstevel@tonic-gate cmdname = basename(argv[0]); 2217c478bd9Sstevel@tonic-gate else 2227c478bd9Sstevel@tonic-gate cmdname = "cfgadm"; 2237c478bd9Sstevel@tonic-gate (void) setlocale(LC_ALL, ""); 2247c478bd9Sstevel@tonic-gate #if !defined(TEXT_DOMAIN) 2257c478bd9Sstevel@tonic-gate #define TEXT_DOMAIN "SYS_TEST" 2267c478bd9Sstevel@tonic-gate #endif 2277c478bd9Sstevel@tonic-gate (void) textdomain(TEXT_DOMAIN); 2287c478bd9Sstevel@tonic-gate 2297c478bd9Sstevel@tonic-gate while ((c = getopt(argc, argv, OPTIONS)) != EOF) { 2307c478bd9Sstevel@tonic-gate static char dup_action[] = 2317c478bd9Sstevel@tonic-gate "%s: more than one action specified (-c,-l,-t,-x)\n"; 2327c478bd9Sstevel@tonic-gate static char dup_option[] = 2337c478bd9Sstevel@tonic-gate "%s: more than one -%c option specified\n"; 2347c478bd9Sstevel@tonic-gate switch (c) { 2357c478bd9Sstevel@tonic-gate case 'a': 2367c478bd9Sstevel@tonic-gate if (dyn_exp) { 2377c478bd9Sstevel@tonic-gate arg_error = 1; 2387c478bd9Sstevel@tonic-gate (void) fprintf(stderr, gettext(dup_option), 2397c478bd9Sstevel@tonic-gate cmdname, c); 2407c478bd9Sstevel@tonic-gate } 2417c478bd9Sstevel@tonic-gate dyn_exp = 1; 2427c478bd9Sstevel@tonic-gate break; 2437c478bd9Sstevel@tonic-gate case 'c': 2447c478bd9Sstevel@tonic-gate if (action != CFGA_OP_NONE) { 2457c478bd9Sstevel@tonic-gate arg_error = 1; 2467c478bd9Sstevel@tonic-gate (void) fprintf(stderr, gettext(dup_action), 2477c478bd9Sstevel@tonic-gate cmdname); 2487c478bd9Sstevel@tonic-gate } 2497c478bd9Sstevel@tonic-gate action = CFGA_OP_CHANGE_STATE; 2507c478bd9Sstevel@tonic-gate subopts = optarg; 2517c478bd9Sstevel@tonic-gate subvalue = NULL; 2527c478bd9Sstevel@tonic-gate /* 2537c478bd9Sstevel@tonic-gate * Reject -c suboption if they are unrecognized 2547c478bd9Sstevel@tonic-gate * or more than one or have a associated value. 2557c478bd9Sstevel@tonic-gate */ 2567c478bd9Sstevel@tonic-gate if ((sc_opt = getsubopt(&subopts, state_opts, 2577c478bd9Sstevel@tonic-gate &subvalue)) == -1 || *subopts != '\0' || 2587c478bd9Sstevel@tonic-gate subvalue != NULL) { 2597c478bd9Sstevel@tonic-gate arg_error = 1; 2607c478bd9Sstevel@tonic-gate break; 2617c478bd9Sstevel@tonic-gate } 2627c478bd9Sstevel@tonic-gate break; 2637c478bd9Sstevel@tonic-gate case 'f': 2647c478bd9Sstevel@tonic-gate if ((flags & CFGA_FLAG_FORCE) != 0) { 2657c478bd9Sstevel@tonic-gate arg_error = 1; 2667c478bd9Sstevel@tonic-gate (void) fprintf(stderr, gettext(dup_option), 2677c478bd9Sstevel@tonic-gate cmdname, c); 2687c478bd9Sstevel@tonic-gate } 2697c478bd9Sstevel@tonic-gate flags |= CFGA_FLAG_FORCE; 2707c478bd9Sstevel@tonic-gate break; 2717c478bd9Sstevel@tonic-gate case 'h': 2727c478bd9Sstevel@tonic-gate if (action != CFGA_OP_NONE) { 2737c478bd9Sstevel@tonic-gate arg_error = 1; 2747c478bd9Sstevel@tonic-gate (void) fprintf(stderr, gettext(dup_action), 2757c478bd9Sstevel@tonic-gate cmdname); 2767c478bd9Sstevel@tonic-gate } 2777c478bd9Sstevel@tonic-gate action = CFGA_OP_HELP; 2787c478bd9Sstevel@tonic-gate break; 2797c478bd9Sstevel@tonic-gate case 'l': 2807c478bd9Sstevel@tonic-gate if (action != CFGA_OP_NONE) { 2817c478bd9Sstevel@tonic-gate arg_error = 1; 2827c478bd9Sstevel@tonic-gate (void) fprintf(stderr, gettext(dup_action), 2837c478bd9Sstevel@tonic-gate cmdname); 2847c478bd9Sstevel@tonic-gate } 2857c478bd9Sstevel@tonic-gate action = CFGA_OP_LIST; 2867c478bd9Sstevel@tonic-gate break; 2877c478bd9Sstevel@tonic-gate case 'n': 2887c478bd9Sstevel@tonic-gate if (confarg != CONFIRM_DEFAULT) { 2897c478bd9Sstevel@tonic-gate arg_error = 1; 2907c478bd9Sstevel@tonic-gate (void) fprintf(stderr, gettext(dup_option), 2917c478bd9Sstevel@tonic-gate cmdname, c); 2927c478bd9Sstevel@tonic-gate } 2937c478bd9Sstevel@tonic-gate confarg = CONFIRM_NO; 2947c478bd9Sstevel@tonic-gate break; 2957c478bd9Sstevel@tonic-gate case 'o': 2967c478bd9Sstevel@tonic-gate if (plat_opts != NULL) { 2977c478bd9Sstevel@tonic-gate arg_error = 1; 2987c478bd9Sstevel@tonic-gate (void) fprintf(stderr, gettext(dup_option), 2997c478bd9Sstevel@tonic-gate cmdname, c); 3007c478bd9Sstevel@tonic-gate } 3017c478bd9Sstevel@tonic-gate plat_opts = optarg; 3027c478bd9Sstevel@tonic-gate break; 3037c478bd9Sstevel@tonic-gate case 's': 3047c478bd9Sstevel@tonic-gate if (list_opts != NULL) { 3057c478bd9Sstevel@tonic-gate arg_error = 1; 3067c478bd9Sstevel@tonic-gate (void) fprintf(stderr, gettext(dup_option), 3077c478bd9Sstevel@tonic-gate cmdname, c); 3087c478bd9Sstevel@tonic-gate } 3097c478bd9Sstevel@tonic-gate list_opts = optarg; 3107c478bd9Sstevel@tonic-gate break; 3117c478bd9Sstevel@tonic-gate case 't': 3127c478bd9Sstevel@tonic-gate if (action != CFGA_OP_NONE) { 3137c478bd9Sstevel@tonic-gate arg_error = 1; 3147c478bd9Sstevel@tonic-gate (void) fprintf(stderr, gettext(dup_action), 3157c478bd9Sstevel@tonic-gate cmdname); 3167c478bd9Sstevel@tonic-gate } 3177c478bd9Sstevel@tonic-gate action = CFGA_OP_TEST; 3187c478bd9Sstevel@tonic-gate break; 3197c478bd9Sstevel@tonic-gate case 'x': 3207c478bd9Sstevel@tonic-gate if (action != CFGA_OP_NONE) { 3217c478bd9Sstevel@tonic-gate arg_error = 1; 3227c478bd9Sstevel@tonic-gate (void) fprintf(stderr, gettext(dup_action), 3237c478bd9Sstevel@tonic-gate cmdname); 3247c478bd9Sstevel@tonic-gate } 3257c478bd9Sstevel@tonic-gate action = CFGA_OP_PRIVATE; 3267c478bd9Sstevel@tonic-gate act_arg = optarg; 3277c478bd9Sstevel@tonic-gate break; 3287c478bd9Sstevel@tonic-gate case 'v': 3297c478bd9Sstevel@tonic-gate if ((flags & CFGA_FLAG_VERBOSE) != 0) { 3307c478bd9Sstevel@tonic-gate arg_error = 1; 3317c478bd9Sstevel@tonic-gate (void) fprintf(stderr, gettext(dup_option), 3327c478bd9Sstevel@tonic-gate cmdname, c); 3337c478bd9Sstevel@tonic-gate } 3347c478bd9Sstevel@tonic-gate flags |= CFGA_FLAG_VERBOSE; 3357c478bd9Sstevel@tonic-gate break; 3367c478bd9Sstevel@tonic-gate case 'y': 3377c478bd9Sstevel@tonic-gate if (confarg != CONFIRM_DEFAULT) { 3387c478bd9Sstevel@tonic-gate arg_error = 1; 3397c478bd9Sstevel@tonic-gate (void) fprintf(stderr, gettext(dup_option), 3407c478bd9Sstevel@tonic-gate cmdname, c); 3417c478bd9Sstevel@tonic-gate } 3427c478bd9Sstevel@tonic-gate confarg = CONFIRM_YES; 3437c478bd9Sstevel@tonic-gate break; 3447c478bd9Sstevel@tonic-gate case '?': /* getopts issues message is this case */ 3457c478bd9Sstevel@tonic-gate default: /* catch programming errors */ 3467c478bd9Sstevel@tonic-gate arg_error = 1; 3477c478bd9Sstevel@tonic-gate break; 3487c478bd9Sstevel@tonic-gate } 3497c478bd9Sstevel@tonic-gate } 3507c478bd9Sstevel@tonic-gate 3517c478bd9Sstevel@tonic-gate /* default action is list */ 3527c478bd9Sstevel@tonic-gate if (action == CFGA_OP_NONE) 3537c478bd9Sstevel@tonic-gate action = CFGA_OP_LIST; 3547c478bd9Sstevel@tonic-gate 3557c478bd9Sstevel@tonic-gate /* -s and -a option only for list */ 3567c478bd9Sstevel@tonic-gate if (action != CFGA_OP_LIST && (list_opts != NULL || dyn_exp)) { 3577c478bd9Sstevel@tonic-gate arg_error = 1; 3587c478bd9Sstevel@tonic-gate } 3597c478bd9Sstevel@tonic-gate 3607c478bd9Sstevel@tonic-gate if (arg_error) { 3617c478bd9Sstevel@tonic-gate usage(); 3627c478bd9Sstevel@tonic-gate exit(EXIT_ARGERROR); 3637c478bd9Sstevel@tonic-gate /*NOTREACHED*/ 3647c478bd9Sstevel@tonic-gate } 3657c478bd9Sstevel@tonic-gate 366*013a79b2SRameshkumar Ramasamy if (getzoneid() != GLOBAL_ZONEID) { 367*013a79b2SRameshkumar Ramasamy cfgadm_error(CFGA_NOTSUPP, 368*013a79b2SRameshkumar Ramasamy gettext("cfgadm can only be run from the global zone")); 369*013a79b2SRameshkumar Ramasamy exit(EXIT_NOTSUPP); 370*013a79b2SRameshkumar Ramasamy } 371*013a79b2SRameshkumar Ramasamy 3727c478bd9Sstevel@tonic-gate ap_args = &argv[optind]; 3737c478bd9Sstevel@tonic-gate 3747c478bd9Sstevel@tonic-gate /* 3757c478bd9Sstevel@tonic-gate * If neither -n of -y was specified, interactive confirmation 3767c478bd9Sstevel@tonic-gate * is used. Check if the program has terminal I/O and 3777c478bd9Sstevel@tonic-gate * enforce -n if not. 3787c478bd9Sstevel@tonic-gate */ 3797c478bd9Sstevel@tonic-gate (void) memset(&confirm, 0, sizeof (confirm)); 3807c478bd9Sstevel@tonic-gate if (action == CFGA_OP_CHANGE_STATE || action == CFGA_OP_PRIVATE) { 3817c478bd9Sstevel@tonic-gate if (confarg == CONFIRM_DEFAULT && 3827c478bd9Sstevel@tonic-gate !(isatty(fileno(stdin)) && isatty(fileno(stderr)))) 3837c478bd9Sstevel@tonic-gate confarg = CONFIRM_NO; 3847c478bd9Sstevel@tonic-gate switch (confarg) { 3857c478bd9Sstevel@tonic-gate case CONFIRM_DEFAULT: 3867c478bd9Sstevel@tonic-gate confirm.confirm = confirm_interactive; 3877c478bd9Sstevel@tonic-gate break; 3887c478bd9Sstevel@tonic-gate case CONFIRM_NO: 3897c478bd9Sstevel@tonic-gate confirm.confirm = confirm_no; 3907c478bd9Sstevel@tonic-gate break; 3917c478bd9Sstevel@tonic-gate case CONFIRM_YES: 3927c478bd9Sstevel@tonic-gate confirm.confirm = confirm_yes; 3937c478bd9Sstevel@tonic-gate break; 3947c478bd9Sstevel@tonic-gate default: /* paranoia */ 3957c478bd9Sstevel@tonic-gate abort(); 3967c478bd9Sstevel@tonic-gate /*NOTREACHED*/ 3977c478bd9Sstevel@tonic-gate } 3987c478bd9Sstevel@tonic-gate } 3997c478bd9Sstevel@tonic-gate 4007c478bd9Sstevel@tonic-gate /* 4017c478bd9Sstevel@tonic-gate * set up message output routine 4027c478bd9Sstevel@tonic-gate */ 4037c478bd9Sstevel@tonic-gate message.message_routine = message_output; 4047c478bd9Sstevel@tonic-gate 4057c478bd9Sstevel@tonic-gate switch (action) { 4067c478bd9Sstevel@tonic-gate case CFGA_OP_CHANGE_STATE: 4077c478bd9Sstevel@tonic-gate /* Sanity check - requires an argument */ 4087c478bd9Sstevel@tonic-gate if ((argc - optind) <= 0) { 4097c478bd9Sstevel@tonic-gate usage(); 4107c478bd9Sstevel@tonic-gate break; 4117c478bd9Sstevel@tonic-gate } 4127c478bd9Sstevel@tonic-gate /* Sanity check - args cannot be ap_types */ 4137c478bd9Sstevel@tonic-gate for (i = 0; i < (argc - optind); i++) { 4147c478bd9Sstevel@tonic-gate if (find_arg_type(ap_args[i]) == AP_TYPE) { 4157c478bd9Sstevel@tonic-gate usage(); 4167c478bd9Sstevel@tonic-gate exit(EXIT_ARGERROR); 4177c478bd9Sstevel@tonic-gate /*NOTREACHED*/ 4187c478bd9Sstevel@tonic-gate } 4197c478bd9Sstevel@tonic-gate } 4207c478bd9Sstevel@tonic-gate ret = config_change_state(sc_opt, argc - optind, ap_args, plat_opts, 4217c478bd9Sstevel@tonic-gate &confirm, &message, &estrp, flags); 4227c478bd9Sstevel@tonic-gate if (ret != CFGA_OK) 4237c478bd9Sstevel@tonic-gate cfgadm_error(ret, estrp); 4247c478bd9Sstevel@tonic-gate break; 4257c478bd9Sstevel@tonic-gate case CFGA_OP_PRIVATE: 4267c478bd9Sstevel@tonic-gate /* Sanity check - requires an argument */ 4277c478bd9Sstevel@tonic-gate if ((argc - optind) <= 0) { 4287c478bd9Sstevel@tonic-gate usage(); 4297c478bd9Sstevel@tonic-gate break; 4307c478bd9Sstevel@tonic-gate } 4317c478bd9Sstevel@tonic-gate /* Sanity check - args cannot be ap_types */ 4327c478bd9Sstevel@tonic-gate for (i = 0; i < (argc - optind); i++) { 4337c478bd9Sstevel@tonic-gate if (find_arg_type(ap_args[i]) == AP_TYPE) { 4347c478bd9Sstevel@tonic-gate usage(); 4357c478bd9Sstevel@tonic-gate exit(EXIT_ARGERROR); 4367c478bd9Sstevel@tonic-gate /*NOTREACHED*/ 4377c478bd9Sstevel@tonic-gate } 4387c478bd9Sstevel@tonic-gate } 4397c478bd9Sstevel@tonic-gate 4407c478bd9Sstevel@tonic-gate ret = config_private_func(act_arg, argc - optind, ap_args, 4417c478bd9Sstevel@tonic-gate plat_opts, &confirm, &message, &estrp, flags); 4427c478bd9Sstevel@tonic-gate 4437c478bd9Sstevel@tonic-gate if (ret != CFGA_OK) 4447c478bd9Sstevel@tonic-gate cfgadm_error(ret, estrp); 4457c478bd9Sstevel@tonic-gate break; 4467c478bd9Sstevel@tonic-gate case CFGA_OP_TEST: 4477c478bd9Sstevel@tonic-gate /* Sanity check - requires an argument */ 4487c478bd9Sstevel@tonic-gate if ((argc - optind) <= 0) { 4497c478bd9Sstevel@tonic-gate usage(); 4507c478bd9Sstevel@tonic-gate break; 4517c478bd9Sstevel@tonic-gate } 4527c478bd9Sstevel@tonic-gate 4537c478bd9Sstevel@tonic-gate if ((flags & ~CFGA_FLAG_VERBOSE) != 0) { 4547c478bd9Sstevel@tonic-gate usage(); 4557c478bd9Sstevel@tonic-gate exit(EXIT_ARGERROR); 4567c478bd9Sstevel@tonic-gate /*NOTREACHED*/ 4577c478bd9Sstevel@tonic-gate } 4587c478bd9Sstevel@tonic-gate 4597c478bd9Sstevel@tonic-gate /* Sanity check - args cannot be ap_types */ 4607c478bd9Sstevel@tonic-gate for (i = 0; i < (argc - optind); i++) { 4617c478bd9Sstevel@tonic-gate if (find_arg_type(ap_args[i]) == AP_TYPE) { 4627c478bd9Sstevel@tonic-gate usage(); 4637c478bd9Sstevel@tonic-gate exit(EXIT_ARGERROR); 4647c478bd9Sstevel@tonic-gate /*NOTREACHED*/ 4657c478bd9Sstevel@tonic-gate } 4667c478bd9Sstevel@tonic-gate } 4677c478bd9Sstevel@tonic-gate ret = config_test(argc - optind, ap_args, plat_opts, &message, 4687c478bd9Sstevel@tonic-gate &estrp, flags); 4697c478bd9Sstevel@tonic-gate if (ret != CFGA_OK) 4707c478bd9Sstevel@tonic-gate cfgadm_error(ret, estrp); 4717c478bd9Sstevel@tonic-gate break; 4727c478bd9Sstevel@tonic-gate case CFGA_OP_HELP: 4737c478bd9Sstevel@tonic-gate 4747c478bd9Sstevel@tonic-gate if ((flags & ~CFGA_FLAG_VERBOSE) != 0) { 4757c478bd9Sstevel@tonic-gate usage(); 4767c478bd9Sstevel@tonic-gate exit(EXIT_ARGERROR); 4777c478bd9Sstevel@tonic-gate /*NOTREACHED*/ 4787c478bd9Sstevel@tonic-gate } 4797c478bd9Sstevel@tonic-gate 4807c478bd9Sstevel@tonic-gate /* always do usage? */ 4817c478bd9Sstevel@tonic-gate usage(); 4827c478bd9Sstevel@tonic-gate ret = config_help(argc - optind, ap_args, &message, plat_opts, 4837c478bd9Sstevel@tonic-gate flags); 4847c478bd9Sstevel@tonic-gate if (ret != CFGA_OK) 4857c478bd9Sstevel@tonic-gate cfgadm_error(ret, estrp); 4867c478bd9Sstevel@tonic-gate break; 4877c478bd9Sstevel@tonic-gate 4887c478bd9Sstevel@tonic-gate case CFGA_OP_LIST: { 4893977d6cdSvikram /* 4903977d6cdSvikram * Note that we leak the strdup strings below (we never free 4913977d6cdSvikram * them). This is ok in this context since cfgadm is 4923977d6cdSvikram * a short lived process that will exit shortly freeing 4933977d6cdSvikram * the memory. 4943977d6cdSvikram */ 4957c478bd9Sstevel@tonic-gate cfga_list_data_t *list_array = NULL; 4967c478bd9Sstevel@tonic-gate int nlist = 0; 4973977d6cdSvikram char *sort_fields = s_strdup(DEF_SORT_FIELDS); 4983977d6cdSvikram char *cols = s_strdup(DEF_COLS); 4993977d6cdSvikram char *cols2 = s_strdup(DEF_COLS2); 5007c478bd9Sstevel@tonic-gate int noheadings = 0; 5013977d6cdSvikram char *delim = s_strdup(DEF_DELIM); 5027c478bd9Sstevel@tonic-gate int exitcode = EXIT_OK; 5037c478bd9Sstevel@tonic-gate int i; 5047c478bd9Sstevel@tonic-gate int type = 0; 5057c478bd9Sstevel@tonic-gate char *selectp = NULL, *matchp = NULL, *prefilt_optp = NULL; 5067c478bd9Sstevel@tonic-gate post_filter_t *post_filtp = NULL; 5077c478bd9Sstevel@tonic-gate 5087c478bd9Sstevel@tonic-gate if ((flags & ~CFGA_FLAG_VERBOSE) != 0) { 5097c478bd9Sstevel@tonic-gate usage(); 5107c478bd9Sstevel@tonic-gate exit(EXIT_ARGERROR); 5117c478bd9Sstevel@tonic-gate /*NOTREACHED*/ 5127c478bd9Sstevel@tonic-gate } 5137c478bd9Sstevel@tonic-gate 5147c478bd9Sstevel@tonic-gate if (flags & CFGA_FLAG_VERBOSE) { 5153977d6cdSvikram cols = s_strdup(DEF_COLS_VERBOSE); 5163977d6cdSvikram cols2 = s_strdup(DEF_COLS2_VERBOSE); 5177c478bd9Sstevel@tonic-gate } 5187c478bd9Sstevel@tonic-gate 5197c478bd9Sstevel@tonic-gate if (list_opts != NULL && !extract_list_suboptions(list_opts, 5207c478bd9Sstevel@tonic-gate &sort_fields, &cols, &cols2, &noheadings, &delim, 5217c478bd9Sstevel@tonic-gate &selectp, &matchp)) { 5227c478bd9Sstevel@tonic-gate usage_field(); 5237c478bd9Sstevel@tonic-gate exit(EXIT_ARGERROR); 5247c478bd9Sstevel@tonic-gate /*NOTREACHED*/ 5257c478bd9Sstevel@tonic-gate } 5267c478bd9Sstevel@tonic-gate 5277c478bd9Sstevel@tonic-gate /* 5287c478bd9Sstevel@tonic-gate * Scan any args and see if there are any ap_types. 5297c478bd9Sstevel@tonic-gate * If there are we get all attachment point stats and 5307c478bd9Sstevel@tonic-gate * then filter what gets printed. 5317c478bd9Sstevel@tonic-gate */ 5327c478bd9Sstevel@tonic-gate 5337c478bd9Sstevel@tonic-gate type = 0; 5347c478bd9Sstevel@tonic-gate for (i = 0; i < (argc - optind); i++) { 5357c478bd9Sstevel@tonic-gate if (find_arg_type(ap_args[i]) == AP_TYPE) { 5367c478bd9Sstevel@tonic-gate type = 1; 5377c478bd9Sstevel@tonic-gate /* ap_types cannot have dynamic components */ 5387c478bd9Sstevel@tonic-gate if (get_dyn(ap_args[i]) != NULL) { 5397c478bd9Sstevel@tonic-gate (void) fprintf(stderr, 5407c478bd9Sstevel@tonic-gate gettext(aptype_no_dyn), 5417c478bd9Sstevel@tonic-gate cmdname, ap_args[i]); 5427c478bd9Sstevel@tonic-gate exit(EXIT_ARGERROR); 5437c478bd9Sstevel@tonic-gate /*NOTREACHED*/ 5447c478bd9Sstevel@tonic-gate } 5457c478bd9Sstevel@tonic-gate break; 5467c478bd9Sstevel@tonic-gate } 5477c478bd9Sstevel@tonic-gate } 5487c478bd9Sstevel@tonic-gate 5497c478bd9Sstevel@tonic-gate /* Setup filter */ 5507c478bd9Sstevel@tonic-gate post_filtp = config_calloc_check(1, sizeof (*post_filtp)); 5517c478bd9Sstevel@tonic-gate if (post_filtp == NULL) { 5527c478bd9Sstevel@tonic-gate exit(EXIT_OPFAILED); 5537c478bd9Sstevel@tonic-gate /*NOTREACHED*/ 5547c478bd9Sstevel@tonic-gate } 5557c478bd9Sstevel@tonic-gate if (setup_filter(selectp, matchp, post_filtp, &prefilt_optp) 5567c478bd9Sstevel@tonic-gate != CFGA_OK) { 5577c478bd9Sstevel@tonic-gate S_FREE(post_filtp); 5587c478bd9Sstevel@tonic-gate exit(EXIT_ARGERROR); 5597c478bd9Sstevel@tonic-gate /*NOTREACHED*/ 5607c478bd9Sstevel@tonic-gate } 5617c478bd9Sstevel@tonic-gate 5627c478bd9Sstevel@tonic-gate list_array = NULL; 5637c478bd9Sstevel@tonic-gate exitcode = EXIT_OK; 5647c478bd9Sstevel@tonic-gate 5657c478bd9Sstevel@tonic-gate /* 5667c478bd9Sstevel@tonic-gate * Check for args. No args means find all libs 5677c478bd9Sstevel@tonic-gate * and call the cfga_list_ext routine with no ap_ids specified. 5687c478bd9Sstevel@tonic-gate * With args, if any one of the args are ap_types we 5697c478bd9Sstevel@tonic-gate * again find all attachment points as in the 5707c478bd9Sstevel@tonic-gate * no-args case above and then select which attachment points 5717c478bd9Sstevel@tonic-gate * are actually displayed. 5727c478bd9Sstevel@tonic-gate */ 5737c478bd9Sstevel@tonic-gate if (((argc - optind) == 0) || (type == 1)) { 5747c478bd9Sstevel@tonic-gate /* 5757c478bd9Sstevel@tonic-gate * No args, or atleast 1 ap_type arg 5767c478bd9Sstevel@tonic-gate */ 5777c478bd9Sstevel@tonic-gate ret = config_list_ext(0, NULL, &list_array, 5787c478bd9Sstevel@tonic-gate &nlist, plat_opts, prefilt_optp, &estrp, 5797c478bd9Sstevel@tonic-gate dyn_exp ? CFGA_FLAG_LIST_ALL : 0); 5807c478bd9Sstevel@tonic-gate } else { 5817c478bd9Sstevel@tonic-gate /* 5827c478bd9Sstevel@tonic-gate * If the args are all ap_ids (no ap_types) we call the 5837c478bd9Sstevel@tonic-gate * cfga_list_ext routine with those specific ap_ids. 5847c478bd9Sstevel@tonic-gate */ 5857c478bd9Sstevel@tonic-gate ret = config_list_ext(argc - optind, ap_args, 5867c478bd9Sstevel@tonic-gate &list_array, &nlist, plat_opts, prefilt_optp, 5877c478bd9Sstevel@tonic-gate &estrp, dyn_exp ? CFGA_FLAG_LIST_ALL : 0); 5887c478bd9Sstevel@tonic-gate } 5897c478bd9Sstevel@tonic-gate 5907c478bd9Sstevel@tonic-gate S_FREE(prefilt_optp); 5917c478bd9Sstevel@tonic-gate 5927c478bd9Sstevel@tonic-gate if (ret == CFGA_OK) { 5937c478bd9Sstevel@tonic-gate 5947c478bd9Sstevel@tonic-gate if (do_config_list( 5957c478bd9Sstevel@tonic-gate (argc - optind), &argv[optind], list_array, nlist, 5967c478bd9Sstevel@tonic-gate sort_fields, cols, cols2, noheadings, delim, 5977c478bd9Sstevel@tonic-gate post_filtp, dyn_exp) != CFGA_OK) { 5987c478bd9Sstevel@tonic-gate exitcode = EXIT_ARGERROR; 5997c478bd9Sstevel@tonic-gate } else { 6007c478bd9Sstevel@tonic-gate exitcode = EXIT_OK; 6017c478bd9Sstevel@tonic-gate } 6027c478bd9Sstevel@tonic-gate 6037c478bd9Sstevel@tonic-gate S_FREE(list_array); 6047c478bd9Sstevel@tonic-gate S_FREE(post_filtp); 6057c478bd9Sstevel@tonic-gate 6067c478bd9Sstevel@tonic-gate if (exitcode != EXIT_OK) { 6077c478bd9Sstevel@tonic-gate exit(exitcode); 6087c478bd9Sstevel@tonic-gate /*NOTREACHED*/ 6097c478bd9Sstevel@tonic-gate } 6107c478bd9Sstevel@tonic-gate } else { 6117c478bd9Sstevel@tonic-gate 6127c478bd9Sstevel@tonic-gate S_FREE(post_filtp); 6137c478bd9Sstevel@tonic-gate cfgadm_error(ret, estrp); 6147c478bd9Sstevel@tonic-gate } 6157c478bd9Sstevel@tonic-gate break; 6167c478bd9Sstevel@tonic-gate } 6177c478bd9Sstevel@tonic-gate default: /* paranoia */ 6187c478bd9Sstevel@tonic-gate abort(); 6197c478bd9Sstevel@tonic-gate /*NOTREACHED*/ 6207c478bd9Sstevel@tonic-gate } 6217c478bd9Sstevel@tonic-gate 6227c478bd9Sstevel@tonic-gate if (ret == CFGA_NOTSUPP) { 6233977d6cdSvikram return (EXIT_NOTSUPP); 6247c478bd9Sstevel@tonic-gate } else if (ret != CFGA_OK) { 6253977d6cdSvikram return (EXIT_OPFAILED); 6267c478bd9Sstevel@tonic-gate } else { 6273977d6cdSvikram return (EXIT_OK); 6287c478bd9Sstevel@tonic-gate } 6297c478bd9Sstevel@tonic-gate /*NOTREACHED*/ 6307c478bd9Sstevel@tonic-gate } 6317c478bd9Sstevel@tonic-gate 6327c478bd9Sstevel@tonic-gate /* 6337c478bd9Sstevel@tonic-gate * usage - outputs the usage help message. 6347c478bd9Sstevel@tonic-gate */ 6357c478bd9Sstevel@tonic-gate static void 6367c478bd9Sstevel@tonic-gate usage( 6377c478bd9Sstevel@tonic-gate void) 6387c478bd9Sstevel@tonic-gate { 6397c478bd9Sstevel@tonic-gate int i; 6407c478bd9Sstevel@tonic-gate 6417c478bd9Sstevel@tonic-gate (void) fprintf(stderr, "%s\n", gettext("Usage:")); 6427c478bd9Sstevel@tonic-gate for (i = 0; i < sizeof (usage_tab)/sizeof (usage_tab[0]); i++) { 6437c478bd9Sstevel@tonic-gate (void) fprintf(stderr, gettext(usage_tab[i]), cmdname); 6447c478bd9Sstevel@tonic-gate } 6457c478bd9Sstevel@tonic-gate } 6467c478bd9Sstevel@tonic-gate 6477c478bd9Sstevel@tonic-gate /* 6487c478bd9Sstevel@tonic-gate * Emit an error message. 6497c478bd9Sstevel@tonic-gate * As a side-effect the hardware specific error message is deallocated 6507c478bd9Sstevel@tonic-gate * as described in config_admin(3X). 6517c478bd9Sstevel@tonic-gate */ 6527c478bd9Sstevel@tonic-gate static void 6537c478bd9Sstevel@tonic-gate cfgadm_error(int errnum, char *estrp) 6547c478bd9Sstevel@tonic-gate { 6557c478bd9Sstevel@tonic-gate const char *ep; 6567c478bd9Sstevel@tonic-gate 6577c478bd9Sstevel@tonic-gate ep = config_strerror(errnum); 6587c478bd9Sstevel@tonic-gate if (ep == NULL) 6597c478bd9Sstevel@tonic-gate ep = gettext("configuration administration unknown error"); 6607c478bd9Sstevel@tonic-gate if (estrp != NULL && *estrp != '\0') { 6617c478bd9Sstevel@tonic-gate (void) fprintf(stderr, "%s: %s: %s\n", cmdname, ep, estrp); 6627c478bd9Sstevel@tonic-gate } else { 6637c478bd9Sstevel@tonic-gate (void) fprintf(stderr, "%s: %s\n", cmdname, ep); 6647c478bd9Sstevel@tonic-gate } 6657c478bd9Sstevel@tonic-gate if (estrp != NULL) 6667c478bd9Sstevel@tonic-gate free((void *)estrp); 6677c478bd9Sstevel@tonic-gate if (errnum == CFGA_INVAL) 6687c478bd9Sstevel@tonic-gate usage(); 6697c478bd9Sstevel@tonic-gate } 6707c478bd9Sstevel@tonic-gate 6717c478bd9Sstevel@tonic-gate /* 6727c478bd9Sstevel@tonic-gate * confirm_interactive - prompt user for confirmation 6737c478bd9Sstevel@tonic-gate */ 6747c478bd9Sstevel@tonic-gate static int 6757c478bd9Sstevel@tonic-gate confirm_interactive( 6767c478bd9Sstevel@tonic-gate void *appdata_ptr, 6777c478bd9Sstevel@tonic-gate const char *message) 6787c478bd9Sstevel@tonic-gate { 6797c478bd9Sstevel@tonic-gate static char yeschr[YESNO_STR_MAX + 2]; 6807c478bd9Sstevel@tonic-gate static char nochr[YESNO_STR_MAX + 2]; 6817c478bd9Sstevel@tonic-gate static int inited = 0; 6827c478bd9Sstevel@tonic-gate int isyes; 6837c478bd9Sstevel@tonic-gate 6847c478bd9Sstevel@tonic-gate #ifdef lint 6857c478bd9Sstevel@tonic-gate appdata_ptr = appdata_ptr; 6867c478bd9Sstevel@tonic-gate #endif /* lint */ 6877c478bd9Sstevel@tonic-gate /* 6887c478bd9Sstevel@tonic-gate * First time through initialisation. In the original 6897c478bd9Sstevel@tonic-gate * version of this command this function is only called once, 6907c478bd9Sstevel@tonic-gate * but this function is generalized for the future. 6917c478bd9Sstevel@tonic-gate */ 6927c478bd9Sstevel@tonic-gate if (!inited) { 6937c478bd9Sstevel@tonic-gate (void) strncpy(yeschr, nl_langinfo(YESSTR), YESNO_STR_MAX + 1); 6947c478bd9Sstevel@tonic-gate (void) strncpy(nochr, nl_langinfo(NOSTR), YESNO_STR_MAX + 1); 6957c478bd9Sstevel@tonic-gate inited = 1; 6967c478bd9Sstevel@tonic-gate } 6977c478bd9Sstevel@tonic-gate 6987c478bd9Sstevel@tonic-gate do { 6997c478bd9Sstevel@tonic-gate (void) fprintf(stderr, "%s (%s/%s)? ", message, yeschr, nochr); 7007c478bd9Sstevel@tonic-gate isyes = yesno(yeschr, nochr); 7017c478bd9Sstevel@tonic-gate } while (isyes == -1); 7027c478bd9Sstevel@tonic-gate return (isyes); 7037c478bd9Sstevel@tonic-gate } 7047c478bd9Sstevel@tonic-gate 7057c478bd9Sstevel@tonic-gate /* 7067c478bd9Sstevel@tonic-gate * If any text is input it must sub-string match either yes or no. 7077c478bd9Sstevel@tonic-gate * Failure of this match is indicated by return of -1. 7087c478bd9Sstevel@tonic-gate * If an empty line is input, this is taken as no. 7097c478bd9Sstevel@tonic-gate */ 7107c478bd9Sstevel@tonic-gate static int 7117c478bd9Sstevel@tonic-gate yesno( 7127c478bd9Sstevel@tonic-gate char *yesp, 7137c478bd9Sstevel@tonic-gate char *nop) 7147c478bd9Sstevel@tonic-gate { 7157c478bd9Sstevel@tonic-gate int i, b; 7167c478bd9Sstevel@tonic-gate char ans[YESNO_STR_MAX + 1]; 7177c478bd9Sstevel@tonic-gate 7187c478bd9Sstevel@tonic-gate i = 0; 7197c478bd9Sstevel@tonic-gate 7207c478bd9Sstevel@tonic-gate /*CONSTCOND*/ 7217c478bd9Sstevel@tonic-gate while (1) { 7227c478bd9Sstevel@tonic-gate b = getc(stdin); /* more explicit that rm.c version */ 7237c478bd9Sstevel@tonic-gate if (b == '\n' || b == '\0' || b == EOF) { 7247c478bd9Sstevel@tonic-gate if (i < YESNO_STR_MAX) /* bug fix to rm.c version */ 7257c478bd9Sstevel@tonic-gate ans[i] = 0; 7267c478bd9Sstevel@tonic-gate break; 7277c478bd9Sstevel@tonic-gate } 7287c478bd9Sstevel@tonic-gate if (i < YESNO_STR_MAX) 7297c478bd9Sstevel@tonic-gate ans[i] = b; 7307c478bd9Sstevel@tonic-gate i++; 7317c478bd9Sstevel@tonic-gate } 7327c478bd9Sstevel@tonic-gate if (i >= YESNO_STR_MAX) { 7337c478bd9Sstevel@tonic-gate i = YESNO_STR_MAX; 7347c478bd9Sstevel@tonic-gate ans[YESNO_STR_MAX] = 0; 7357c478bd9Sstevel@tonic-gate } 7367c478bd9Sstevel@tonic-gate /* changes to rm.c version follow */ 7377c478bd9Sstevel@tonic-gate if (i == 0) 7387c478bd9Sstevel@tonic-gate return (0); 7397c478bd9Sstevel@tonic-gate if (strncmp(nop, ans, i) == 0) 7407c478bd9Sstevel@tonic-gate return (0); 7417c478bd9Sstevel@tonic-gate if (strncmp(yesp, ans, i) == 0) 7427c478bd9Sstevel@tonic-gate return (1); 7437c478bd9Sstevel@tonic-gate return (-1); 7447c478bd9Sstevel@tonic-gate } 7457c478bd9Sstevel@tonic-gate 7467c478bd9Sstevel@tonic-gate /*ARGSUSED*/ 7477c478bd9Sstevel@tonic-gate static int 7487c478bd9Sstevel@tonic-gate confirm_no( 7497c478bd9Sstevel@tonic-gate void *appdata_ptr, 7507c478bd9Sstevel@tonic-gate const char *message) 7517c478bd9Sstevel@tonic-gate { 7527c478bd9Sstevel@tonic-gate return (0); 7537c478bd9Sstevel@tonic-gate } 7547c478bd9Sstevel@tonic-gate 7557c478bd9Sstevel@tonic-gate /*ARGSUSED*/ 7567c478bd9Sstevel@tonic-gate static int 7577c478bd9Sstevel@tonic-gate confirm_yes( 7587c478bd9Sstevel@tonic-gate void *appdata_ptr, 7597c478bd9Sstevel@tonic-gate const char *message) 7607c478bd9Sstevel@tonic-gate { 7617c478bd9Sstevel@tonic-gate return (1); 7627c478bd9Sstevel@tonic-gate } 7637c478bd9Sstevel@tonic-gate 7647c478bd9Sstevel@tonic-gate /* 7657c478bd9Sstevel@tonic-gate * Find base name of filename. 7667c478bd9Sstevel@tonic-gate */ 7677c478bd9Sstevel@tonic-gate static char * 7687c478bd9Sstevel@tonic-gate basename( 7697c478bd9Sstevel@tonic-gate char *cp) 7707c478bd9Sstevel@tonic-gate { 7717c478bd9Sstevel@tonic-gate char *sp; 7727c478bd9Sstevel@tonic-gate 7737c478bd9Sstevel@tonic-gate if ((sp = strrchr(cp, '/')) != NULL) 7747c478bd9Sstevel@tonic-gate return (sp + 1); 7757c478bd9Sstevel@tonic-gate return (cp); 7767c478bd9Sstevel@tonic-gate } 7777c478bd9Sstevel@tonic-gate 7787c478bd9Sstevel@tonic-gate /*ARGSUSED*/ 7797c478bd9Sstevel@tonic-gate static int 7807c478bd9Sstevel@tonic-gate message_output( 7817c478bd9Sstevel@tonic-gate void *appdata_ptr, 7827c478bd9Sstevel@tonic-gate const char *message) 7837c478bd9Sstevel@tonic-gate { 7847c478bd9Sstevel@tonic-gate (void) fprintf(stderr, "%s", message); 7857c478bd9Sstevel@tonic-gate return (CFGA_OK); 7867c478bd9Sstevel@tonic-gate 7877c478bd9Sstevel@tonic-gate } 7887c478bd9Sstevel@tonic-gate 7897c478bd9Sstevel@tonic-gate /* 7907c478bd9Sstevel@tonic-gate * extract_list_suboptions - process list option string 7917c478bd9Sstevel@tonic-gate */ 7927c478bd9Sstevel@tonic-gate static int 7937c478bd9Sstevel@tonic-gate extract_list_suboptions( 7947c478bd9Sstevel@tonic-gate char *arg, 7957c478bd9Sstevel@tonic-gate char **sortpp, 7967c478bd9Sstevel@tonic-gate char **colspp, 7977c478bd9Sstevel@tonic-gate char **cols2pp, 7987c478bd9Sstevel@tonic-gate int *noheadingsp, 7997c478bd9Sstevel@tonic-gate char **delimpp, 8007c478bd9Sstevel@tonic-gate char **selectpp, 8017c478bd9Sstevel@tonic-gate char **matchpp) 8027c478bd9Sstevel@tonic-gate { 8037c478bd9Sstevel@tonic-gate char *value = NULL; 8047c478bd9Sstevel@tonic-gate int subopt = 0; 8057c478bd9Sstevel@tonic-gate int err = 0; 8067c478bd9Sstevel@tonic-gate 8077c478bd9Sstevel@tonic-gate while (*arg != '\0') { 8087c478bd9Sstevel@tonic-gate static char need_value[] = 8097c478bd9Sstevel@tonic-gate "%s: sub-option \"%s\" requires a value\n"; 8107c478bd9Sstevel@tonic-gate static char no_value[] = 8117c478bd9Sstevel@tonic-gate "%s: sub-option \"%s\" does not take a value\n"; 8127c478bd9Sstevel@tonic-gate static char unk_subopt[] = 8137c478bd9Sstevel@tonic-gate "%s: sub-option \"%s\" unknown\n"; 8147c478bd9Sstevel@tonic-gate char **pptr; 8157c478bd9Sstevel@tonic-gate 8167c478bd9Sstevel@tonic-gate subopt = getsubopt(&arg, list_options, &value); 8177c478bd9Sstevel@tonic-gate switch (subopt) { 8187c478bd9Sstevel@tonic-gate case LIST_SORT: 8197c478bd9Sstevel@tonic-gate pptr = sortpp; 8207c478bd9Sstevel@tonic-gate goto valcom; 8217c478bd9Sstevel@tonic-gate case LIST_COLS: 8227c478bd9Sstevel@tonic-gate pptr = colspp; 8237c478bd9Sstevel@tonic-gate goto valcom; 8247c478bd9Sstevel@tonic-gate case LIST_COLS2: 8257c478bd9Sstevel@tonic-gate pptr = cols2pp; 8267c478bd9Sstevel@tonic-gate goto valcom; 8277c478bd9Sstevel@tonic-gate case LIST_SELECT: 8287c478bd9Sstevel@tonic-gate pptr = selectpp; 8297c478bd9Sstevel@tonic-gate goto valcom; 8307c478bd9Sstevel@tonic-gate case LIST_MATCH: 8317c478bd9Sstevel@tonic-gate pptr = matchpp; 8327c478bd9Sstevel@tonic-gate goto valcom; 8337c478bd9Sstevel@tonic-gate case LIST_DELIM: 8347c478bd9Sstevel@tonic-gate pptr = delimpp; 8357c478bd9Sstevel@tonic-gate valcom: 8367c478bd9Sstevel@tonic-gate if (value == NULL) { 8377c478bd9Sstevel@tonic-gate (void) fprintf(stderr, gettext(need_value), 8387c478bd9Sstevel@tonic-gate cmdname, list_options[subopt]); 8397c478bd9Sstevel@tonic-gate err = 1; 8407c478bd9Sstevel@tonic-gate } else 8417c478bd9Sstevel@tonic-gate *pptr = value; 8427c478bd9Sstevel@tonic-gate break; 8437c478bd9Sstevel@tonic-gate case LIST_NOHEADINGS: 8447c478bd9Sstevel@tonic-gate if (value != NULL) { 8457c478bd9Sstevel@tonic-gate (void) fprintf(stderr, gettext(no_value), 8467c478bd9Sstevel@tonic-gate cmdname, list_options[subopt]); 8477c478bd9Sstevel@tonic-gate err = 1; 8487c478bd9Sstevel@tonic-gate } else 8497c478bd9Sstevel@tonic-gate *noheadingsp = 1; 8507c478bd9Sstevel@tonic-gate break; 8517c478bd9Sstevel@tonic-gate default: 8527c478bd9Sstevel@tonic-gate (void) fprintf(stderr, gettext(unk_subopt), 8537c478bd9Sstevel@tonic-gate cmdname, value); 8547c478bd9Sstevel@tonic-gate err = 1; 8557c478bd9Sstevel@tonic-gate break; 8567c478bd9Sstevel@tonic-gate } 8577c478bd9Sstevel@tonic-gate } 8587c478bd9Sstevel@tonic-gate return (err == 0); 8597c478bd9Sstevel@tonic-gate } 8607c478bd9Sstevel@tonic-gate 8617c478bd9Sstevel@tonic-gate static cfga_err_t 8627c478bd9Sstevel@tonic-gate setup_prefilter(post_filter_t *post_filtp, char **prefilt_optpp) 8637c478bd9Sstevel@tonic-gate { 8647c478bd9Sstevel@tonic-gate size_t len; 8657c478bd9Sstevel@tonic-gate const char *clopt = PREFILT_CLASS_STR; 8667c478bd9Sstevel@tonic-gate int idx; 8677c478bd9Sstevel@tonic-gate 8687c478bd9Sstevel@tonic-gate 8697c478bd9Sstevel@tonic-gate *prefilt_optpp = NULL; 8707c478bd9Sstevel@tonic-gate 8717c478bd9Sstevel@tonic-gate /* Get the index for the "class" field */ 8727c478bd9Sstevel@tonic-gate for (idx = 0; idx < N_FIELDS; idx++) { 8737c478bd9Sstevel@tonic-gate if (strcmp(all_fields[idx].name, PREFILT_CLASS_STR) == 0) 8747c478bd9Sstevel@tonic-gate break; 8757c478bd9Sstevel@tonic-gate } 8767c478bd9Sstevel@tonic-gate 8777c478bd9Sstevel@tonic-gate /* 8787c478bd9Sstevel@tonic-gate * Currently pre-filter available only for class fld w/ EXACT match 8797c478bd9Sstevel@tonic-gate */ 8807c478bd9Sstevel@tonic-gate if (idx >= N_FIELDS || 8817c478bd9Sstevel@tonic-gate post_filtp->match_type_p[idx] != CFGA_MATCH_EXACT) { 8827c478bd9Sstevel@tonic-gate return (CFGA_OK); 8837c478bd9Sstevel@tonic-gate } 8847c478bd9Sstevel@tonic-gate 8857c478bd9Sstevel@tonic-gate len = strlen(clopt) + strlen(post_filtp->ldata.ap_class) + 1; 8867c478bd9Sstevel@tonic-gate if ((*prefilt_optpp = config_calloc_check(1, len)) == NULL) { 8877c478bd9Sstevel@tonic-gate return (CFGA_LIB_ERROR); 8887c478bd9Sstevel@tonic-gate } 8897c478bd9Sstevel@tonic-gate 8907c478bd9Sstevel@tonic-gate (void) strcpy(*prefilt_optpp, clopt); 8917c478bd9Sstevel@tonic-gate (void) strcat(*prefilt_optpp, post_filtp->ldata.ap_class); 8927c478bd9Sstevel@tonic-gate 8937c478bd9Sstevel@tonic-gate /* 8947c478bd9Sstevel@tonic-gate * Since it is being pre-filtered, this attribute does not need 8957c478bd9Sstevel@tonic-gate * post-filtering. 8967c478bd9Sstevel@tonic-gate */ 8977c478bd9Sstevel@tonic-gate post_filtp->match_type_p[idx] = CFGA_MATCH_NOFILTER; 8987c478bd9Sstevel@tonic-gate if (all_fields[idx].set_filter != NULL) { 8997c478bd9Sstevel@tonic-gate (void) all_fields[idx].set_filter(&post_filtp->ldata, ""); 9007c478bd9Sstevel@tonic-gate } 9017c478bd9Sstevel@tonic-gate 9027c478bd9Sstevel@tonic-gate return (CFGA_OK); 9037c478bd9Sstevel@tonic-gate } 9047c478bd9Sstevel@tonic-gate 9057c478bd9Sstevel@tonic-gate static cfga_err_t 9067c478bd9Sstevel@tonic-gate set_attrval( 9077c478bd9Sstevel@tonic-gate const char *attr, 9087c478bd9Sstevel@tonic-gate const char *val, 9097c478bd9Sstevel@tonic-gate post_filter_t *post_filtp, 9107c478bd9Sstevel@tonic-gate match_type_t match_type) 9117c478bd9Sstevel@tonic-gate { 9127c478bd9Sstevel@tonic-gate int fld = 0; 9137c478bd9Sstevel@tonic-gate cfga_err_t ret = CFGA_ERROR; 9147c478bd9Sstevel@tonic-gate 9157c478bd9Sstevel@tonic-gate for (fld = 0; fld < N_FIELDS; fld++) { 9167c478bd9Sstevel@tonic-gate if (strcmp(attr, all_fields[fld].name) == 0) 9177c478bd9Sstevel@tonic-gate break; 9187c478bd9Sstevel@tonic-gate } 9197c478bd9Sstevel@tonic-gate 9207c478bd9Sstevel@tonic-gate /* Valid field or is the select option supported for this field */ 9217c478bd9Sstevel@tonic-gate if (fld >= N_FIELDS || all_fields[fld].set_filter == NULL) { 9227c478bd9Sstevel@tonic-gate return (CFGA_ATTR_INVAL); 9237c478bd9Sstevel@tonic-gate } 9247c478bd9Sstevel@tonic-gate 9257c478bd9Sstevel@tonic-gate if ((ret = all_fields[fld].set_filter(&post_filtp->ldata, val)) 9267c478bd9Sstevel@tonic-gate == CFGA_OK) { 9277c478bd9Sstevel@tonic-gate post_filtp->match_type_p[fld] = match_type; 9287c478bd9Sstevel@tonic-gate } 9297c478bd9Sstevel@tonic-gate 9307c478bd9Sstevel@tonic-gate return (ret); 9317c478bd9Sstevel@tonic-gate 9327c478bd9Sstevel@tonic-gate } 9337c478bd9Sstevel@tonic-gate 9347c478bd9Sstevel@tonic-gate static char inval_optarg[] = 9357c478bd9Sstevel@tonic-gate "%s: invalid value \"%s\" for %s suboption.\n"; 9367c478bd9Sstevel@tonic-gate 9377c478bd9Sstevel@tonic-gate /* 9387c478bd9Sstevel@tonic-gate * Parses the "select" string and fills in the post_filter structure 9397c478bd9Sstevel@tonic-gate */ 9407c478bd9Sstevel@tonic-gate static cfga_err_t 9417c478bd9Sstevel@tonic-gate parse_select_opt( 9427c478bd9Sstevel@tonic-gate const char *selectp, 9437c478bd9Sstevel@tonic-gate post_filter_t *post_filtp, 9447c478bd9Sstevel@tonic-gate match_type_t match_type) 9457c478bd9Sstevel@tonic-gate { 9467c478bd9Sstevel@tonic-gate parse_state_t state = CFGA_PSTATE_INIT; 9477c478bd9Sstevel@tonic-gate char *cp = NULL, *optstr = NULL, *attr = NULL, *val = NULL; 9487c478bd9Sstevel@tonic-gate int bal = 0; /* Tracks balancing */ 9497c478bd9Sstevel@tonic-gate char chr; 9507c478bd9Sstevel@tonic-gate cfga_err_t ret; 9517c478bd9Sstevel@tonic-gate 9527c478bd9Sstevel@tonic-gate 9537c478bd9Sstevel@tonic-gate if (selectp == NULL || post_filtp == NULL) { 9547c478bd9Sstevel@tonic-gate return (CFGA_ERROR); 9557c478bd9Sstevel@tonic-gate } 9567c478bd9Sstevel@tonic-gate 9577c478bd9Sstevel@tonic-gate optstr = config_calloc_check(1, strlen(selectp) + 1); 9587c478bd9Sstevel@tonic-gate if (optstr == NULL) { 9597c478bd9Sstevel@tonic-gate return (CFGA_LIB_ERROR); 9607c478bd9Sstevel@tonic-gate } 9617c478bd9Sstevel@tonic-gate 9627c478bd9Sstevel@tonic-gate (void) strcpy(optstr, selectp); 9637c478bd9Sstevel@tonic-gate 9647c478bd9Sstevel@tonic-gate /* Init */ 9657c478bd9Sstevel@tonic-gate ret = CFGA_ATTR_INVAL; 9667c478bd9Sstevel@tonic-gate bal = 0; 9677c478bd9Sstevel@tonic-gate cp = attr = optstr; 9687c478bd9Sstevel@tonic-gate state = CFGA_PSTATE_INIT; 9697c478bd9Sstevel@tonic-gate 9707c478bd9Sstevel@tonic-gate for (; *cp != '\0'; cp++) { 9717c478bd9Sstevel@tonic-gate switch (state) { 9727c478bd9Sstevel@tonic-gate case CFGA_PSTATE_INIT: 9737c478bd9Sstevel@tonic-gate if (*cp != LEFT_PAREN) 9747c478bd9Sstevel@tonic-gate break; 9757c478bd9Sstevel@tonic-gate *cp = '\0'; 9767c478bd9Sstevel@tonic-gate val = cp + 1; 9777c478bd9Sstevel@tonic-gate bal = 1; 9787c478bd9Sstevel@tonic-gate state = CFGA_PSTATE_ATTR_DONE; 9797c478bd9Sstevel@tonic-gate break; 9807c478bd9Sstevel@tonic-gate case CFGA_PSTATE_ATTR_DONE: 9817c478bd9Sstevel@tonic-gate chr = *cp; 9827c478bd9Sstevel@tonic-gate switch (chr) { 9837c478bd9Sstevel@tonic-gate case LEFT_PAREN: 9847c478bd9Sstevel@tonic-gate bal++; 9857c478bd9Sstevel@tonic-gate break; 9867c478bd9Sstevel@tonic-gate case RIGHT_PAREN: 9877c478bd9Sstevel@tonic-gate bal--; 9887c478bd9Sstevel@tonic-gate if (bal == 0) { 9897c478bd9Sstevel@tonic-gate *cp = '\0'; 9907c478bd9Sstevel@tonic-gate state = CFGA_PSTATE_VAL_DONE; 9917c478bd9Sstevel@tonic-gate } 9927c478bd9Sstevel@tonic-gate break; 9937c478bd9Sstevel@tonic-gate } 9947c478bd9Sstevel@tonic-gate break; 9957c478bd9Sstevel@tonic-gate case CFGA_PSTATE_VAL_DONE: 9967c478bd9Sstevel@tonic-gate if (*cp != ':') { 9977c478bd9Sstevel@tonic-gate state = CFGA_PSTATE_ERR; 9987c478bd9Sstevel@tonic-gate goto out; 9997c478bd9Sstevel@tonic-gate } 10007c478bd9Sstevel@tonic-gate 10017c478bd9Sstevel@tonic-gate *cp = '\0'; 10027c478bd9Sstevel@tonic-gate if (set_attrval(attr, val, post_filtp, 10037c478bd9Sstevel@tonic-gate match_type) != CFGA_OK) { 10047c478bd9Sstevel@tonic-gate state = CFGA_PSTATE_ERR; 10057c478bd9Sstevel@tonic-gate goto out; 10067c478bd9Sstevel@tonic-gate } 10077c478bd9Sstevel@tonic-gate state = CFGA_PSTATE_INIT; 10087c478bd9Sstevel@tonic-gate attr = cp + 1; 10097c478bd9Sstevel@tonic-gate break; 10107c478bd9Sstevel@tonic-gate default: 10117c478bd9Sstevel@tonic-gate state = CFGA_PSTATE_ERR; 10127c478bd9Sstevel@tonic-gate /* FALLTHROUGH */ 10137c478bd9Sstevel@tonic-gate case CFGA_PSTATE_ERR: 10147c478bd9Sstevel@tonic-gate goto out; 10157c478bd9Sstevel@tonic-gate } 10167c478bd9Sstevel@tonic-gate } 10177c478bd9Sstevel@tonic-gate 10187c478bd9Sstevel@tonic-gate /*FALLTHRU*/ 10197c478bd9Sstevel@tonic-gate out: 10207c478bd9Sstevel@tonic-gate if (state == CFGA_PSTATE_VAL_DONE) { 10217c478bd9Sstevel@tonic-gate ret = set_attrval(attr, val, post_filtp, match_type); 10227c478bd9Sstevel@tonic-gate } else { 10237c478bd9Sstevel@tonic-gate ret = CFGA_ATTR_INVAL; 10247c478bd9Sstevel@tonic-gate } 10257c478bd9Sstevel@tonic-gate 10267c478bd9Sstevel@tonic-gate if (ret != CFGA_OK) { 10277c478bd9Sstevel@tonic-gate (void) fprintf(stderr, gettext(inval_optarg), cmdname, 10287c478bd9Sstevel@tonic-gate selectp, list_options[LIST_SELECT]); 10297c478bd9Sstevel@tonic-gate } 10307c478bd9Sstevel@tonic-gate 10317c478bd9Sstevel@tonic-gate S_FREE(optstr); 10327c478bd9Sstevel@tonic-gate return (ret); 10337c478bd9Sstevel@tonic-gate } 10347c478bd9Sstevel@tonic-gate 10357c478bd9Sstevel@tonic-gate 10367c478bd9Sstevel@tonic-gate 10377c478bd9Sstevel@tonic-gate static cfga_err_t 10387c478bd9Sstevel@tonic-gate setup_filter( 10397c478bd9Sstevel@tonic-gate const char *selectp, 10407c478bd9Sstevel@tonic-gate const char *matchp, 10417c478bd9Sstevel@tonic-gate post_filter_t *post_filtp, 10427c478bd9Sstevel@tonic-gate char **prefilt_optpp) 10437c478bd9Sstevel@tonic-gate { 10447c478bd9Sstevel@tonic-gate cfga_err_t ret = CFGA_ERROR; 10457c478bd9Sstevel@tonic-gate match_type_t match_type = CFGA_MATCH_NOFILTER; 10467c478bd9Sstevel@tonic-gate int i; 10477c478bd9Sstevel@tonic-gate 10487c478bd9Sstevel@tonic-gate static char match_needs_select[] = 10497c478bd9Sstevel@tonic-gate "%s: %s suboption can only be used with %s suboption.\n"; 10507c478bd9Sstevel@tonic-gate 10517c478bd9Sstevel@tonic-gate 10527c478bd9Sstevel@tonic-gate *prefilt_optpp = NULL; 10537c478bd9Sstevel@tonic-gate 10547c478bd9Sstevel@tonic-gate /* 10557c478bd9Sstevel@tonic-gate * Initial: no filtering. 10567c478bd9Sstevel@tonic-gate * CFGA_MATCH_NOFILTER is NOT a valid user input 10577c478bd9Sstevel@tonic-gate */ 10587c478bd9Sstevel@tonic-gate for (i = 0; i < N_FIELDS; i++) { 10597c478bd9Sstevel@tonic-gate post_filtp->match_type_p[i] = CFGA_MATCH_NOFILTER; 10607c478bd9Sstevel@tonic-gate } 10617c478bd9Sstevel@tonic-gate 10627c478bd9Sstevel@tonic-gate /* Determine type of match */ 10637c478bd9Sstevel@tonic-gate if (matchp == NULL && selectp == NULL) { 10647c478bd9Sstevel@tonic-gate /* No filtering */ 10657c478bd9Sstevel@tonic-gate return (CFGA_OK); 10667c478bd9Sstevel@tonic-gate } else if (matchp == NULL && selectp != NULL) { 10677c478bd9Sstevel@tonic-gate match_type = CFGA_DEFAULT_MATCH; 10687c478bd9Sstevel@tonic-gate } else if (matchp != NULL && selectp == NULL) { 10697c478bd9Sstevel@tonic-gate /* If only match specified, select criteria also needed */ 10707c478bd9Sstevel@tonic-gate (void) fprintf(stderr, gettext(match_needs_select), 10717c478bd9Sstevel@tonic-gate cmdname, list_options[LIST_MATCH], 10727c478bd9Sstevel@tonic-gate list_options[LIST_SELECT]); 10737c478bd9Sstevel@tonic-gate return (CFGA_ERROR); 10747c478bd9Sstevel@tonic-gate } else { 10757c478bd9Sstevel@tonic-gate for (i = 0; i < N_MATCH_TYPES; i++) { 10767c478bd9Sstevel@tonic-gate if (strcmp(matchp, match_type_array[i].str) == 0) { 10777c478bd9Sstevel@tonic-gate match_type = match_type_array[i].type; 10787c478bd9Sstevel@tonic-gate break; 10797c478bd9Sstevel@tonic-gate } 10807c478bd9Sstevel@tonic-gate } 10817c478bd9Sstevel@tonic-gate if (i >= N_MATCH_TYPES) { 10827c478bd9Sstevel@tonic-gate (void) fprintf(stderr, gettext(inval_optarg), cmdname, 10837c478bd9Sstevel@tonic-gate matchp, list_options[LIST_MATCH]); 10847c478bd9Sstevel@tonic-gate return (CFGA_ERROR); 10857c478bd9Sstevel@tonic-gate } 10867c478bd9Sstevel@tonic-gate } 10877c478bd9Sstevel@tonic-gate 10887c478bd9Sstevel@tonic-gate if ((ret = parse_select_opt(selectp, post_filtp, match_type)) 10897c478bd9Sstevel@tonic-gate != CFGA_OK) { 10907c478bd9Sstevel@tonic-gate return (ret); 10917c478bd9Sstevel@tonic-gate } 10927c478bd9Sstevel@tonic-gate 10937c478bd9Sstevel@tonic-gate /* Handle pre-filtering. */ 10947c478bd9Sstevel@tonic-gate if ((ret = setup_prefilter(post_filtp, prefilt_optpp)) != CFGA_OK) { 10957c478bd9Sstevel@tonic-gate /* Cleanup */ 10967c478bd9Sstevel@tonic-gate for (i = 0; i < N_FIELDS; i++) { 10977c478bd9Sstevel@tonic-gate post_filtp->match_type_p[i] = CFGA_MATCH_NOFILTER; 10987c478bd9Sstevel@tonic-gate } 10997c478bd9Sstevel@tonic-gate return (ret); 11007c478bd9Sstevel@tonic-gate } 11017c478bd9Sstevel@tonic-gate 11027c478bd9Sstevel@tonic-gate 11037c478bd9Sstevel@tonic-gate return (CFGA_OK); 11047c478bd9Sstevel@tonic-gate } 11057c478bd9Sstevel@tonic-gate 11067c478bd9Sstevel@tonic-gate /* 11077c478bd9Sstevel@tonic-gate * compare_ap_id - compare two ap_id's 11087c478bd9Sstevel@tonic-gate * 11097c478bd9Sstevel@tonic-gate * For partial matches, argument order is significant. The filtering criterion 11107c478bd9Sstevel@tonic-gate * should be the first argument. 11117c478bd9Sstevel@tonic-gate */ 11127c478bd9Sstevel@tonic-gate 11137c478bd9Sstevel@tonic-gate static int 11147c478bd9Sstevel@tonic-gate compare_ap_id( 11157c478bd9Sstevel@tonic-gate cfga_list_data_t *p1, 11167c478bd9Sstevel@tonic-gate cfga_list_data_t *p2, 11177c478bd9Sstevel@tonic-gate match_type_t match_type) 11187c478bd9Sstevel@tonic-gate { 11197c478bd9Sstevel@tonic-gate 11207c478bd9Sstevel@tonic-gate switch (match_type) { 11217c478bd9Sstevel@tonic-gate case CFGA_MATCH_NOFILTER: 11227c478bd9Sstevel@tonic-gate return (0); /* No filtering. all pass */ 11237c478bd9Sstevel@tonic-gate case CFGA_MATCH_PARTIAL: 11247c478bd9Sstevel@tonic-gate return (strncmp(p1->ap_log_id, p2->ap_log_id, 11257c478bd9Sstevel@tonic-gate strlen(p1->ap_log_id))); 11267c478bd9Sstevel@tonic-gate case CFGA_MATCH_EXACT: 11277c478bd9Sstevel@tonic-gate return (strcmp(p1->ap_log_id, p2->ap_log_id)); 11287c478bd9Sstevel@tonic-gate case CFGA_MATCH_ORDER: 11297c478bd9Sstevel@tonic-gate default: 11307c478bd9Sstevel@tonic-gate return (config_ap_id_cmp(p1->ap_log_id, p2->ap_log_id)); 11317c478bd9Sstevel@tonic-gate } 11327c478bd9Sstevel@tonic-gate } 11337c478bd9Sstevel@tonic-gate 11347c478bd9Sstevel@tonic-gate /* 11357c478bd9Sstevel@tonic-gate * print_log_id - print logical ap_id 11367c478bd9Sstevel@tonic-gate */ 11377c478bd9Sstevel@tonic-gate static void 11387c478bd9Sstevel@tonic-gate print_log_id( 11397c478bd9Sstevel@tonic-gate cfga_list_data_t *p, 11407c478bd9Sstevel@tonic-gate int width, 11417c478bd9Sstevel@tonic-gate char *lp) 11427c478bd9Sstevel@tonic-gate { 11437c478bd9Sstevel@tonic-gate (void) sprintf(lp, "%-*.*s", width, sizeof (p->ap_log_id), 11447c478bd9Sstevel@tonic-gate p->ap_log_id); 11457c478bd9Sstevel@tonic-gate } 11467c478bd9Sstevel@tonic-gate 11477c478bd9Sstevel@tonic-gate /* 11487c478bd9Sstevel@tonic-gate * set_log_flt - Setup filter for logical ap_id 11497c478bd9Sstevel@tonic-gate */ 11507c478bd9Sstevel@tonic-gate static cfga_err_t 11517c478bd9Sstevel@tonic-gate set_log_flt( 11527c478bd9Sstevel@tonic-gate cfga_list_data_t *p, 11537c478bd9Sstevel@tonic-gate const char *val) 11547c478bd9Sstevel@tonic-gate { 11557c478bd9Sstevel@tonic-gate if (strlen(val) > sizeof (p->ap_log_id) - 1) 11567c478bd9Sstevel@tonic-gate return (CFGA_ATTR_INVAL); 11577c478bd9Sstevel@tonic-gate 11587c478bd9Sstevel@tonic-gate (void) strcpy(p->ap_log_id, val); 11597c478bd9Sstevel@tonic-gate 11607c478bd9Sstevel@tonic-gate return (CFGA_OK); 11617c478bd9Sstevel@tonic-gate } 11627c478bd9Sstevel@tonic-gate 11637c478bd9Sstevel@tonic-gate /* 11647c478bd9Sstevel@tonic-gate * set_type_flt - Setup filter for type field 11657c478bd9Sstevel@tonic-gate */ 11667c478bd9Sstevel@tonic-gate 11677c478bd9Sstevel@tonic-gate static cfga_err_t 11687c478bd9Sstevel@tonic-gate set_type_flt( 11697c478bd9Sstevel@tonic-gate cfga_list_data_t *p, 11707c478bd9Sstevel@tonic-gate const char *val) 11717c478bd9Sstevel@tonic-gate { 11727c478bd9Sstevel@tonic-gate if (strlen(val) > sizeof (p->ap_type) - 1) 11737c478bd9Sstevel@tonic-gate return (CFGA_ATTR_INVAL); 11747c478bd9Sstevel@tonic-gate 11757c478bd9Sstevel@tonic-gate (void) strcpy(p->ap_type, val); 11767c478bd9Sstevel@tonic-gate 11777c478bd9Sstevel@tonic-gate return (CFGA_OK); 11787c478bd9Sstevel@tonic-gate } 11797c478bd9Sstevel@tonic-gate 11807c478bd9Sstevel@tonic-gate /* 11817c478bd9Sstevel@tonic-gate * set_class_flt - Setup filter for class field 11827c478bd9Sstevel@tonic-gate */ 11837c478bd9Sstevel@tonic-gate static cfga_err_t 11847c478bd9Sstevel@tonic-gate set_class_flt( 11857c478bd9Sstevel@tonic-gate cfga_list_data_t *p, 11867c478bd9Sstevel@tonic-gate const char *val) 11877c478bd9Sstevel@tonic-gate { 11887c478bd9Sstevel@tonic-gate if (strlen(val) > sizeof (p->ap_class) - 1) 11897c478bd9Sstevel@tonic-gate return (CFGA_ATTR_INVAL); 11907c478bd9Sstevel@tonic-gate 11917c478bd9Sstevel@tonic-gate (void) strcpy(p->ap_class, val); 11927c478bd9Sstevel@tonic-gate 11937c478bd9Sstevel@tonic-gate return (CFGA_OK); 11947c478bd9Sstevel@tonic-gate } 11957c478bd9Sstevel@tonic-gate 11967c478bd9Sstevel@tonic-gate 11977c478bd9Sstevel@tonic-gate /* 11987c478bd9Sstevel@tonic-gate * compare_r_state - compare receptacle state of two ap_id's 11997c478bd9Sstevel@tonic-gate */ 12007c478bd9Sstevel@tonic-gate static int 12017c478bd9Sstevel@tonic-gate compare_r_state( 12027c478bd9Sstevel@tonic-gate cfga_list_data_t *p1, 12037c478bd9Sstevel@tonic-gate cfga_list_data_t *p2, 12047c478bd9Sstevel@tonic-gate match_type_t match_type) 12057c478bd9Sstevel@tonic-gate { 12067c478bd9Sstevel@tonic-gate switch (match_type) { 12077c478bd9Sstevel@tonic-gate case CFGA_MATCH_NOFILTER: /* no filtering. pass all */ 12087c478bd9Sstevel@tonic-gate return (0); 12097c478bd9Sstevel@tonic-gate case CFGA_MATCH_ORDER: 12107c478bd9Sstevel@tonic-gate default: 12117c478bd9Sstevel@tonic-gate return (p1->ap_r_state - p2->ap_r_state); 12127c478bd9Sstevel@tonic-gate } 12137c478bd9Sstevel@tonic-gate } 12147c478bd9Sstevel@tonic-gate 12157c478bd9Sstevel@tonic-gate /* 12167c478bd9Sstevel@tonic-gate * compare_o_state - compare occupant state of two ap_id's 12177c478bd9Sstevel@tonic-gate */ 12187c478bd9Sstevel@tonic-gate static int 12197c478bd9Sstevel@tonic-gate compare_o_state( 12207c478bd9Sstevel@tonic-gate cfga_list_data_t *p1, 12217c478bd9Sstevel@tonic-gate cfga_list_data_t *p2, 12227c478bd9Sstevel@tonic-gate match_type_t match_type) 12237c478bd9Sstevel@tonic-gate { 12247c478bd9Sstevel@tonic-gate switch (match_type) { 12257c478bd9Sstevel@tonic-gate case CFGA_MATCH_NOFILTER: /* no filtering. all pass */ 12267c478bd9Sstevel@tonic-gate return (0); 12277c478bd9Sstevel@tonic-gate case CFGA_MATCH_ORDER: 12287c478bd9Sstevel@tonic-gate default: 12297c478bd9Sstevel@tonic-gate return (p1->ap_o_state - p2->ap_o_state); 12307c478bd9Sstevel@tonic-gate } 12317c478bd9Sstevel@tonic-gate } 12327c478bd9Sstevel@tonic-gate 12337c478bd9Sstevel@tonic-gate /* 12347c478bd9Sstevel@tonic-gate * compare_busy - compare busy field of two ap_id's 12357c478bd9Sstevel@tonic-gate */ 12367c478bd9Sstevel@tonic-gate static int 12377c478bd9Sstevel@tonic-gate compare_busy( 12387c478bd9Sstevel@tonic-gate cfga_list_data_t *p1, 12397c478bd9Sstevel@tonic-gate cfga_list_data_t *p2, 12407c478bd9Sstevel@tonic-gate match_type_t match_type) 12417c478bd9Sstevel@tonic-gate { 12427c478bd9Sstevel@tonic-gate 12437c478bd9Sstevel@tonic-gate switch (match_type) { 12447c478bd9Sstevel@tonic-gate case CFGA_MATCH_NOFILTER: /* no filtering. all pass */ 12457c478bd9Sstevel@tonic-gate return (0); 12467c478bd9Sstevel@tonic-gate case CFGA_MATCH_ORDER: 12477c478bd9Sstevel@tonic-gate default: 12487c478bd9Sstevel@tonic-gate return (p1->ap_busy - p2->ap_busy); 12497c478bd9Sstevel@tonic-gate } 12507c478bd9Sstevel@tonic-gate } 12517c478bd9Sstevel@tonic-gate 12527c478bd9Sstevel@tonic-gate /* 12537c478bd9Sstevel@tonic-gate * print_r_state - print receptacle state 12547c478bd9Sstevel@tonic-gate */ 12557c478bd9Sstevel@tonic-gate static void 12567c478bd9Sstevel@tonic-gate print_r_state( 12577c478bd9Sstevel@tonic-gate cfga_list_data_t *p, 12587c478bd9Sstevel@tonic-gate int width, 12597c478bd9Sstevel@tonic-gate char *lp) 12607c478bd9Sstevel@tonic-gate { 12617c478bd9Sstevel@tonic-gate char *cp; 12627c478bd9Sstevel@tonic-gate 12637c478bd9Sstevel@tonic-gate switch (p->ap_r_state) { 12647c478bd9Sstevel@tonic-gate case CFGA_STAT_EMPTY: 12657c478bd9Sstevel@tonic-gate cp = "empty"; 12667c478bd9Sstevel@tonic-gate break; 12677c478bd9Sstevel@tonic-gate case CFGA_STAT_CONNECTED: 12687c478bd9Sstevel@tonic-gate cp = "connected"; 12697c478bd9Sstevel@tonic-gate break; 12707c478bd9Sstevel@tonic-gate case CFGA_STAT_DISCONNECTED: 12717c478bd9Sstevel@tonic-gate cp = "disconnected"; 12727c478bd9Sstevel@tonic-gate break; 12737c478bd9Sstevel@tonic-gate default: 12747c478bd9Sstevel@tonic-gate cp = "???"; 12757c478bd9Sstevel@tonic-gate break; 12767c478bd9Sstevel@tonic-gate } 12777c478bd9Sstevel@tonic-gate (void) sprintf(lp, "%-*s", width, cp); 12787c478bd9Sstevel@tonic-gate } 12797c478bd9Sstevel@tonic-gate 12807c478bd9Sstevel@tonic-gate /* 12817c478bd9Sstevel@tonic-gate * print_o_state - print occupant state 12827c478bd9Sstevel@tonic-gate */ 12837c478bd9Sstevel@tonic-gate static void 12847c478bd9Sstevel@tonic-gate print_o_state( 12857c478bd9Sstevel@tonic-gate cfga_list_data_t *p, 12867c478bd9Sstevel@tonic-gate int width, 12877c478bd9Sstevel@tonic-gate char *lp) 12887c478bd9Sstevel@tonic-gate { 12897c478bd9Sstevel@tonic-gate char *cp; 12907c478bd9Sstevel@tonic-gate 12917c478bd9Sstevel@tonic-gate switch (p->ap_o_state) { 12927c478bd9Sstevel@tonic-gate case CFGA_STAT_UNCONFIGURED: 12937c478bd9Sstevel@tonic-gate cp = "unconfigured"; 12947c478bd9Sstevel@tonic-gate break; 12957c478bd9Sstevel@tonic-gate case CFGA_STAT_CONFIGURED: 12967c478bd9Sstevel@tonic-gate cp = "configured"; 12977c478bd9Sstevel@tonic-gate break; 12987c478bd9Sstevel@tonic-gate default: 12997c478bd9Sstevel@tonic-gate cp = "???"; 13007c478bd9Sstevel@tonic-gate break; 13017c478bd9Sstevel@tonic-gate } 13027c478bd9Sstevel@tonic-gate (void) sprintf(lp, "%-*s", width, cp); 13037c478bd9Sstevel@tonic-gate } 13047c478bd9Sstevel@tonic-gate 13057c478bd9Sstevel@tonic-gate /* 13067c478bd9Sstevel@tonic-gate * compare_cond - compare condition field of two ap_id's 13077c478bd9Sstevel@tonic-gate */ 13087c478bd9Sstevel@tonic-gate static int 13097c478bd9Sstevel@tonic-gate compare_cond( 13107c478bd9Sstevel@tonic-gate cfga_list_data_t *p1, 13117c478bd9Sstevel@tonic-gate cfga_list_data_t *p2, 13127c478bd9Sstevel@tonic-gate match_type_t match_type) 13137c478bd9Sstevel@tonic-gate { 13147c478bd9Sstevel@tonic-gate 13157c478bd9Sstevel@tonic-gate switch (match_type) { 13167c478bd9Sstevel@tonic-gate case CFGA_MATCH_NOFILTER: 13177c478bd9Sstevel@tonic-gate return (0); 13187c478bd9Sstevel@tonic-gate case CFGA_MATCH_ORDER: 13197c478bd9Sstevel@tonic-gate default: 13207c478bd9Sstevel@tonic-gate return (p1->ap_cond - p2->ap_cond); 13217c478bd9Sstevel@tonic-gate } 13227c478bd9Sstevel@tonic-gate } 13237c478bd9Sstevel@tonic-gate 13247c478bd9Sstevel@tonic-gate /* 13257c478bd9Sstevel@tonic-gate * print_cond - print attachment point condition 13267c478bd9Sstevel@tonic-gate */ 13277c478bd9Sstevel@tonic-gate static void 13287c478bd9Sstevel@tonic-gate print_cond( 13297c478bd9Sstevel@tonic-gate cfga_list_data_t *p, 13307c478bd9Sstevel@tonic-gate int width, 13317c478bd9Sstevel@tonic-gate char *lp) 13327c478bd9Sstevel@tonic-gate { 13337c478bd9Sstevel@tonic-gate char *cp; 13347c478bd9Sstevel@tonic-gate 13357c478bd9Sstevel@tonic-gate switch (p->ap_cond) { 13367c478bd9Sstevel@tonic-gate case CFGA_COND_UNKNOWN: 13377c478bd9Sstevel@tonic-gate cp = "unknown"; 13387c478bd9Sstevel@tonic-gate break; 13397c478bd9Sstevel@tonic-gate case CFGA_COND_UNUSABLE: 13407c478bd9Sstevel@tonic-gate cp = "unusable"; 13417c478bd9Sstevel@tonic-gate break; 13427c478bd9Sstevel@tonic-gate case CFGA_COND_FAILING: 13437c478bd9Sstevel@tonic-gate cp = "failing"; 13447c478bd9Sstevel@tonic-gate break; 13457c478bd9Sstevel@tonic-gate case CFGA_COND_FAILED: 13467c478bd9Sstevel@tonic-gate cp = "failed"; 13477c478bd9Sstevel@tonic-gate break; 13487c478bd9Sstevel@tonic-gate case CFGA_COND_OK: 13497c478bd9Sstevel@tonic-gate cp = "ok"; 13507c478bd9Sstevel@tonic-gate break; 13517c478bd9Sstevel@tonic-gate default: 13527c478bd9Sstevel@tonic-gate cp = "???"; 13537c478bd9Sstevel@tonic-gate break; 13547c478bd9Sstevel@tonic-gate } 13557c478bd9Sstevel@tonic-gate (void) sprintf(lp, "%-*s", width, cp); 13567c478bd9Sstevel@tonic-gate } 13577c478bd9Sstevel@tonic-gate 13587c478bd9Sstevel@tonic-gate /* 13597c478bd9Sstevel@tonic-gate * compare_time - compare time field of two ap_id's 13607c478bd9Sstevel@tonic-gate */ 13617c478bd9Sstevel@tonic-gate static int 13627c478bd9Sstevel@tonic-gate compare_time( 13637c478bd9Sstevel@tonic-gate cfga_list_data_t *p1, 13647c478bd9Sstevel@tonic-gate cfga_list_data_t *p2, 13657c478bd9Sstevel@tonic-gate match_type_t match_type) 13667c478bd9Sstevel@tonic-gate { 13677c478bd9Sstevel@tonic-gate switch (match_type) { 13687c478bd9Sstevel@tonic-gate case CFGA_MATCH_NOFILTER: 13697c478bd9Sstevel@tonic-gate return (0); 13707c478bd9Sstevel@tonic-gate case CFGA_MATCH_ORDER: 13717c478bd9Sstevel@tonic-gate default: 13727c478bd9Sstevel@tonic-gate return (p1->ap_status_time - p2->ap_status_time); 13737c478bd9Sstevel@tonic-gate } 13747c478bd9Sstevel@tonic-gate } 13757c478bd9Sstevel@tonic-gate 13767c478bd9Sstevel@tonic-gate 13777c478bd9Sstevel@tonic-gate /* 13787c478bd9Sstevel@tonic-gate * print_time - print time from cfga_list_data. 13797c478bd9Sstevel@tonic-gate * Time print based on ls(1). 13807c478bd9Sstevel@tonic-gate */ 13817c478bd9Sstevel@tonic-gate static void 13827c478bd9Sstevel@tonic-gate print_time( 13837c478bd9Sstevel@tonic-gate cfga_list_data_t *p, 13847c478bd9Sstevel@tonic-gate int width, 13857c478bd9Sstevel@tonic-gate char *lp) 13867c478bd9Sstevel@tonic-gate { 13877c478bd9Sstevel@tonic-gate static time_t year, now; 13887c478bd9Sstevel@tonic-gate time_t stime; 13897c478bd9Sstevel@tonic-gate char time_buf[50]; /* array to hold day and time */ 13907c478bd9Sstevel@tonic-gate 13917c478bd9Sstevel@tonic-gate if (year == 0) { 13927c478bd9Sstevel@tonic-gate now = time((long *)NULL); 13937c478bd9Sstevel@tonic-gate year = now - 6L*30L*24L*60L*60L; /* 6 months ago */ 13947c478bd9Sstevel@tonic-gate now = now + 60; 13957c478bd9Sstevel@tonic-gate } 13967c478bd9Sstevel@tonic-gate stime = p->ap_status_time; 13977c478bd9Sstevel@tonic-gate if (stime == (time_t)-1) { 13987c478bd9Sstevel@tonic-gate (void) sprintf(lp, "%-*s", width, gettext("unavailable")); 13997c478bd9Sstevel@tonic-gate return; 14007c478bd9Sstevel@tonic-gate } 14017c478bd9Sstevel@tonic-gate 14027c478bd9Sstevel@tonic-gate if ((stime < year) || (stime > now)) { 14037c478bd9Sstevel@tonic-gate (void) strftime(time_buf, sizeof (time_buf), 14047c478bd9Sstevel@tonic-gate dcgettext(NULL, FORMAT1, LC_TIME), localtime(&stime)); 14057c478bd9Sstevel@tonic-gate } else { 14067c478bd9Sstevel@tonic-gate (void) strftime(time_buf, sizeof (time_buf), 14077c478bd9Sstevel@tonic-gate dcgettext(NULL, FORMAT2, LC_TIME), localtime(&stime)); 14087c478bd9Sstevel@tonic-gate } 14097c478bd9Sstevel@tonic-gate (void) sprintf(lp, "%-*s", width, time_buf); 14107c478bd9Sstevel@tonic-gate } 14117c478bd9Sstevel@tonic-gate 14127c478bd9Sstevel@tonic-gate /* 14137c478bd9Sstevel@tonic-gate * print_time_p - print time from cfga_list_data. 14147c478bd9Sstevel@tonic-gate */ 14157c478bd9Sstevel@tonic-gate static void 14167c478bd9Sstevel@tonic-gate print_time_p( 14177c478bd9Sstevel@tonic-gate cfga_list_data_t *p, 14187c478bd9Sstevel@tonic-gate int width, 14197c478bd9Sstevel@tonic-gate char *lp) 14207c478bd9Sstevel@tonic-gate { 14217c478bd9Sstevel@tonic-gate struct tm *tp; 14227c478bd9Sstevel@tonic-gate char tstr[TIME_P_WIDTH+1]; 14237c478bd9Sstevel@tonic-gate 14247c478bd9Sstevel@tonic-gate tp = localtime(&p->ap_status_time); 14257c478bd9Sstevel@tonic-gate (void) sprintf(tstr, "%04d%02d%02d%02d%02d%02d", tp->tm_year + 1900, 14267c478bd9Sstevel@tonic-gate tp->tm_mon + 1, tp->tm_mday, tp->tm_hour, tp->tm_min, tp->tm_sec); 14277c478bd9Sstevel@tonic-gate (void) sprintf(lp, "%-*s", width, tstr); 14287c478bd9Sstevel@tonic-gate } 14297c478bd9Sstevel@tonic-gate 14307c478bd9Sstevel@tonic-gate /* 14317c478bd9Sstevel@tonic-gate * compare_info - compare info from two cfga_list_data structs 14327c478bd9Sstevel@tonic-gate */ 14337c478bd9Sstevel@tonic-gate static int 14347c478bd9Sstevel@tonic-gate compare_info( 14357c478bd9Sstevel@tonic-gate cfga_list_data_t *p1, 14367c478bd9Sstevel@tonic-gate cfga_list_data_t *p2, 14377c478bd9Sstevel@tonic-gate match_type_t match_type) 14387c478bd9Sstevel@tonic-gate { 14397c478bd9Sstevel@tonic-gate switch (match_type) { 14407c478bd9Sstevel@tonic-gate case CFGA_MATCH_NOFILTER: 14417c478bd9Sstevel@tonic-gate return (0); 14427c478bd9Sstevel@tonic-gate case CFGA_MATCH_ORDER: 14437c478bd9Sstevel@tonic-gate default: 14447c478bd9Sstevel@tonic-gate return (strncmp(p1->ap_info, p2->ap_info, 14457c478bd9Sstevel@tonic-gate sizeof (p2->ap_info))); 14467c478bd9Sstevel@tonic-gate } 14477c478bd9Sstevel@tonic-gate } 14487c478bd9Sstevel@tonic-gate 14497c478bd9Sstevel@tonic-gate /* 14507c478bd9Sstevel@tonic-gate * print_info - print info from cfga_list_data struct 14517c478bd9Sstevel@tonic-gate */ 14527c478bd9Sstevel@tonic-gate static void 14537c478bd9Sstevel@tonic-gate print_info( 14547c478bd9Sstevel@tonic-gate cfga_list_data_t *p, 14557c478bd9Sstevel@tonic-gate int width, 14567c478bd9Sstevel@tonic-gate char *lp) 14577c478bd9Sstevel@tonic-gate { 14587c478bd9Sstevel@tonic-gate (void) sprintf(lp, "%-*.*s", width, sizeof (p->ap_info), p->ap_info); 14597c478bd9Sstevel@tonic-gate } 14607c478bd9Sstevel@tonic-gate 14617c478bd9Sstevel@tonic-gate /* 14627c478bd9Sstevel@tonic-gate * compare_type - compare type from two cfga_list_data structs 14637c478bd9Sstevel@tonic-gate * 14647c478bd9Sstevel@tonic-gate * For partial matches, argument order is significant. The filtering criterion 14657c478bd9Sstevel@tonic-gate * should be the first argument. 14667c478bd9Sstevel@tonic-gate */ 14677c478bd9Sstevel@tonic-gate static int 14687c478bd9Sstevel@tonic-gate compare_type( 14697c478bd9Sstevel@tonic-gate cfga_list_data_t *p1, 14707c478bd9Sstevel@tonic-gate cfga_list_data_t *p2, 14717c478bd9Sstevel@tonic-gate match_type_t match_type) 14727c478bd9Sstevel@tonic-gate { 14737c478bd9Sstevel@tonic-gate switch (match_type) { 14747c478bd9Sstevel@tonic-gate case CFGA_MATCH_NOFILTER: 14757c478bd9Sstevel@tonic-gate return (0); 14767c478bd9Sstevel@tonic-gate case CFGA_MATCH_PARTIAL: 14777c478bd9Sstevel@tonic-gate return (strncmp(p1->ap_type, p2->ap_type, strlen(p1->ap_type))); 14787c478bd9Sstevel@tonic-gate case CFGA_MATCH_EXACT: 14797c478bd9Sstevel@tonic-gate case CFGA_MATCH_ORDER: 14807c478bd9Sstevel@tonic-gate default: 14817c478bd9Sstevel@tonic-gate return (strncmp(p1->ap_type, p2->ap_type, 14827c478bd9Sstevel@tonic-gate sizeof (p2->ap_type))); 14837c478bd9Sstevel@tonic-gate } 14847c478bd9Sstevel@tonic-gate } 14857c478bd9Sstevel@tonic-gate 14867c478bd9Sstevel@tonic-gate /* 14877c478bd9Sstevel@tonic-gate * print_type - print type from cfga_list_data struct 14887c478bd9Sstevel@tonic-gate */ 14897c478bd9Sstevel@tonic-gate static void 14907c478bd9Sstevel@tonic-gate print_type( 14917c478bd9Sstevel@tonic-gate cfga_list_data_t *p, 14927c478bd9Sstevel@tonic-gate int width, 14937c478bd9Sstevel@tonic-gate char *lp) 14947c478bd9Sstevel@tonic-gate { 14957c478bd9Sstevel@tonic-gate (void) sprintf(lp, "%-*.*s", width, sizeof (p->ap_type), p->ap_type); 14967c478bd9Sstevel@tonic-gate } 14977c478bd9Sstevel@tonic-gate 14987c478bd9Sstevel@tonic-gate 14997c478bd9Sstevel@tonic-gate /* 15007c478bd9Sstevel@tonic-gate * compare_class - compare class from two cfga_list_data structs 15017c478bd9Sstevel@tonic-gate * 15027c478bd9Sstevel@tonic-gate * For partial matches, argument order is significant. The filtering criterion 15037c478bd9Sstevel@tonic-gate * should be the first argument. 15047c478bd9Sstevel@tonic-gate */ 15057c478bd9Sstevel@tonic-gate static int 15067c478bd9Sstevel@tonic-gate compare_class( 15077c478bd9Sstevel@tonic-gate cfga_list_data_t *p1, 15087c478bd9Sstevel@tonic-gate cfga_list_data_t *p2, 15097c478bd9Sstevel@tonic-gate match_type_t match_type) 15107c478bd9Sstevel@tonic-gate { 15117c478bd9Sstevel@tonic-gate 15127c478bd9Sstevel@tonic-gate switch (match_type) { 15137c478bd9Sstevel@tonic-gate case CFGA_MATCH_NOFILTER: 15147c478bd9Sstevel@tonic-gate return (0); 15157c478bd9Sstevel@tonic-gate case CFGA_MATCH_PARTIAL: 15167c478bd9Sstevel@tonic-gate return (strncmp(p1->ap_class, p2->ap_class, 15177c478bd9Sstevel@tonic-gate strlen(p1->ap_class))); 15187c478bd9Sstevel@tonic-gate case CFGA_MATCH_EXACT: 15197c478bd9Sstevel@tonic-gate case CFGA_MATCH_ORDER: 15207c478bd9Sstevel@tonic-gate default: 15217c478bd9Sstevel@tonic-gate return (strncmp(p1->ap_class, p2->ap_class, 15227c478bd9Sstevel@tonic-gate sizeof (p2->ap_class))); 15237c478bd9Sstevel@tonic-gate } 15247c478bd9Sstevel@tonic-gate } 15257c478bd9Sstevel@tonic-gate 15267c478bd9Sstevel@tonic-gate /* 15277c478bd9Sstevel@tonic-gate * print_class - print class from cfga_list_data struct 15287c478bd9Sstevel@tonic-gate */ 15297c478bd9Sstevel@tonic-gate static void 15307c478bd9Sstevel@tonic-gate print_class( 15317c478bd9Sstevel@tonic-gate cfga_list_data_t *p, 15327c478bd9Sstevel@tonic-gate int width, 15337c478bd9Sstevel@tonic-gate char *lp) 15347c478bd9Sstevel@tonic-gate { 15357c478bd9Sstevel@tonic-gate (void) sprintf(lp, "%-*.*s", width, sizeof (p->ap_class), p->ap_class); 15367c478bd9Sstevel@tonic-gate } 15377c478bd9Sstevel@tonic-gate /* 15387c478bd9Sstevel@tonic-gate * print_busy - print busy from cfga_list_data struct 15397c478bd9Sstevel@tonic-gate */ 15407c478bd9Sstevel@tonic-gate /* ARGSUSED */ 15417c478bd9Sstevel@tonic-gate static void 15427c478bd9Sstevel@tonic-gate print_busy( 15437c478bd9Sstevel@tonic-gate cfga_list_data_t *p, 15447c478bd9Sstevel@tonic-gate int width, 15457c478bd9Sstevel@tonic-gate char *lp) 15467c478bd9Sstevel@tonic-gate { 15477c478bd9Sstevel@tonic-gate if (p->ap_busy) 15487c478bd9Sstevel@tonic-gate (void) sprintf(lp, "%-*.*s", width, width, "y"); 15497c478bd9Sstevel@tonic-gate else 15507c478bd9Sstevel@tonic-gate (void) sprintf(lp, "%-*.*s", width, width, "n"); 15517c478bd9Sstevel@tonic-gate } 15527c478bd9Sstevel@tonic-gate 15537c478bd9Sstevel@tonic-gate /* 15547c478bd9Sstevel@tonic-gate * print_phys_id - print physical ap_id 15557c478bd9Sstevel@tonic-gate */ 15567c478bd9Sstevel@tonic-gate static void 15577c478bd9Sstevel@tonic-gate print_phys_id( 15587c478bd9Sstevel@tonic-gate cfga_list_data_t *p, 15597c478bd9Sstevel@tonic-gate int width, 15607c478bd9Sstevel@tonic-gate char *lp) 15617c478bd9Sstevel@tonic-gate { 15627c478bd9Sstevel@tonic-gate (void) sprintf(lp, "%-*.*s", width, sizeof (p->ap_phys_id), 15637c478bd9Sstevel@tonic-gate p->ap_phys_id); 15647c478bd9Sstevel@tonic-gate } 15657c478bd9Sstevel@tonic-gate 15667c478bd9Sstevel@tonic-gate 15677c478bd9Sstevel@tonic-gate /* 15687c478bd9Sstevel@tonic-gate * find_field - find the named field 15697c478bd9Sstevel@tonic-gate */ 15707c478bd9Sstevel@tonic-gate static struct field_info * 15717c478bd9Sstevel@tonic-gate find_field(char *fname) 15727c478bd9Sstevel@tonic-gate { 15737c478bd9Sstevel@tonic-gate struct field_info *fldp; 15747c478bd9Sstevel@tonic-gate 15757c478bd9Sstevel@tonic-gate for (fldp = all_fields; fldp < &all_fields[N_FIELDS]; fldp++) 15767c478bd9Sstevel@tonic-gate if (strcmp(fname, fldp->name) == 0) 15777c478bd9Sstevel@tonic-gate return (fldp); 15787c478bd9Sstevel@tonic-gate return (NULL); 15797c478bd9Sstevel@tonic-gate } 15807c478bd9Sstevel@tonic-gate 15817c478bd9Sstevel@tonic-gate /* 15827c478bd9Sstevel@tonic-gate * usage_field - print field usage 15837c478bd9Sstevel@tonic-gate */ 15847c478bd9Sstevel@tonic-gate static void 15857c478bd9Sstevel@tonic-gate usage_field() 15867c478bd9Sstevel@tonic-gate { 15877c478bd9Sstevel@tonic-gate struct field_info *fldp = NULL; 15887c478bd9Sstevel@tonic-gate const char *sep; 15897c478bd9Sstevel@tonic-gate static char field_list[] = "%s: print or sort fields must be one of:"; 15907c478bd9Sstevel@tonic-gate 15917c478bd9Sstevel@tonic-gate (void) fprintf(stderr, gettext(field_list), cmdname); 15927c478bd9Sstevel@tonic-gate sep = ""; 15937c478bd9Sstevel@tonic-gate 15947c478bd9Sstevel@tonic-gate for (fldp = all_fields; fldp < &all_fields[N_FIELDS]; fldp++) { 15957c478bd9Sstevel@tonic-gate (void) fprintf(stderr, "%s %s", sep, fldp->name); 15967c478bd9Sstevel@tonic-gate sep = ","; 15977c478bd9Sstevel@tonic-gate } 15987c478bd9Sstevel@tonic-gate (void) fprintf(stderr, "\n"); 15997c478bd9Sstevel@tonic-gate } 16007c478bd9Sstevel@tonic-gate 16017c478bd9Sstevel@tonic-gate /* 16027c478bd9Sstevel@tonic-gate * compare_null - null comparison routine 16037c478bd9Sstevel@tonic-gate */ 16047c478bd9Sstevel@tonic-gate /*ARGSUSED*/ 16057c478bd9Sstevel@tonic-gate static int 16067c478bd9Sstevel@tonic-gate compare_null( 16077c478bd9Sstevel@tonic-gate cfga_list_data_t *p1, 16087c478bd9Sstevel@tonic-gate cfga_list_data_t *p2, 16097c478bd9Sstevel@tonic-gate match_type_t match_type) 16107c478bd9Sstevel@tonic-gate { 16117c478bd9Sstevel@tonic-gate return (0); 16127c478bd9Sstevel@tonic-gate } 16137c478bd9Sstevel@tonic-gate 16147c478bd9Sstevel@tonic-gate /* 16157c478bd9Sstevel@tonic-gate * print_null - print out a field of spaces 16167c478bd9Sstevel@tonic-gate */ 16177c478bd9Sstevel@tonic-gate /*ARGSUSED*/ 16187c478bd9Sstevel@tonic-gate static void 16197c478bd9Sstevel@tonic-gate print_null( 16207c478bd9Sstevel@tonic-gate cfga_list_data_t *p, 16217c478bd9Sstevel@tonic-gate int width, 16227c478bd9Sstevel@tonic-gate char *lp) 16237c478bd9Sstevel@tonic-gate { 16247c478bd9Sstevel@tonic-gate (void) sprintf(lp, "%-*s", width, ""); 16257c478bd9Sstevel@tonic-gate } 16267c478bd9Sstevel@tonic-gate 16277c478bd9Sstevel@tonic-gate /* 16287c478bd9Sstevel@tonic-gate * do_config_list - directs the output of the listing functions 16297c478bd9Sstevel@tonic-gate */ 16307c478bd9Sstevel@tonic-gate static int 16317c478bd9Sstevel@tonic-gate do_config_list( 16327c478bd9Sstevel@tonic-gate int l_argc, 16337c478bd9Sstevel@tonic-gate char *l_argv[], 16347c478bd9Sstevel@tonic-gate cfga_list_data_t *statlist, 16357c478bd9Sstevel@tonic-gate int nlist, 16367c478bd9Sstevel@tonic-gate char *sortp, 16377c478bd9Sstevel@tonic-gate char *colsp, 16387c478bd9Sstevel@tonic-gate char *cols2p, 16397c478bd9Sstevel@tonic-gate int noheadings, 16407c478bd9Sstevel@tonic-gate char *delimp, 16417c478bd9Sstevel@tonic-gate post_filter_t *post_filtp, 16427c478bd9Sstevel@tonic-gate int dyn_exp) 16437c478bd9Sstevel@tonic-gate { 16447c478bd9Sstevel@tonic-gate int nprcols = 0, ncols2 = 0; 16457c478bd9Sstevel@tonic-gate struct print_col *prnt_list = NULL; 16467c478bd9Sstevel@tonic-gate int napids_to_list = 0; 16477c478bd9Sstevel@tonic-gate FILE *fp = NULL; 16487c478bd9Sstevel@tonic-gate int f_err; 16497c478bd9Sstevel@tonic-gate cfga_list_data_t **sel_boards = NULL; 16507c478bd9Sstevel@tonic-gate int nsel = 0; 16517c478bd9Sstevel@tonic-gate int i, j; 16527c478bd9Sstevel@tonic-gate cfga_err_t ret; 16537c478bd9Sstevel@tonic-gate 16547c478bd9Sstevel@tonic-gate ap_arg_t *arg_array = NULL; 16557c478bd9Sstevel@tonic-gate ap_out_t *out_array = NULL; 16567c478bd9Sstevel@tonic-gate 16577c478bd9Sstevel@tonic-gate 16587c478bd9Sstevel@tonic-gate sort_list = NULL; 16597c478bd9Sstevel@tonic-gate f_err = 0; 16607c478bd9Sstevel@tonic-gate fp = stdout; 16617c478bd9Sstevel@tonic-gate nsort_list = count_fields(sortp, FDELIM); 16627c478bd9Sstevel@tonic-gate if (nsort_list != 0) { 16637c478bd9Sstevel@tonic-gate sort_list = config_calloc_check(nsort_list, 16647c478bd9Sstevel@tonic-gate sizeof (*sort_list)); 16657c478bd9Sstevel@tonic-gate if (sort_list == NULL) { 16667c478bd9Sstevel@tonic-gate ret = CFGA_LIB_ERROR; 16677c478bd9Sstevel@tonic-gate goto out; 16687c478bd9Sstevel@tonic-gate } 16697c478bd9Sstevel@tonic-gate f_err |= process_sort_fields(nsort_list, sort_list, sortp); 16707c478bd9Sstevel@tonic-gate } else 16717c478bd9Sstevel@tonic-gate sort_list = NULL; 16727c478bd9Sstevel@tonic-gate 16737c478bd9Sstevel@tonic-gate nprcols = count_fields(colsp, FDELIM); 16747c478bd9Sstevel@tonic-gate if ((ncols2 = count_fields(cols2p, FDELIM)) > nprcols) 16757c478bd9Sstevel@tonic-gate nprcols = ncols2; 16767c478bd9Sstevel@tonic-gate if (nprcols != 0) { 16777c478bd9Sstevel@tonic-gate prnt_list = config_calloc_check(nprcols, sizeof (*prnt_list)); 16787c478bd9Sstevel@tonic-gate if (prnt_list == NULL) { 16797c478bd9Sstevel@tonic-gate ret = CFGA_LIB_ERROR; 16807c478bd9Sstevel@tonic-gate goto out; 16817c478bd9Sstevel@tonic-gate } 16827c478bd9Sstevel@tonic-gate f_err |= process_fields(nprcols, prnt_list, 0, colsp); 16837c478bd9Sstevel@tonic-gate if (ncols2 != 0) 16847c478bd9Sstevel@tonic-gate f_err |= process_fields(nprcols, prnt_list, 1, cols2p); 16857c478bd9Sstevel@tonic-gate } else 16867c478bd9Sstevel@tonic-gate prnt_list = NULL; 16877c478bd9Sstevel@tonic-gate 16887c478bd9Sstevel@tonic-gate if (f_err) { 16897c478bd9Sstevel@tonic-gate usage_field(); 16907c478bd9Sstevel@tonic-gate ret = CFGA_ERROR; 16917c478bd9Sstevel@tonic-gate goto out; 16927c478bd9Sstevel@tonic-gate } 16937c478bd9Sstevel@tonic-gate 16947c478bd9Sstevel@tonic-gate /* Create an array of all user args (if any) */ 16957c478bd9Sstevel@tonic-gate if (l_argc != 0) { 16967c478bd9Sstevel@tonic-gate int i, j; 16977c478bd9Sstevel@tonic-gate 16987c478bd9Sstevel@tonic-gate napids_to_list = 0; 16997c478bd9Sstevel@tonic-gate 17007c478bd9Sstevel@tonic-gate for (i = 0; i < l_argc; i++) { 17017c478bd9Sstevel@tonic-gate napids_to_list += count_fields(l_argv[i], ARG_DELIM); 17027c478bd9Sstevel@tonic-gate } 17037c478bd9Sstevel@tonic-gate 17047c478bd9Sstevel@tonic-gate arg_array = config_calloc_check(napids_to_list, 17057c478bd9Sstevel@tonic-gate sizeof (*arg_array)); 17067c478bd9Sstevel@tonic-gate if (arg_array == NULL) { 17077c478bd9Sstevel@tonic-gate ret = CFGA_LIB_ERROR; 17087c478bd9Sstevel@tonic-gate goto out; 17097c478bd9Sstevel@tonic-gate } 17107c478bd9Sstevel@tonic-gate 17117c478bd9Sstevel@tonic-gate for (i = 0, j = 0; i < l_argc; i++) { 17127c478bd9Sstevel@tonic-gate int n; 17137c478bd9Sstevel@tonic-gate 17147c478bd9Sstevel@tonic-gate n = count_fields(l_argv[i], ARG_DELIM); 17157c478bd9Sstevel@tonic-gate if (n == 0) { 17167c478bd9Sstevel@tonic-gate continue; 17177c478bd9Sstevel@tonic-gate } else if (n == 1) { 17187c478bd9Sstevel@tonic-gate arg_array[j].arg = l_argv[i]; 17197c478bd9Sstevel@tonic-gate arg_array[j].resp = 0; 17207c478bd9Sstevel@tonic-gate j++; 17217c478bd9Sstevel@tonic-gate } else { 17227c478bd9Sstevel@tonic-gate char *cp, *ncp; 17237c478bd9Sstevel@tonic-gate 17247c478bd9Sstevel@tonic-gate cp = l_argv[i]; 17257c478bd9Sstevel@tonic-gate for (;;) { 17267c478bd9Sstevel@tonic-gate arg_array[j].arg = cp; 17277c478bd9Sstevel@tonic-gate arg_array[j].resp = 0; 17287c478bd9Sstevel@tonic-gate j++; 17297c478bd9Sstevel@tonic-gate ncp = strchr(cp, ARG_DELIM); 17307c478bd9Sstevel@tonic-gate if (ncp == NULL) 17317c478bd9Sstevel@tonic-gate break; 17327c478bd9Sstevel@tonic-gate *ncp = '\0'; 17337c478bd9Sstevel@tonic-gate cp = ncp + 1; 17347c478bd9Sstevel@tonic-gate } 17357c478bd9Sstevel@tonic-gate } 17367c478bd9Sstevel@tonic-gate } 17377c478bd9Sstevel@tonic-gate assert(j == napids_to_list); 17387c478bd9Sstevel@tonic-gate } else { 17397c478bd9Sstevel@tonic-gate napids_to_list = 0; 17407c478bd9Sstevel@tonic-gate arg_array = NULL; 17417c478bd9Sstevel@tonic-gate } 17427c478bd9Sstevel@tonic-gate 17437c478bd9Sstevel@tonic-gate assert(nlist != 0); 17447c478bd9Sstevel@tonic-gate 17457c478bd9Sstevel@tonic-gate out_array = config_calloc_check(nlist, sizeof (*out_array)); 17467c478bd9Sstevel@tonic-gate if (out_array == NULL) { 17477c478bd9Sstevel@tonic-gate ret = CFGA_LIB_ERROR; 17487c478bd9Sstevel@tonic-gate goto out; 17497c478bd9Sstevel@tonic-gate } 17507c478bd9Sstevel@tonic-gate 17517c478bd9Sstevel@tonic-gate 17527c478bd9Sstevel@tonic-gate /* create a list of output stat data */ 17537c478bd9Sstevel@tonic-gate for (i = 0; i < nlist; i++) { 17547c478bd9Sstevel@tonic-gate out_array[i].ldatap = &statlist[i]; 17557c478bd9Sstevel@tonic-gate out_array[i].req = 0; 17567c478bd9Sstevel@tonic-gate } 17577c478bd9Sstevel@tonic-gate 17587c478bd9Sstevel@tonic-gate /* 17597c478bd9Sstevel@tonic-gate * Mark all user input which got atleast 1 stat data in response 17607c478bd9Sstevel@tonic-gate */ 17617c478bd9Sstevel@tonic-gate for (i = 0; i < napids_to_list; i++) { 17627c478bd9Sstevel@tonic-gate arg_got_resp(&arg_array[i], out_array, nlist, dyn_exp); 17637c478bd9Sstevel@tonic-gate } 17647c478bd9Sstevel@tonic-gate 17657c478bd9Sstevel@tonic-gate /* 17667c478bd9Sstevel@tonic-gate * Process output data 17677c478bd9Sstevel@tonic-gate */ 17687c478bd9Sstevel@tonic-gate nsel = 0; 17697c478bd9Sstevel@tonic-gate for (i = 0; i < nlist; i++) { 17707c478bd9Sstevel@tonic-gate /* 17717c478bd9Sstevel@tonic-gate * Mark all the stats which were actually requested by user 17727c478bd9Sstevel@tonic-gate */ 17737c478bd9Sstevel@tonic-gate out_was_req(&out_array[i], arg_array, napids_to_list, 0); 17747c478bd9Sstevel@tonic-gate if (out_array[i].req == 0 && dyn_exp) { 17757c478bd9Sstevel@tonic-gate /* 17767c478bd9Sstevel@tonic-gate * Try again without the dynamic component for the 17777c478bd9Sstevel@tonic-gate * if dynamic expansion was requested. 17787c478bd9Sstevel@tonic-gate */ 17797c478bd9Sstevel@tonic-gate out_was_req(&out_array[i], arg_array, 17807c478bd9Sstevel@tonic-gate napids_to_list, 1); 17817c478bd9Sstevel@tonic-gate } 17827c478bd9Sstevel@tonic-gate 17837c478bd9Sstevel@tonic-gate /* 17847c478bd9Sstevel@tonic-gate * post filter data which was actually requested 17857c478bd9Sstevel@tonic-gate */ 17867c478bd9Sstevel@tonic-gate if (out_array[i].req == 1) { 17877c478bd9Sstevel@tonic-gate do_post_filter(&out_array[i], post_filtp, &nsel); 17887c478bd9Sstevel@tonic-gate } 17897c478bd9Sstevel@tonic-gate } 17907c478bd9Sstevel@tonic-gate 17917c478bd9Sstevel@tonic-gate sel_boards = config_calloc_check(nsel, sizeof (*sel_boards)); 17927c478bd9Sstevel@tonic-gate if (sel_boards == NULL) { 17937c478bd9Sstevel@tonic-gate ret = CFGA_LIB_ERROR; 17947c478bd9Sstevel@tonic-gate goto out; 17957c478bd9Sstevel@tonic-gate } 17967c478bd9Sstevel@tonic-gate 17977c478bd9Sstevel@tonic-gate for (i = 0, j = 0; i < nlist; i++) { 17987c478bd9Sstevel@tonic-gate if (out_array[i].req == 1) { 17997c478bd9Sstevel@tonic-gate sel_boards[j] = out_array[i].ldatap; 18007c478bd9Sstevel@tonic-gate j++; 18017c478bd9Sstevel@tonic-gate } 18027c478bd9Sstevel@tonic-gate } 18037c478bd9Sstevel@tonic-gate 18047c478bd9Sstevel@tonic-gate assert(j == nsel); 18057c478bd9Sstevel@tonic-gate 18067c478bd9Sstevel@tonic-gate /* 18077c478bd9Sstevel@tonic-gate * Print headings even if no list entries - Bug or feature ? 18087c478bd9Sstevel@tonic-gate */ 18097c478bd9Sstevel@tonic-gate if (!noheadings && prnt_list != NULL) { 18107c478bd9Sstevel@tonic-gate if ((ret = print_fields(nprcols, prnt_list, 1, 0, 18117c478bd9Sstevel@tonic-gate delimp, NULL, fp)) != CFGA_OK) { 18127c478bd9Sstevel@tonic-gate goto out; 18137c478bd9Sstevel@tonic-gate } 18147c478bd9Sstevel@tonic-gate if (ncols2 != 0) { 18157c478bd9Sstevel@tonic-gate if ((ret = print_fields(nprcols, prnt_list, 1, 18167c478bd9Sstevel@tonic-gate 1, delimp, NULL, fp)) != CFGA_OK) { 18177c478bd9Sstevel@tonic-gate goto out; 18187c478bd9Sstevel@tonic-gate } 18197c478bd9Sstevel@tonic-gate } 18207c478bd9Sstevel@tonic-gate } 18217c478bd9Sstevel@tonic-gate 18227c478bd9Sstevel@tonic-gate if (nsel != 0) { 18237c478bd9Sstevel@tonic-gate if (sort_list != NULL && nsel > 1) { 18247c478bd9Sstevel@tonic-gate qsort(sel_boards, nsel, sizeof (sel_boards[0]), 18257c478bd9Sstevel@tonic-gate ldata_compare); 18267c478bd9Sstevel@tonic-gate } 18277c478bd9Sstevel@tonic-gate 18287c478bd9Sstevel@tonic-gate if (prnt_list != NULL) { 18297c478bd9Sstevel@tonic-gate for (i = 0; i < nsel; i++) { 18307c478bd9Sstevel@tonic-gate if ((ret = print_fields(nprcols, 18317c478bd9Sstevel@tonic-gate prnt_list, 0, 0, delimp, sel_boards[i], fp)) 18327c478bd9Sstevel@tonic-gate != CFGA_OK) 18337c478bd9Sstevel@tonic-gate goto out; 18347c478bd9Sstevel@tonic-gate if (ncols2 != 0) { 18357c478bd9Sstevel@tonic-gate if ((ret = print_fields( 18367c478bd9Sstevel@tonic-gate nprcols, prnt_list, 0, 1, delimp, 18377c478bd9Sstevel@tonic-gate sel_boards[i], fp)) != CFGA_OK) 18387c478bd9Sstevel@tonic-gate goto out; 18397c478bd9Sstevel@tonic-gate } 18407c478bd9Sstevel@tonic-gate } 18417c478bd9Sstevel@tonic-gate } 18427c478bd9Sstevel@tonic-gate } 18437c478bd9Sstevel@tonic-gate /* 18447c478bd9Sstevel@tonic-gate * Go thru the argument list and notify user about args 18457c478bd9Sstevel@tonic-gate * which did not have a match 18467c478bd9Sstevel@tonic-gate */ 18477c478bd9Sstevel@tonic-gate report_no_response(arg_array, napids_to_list); 18487c478bd9Sstevel@tonic-gate ret = CFGA_OK; 18497c478bd9Sstevel@tonic-gate /*FALLTHRU*/ 18507c478bd9Sstevel@tonic-gate out: 18517c478bd9Sstevel@tonic-gate S_FREE(sel_boards); 18527c478bd9Sstevel@tonic-gate S_FREE(arg_array); 18537c478bd9Sstevel@tonic-gate S_FREE(out_array); 18547c478bd9Sstevel@tonic-gate 18557c478bd9Sstevel@tonic-gate S_FREE(sort_list); 18567c478bd9Sstevel@tonic-gate S_FREE(prnt_list); 18577c478bd9Sstevel@tonic-gate 18587c478bd9Sstevel@tonic-gate return (ret); 18597c478bd9Sstevel@tonic-gate } 18607c478bd9Sstevel@tonic-gate 18617c478bd9Sstevel@tonic-gate 18627c478bd9Sstevel@tonic-gate /* 18637c478bd9Sstevel@tonic-gate * Mark all user inputs which got a response 18647c478bd9Sstevel@tonic-gate */ 18657c478bd9Sstevel@tonic-gate static void 18667c478bd9Sstevel@tonic-gate arg_got_resp(ap_arg_t *inp, ap_out_t *out_array, int nouts, int dyn_exp) 18677c478bd9Sstevel@tonic-gate { 18687c478bd9Sstevel@tonic-gate int i; 18697c478bd9Sstevel@tonic-gate cfga_ap_types_t type; 18707c478bd9Sstevel@tonic-gate 18717c478bd9Sstevel@tonic-gate 18727c478bd9Sstevel@tonic-gate if (nouts == 0) { 18737c478bd9Sstevel@tonic-gate return; 18747c478bd9Sstevel@tonic-gate } 18757c478bd9Sstevel@tonic-gate 18767c478bd9Sstevel@tonic-gate type = find_arg_type(inp->arg); 18777c478bd9Sstevel@tonic-gate 18787c478bd9Sstevel@tonic-gate /* 18797c478bd9Sstevel@tonic-gate * Go through list of output stats and check if argument 18807c478bd9Sstevel@tonic-gate * produced that output 18817c478bd9Sstevel@tonic-gate */ 18827c478bd9Sstevel@tonic-gate for (i = 0; i < nouts; i++) { 18837c478bd9Sstevel@tonic-gate if (type == PHYSICAL_AP_ID) { 18847c478bd9Sstevel@tonic-gate if (config_ap_id_cmp(out_array[i].ldatap->ap_phys_id, 18857c478bd9Sstevel@tonic-gate inp->arg) == 0) { 18867c478bd9Sstevel@tonic-gate break; 18877c478bd9Sstevel@tonic-gate } 18887c478bd9Sstevel@tonic-gate } else if (type == LOGICAL_AP_ID) { 18897c478bd9Sstevel@tonic-gate if (config_ap_id_cmp(out_array[i].ldatap->ap_log_id, 18907c478bd9Sstevel@tonic-gate inp->arg) == 0) { 18917c478bd9Sstevel@tonic-gate break; 18927c478bd9Sstevel@tonic-gate } 18937c478bd9Sstevel@tonic-gate } else if (type == AP_TYPE) { 18947c478bd9Sstevel@tonic-gate /* 18957c478bd9Sstevel@tonic-gate * An AP_TYPE argument cannot generate dynamic 18967c478bd9Sstevel@tonic-gate * attachment point stats unless dynamic expansion was 18977c478bd9Sstevel@tonic-gate * requested by user. 18987c478bd9Sstevel@tonic-gate */ 18997c478bd9Sstevel@tonic-gate if (!dyn_exp && get_dyn(out_array[i].ldatap->ap_log_id) 19007c478bd9Sstevel@tonic-gate != NULL) { 19017c478bd9Sstevel@tonic-gate continue; 19027c478bd9Sstevel@tonic-gate } 19037c478bd9Sstevel@tonic-gate 19047c478bd9Sstevel@tonic-gate if (strncmp(out_array[i].ldatap->ap_log_id, inp->arg, 19057c478bd9Sstevel@tonic-gate strlen(inp->arg)) == 0) { 19067c478bd9Sstevel@tonic-gate break; 19077c478bd9Sstevel@tonic-gate } 19087c478bd9Sstevel@tonic-gate } else { 19097c478bd9Sstevel@tonic-gate return; 19107c478bd9Sstevel@tonic-gate } 19117c478bd9Sstevel@tonic-gate } 19127c478bd9Sstevel@tonic-gate 19137c478bd9Sstevel@tonic-gate if (i < nouts) { 19147c478bd9Sstevel@tonic-gate inp->resp = 1; 19157c478bd9Sstevel@tonic-gate } 19167c478bd9Sstevel@tonic-gate } 19177c478bd9Sstevel@tonic-gate 19187c478bd9Sstevel@tonic-gate /* Mark all stat data which were requested by user */ 19197c478bd9Sstevel@tonic-gate static void 19207c478bd9Sstevel@tonic-gate out_was_req(ap_out_t *outp, ap_arg_t *in_array, int nargs, int no_dyn) 19217c478bd9Sstevel@tonic-gate { 19227c478bd9Sstevel@tonic-gate int i; 19237c478bd9Sstevel@tonic-gate cfga_ap_types_t type = UNKNOWN_AP; 19247c478bd9Sstevel@tonic-gate char physid[MAXPATHLEN], logid[MAXPATHLEN]; 19257c478bd9Sstevel@tonic-gate 19267c478bd9Sstevel@tonic-gate 19277c478bd9Sstevel@tonic-gate /* If no user args, all output is acceptable */ 19287c478bd9Sstevel@tonic-gate if (nargs == 0) { 19297c478bd9Sstevel@tonic-gate outp->req = 1; 19307c478bd9Sstevel@tonic-gate return; 19317c478bd9Sstevel@tonic-gate } 19327c478bd9Sstevel@tonic-gate 19337c478bd9Sstevel@tonic-gate 19347c478bd9Sstevel@tonic-gate (void) snprintf(physid, sizeof (physid), "%s", 19357c478bd9Sstevel@tonic-gate outp->ldatap->ap_phys_id); 19367c478bd9Sstevel@tonic-gate (void) snprintf(logid, sizeof (logid), "%s", outp->ldatap->ap_log_id); 19377c478bd9Sstevel@tonic-gate 19387c478bd9Sstevel@tonic-gate /* 19397c478bd9Sstevel@tonic-gate * Do comparison with or without dynamic component as requested by 19407c478bd9Sstevel@tonic-gate * user. 19417c478bd9Sstevel@tonic-gate */ 19427c478bd9Sstevel@tonic-gate if (no_dyn) { 19437c478bd9Sstevel@tonic-gate /* Remove the dynamic component */ 19447c478bd9Sstevel@tonic-gate remove_dyn(physid); 19457c478bd9Sstevel@tonic-gate remove_dyn(logid); 19467c478bd9Sstevel@tonic-gate } 19477c478bd9Sstevel@tonic-gate 19487c478bd9Sstevel@tonic-gate for (i = 0; i < nargs; i++) { 19497c478bd9Sstevel@tonic-gate type = find_arg_type(in_array[i].arg); 19507c478bd9Sstevel@tonic-gate if (type == PHYSICAL_AP_ID) { 19517c478bd9Sstevel@tonic-gate 19527c478bd9Sstevel@tonic-gate if (config_ap_id_cmp(in_array[i].arg, physid) == 0) { 19537c478bd9Sstevel@tonic-gate break; 19547c478bd9Sstevel@tonic-gate } 19557c478bd9Sstevel@tonic-gate } else if (type == LOGICAL_AP_ID) { 19567c478bd9Sstevel@tonic-gate 19577c478bd9Sstevel@tonic-gate if (config_ap_id_cmp(in_array[i].arg, logid) == 0) { 19587c478bd9Sstevel@tonic-gate break; 19597c478bd9Sstevel@tonic-gate } 19607c478bd9Sstevel@tonic-gate } else if (type == AP_TYPE) { 19617c478bd9Sstevel@tonic-gate /* 19627c478bd9Sstevel@tonic-gate * Aptypes cannot generate dynamic attachment 19637c478bd9Sstevel@tonic-gate * points unless dynamic expansion is specified. 19647c478bd9Sstevel@tonic-gate * in which case this routine would be called a 19657c478bd9Sstevel@tonic-gate * 2nd time with the no_dyn flag set and there 19667c478bd9Sstevel@tonic-gate * would be no dynamic ap_ids. 19677c478bd9Sstevel@tonic-gate */ 19687c478bd9Sstevel@tonic-gate if (get_dyn(logid) != NULL) { 19697c478bd9Sstevel@tonic-gate continue; 19707c478bd9Sstevel@tonic-gate } 19717c478bd9Sstevel@tonic-gate 19727c478bd9Sstevel@tonic-gate if (strncmp(in_array[i].arg, logid, 19737c478bd9Sstevel@tonic-gate strlen(in_array[i].arg)) == 0) { 19747c478bd9Sstevel@tonic-gate break; 19757c478bd9Sstevel@tonic-gate } 19767c478bd9Sstevel@tonic-gate } else { 19777c478bd9Sstevel@tonic-gate continue; 19787c478bd9Sstevel@tonic-gate } 19797c478bd9Sstevel@tonic-gate } 19807c478bd9Sstevel@tonic-gate 19817c478bd9Sstevel@tonic-gate if (i < nargs) { 19827c478bd9Sstevel@tonic-gate /* Ok, this output was requested */ 19837c478bd9Sstevel@tonic-gate outp->req = 1; 19847c478bd9Sstevel@tonic-gate } 19857c478bd9Sstevel@tonic-gate 19867c478bd9Sstevel@tonic-gate } 19877c478bd9Sstevel@tonic-gate 19887c478bd9Sstevel@tonic-gate static void 19897c478bd9Sstevel@tonic-gate do_post_filter(ap_out_t *outp, post_filter_t *post_filtp, int *nselp) 19907c478bd9Sstevel@tonic-gate { 19917c478bd9Sstevel@tonic-gate int i; 19927c478bd9Sstevel@tonic-gate 19937c478bd9Sstevel@tonic-gate if (outp->req != 1) { 19947c478bd9Sstevel@tonic-gate return; 19957c478bd9Sstevel@tonic-gate } 19967c478bd9Sstevel@tonic-gate 19977c478bd9Sstevel@tonic-gate /* 19987c478bd9Sstevel@tonic-gate * For fields without filtering (CFGA_MATCH_NOFILTER), 19997c478bd9Sstevel@tonic-gate * compare always returns 0 (success) 20007c478bd9Sstevel@tonic-gate */ 20017c478bd9Sstevel@tonic-gate for (i = 0; i < N_FIELDS; i++) { 20027c478bd9Sstevel@tonic-gate /* 20037c478bd9Sstevel@tonic-gate * Note: Order is important for partial match (via strncmp). 20047c478bd9Sstevel@tonic-gate * The first argument for compare must be the filter. 20057c478bd9Sstevel@tonic-gate */ 20067c478bd9Sstevel@tonic-gate if (all_fields[i].compare(&post_filtp->ldata, outp->ldatap, 20077c478bd9Sstevel@tonic-gate post_filtp->match_type_p[i])) { 20087c478bd9Sstevel@tonic-gate outp->req = 0; /* Blocked by filter */ 20097c478bd9Sstevel@tonic-gate return; 20107c478bd9Sstevel@tonic-gate } 20117c478bd9Sstevel@tonic-gate } 20127c478bd9Sstevel@tonic-gate 20137c478bd9Sstevel@tonic-gate /* 20147c478bd9Sstevel@tonic-gate * Passed through filter 20157c478bd9Sstevel@tonic-gate */ 20167c478bd9Sstevel@tonic-gate (*nselp)++; 20177c478bd9Sstevel@tonic-gate } 20187c478bd9Sstevel@tonic-gate 20197c478bd9Sstevel@tonic-gate static void 20207c478bd9Sstevel@tonic-gate report_no_response(ap_arg_t *arg_array, int nargs) 20217c478bd9Sstevel@tonic-gate { 20227c478bd9Sstevel@tonic-gate int i; 20237c478bd9Sstevel@tonic-gate 20247c478bd9Sstevel@tonic-gate if (nargs == 0) { 20257c478bd9Sstevel@tonic-gate return; 20267c478bd9Sstevel@tonic-gate } 20277c478bd9Sstevel@tonic-gate 20287c478bd9Sstevel@tonic-gate 20297c478bd9Sstevel@tonic-gate /* 20307c478bd9Sstevel@tonic-gate * nop if no user arguments 20317c478bd9Sstevel@tonic-gate */ 20327c478bd9Sstevel@tonic-gate for (i = 0; i < nargs; i++) { 20337c478bd9Sstevel@tonic-gate if (arg_array[i].resp == 0) { 20347c478bd9Sstevel@tonic-gate (void) fprintf(stderr, 20357c478bd9Sstevel@tonic-gate gettext("%s: No matching library found\n"), 20367c478bd9Sstevel@tonic-gate arg_array[i].arg); 20377c478bd9Sstevel@tonic-gate } 20387c478bd9Sstevel@tonic-gate } 20397c478bd9Sstevel@tonic-gate } 20407c478bd9Sstevel@tonic-gate 20417c478bd9Sstevel@tonic-gate /* 20427c478bd9Sstevel@tonic-gate * ldata_compare - compare two attachment point list data structures. 20437c478bd9Sstevel@tonic-gate */ 20447c478bd9Sstevel@tonic-gate static int 20457c478bd9Sstevel@tonic-gate ldata_compare( 20467c478bd9Sstevel@tonic-gate const void *vb1, 20477c478bd9Sstevel@tonic-gate const void *vb2) 20487c478bd9Sstevel@tonic-gate { 20497c478bd9Sstevel@tonic-gate int i; 20507c478bd9Sstevel@tonic-gate int res = -1; 20517c478bd9Sstevel@tonic-gate cfga_list_data_t *b1, *b2; 20527c478bd9Sstevel@tonic-gate 20537c478bd9Sstevel@tonic-gate 20547c478bd9Sstevel@tonic-gate b1 = *(cfga_list_data_t **)vb1; 20557c478bd9Sstevel@tonic-gate b2 = *(cfga_list_data_t **)vb2; 20567c478bd9Sstevel@tonic-gate 20577c478bd9Sstevel@tonic-gate for (i = 0; i < nsort_list; i++) { 20587c478bd9Sstevel@tonic-gate res = (*(sort_list[i].fld->compare))(b1, b2, CFGA_MATCH_ORDER); 20597c478bd9Sstevel@tonic-gate if (res != 0) { 20607c478bd9Sstevel@tonic-gate if (sort_list[i].reverse) 20617c478bd9Sstevel@tonic-gate res = -res; 20627c478bd9Sstevel@tonic-gate break; 20637c478bd9Sstevel@tonic-gate } 20647c478bd9Sstevel@tonic-gate } 20657c478bd9Sstevel@tonic-gate 20667c478bd9Sstevel@tonic-gate return (res); 20677c478bd9Sstevel@tonic-gate } 20687c478bd9Sstevel@tonic-gate 20697c478bd9Sstevel@tonic-gate /* 20707c478bd9Sstevel@tonic-gate * count_fields - Count the number of fields, using supplied delimiter. 20717c478bd9Sstevel@tonic-gate */ 20727c478bd9Sstevel@tonic-gate static int 20737c478bd9Sstevel@tonic-gate count_fields(char *fspec, char delim) 20747c478bd9Sstevel@tonic-gate { 20757c478bd9Sstevel@tonic-gate char *cp = NULL; 20767c478bd9Sstevel@tonic-gate int n; 20777c478bd9Sstevel@tonic-gate 20787c478bd9Sstevel@tonic-gate if (fspec == 0 || *fspec == '\0') 20797c478bd9Sstevel@tonic-gate return (0); 20807c478bd9Sstevel@tonic-gate n = 1; 20817c478bd9Sstevel@tonic-gate for (cp = fspec; *cp != '\0'; cp++) 20827c478bd9Sstevel@tonic-gate if (*cp == delim) 20837c478bd9Sstevel@tonic-gate n++; 20847c478bd9Sstevel@tonic-gate return (n); 20857c478bd9Sstevel@tonic-gate } 20867c478bd9Sstevel@tonic-gate 20877c478bd9Sstevel@tonic-gate /* 20887c478bd9Sstevel@tonic-gate * get_field 20897c478bd9Sstevel@tonic-gate * This function is not a re-implementation of strtok(). 20907c478bd9Sstevel@tonic-gate * There can be null fields - strtok() eats spans of delimiters. 20917c478bd9Sstevel@tonic-gate */ 20927c478bd9Sstevel@tonic-gate static char * 20937c478bd9Sstevel@tonic-gate get_field(char **fspp) 20947c478bd9Sstevel@tonic-gate { 20957c478bd9Sstevel@tonic-gate char *cp = NULL, *fld; 20967c478bd9Sstevel@tonic-gate 20977c478bd9Sstevel@tonic-gate fld = *fspp; 20987c478bd9Sstevel@tonic-gate 20997c478bd9Sstevel@tonic-gate if (fld != NULL && *fld == '\0') 21007c478bd9Sstevel@tonic-gate fld = NULL; 21017c478bd9Sstevel@tonic-gate 21027c478bd9Sstevel@tonic-gate if (fld != NULL) { 21037c478bd9Sstevel@tonic-gate cp = strchr(*fspp, FDELIM); 21047c478bd9Sstevel@tonic-gate if (cp == NULL) { 21057c478bd9Sstevel@tonic-gate *fspp = NULL; 21067c478bd9Sstevel@tonic-gate } else { 21077c478bd9Sstevel@tonic-gate *cp = '\0'; 21087c478bd9Sstevel@tonic-gate *fspp = cp + 1; 21097c478bd9Sstevel@tonic-gate if (*fld == '\0') 21107c478bd9Sstevel@tonic-gate fld = NULL; 21117c478bd9Sstevel@tonic-gate } 21127c478bd9Sstevel@tonic-gate } 21137c478bd9Sstevel@tonic-gate return (fld); 21147c478bd9Sstevel@tonic-gate } 21157c478bd9Sstevel@tonic-gate 21167c478bd9Sstevel@tonic-gate /* 21177c478bd9Sstevel@tonic-gate * process_fields - 21187c478bd9Sstevel@tonic-gate */ 21197c478bd9Sstevel@tonic-gate static int 21207c478bd9Sstevel@tonic-gate process_fields( 21217c478bd9Sstevel@tonic-gate int ncol, 21227c478bd9Sstevel@tonic-gate struct print_col *list, 21237c478bd9Sstevel@tonic-gate int line2, 21247c478bd9Sstevel@tonic-gate char *fmt) 21257c478bd9Sstevel@tonic-gate { 21267c478bd9Sstevel@tonic-gate struct print_col *pp = NULL; 21277c478bd9Sstevel@tonic-gate struct field_info *fldp = NULL; 21287c478bd9Sstevel@tonic-gate char *fmtx; 21297c478bd9Sstevel@tonic-gate char *fldn; 21307c478bd9Sstevel@tonic-gate int err; 21317c478bd9Sstevel@tonic-gate 21327c478bd9Sstevel@tonic-gate err = 0; 21337c478bd9Sstevel@tonic-gate fmtx = fmt; 21347c478bd9Sstevel@tonic-gate for (pp = list; pp < &list[ncol]; pp++) { 21357c478bd9Sstevel@tonic-gate fldn = get_field(&fmtx); 21367c478bd9Sstevel@tonic-gate fldp = &null_field; 21377c478bd9Sstevel@tonic-gate if (fldn != NULL) { 21387c478bd9Sstevel@tonic-gate struct field_info *tfldp; 21397c478bd9Sstevel@tonic-gate 21407c478bd9Sstevel@tonic-gate tfldp = find_field(fldn); 21417c478bd9Sstevel@tonic-gate if (tfldp != NULL) { 21427c478bd9Sstevel@tonic-gate fldp = tfldp; 21437c478bd9Sstevel@tonic-gate } else { 21447c478bd9Sstevel@tonic-gate (void) fprintf(stderr, gettext(unk_field), 21457c478bd9Sstevel@tonic-gate cmdname, fldn); 21467c478bd9Sstevel@tonic-gate err = 1; 21477c478bd9Sstevel@tonic-gate } 21487c478bd9Sstevel@tonic-gate } 21497c478bd9Sstevel@tonic-gate if (line2) { 21507c478bd9Sstevel@tonic-gate pp->line2 = fldp; 21517c478bd9Sstevel@tonic-gate if (fldp->width > pp->width) 21527c478bd9Sstevel@tonic-gate pp->width = fldp->width; 21537c478bd9Sstevel@tonic-gate } else { 21547c478bd9Sstevel@tonic-gate pp->line1 = fldp; 21557c478bd9Sstevel@tonic-gate pp->width = fldp->width; 21567c478bd9Sstevel@tonic-gate } 21577c478bd9Sstevel@tonic-gate } 21587c478bd9Sstevel@tonic-gate return (err); 21597c478bd9Sstevel@tonic-gate } 21607c478bd9Sstevel@tonic-gate 21617c478bd9Sstevel@tonic-gate /* 21627c478bd9Sstevel@tonic-gate * process_sort_fields - 21637c478bd9Sstevel@tonic-gate */ 21647c478bd9Sstevel@tonic-gate static int 21657c478bd9Sstevel@tonic-gate process_sort_fields( 21667c478bd9Sstevel@tonic-gate int nsort, 21677c478bd9Sstevel@tonic-gate struct sort_el *list, 21687c478bd9Sstevel@tonic-gate char *fmt) 21697c478bd9Sstevel@tonic-gate { 21707c478bd9Sstevel@tonic-gate int i; 21717c478bd9Sstevel@tonic-gate int rev; 21727c478bd9Sstevel@tonic-gate struct field_info *fldp = NULL; 21737c478bd9Sstevel@tonic-gate char *fmtx; 21747c478bd9Sstevel@tonic-gate char *fldn; 21757c478bd9Sstevel@tonic-gate int err; 21767c478bd9Sstevel@tonic-gate 21777c478bd9Sstevel@tonic-gate err = 0; 21787c478bd9Sstevel@tonic-gate fmtx = fmt; 21797c478bd9Sstevel@tonic-gate for (i = 0; i < nsort; i++) { 21807c478bd9Sstevel@tonic-gate fldn = get_field(&fmtx); 21817c478bd9Sstevel@tonic-gate fldp = &null_field; 21827c478bd9Sstevel@tonic-gate rev = 0; 21837c478bd9Sstevel@tonic-gate if (fldn != NULL) { 21847c478bd9Sstevel@tonic-gate struct field_info *tfldp = NULL; 21857c478bd9Sstevel@tonic-gate 21867c478bd9Sstevel@tonic-gate if (*fldn == '-') { 21877c478bd9Sstevel@tonic-gate rev = 1; 21887c478bd9Sstevel@tonic-gate fldn++; 21897c478bd9Sstevel@tonic-gate } 21907c478bd9Sstevel@tonic-gate tfldp = find_field(fldn); 21917c478bd9Sstevel@tonic-gate if (tfldp != NULL) { 21927c478bd9Sstevel@tonic-gate fldp = tfldp; 21937c478bd9Sstevel@tonic-gate } else { 21947c478bd9Sstevel@tonic-gate (void) fprintf(stderr, gettext(unk_field), 21957c478bd9Sstevel@tonic-gate cmdname, fldn); 21967c478bd9Sstevel@tonic-gate err = 1; 21977c478bd9Sstevel@tonic-gate } 21987c478bd9Sstevel@tonic-gate } 21997c478bd9Sstevel@tonic-gate list[i].reverse = rev; 22007c478bd9Sstevel@tonic-gate list[i].fld = fldp; 22017c478bd9Sstevel@tonic-gate } 22027c478bd9Sstevel@tonic-gate return (err); 22037c478bd9Sstevel@tonic-gate } 22047c478bd9Sstevel@tonic-gate 22057c478bd9Sstevel@tonic-gate /* 22067c478bd9Sstevel@tonic-gate * print_fields - 22077c478bd9Sstevel@tonic-gate */ 22087c478bd9Sstevel@tonic-gate static cfga_err_t 22097c478bd9Sstevel@tonic-gate print_fields( 22107c478bd9Sstevel@tonic-gate int ncol, 22117c478bd9Sstevel@tonic-gate struct print_col *list, 22127c478bd9Sstevel@tonic-gate int heading, 22137c478bd9Sstevel@tonic-gate int line2, 22147c478bd9Sstevel@tonic-gate char *delim, 22157c478bd9Sstevel@tonic-gate cfga_list_data_t *bdp, 22167c478bd9Sstevel@tonic-gate FILE *fp) 22177c478bd9Sstevel@tonic-gate { 22187c478bd9Sstevel@tonic-gate char *del = NULL; 22197c478bd9Sstevel@tonic-gate struct print_col *pp = NULL; 22207c478bd9Sstevel@tonic-gate struct field_info *fldp = NULL; 22217c478bd9Sstevel@tonic-gate static char *outline, *end; 22227c478bd9Sstevel@tonic-gate char *lp; 22237c478bd9Sstevel@tonic-gate 22247c478bd9Sstevel@tonic-gate if (outline == NULL) { 22257c478bd9Sstevel@tonic-gate int out_len, delim_len; 22267c478bd9Sstevel@tonic-gate 22277c478bd9Sstevel@tonic-gate delim_len = strlen(delim); 22287c478bd9Sstevel@tonic-gate out_len = 0; 22297c478bd9Sstevel@tonic-gate for (pp = list; pp < &list[ncol]; pp++) { 22307c478bd9Sstevel@tonic-gate out_len += pp->width; 22317c478bd9Sstevel@tonic-gate out_len += delim_len; 22327c478bd9Sstevel@tonic-gate } 22337c478bd9Sstevel@tonic-gate out_len -= delim_len; 22347c478bd9Sstevel@tonic-gate outline = config_calloc_check(out_len + 1, 1); 22357c478bd9Sstevel@tonic-gate if (outline == NULL) { 22367c478bd9Sstevel@tonic-gate return (CFGA_LIB_ERROR); 22377c478bd9Sstevel@tonic-gate } 22387c478bd9Sstevel@tonic-gate end = &outline[out_len + 1]; 22397c478bd9Sstevel@tonic-gate } 22407c478bd9Sstevel@tonic-gate 22417c478bd9Sstevel@tonic-gate lp = outline; 22427c478bd9Sstevel@tonic-gate del = ""; 22437c478bd9Sstevel@tonic-gate for (pp = list; pp < &list[ncol]; pp++) { 22447c478bd9Sstevel@tonic-gate fldp = line2 ? pp->line2 : pp->line1; 22457c478bd9Sstevel@tonic-gate (void) snprintf(lp, end - lp, "%s", del); 22467c478bd9Sstevel@tonic-gate lp += strlen(lp); 22477c478bd9Sstevel@tonic-gate if (heading) { 22487c478bd9Sstevel@tonic-gate (void) snprintf(lp, end - lp, "%-*s", 22497c478bd9Sstevel@tonic-gate fldp->width, fldp->heading); 22507c478bd9Sstevel@tonic-gate } else { 22517c478bd9Sstevel@tonic-gate (*fldp->printfn)(bdp, fldp->width, lp); 22527c478bd9Sstevel@tonic-gate } 22537c478bd9Sstevel@tonic-gate lp += strlen(lp); 22547c478bd9Sstevel@tonic-gate del = delim; 22557c478bd9Sstevel@tonic-gate } 22567c478bd9Sstevel@tonic-gate 22577c478bd9Sstevel@tonic-gate /* 22587c478bd9Sstevel@tonic-gate * Trim trailing spaces 22597c478bd9Sstevel@tonic-gate */ 22607c478bd9Sstevel@tonic-gate while (--lp >= outline && *lp == ' ') 22617c478bd9Sstevel@tonic-gate *lp = '\0'; 22627c478bd9Sstevel@tonic-gate (void) fprintf(fp, "%s\n", outline); 22637c478bd9Sstevel@tonic-gate return (CFGA_OK); 22647c478bd9Sstevel@tonic-gate } 22657c478bd9Sstevel@tonic-gate 22667c478bd9Sstevel@tonic-gate /* 22677c478bd9Sstevel@tonic-gate * config_calloc_check - perform allocation, check result and 22687c478bd9Sstevel@tonic-gate * set error indicator 22697c478bd9Sstevel@tonic-gate */ 22707c478bd9Sstevel@tonic-gate static void * 22717c478bd9Sstevel@tonic-gate config_calloc_check( 22727c478bd9Sstevel@tonic-gate size_t nelem, 22737c478bd9Sstevel@tonic-gate size_t elsize) 22747c478bd9Sstevel@tonic-gate { 22757c478bd9Sstevel@tonic-gate void *p; 22767c478bd9Sstevel@tonic-gate static char alloc_fail[] = 22777c478bd9Sstevel@tonic-gate "%s: memory allocation failed (%d*%d bytes)\n"; 22787c478bd9Sstevel@tonic-gate 22797c478bd9Sstevel@tonic-gate 22807c478bd9Sstevel@tonic-gate p = calloc(nelem, elsize); 22817c478bd9Sstevel@tonic-gate if (p == NULL) { 22827c478bd9Sstevel@tonic-gate (void) fprintf(stderr, gettext(alloc_fail), cmdname, 22837c478bd9Sstevel@tonic-gate nelem, elsize); 22847c478bd9Sstevel@tonic-gate } 22857c478bd9Sstevel@tonic-gate return (p); 22867c478bd9Sstevel@tonic-gate } 22877c478bd9Sstevel@tonic-gate 22887c478bd9Sstevel@tonic-gate /* 22897c478bd9Sstevel@tonic-gate * find_arg_type - determine if an argument is an ap_id or an ap_type. 22907c478bd9Sstevel@tonic-gate */ 22917c478bd9Sstevel@tonic-gate static cfga_ap_types_t 22927c478bd9Sstevel@tonic-gate find_arg_type(const char *ap_id) 22937c478bd9Sstevel@tonic-gate { 22947c478bd9Sstevel@tonic-gate struct stat sbuf; 22957c478bd9Sstevel@tonic-gate cfga_ap_types_t type; 22967c478bd9Sstevel@tonic-gate char *mkr = NULL, *cp; 22977c478bd9Sstevel@tonic-gate int size_ap = 0, size_mkr = 0, digit = 0, i = 0; 22987c478bd9Sstevel@tonic-gate char path[MAXPATHLEN]; 22997c478bd9Sstevel@tonic-gate char apbuf[MAXPATHLEN]; 23007c478bd9Sstevel@tonic-gate size_t len; 23017c478bd9Sstevel@tonic-gate 23027c478bd9Sstevel@tonic-gate 23037c478bd9Sstevel@tonic-gate /* 23047c478bd9Sstevel@tonic-gate * sanity checks 23057c478bd9Sstevel@tonic-gate */ 23067c478bd9Sstevel@tonic-gate if (ap_id == NULL || *ap_id == '\0') { 23077c478bd9Sstevel@tonic-gate return (UNKNOWN_AP); 23087c478bd9Sstevel@tonic-gate } 23097c478bd9Sstevel@tonic-gate 23107c478bd9Sstevel@tonic-gate /* 23117c478bd9Sstevel@tonic-gate * Mask the dynamic component if any 23127c478bd9Sstevel@tonic-gate */ 23137c478bd9Sstevel@tonic-gate if ((cp = GET_DYN(ap_id)) != NULL) { 23147c478bd9Sstevel@tonic-gate len = cp - ap_id; 23157c478bd9Sstevel@tonic-gate } else { 23167c478bd9Sstevel@tonic-gate len = strlen(ap_id); 23177c478bd9Sstevel@tonic-gate } 23187c478bd9Sstevel@tonic-gate 23197c478bd9Sstevel@tonic-gate if (len >= sizeof (apbuf)) { 23207c478bd9Sstevel@tonic-gate return (UNKNOWN_AP); 23217c478bd9Sstevel@tonic-gate } 23227c478bd9Sstevel@tonic-gate 23237c478bd9Sstevel@tonic-gate (void) strncpy(apbuf, ap_id, len); 23247c478bd9Sstevel@tonic-gate apbuf[len] = '\0'; 23257c478bd9Sstevel@tonic-gate 23267c478bd9Sstevel@tonic-gate /* 23277c478bd9Sstevel@tonic-gate * If it starts with a slash and is stat-able 23287c478bd9Sstevel@tonic-gate * its a physical. 23297c478bd9Sstevel@tonic-gate */ 23307c478bd9Sstevel@tonic-gate if (*apbuf == '/' && stat(apbuf, &sbuf) == 0) { 23317c478bd9Sstevel@tonic-gate return (PHYSICAL_AP_ID); 23327c478bd9Sstevel@tonic-gate } 23337c478bd9Sstevel@tonic-gate 23347c478bd9Sstevel@tonic-gate /* 23357c478bd9Sstevel@tonic-gate * Is this a symlink in CFGA_DEV_DIR ? 23367c478bd9Sstevel@tonic-gate */ 23377c478bd9Sstevel@tonic-gate (void) snprintf(path, sizeof (path), "%s/%s", CFGA_DEV_DIR, apbuf); 23387c478bd9Sstevel@tonic-gate 23397c478bd9Sstevel@tonic-gate if (lstat(path, &sbuf) == 0 && S_ISLNK(sbuf.st_mode) && 23407c478bd9Sstevel@tonic-gate stat(path, &sbuf) == 0) { 23417c478bd9Sstevel@tonic-gate return (LOGICAL_AP_ID); 23427c478bd9Sstevel@tonic-gate } 23437c478bd9Sstevel@tonic-gate 23447c478bd9Sstevel@tonic-gate /* 23457c478bd9Sstevel@tonic-gate * Check for ":" which is always present in an ap_id but not maybe 23467c478bd9Sstevel@tonic-gate * present or absent in an ap_type. 23477c478bd9Sstevel@tonic-gate * We need to check that the characters right before the : are digits 23487c478bd9Sstevel@tonic-gate * since an ap_id is of the form <name><instance>:<specific ap name> 23497c478bd9Sstevel@tonic-gate */ 23507c478bd9Sstevel@tonic-gate if ((mkr = strchr(apbuf, ':')) == NULL) { 23517c478bd9Sstevel@tonic-gate type = AP_TYPE; 23527c478bd9Sstevel@tonic-gate } else { 23537c478bd9Sstevel@tonic-gate size_ap = strlen(apbuf); 23547c478bd9Sstevel@tonic-gate size_mkr = strlen(mkr); 23557c478bd9Sstevel@tonic-gate mkr = apbuf; 23567c478bd9Sstevel@tonic-gate 23577c478bd9Sstevel@tonic-gate digit = 0; 23587c478bd9Sstevel@tonic-gate for (i = size_ap - size_mkr - 1; i > 0; i--) { 23597c478bd9Sstevel@tonic-gate if ((int)isdigit(mkr[i])) { 23607c478bd9Sstevel@tonic-gate digit++; 23617c478bd9Sstevel@tonic-gate break; 23627c478bd9Sstevel@tonic-gate } 23637c478bd9Sstevel@tonic-gate } 23647c478bd9Sstevel@tonic-gate if (digit == 0) { 23657c478bd9Sstevel@tonic-gate type = AP_TYPE; 23667c478bd9Sstevel@tonic-gate } else { 23677c478bd9Sstevel@tonic-gate type = LOGICAL_AP_ID; 23687c478bd9Sstevel@tonic-gate } 23697c478bd9Sstevel@tonic-gate } 23707c478bd9Sstevel@tonic-gate 23717c478bd9Sstevel@tonic-gate return (type); 23727c478bd9Sstevel@tonic-gate } 23737c478bd9Sstevel@tonic-gate 23747c478bd9Sstevel@tonic-gate 23757c478bd9Sstevel@tonic-gate static char * 23767c478bd9Sstevel@tonic-gate get_dyn(const char *ap_id) 23777c478bd9Sstevel@tonic-gate { 23787c478bd9Sstevel@tonic-gate if (ap_id == NULL) { 23797c478bd9Sstevel@tonic-gate return (NULL); 23807c478bd9Sstevel@tonic-gate } 23817c478bd9Sstevel@tonic-gate 23827c478bd9Sstevel@tonic-gate return (strstr(ap_id, CFGA_DYN_SEP)); 23837c478bd9Sstevel@tonic-gate } 23847c478bd9Sstevel@tonic-gate 23857c478bd9Sstevel@tonic-gate /* 23867c478bd9Sstevel@tonic-gate * removes the dynamic component 23877c478bd9Sstevel@tonic-gate */ 23887c478bd9Sstevel@tonic-gate static void 23897c478bd9Sstevel@tonic-gate remove_dyn(char *ap_id) 23907c478bd9Sstevel@tonic-gate { 23917c478bd9Sstevel@tonic-gate char *cp; 23927c478bd9Sstevel@tonic-gate 23937c478bd9Sstevel@tonic-gate if (ap_id == NULL) { 23947c478bd9Sstevel@tonic-gate return; 23957c478bd9Sstevel@tonic-gate } 23967c478bd9Sstevel@tonic-gate 23977c478bd9Sstevel@tonic-gate cp = strstr(ap_id, CFGA_DYN_SEP); 23987c478bd9Sstevel@tonic-gate if (cp != NULL) { 23997c478bd9Sstevel@tonic-gate *cp = '\0'; 24007c478bd9Sstevel@tonic-gate } 24017c478bd9Sstevel@tonic-gate } 24023977d6cdSvikram 24033977d6cdSvikram 24043977d6cdSvikram static char * 24053977d6cdSvikram s_strdup(char *str) 24063977d6cdSvikram { 24073977d6cdSvikram char *dup; 24083977d6cdSvikram 24093977d6cdSvikram /* 24103977d6cdSvikram * sometimes NULL strings may be passed in (see DEF_COLS2). This 24113977d6cdSvikram * is not an error. 24123977d6cdSvikram */ 24133977d6cdSvikram if (str == NULL) { 24143977d6cdSvikram return (NULL); 24153977d6cdSvikram } 24163977d6cdSvikram 24173977d6cdSvikram dup = strdup(str); 24183977d6cdSvikram if (dup == NULL) { 24193977d6cdSvikram (void) fprintf(stderr, 24203977d6cdSvikram "%s \"%s\"\n", gettext("Cannot copy string"), str); 24213977d6cdSvikram return (NULL); 24223977d6cdSvikram } 24233977d6cdSvikram 24243977d6cdSvikram return (dup); 24253977d6cdSvikram } 2426