/* * Read all the basic and method properties for instance 'inst', as inetd_prop_t * tables, into the spaces referenced by 'bprops' and 'mprops' respectively. * Each of the properties in the tables are flagged to indicate if the * property was present or not, and if it was the value is stored within it. * If an error occurs at any time -1 is returned and 'err' is set to * indicate the reason, else 0 is returned. */ static int read_inst_props(const char *fmri, inetd_prop_t **bprops, inetd_prop_t **mprops, scf_error_t *err) { size_t nprops; int i; debug_msg("Entering read_inst_props"); if ((*bprops = read_instance_props(rep_handle, (char *)fmri, &nprops, err)) == NULL) return (-1); for (i = 0; i < NUM_METHODS; i++) { if ((mprops[i] = read_method_props(fmri, (instance_method_t)i, err)) == NULL) { for (i--; i >= 0; i--) destroy_method_props(mprops[i]); free_instance_props(*bprops); return (-1); } } return (0); }
/* * read_props reads either the full set of properties for instance 'instance' * (including defaults - pulling them in from inetd where necessary) if * 'instance' is non-null, else just the defaults from inetd. The properties * are returned in an allocated inetd_prop_t array, which must be freed * using free_instance_props(). If an error occurs NULL is returned and 'err' * is set to indicate the cause, else a pointer to the read properties is * returned. */ static inetd_prop_t * read_props(scf_handle_t *h, const char *instance, size_t *num_elements, scf_error_t *err) { inetd_prop_t *ret = NULL; int i; boolean_t defaults_only = (instance == NULL); if ((ret = malloc(sizeof (inetd_properties))) == NULL) { *err = SCF_ERROR_NO_MEMORY; return (NULL); } (void) memcpy(ret, &inetd_properties, sizeof (inetd_properties)); if (defaults_only) instance = INETD_INSTANCE_FMRI; for (i = 0; ret[i].ip_name != NULL; i++) { if (defaults_only && !ret[i].ip_default) continue; switch (*err = read_prop(h, &ret[i], i, instance, defaults_only ? PG_NAME_SERVICE_DEFAULTS : ret[i].ip_pg)) { case 0: break; case SCF_ERROR_INVALID_ARGUMENT: goto failure_cleanup; case SCF_ERROR_NOT_FOUND: /* * In non-default-only mode where we're reading a * default property, since the property wasn't * found in the instance, try and read inetd's default * value. */ if (!ret[i].ip_default || defaults_only) continue; switch (*err = read_prop(h, &ret[i], i, INETD_INSTANCE_FMRI, PG_NAME_SERVICE_DEFAULTS)) { case 0: ret[i].from_inetd = B_TRUE; continue; case SCF_ERROR_NOT_FOUND: continue; default: goto failure_cleanup; } default: goto failure_cleanup; } } *num_elements = i; return (ret); failure_cleanup: free_instance_props(ret); return (NULL); }
/* * Destroy the basic and method properties returned by read_inst_props(). */ static void destroy_inst_props(inetd_prop_t *bprops, inetd_prop_t **mprops) { int i; free_instance_props(bprops); for (i = 0; i < NUM_METHODS; i++) destroy_method_props(mprops[i]); }
static void list_defaults() { scf_handle_t *h; scf_error_t err; int i; inetd_prop_t *proptable; size_t numprops; if (((h = scf_handle_create(SCF_VERSION)) == NULL) || (scf_handle_bind(h) == -1)) scfdie(); if ((proptable = read_default_props(h, &numprops, &err)) == NULL) { uu_die(gettext("Unexpected libscf error: %s. Exiting.\n"), scf_strerror(err)); } (void) printf("NAME=VALUE\n"); for (i = 0; i < numprops; i++) { if (!proptable[i].ip_default) continue; if (proptable[i].ip_error == IVE_UNSET) { (void) uu_warn(gettext("Error: Default property %s " "missing.\n"), proptable[i].ip_name); continue; } (void) printf("%s=", proptable[i].ip_name); print_prop_val(&proptable[i]); } free_instance_props(proptable); }
/* ARGSUSED0 */ static int list_props_cb(void *data, scf_walkinfo_t *wip) { int i; const char *instname = wip->fmri; scf_simple_prop_t *prop; inetd_prop_t *proplist; const char *restart_str; boolean_t is_rpc = B_FALSE; size_t numprops; scf_handle_t *h; scf_error_t err; if (((h = scf_handle_create(SCF_VERSION)) == NULL) || (scf_handle_bind(h) == -1)) scfdie(); /* * Get the property that holds the name of this instance's * restarter, and make sure that it is inetd. */ if ((prop = scf_simple_prop_get(h, instname, SCF_PG_GENERAL, SCF_PROPERTY_RESTARTER)) == NULL) { if (scf_error() == SCF_ERROR_NOT_FOUND) uu_die(gettext("Error: Specified service instance " "\"%s\" has no restarter property. inetd is not " "the delegated restarter of this instance.\n"), instname); if (scf_error() == SCF_ERROR_INVALID_ARGUMENT) uu_die(gettext("Error: \"%s\" is not a valid service " "instance.\n"), instname); scfdie(); } if (((restart_str = scf_simple_prop_next_ustring(prop)) == NULL) || (strstr(restart_str, INETADM_INETD_STR) == NULL)) { uu_die(gettext("Error: inetd is not the delegated restarter of " "specified service instance \"%s\".\n"), instname); } scf_simple_prop_free(prop); /* * This instance is controlled by inetd, so now we display all * of its properties. First the mandatory properties, and then * the properties that have default values, substituting the * default values inherited from inetd as necessary (this is done * for us by read_instance_props()). */ if ((proplist = read_instance_props(h, instname, &numprops, &err)) == NULL) { uu_die(gettext("Unexpected libscf error: %s. Exiting.\n"), scf_strerror(err)); } scf_handle_destroy(h); (void) printf("%-9s%s\n", "SCOPE", "NAME=VALUE"); for (i = 0; i < numprops; i++) { /* Skip rpc version properties if it's not an RPC service */ if ((strcmp(PR_RPC_LW_VER_NAME, proplist[i].ip_name) == 0) || (strcmp(PR_RPC_HI_VER_NAME, proplist[i].ip_name) == 0)) if (!is_rpc) continue; /* If it's not an unset property, print it out. */ if (proplist[i].ip_error != IVE_UNSET) { if (strcmp(PR_ISRPC_NAME, proplist[i].ip_name) == 0) is_rpc = proplist[i].ip_value.iv_boolean; (void) printf("%-9s%s=", proplist[i].from_inetd ? INETADM_DEFAULT_STR : "", proplist[i].ip_name); print_prop_val(&proplist[i]); continue; } /* arg0 is non-default, but also doesn't have to be set. */ if (i == PT_ARG0_INDEX) continue; /* all other properties should have values. */ if (proplist[i].ip_default) { (void) uu_warn(gettext("Error: Property %s is missing " "and has no defined default value.\n"), proplist[i].ip_name); } else { (void) uu_warn(gettext("Error: Required property %s is " "missing.\n"), proplist[i].ip_name); } } free_instance_props(proplist); return (0); }