Print this page
8225 passing invalid global pattern to coreadm wedges it nicely
*** 19,28 ****
--- 19,30 ----
* CDDL HEADER END
*/
/*
* Copyright 2008 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
+ *
+ * Copyright 2017 RackTop Systems.
*/
#include <stdio.h>
#include <fcntl.h>
#include <ctype.h>
*** 75,85 ****
static size_t proc_size;
static core_content_t proc_content = CC_CONTENT_INVALID;
static int report_settings(void);
static int do_processes(int, char **);
! static int do_modify(boolean_t);
static int do_update(void);
static int do_legacy(void);
static scf_propvec_t prop_gpattern = { GLOBAL_PATTERN, NULL, SCF_TYPE_ASTRING };
static scf_propvec_t prop_gcontent = { GLOBAL_CONTENT, NULL, SCF_TYPE_ASTRING };
--- 77,87 ----
static size_t proc_size;
static core_content_t proc_content = CC_CONTENT_INVALID;
static int report_settings(void);
static int do_processes(int, char **);
! static int do_modify(void);
static int do_update(void);
static int do_legacy(void);
static scf_propvec_t prop_gpattern = { GLOBAL_PATTERN, NULL, SCF_TYPE_ASTRING };
static scf_propvec_t prop_gcontent = { GLOBAL_CONTENT, NULL, SCF_TYPE_ASTRING };
*** 87,97 ****
static scf_propvec_t prop_icontent = { INIT_CONTENT, NULL, SCF_TYPE_ASTRING };
static scf_propvec_t prop_option[] = {
{ GLOBAL_ENABLED, NULL, SCF_TYPE_BOOLEAN, NULL, CC_GLOBAL_PATH },
{ PROCESS_ENABLED, NULL, SCF_TYPE_BOOLEAN, NULL, CC_PROCESS_PATH },
{ GLOBAL_SETID_ENABLED, NULL, SCF_TYPE_BOOLEAN, NULL, CC_GLOBAL_SETID },
! { PROCESS_SETID_ENABLED, NULL, SCF_TYPE_BOOLEAN, NULL, CC_PROCESS_SETID },
{ GLOBAL_LOG_ENABLED, NULL, SCF_TYPE_BOOLEAN, NULL, CC_GLOBAL_LOG },
{ NULL }
};
#define MAX_PROPS (4 + (sizeof (prop_option) / sizeof (scf_propvec_t)))
--- 89,100 ----
static scf_propvec_t prop_icontent = { INIT_CONTENT, NULL, SCF_TYPE_ASTRING };
static scf_propvec_t prop_option[] = {
{ GLOBAL_ENABLED, NULL, SCF_TYPE_BOOLEAN, NULL, CC_GLOBAL_PATH },
{ PROCESS_ENABLED, NULL, SCF_TYPE_BOOLEAN, NULL, CC_PROCESS_PATH },
{ GLOBAL_SETID_ENABLED, NULL, SCF_TYPE_BOOLEAN, NULL, CC_GLOBAL_SETID },
! { PROCESS_SETID_ENABLED, NULL, SCF_TYPE_BOOLEAN, NULL,
! CC_PROCESS_SETID },
{ GLOBAL_LOG_ENABLED, NULL, SCF_TYPE_BOOLEAN, NULL, CC_GLOBAL_LOG },
{ NULL }
};
#define MAX_PROPS (4 + (sizeof (prop_option) / sizeof (scf_propvec_t)))
*** 241,250 ****
--- 244,259 ----
(void) fprintf(stderr, gettext(
"%s: -[GIgied] options cannot have a process-id list\n"),
command);
usage();
}
+ if (glob_pattern != NULL && glob_pattern[0] != '/') {
+ (void) fprintf(stderr, gettext(
+ "%s: the -g option must specify an absolute path\n"),
+ command);
+ usage();
+ }
if ((proc_pattern != NULL || proc_content != CC_CONTENT_INVALID) &&
npids == 0) {
(void) sprintf(curpid, "%u", (uint_t)getppid());
npids = 1;
pidlist = &curpid_ptr;
*** 253,263 ****
if (legacy_update)
return (do_legacy());
if (update)
return (do_update());
if (modify)
! return (do_modify(B_FALSE));
if (npids != 0)
return (do_processes(npids, pidlist));
return (report_settings());
}
--- 262,272 ----
if (legacy_update)
return (do_legacy());
if (update)
return (do_update());
if (modify)
! return (do_modify());
if (npids != 0)
return (do_processes(npids, pidlist));
return (report_settings());
}
*** 380,398 ****
assert(count + 1 < size);
props[count] = *pv;
props[count].pv_ptr = ptr;
}
! static boolean_t
! is_online(const char *fmri)
{
! char *state = smf_get_state(fmri);
! boolean_t result = state != NULL &&
! strcmp(state, SCF_STATE_STRING_ONLINE) == 0;
! free(state);
! return (result);
}
/*
* The user has specified the -g, -G, -i, -I, -d, or -e options to
* modify the given configuration parameter. Perform the modification
--- 389,441 ----
assert(count + 1 < size);
props[count] = *pv;
props[count].pv_ptr = ptr;
}
! static int
! make_active(void)
{
! char *state = smf_get_state(COREADM_INST_FMRI);
! switch (state == NULL ? -1 : smf_state_from_string(state)) {
! case SCF_STATE_ONLINE:
! if (smf_refresh_instance_synchronous(COREADM_INST_FMRI) != 0) {
! (void) fprintf(stderr,
! gettext("%s: Unable to refresh %s: %s\n"),
! command, COREADM_INST_FMRI,
! scf_strerror(scf_error()));
! return (-1);
! }
! break;
! case SCF_STATE_DEGRADED:
! case SCF_STATE_MAINT:
! if (smf_restore_instance_synchronous(COREADM_INST_FMRI) != 0) {
! (void) fprintf(stderr,
! gettext("%s: Unable to clear %s: %s\n"),
! command, COREADM_INST_FMRI,
! scf_strerror(scf_error()));
! return (-1);
! }
! break;
! case SCF_STATE_DISABLED:
! if (smf_enable_instance_synchronous(COREADM_INST_FMRI,
! 0) != 0) {
! (void) fprintf(stderr,
! gettext("%s: Unable to enable %s: %s\n"),
! command, COREADM_INST_FMRI,
! scf_strerror(scf_error()));
! return (-1);
! }
! break;
! case SCF_STATE_OFFLINE:
! default:
! (void) fprintf(stderr,
! gettext("%s: coreadm service not online\n"), command);
! return (-1);
! }
!
! return (0);
}
/*
* The user has specified the -g, -G, -i, -I, -d, or -e options to
* modify the given configuration parameter. Perform the modification
*** 399,422 ****
* in the smf repository and then perform a smf_refresh_instance which
* will cause a coreadm -u to occur which will transfer ALL coreadm
* configuration information from the repository to the kernel.
*/
static int
! do_modify(boolean_t method)
{
char gcontentstr[PRCONTENTBUFSZ];
char icontentstr[PRCONTENTBUFSZ];
scf_propvec_t *prop;
scf_propvec_t properties[MAX_PROPS + 1];
int count = 0;
- if (!method && !is_online(COREADM_INST_FMRI)) {
- (void) fprintf(stderr,
- gettext("%s: coreadm service not online\n"), command);
- return (E_ERROR);
- }
-
if (glob_pattern != NULL)
addprop(properties, MAX_PROPS, count++, &prop_gpattern,
glob_pattern);
if (glob_content != CC_CONTENT_INVALID) {
--- 442,459 ----
* in the smf repository and then perform a smf_refresh_instance which
* will cause a coreadm -u to occur which will transfer ALL coreadm
* configuration information from the repository to the kernel.
*/
static int
! do_modify(void)
{
char gcontentstr[PRCONTENTBUFSZ];
char icontentstr[PRCONTENTBUFSZ];
scf_propvec_t *prop;
scf_propvec_t properties[MAX_PROPS + 1];
int count = 0;
if (glob_pattern != NULL)
addprop(properties, MAX_PROPS, count++, &prop_gpattern,
glob_pattern);
if (glob_content != CC_CONTENT_INVALID) {
*** 456,470 ****
command, scf_strerror(scf_error()));
}
return (E_ERROR);
}
! if (smf_refresh_instance(COREADM_INST_FMRI) != 0) {
! (void) fprintf(stderr,
! gettext("%s: Unable to refresh %s: %s\n"
! "Configuration stored but not made active.\n"),
! command, COREADM_INST_FMRI, scf_strerror(scf_error()));
return (E_ERROR);
}
return (E_SUCCESS);
}
--- 493,505 ----
command, scf_strerror(scf_error()));
}
return (E_ERROR);
}
! if (make_active() != 0) {
! (void) fprintf(stderr, gettext(
! "Configuration stored but not made active.\n"));
return (E_ERROR);
}
return (E_SUCCESS);
}
*** 620,630 ****
if (read_legacy()) {
if ((errstr = write_kernel()) != NULL)
goto error;
! if (do_modify(B_TRUE) != 0 ||
rename(PATH_CONFIG, PATH_CONFIG_OLD) != 0) {
(void) fprintf(stderr, gettext(
"%s: failed to import legacy configuration.\n"),
command);
return (SMF_EXIT_ERR_FATAL);
--- 655,665 ----
if (read_legacy()) {
if ((errstr = write_kernel()) != NULL)
goto error;
! if (do_modify() != 0 ||
rename(PATH_CONFIG, PATH_CONFIG_OLD) != 0) {
(void) fprintf(stderr, gettext(
"%s: failed to import legacy configuration.\n"),
command);
return (SMF_EXIT_ERR_FATAL);
*** 639,649 ****
for (prop = prop_option; prop->pv_prop != NULL; prop++)
addprop(properties, MAX_PROPS, count++, prop, &options);
properties[count].pv_prop = NULL;
alloptions = CC_OPTIONS;
! if (scf_read_propvec(COREADM_INST_FMRI, CONFIG_PARAMS, B_TRUE,
properties, &prop) == SCF_FAILED) {
if (prop != NULL) {
(void) fprintf(stderr, gettext(
"%s: configuration property '%s' not found.\n"),
command, prop->pv_prop);
--- 674,684 ----
for (prop = prop_option; prop->pv_prop != NULL; prop++)
addprop(properties, MAX_PROPS, count++, prop, &options);
properties[count].pv_prop = NULL;
alloptions = CC_OPTIONS;
! if (scf_read_propvec(COREADM_INST_FMRI, CONFIG_PARAMS, B_FALSE,
properties, &prop) == SCF_FAILED) {
if (prop != NULL) {
(void) fprintf(stderr, gettext(
"%s: configuration property '%s' not found.\n"),
command, prop->pv_prop);
*** 667,677 ****
if (errno == EPERM) {
(void) perm();
return (SMF_EXIT_ERR_PERM);
}
perror(errstr);
! return (SMF_EXIT_ERR_FATAL);
}
static int do_legacy()
{
const char *errstr;
--- 702,712 ----
if (errno == EPERM) {
(void) perm();
return (SMF_EXIT_ERR_PERM);
}
perror(errstr);
! return (errno == EINVAL ? SMF_EXIT_ERR_CONFIG : SMF_EXIT_ERR_FATAL);
}
static int do_legacy()
{
const char *errstr;