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