mgmt_mm.c revision cee0fb94c0d4227de0a00efc162fb2739844b641
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2008 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#include <libgen.h>
#include <stdio.h>
#include <libnvpair.h>
#include <fcntl.h>
#include "mms_mgmt.h"
#include "mgmt_util.h"
#include "mms_cfg.h"
#include "net_cfg_service.h"
typedef struct {
char *name;
char *cfgnam;
int svc;
static mms_mgmt_cfgopt_t mmscfgopts[] = {
{O_OBJTYPE, MMS_CFG_CONFIG_TYPE, 0},
};
#ifdef MMS_VAR_CFG
/* MMS Client Options */
static mms_mgmt_setopt_t mms_client_opts[] = {
};
#endif /* MMS_VAR_CFG */
/* MMS Server Options */
static mms_mgmt_setopt_t mms_server_opts[] = {
val_path},
};
static mms_mgmt_setopt_t application_opts[] = {
};
static int mgmt_set_pass(char *inpw);
#ifdef MMS_VAR_CFG
#endif /* MMS_VAR_CFG */
/*
* The create_mm_clnt() function establishes a session with
* MM. If "app" is not MMS and "inst" is not "admin", the password must
* also be provided. "tag" is an optional identifier to be used
* in the session API.
*/
int
{
int version;
int st;
char *tagp = "";
#ifdef MMS_OPENSSL
char ebuf[1024];
#endif /* MMS_OPENSSL */
if (!session) {
return (MMS_MGMT_NOARG);
}
/*
* mms_net_cfg_service() expects to fetch information
* for MMS admin only. However, we can use this to
* fetch the non-auth information for any app.
*/
if (st == 2) {
/* password not available */
if (!pass) {
} else {
st = 0;
}
} else if (st == 1) {
}
if (st != 0) {
return (st);
}
if (app) {
return (ENOMEM);
}
}
}
if (inst) {
return (ENOMEM);
}
}
}
if (pass) {
}
return (ENOMEM);
}
}
if (tag) {
}
return (st);
}
#ifdef MMS_OPENSSL
if (cfg.ssl_enabled != 0) {
if (st != 0) {
return (st);
}
}
#endif /* MMS_OPENSSL */
if (st != MMS_API_OK) {
"Unable to create a session with MM, ret = %d [%s]",
return (st);
}
return (0);
}
/*
* mms_mgmt_init_host()
*
* DESCRIPTION:
*
* Sets all required MMS options, and starts required services.
*
* On an MMS client system,
* sets MM host, port and administrative password
* sets SSL options, if desired
* starts the Watcher daemon
*
* On on MMS server system,
* creates MMS database admin user
* initializes MMS database and starts database server
* sets MM options [TBD: list these with explanation]
* starts MM daemon and Watcher daemon
*
* ARGUMENTS:
* nvlist_t **errs optional - used to return detailed errors
* operational failures during initialization.
* If 'errs' is non-NULL, a new nvlist will be
* allocated. The caller should free this list
* with nvlist_free().
*
* RETURN VALUES:
*
* 0 Success
* MMS_MGMT_NOARG 'opts' argument missing
* EINVAL One or more requested options is invalid
* EALREADY Host has already been initialized for MMS
* ENOMEM Out of memory
* [others TBD]
*/
int
{
int st = 0;
int nst = 0;
char *val;
int scf_size = MMS_CFG_MAX_VALUE;
char *bufp;
int i;
if (!opts) {
return (MMS_MGMT_NOARG);
}
if (!mgmt_chk_auth("solaris.mms.create")) {
return (EACCES);
}
#ifdef MMS_VAR_CFG
/* make sure we've not already been initialized */
if (st != 0) {
return (st);
}
} else {
/* host already configured */
return (EALREADY);
}
#endif /* MMS_VAR_CFG */
if (errs) {
if (st != 0) {
return (st);
}
}
if (st == 0) {
if (*hosttype == 's') {
#ifdef MMS_VAR_CFG
} else if (*hosttype == 'c') {
#endif /* MMS_VAR_CFG */
} else {
}
}
if (st != 0) {
return (st);
}
if (st != 0) {
return (st);
}
if (st != 0) {
"/:properties/method_context/user", buf);
}
}
if (st != 0) {
/* major configuration error */
"mmsdb method_context/user",
st);
goto done;
}
#ifndef MMS_VAR_CFG
/* We can only set opts in MMP until SMF gets sorted */
continue;
}
#endif /* MMS_VAR_CFG */
if (nst == 0) {
if (optp[i].validate_func) {
}
nst = 0;
}
}
if (nst != 0) {
if (errs) {
nst);
} else {
/* fail on first error */
break;
}
}
}
if (st != 0) {
goto done;
}
#ifdef MMS_VAR_CFG
/*
* special case for DB logdir. If not specified, should be set to
*/
if (*hosttype == 's') {
if (st == 0) {
val, "log");
}
}
if (st != 0) {
goto done;
}
}
/* TODO: support ssl enabled */
/* have the full complement of required options - set SMF config */
if (nst == 0) {
}
}
#endif /* MMS_VAR_CFG */
/* Set the MMS Admin password */
if (st != 0) {
goto done;
}
/* If we're setting up the server, configure the DB and start MM */
if (*hosttype == 's') {
#ifndef MMS_VAR_CFG
/*
* TEMPORARY: Fetch variables from SMF, rather than
* require them to be passed in.
*/
if (st != 0) {
goto done;
} else {
/*
* currently storing up to data in SMF.
* Change to parent dir for creating subdirs.
*/
*bufp = '\0';
}
}
/* fixed path for log dir */
}
if (st == 0) {
} else {
goto done;
}
if (st == 0) {
} else {
goto done;
}
if (st == 0) {
} else {
goto done;
}
#endif /* !MMS_VAR_CFG */
if (st == 0) {
/* Database will be functional after this call */
}
if (st != 0) {
goto done;
}
}
/* Watcher needs to be started for both host types */
if (st == 0) {
}
done:
if (st != 0) {
if (errs) {
}
/* don't stop services if we haven't changed anything */
(void) mms_mgmt_uninitialize();
}
} else if (init_errs) {
}
return (st);
}
/*
* mms_mgmt_get_opts()
*/
int
{
int st;
int i;
int scf_size = MMS_CFG_MAX_VALUE;
char tid[64];
return (MMS_MGMT_NOARG);
}
/* get MM system vals */
(void) mms_gen_taskid(tid);
"show task['%s'] report[SYSTEM] reportmode[namevalue];", tid);
if (st != 0) {
goto done;
}
&response);
(void) mms_goodbye(session, 0);
if (st != 0) {
goto done;
}
if (st != 0) {
goto done;
}
/* should never happen */
goto done;
}
if (st != 0) {
goto done;
}
/* add the SMF variables */
if (st != 0) {
/* probably unset, keep going */
st = 0;
continue;
}
}
}
if (st != 0) {
goto done;
}
if (st != 0) {
goto done;
}
}
/* don't want a proper name for this list */
done:
if (sysattrs) {
}
if (st != 0) {
nvlist_free(*opts);
}
return (st);
}
/*
* Required opts that are not in inopts, and options with invalid values
* are added to the argument nvlist "errlist".
*/
int
{
int st;
int i;
int errs = 0;
char *opt;
char *val;
int refresh_svcs = 0;
#ifdef MMS_VAR_CFG
int svc_to_check = 0;
#endif /* MMS_VAR_CFG */
int scf_size = MMS_CFG_MAX_VALUE;
char cmd[8192];
char tid[64];
int count = 0;
return (MMS_MGMT_NOARG);
}
if (!mgmt_chk_auth("solaris.mms.modify")) {
return (EACCES);
}
/* check the type of system we're on */
if (st != 0) {
return (ENOTSUP);
}
#ifdef MMS_VAR_CFG
if (*mmtype == 'c') {
svc_to_check = WCR;
} else {
}
#endif /* MMS_VAR_CFG */
/* ignore type on 'set' */
continue;
}
if (st != 0) {
break;
}
/* unrecognized options are ignored */
continue;
}
st = 0;
if (optp[i].validate_func) {
}
if (st != 0) {
errs++;
if (errlist) {
st);
}
}
break;
}
break;
}
}
if (st != 0) {
goto done;
}
#ifdef MMS_VAR_CFG
/* set SMF config */
/* again, skip for set */
continue;
}
if (st == 0) {
continue;
}
}
}
st = 0;
/* set DB opts, if any were specified */
if (refresh_svcs & DB) {
if (st != 0) {
goto done;
}
}
#endif /* MMS_VAR_CFG */
(void) mms_gen_taskid(tid);
continue;
}
&val);
if (st != 0) {
continue;
}
/* set */
" set[SYSTEM.'%s' '%s']",
} else {
/* unset */
" unset[SYSTEM.'%s']",
mms_server_opts[i].mmpopt);
}
count++;
}
/* if no MM opts specified, nothing to set */
if (count > 0) {
if (st != 0) {
goto done;
}
&response);
(void) mms_goodbye(session, 0);
if (st != 0) {
goto done;
}
}
#ifdef MMS_VAR_CFG
/* TODO: set SSL opts */
if (st != 0) {
goto done;
}
#endif /* MMS_VAR_CFG */
/* refresh services */
if (*mmtype == 's') {
if (refresh_svcs & DB) {
}
if (refresh_svcs & MM) {
}
}
if (refresh_svcs & WCR) {
}
done:
return (st);
}
int
mms_mgmt_uninitialize(void)
{
int st = 0;
int i;
if (!mgmt_chk_auth("solaris.mms.delete")) {
return (EACCES);
}
/* stop all running services */
if (st != 0) {
break;
}
}
#ifdef MMS_VAR_CFG
/* get rid of all the configuration information */
if (st == 0) {
}
#endif /* MMS_VAR_CFG */
return (st);
}
static int
mgmt_set_pass(char *inpw)
{
int st = 0;
int fd = -1;
if (!inpw) {
return (EINVAL);
}
0600);
if (fd == -1) {
return (errno);
}
}
if (st == 0) {
} else {
}
return (st);
}
#ifdef MMS_VAR_CFG
static int
{
if (!opts) {
return (EINVAL);
}
#if TODO
} else {
/* TODO: Create the certs, etc. for SSL */
/* leave existng cfg alone for now */
#endif
}
return (0);
}
#endif /* MMS_VAR_CFG */
int
{
int st;
int nst;
char tid[64];
char cmd[8192];
char buf[1024];
void *response;
char *name;
char *val;
char *pass;
int i;
if (!nvl) {
return (MMS_MGMT_NOARG);
}
if (!mgmt_chk_auth("solaris.mms.create")) {
return (EACCES);
}
if (st != 0) {
if (errs) {
}
return (st);
}
if (st != 0) {
if (errs) {
}
return (st);
}
(void) mms_gen_taskid(tid);
"create task['%s'] type[APPLICATION]"
continue;
}
if (nst == 0) {
if (optp[i].validate_func) {
}
nst = 0;
continue;
}
}
if (nst != 0) {
if (errs) {
nst);
} else {
/* fail on first error */
break;
}
} else {
" set[APPLICATION.'%s' '%s']",
}
}
if (!session) {
if (st != 0) {
return (st);
}
}
if (st == 0) {
/* add an application instance for administrative purposes */
(void) mms_gen_taskid(tid);
"create task['%s'] type[AI] "
"set[AI.'ApplicationName' '%s'] "
"set[AI.'AIName' 'admin'] "
"set[AI.'SessionsAllowed' 'multiple'];",
"add application instance", &response);
}
if (st == 0) {
}
if (st != 0) {
}
if (sess) {
(void) mms_goodbye(sess, 0);
}
return (st);
}
int
{
int st;
char tid[64];
char cmd[8192];
void *response;
char *name;
if (!nvl) {
return (MMS_MGMT_NOARG);
}
if (!mgmt_chk_auth("solaris.mms.delete")) {
return (EACCES);
}
if (st != 0) {
return (st);
}
if (!session) {
if (st != 0) {
return (st);
}
}
/*
* See if there are any volumes in use by this application
* before removing it. Fail the op so we don't lose any
* customer data.
*/
(void) mms_gen_taskid(tid);
"show task['%s'] report[VOLUME] reportmode[number] "
"match[streq(VOLUME.'ApplicationName' '%s')];",
"find volumes for app", &response);
if (st == 0) {
}
if (volcnt != 0) {
}
if (st != 0) {
goto done;
}
/* delete any CARTRIDGEGROUPAPPLICATIONS */
(void) mms_gen_taskid(tid);
"delete task['%s'] type[CARTRIDGEGROUPAPPLICATION] "
"match[streq(CARTRIDGEGROUPAPPLICATION.'ApplicationName' '%s')];",
&response);
if (st != 0) {
goto done;
}
/* delete any DRIVEGROUPAPPLICATIONS */
(void) mms_gen_taskid(tid);
"delete task['%s'] type[DRIVEGROUPAPPLICATION] "
"match[streq(DRIVEGROUPAPPLICATION.'ApplicationName' '%s')];",
&response);
if (st != 0) {
goto done;
}
/* next, delete the application instances. */
(void) mms_gen_taskid(tid);
"delete task['%s'] type[AI] "
&response);
if (st == 0) {
/* Finally, the application itself */
(void) mms_gen_taskid(tid);
"delete task['%s'] type[APPLICATION]"
" match[streq(APPLICATION.'ApplicationName' '%s')];",
&response);
}
done:
if (sess) {
(void) mms_goodbye(sess, 0);
}
return (st);
}
int
{
int st;
char tid[64];
char cmd[8192];
char buf[1024];
void *response;
char *name;
char *val;
char *val2;
int i;
int changed = 0;
int nst;
if (!nvl) {
return (MMS_MGMT_NOARG);
}
if (!mgmt_chk_auth("solaris.mms.modify")) {
return (EACCES);
}
if (st != 0) {
if (errs) {
}
return (st);
}
(void) mms_gen_taskid(tid);
"show task['%s'] report[APPLICATION] reportmode[namevalue]"
if (!session) {
if (st != 0) {
return (st);
}
}
if (st != 0) {
goto done;
}
if (st != 0) {
goto done;
}
goto done;
}
if (st != 0) {
goto done;
}
(void) mms_gen_taskid(tid);
"attribute task['%s'] "
"match[streq(APPLICATION.'ApplicationName' '%s')] ",
continue;
}
continue;
}
changed++;
} else {
if (nst == 0) {
continue;
}
}
" set[APPLICATION.'%s' '%s']",
changed++;
}
}
if (changed == 0) {
goto done;
}
&response);
done:
if (sess) {
(void) mms_goodbye(sess, 0);
}
return (st);
}
int
{
int st;
char tid[64];
char cmd[8192];
if (!nvl) {
return (MMS_MGMT_NOARG);
}
if (!mgmt_chk_auth("solaris.mms.modify")) {
return (EACCES);
}
if (st != 0) {
if (errs) {
}
return (st);
}
if (st != 0) {
return (st);
}
namep = "MMS";
/* special case - doesn't modify MM at all */
return (st);
}
if (!session) {
if (st != 0) {
return (st);
}
}
(void) mms_gen_taskid(tid);
"setpassword task['%s'] password['%s'] name['%s'];",
"set password", &response);
if (sess) {
(void) mms_goodbye(sess, 0);
}
if (st != 0) {
}
return (st);
}
int
{
int st;
char tid[64];
char cmd[8192];
if (!supported) {
return (MMS_MGMT_NOARG);
}
if (st != 0) {
return (st);
}
if (!sessp) {
if (st != 0) {
return (st);
}
}
(void) mms_gen_taskid(tid);
"show task['%s'] reportmode[namevalue] report[LIBRARYLIST];", tid);
if (st == 0) {
if (st == 0) {
}
}
if (st != 0) {
goto done;
}
(void) mms_gen_taskid(tid);
"show task['%s'] reportmode[namevalue] report[DRIVELIST];", tid);
if (st == 0) {
if (st == 0) {
}
}
if (st != 0) {
goto done;
}
(void) mms_gen_taskid(tid);
"show task['%s'] reportmode[namevalue] "
"report[CARTRIDGELIST];", tid);
if (st == 0) {
&nvl);
if (st == 0) {
}
}
done:
if (sess) {
(void) mms_goodbye(sess, 0);
}
return (st);
}
int
{
int st;
char tid[64];
char cmd[8192];
char buf[2048];
int count = 0;
int i;
return (MMS_MGMT_NOARG);
}
if (!session) {
if (st != 0) {
return (st);
}
}
(void) mms_gen_taskid(tid);
if (count == 0) {
/* show all, filtering out the MMS Admin application */
"show task['%s'] reportmode[namevalue] "
"match[strne(APPLICATION.'ApplicationName' 'MMS')] "
"report[APPLICATION];",
tid);
} else {
"show task['%s'] reportmode[namevalue] "
"report[APPLICATION] ",
tid);
if (count > 1) {
} else {
}
for (i = 0; i < count; i++) {
" streq (APPLICATION.'ApplicationName' '%s')",
names[i]);
}
}
&response);
if (st == 0) {
}
if (st != 0) {
goto done;
}
done:
if (sess) {
(void) mms_goodbye(sess, 0);
}
if (names) {
}
return (st);
}
int
{
int st;
char tid[64];
char cmd[8192];
char buf[2048];
int count = 0;
int i;
char *val;
char *key = "request-id";
char *tkey = "requestor-type";
return (MMS_MGMT_NOARG);
}
if (!mgmt_chk_auth("solaris.mms.request")) {
return (EACCES);
}
if (!session) {
if (st != 0) {
return (st);
}
}
(void) mms_gen_taskid(tid);
if (count == 0) {
/* show all */
"show task['%s'] reportmode[namevalue] report[REQUEST];",
tid);
} else {
"show task['%s'] reportmode[namevalue] report[REQUEST] ",
tid);
if (count > 1) {
} else {
}
for (i = 0; i < count; i++) {
" streq (REQUEST.'RequestingClient' '%s')",
names[i]);
}
}
&response);
if (st == 0) {
reqs);
}
if (st != 0) {
goto done;
}
if (st != 0) {
continue;
}
if (st == 0) {
val = "library";
val = "drive";
val = "system";
}
}
}
done:
if (sess) {
(void) mms_goodbye(sess, 0);
}
if (names) {
}
return (st);
}
int
{
int st;
char tid[64];
char cmd[8192];
if (!reqID) {
return (MMS_MGMT_NOARG);
}
if (!mgmt_chk_auth("solaris.mms.request")) {
return (EACCES);
}
if (!session) {
if (st != 0) {
return (st);
}
}
if (!textp) {
textp = "ok";
}
/* accept responsibility for this request, then respond to it */
(void) mms_gen_taskid(tid);
"accept task['%s'] reqid['%s'];",
&response);
if (st == 0) {
(void) mms_gen_taskid(tid);
"respond task['%s'] reqid['%s'] "
"message[id ['SUNW' 'MMS' '1000'] loctext ['EN' '%s']];",
&response);
}
if (sess) {
(void) mms_goodbye(sess, 0);
}
return (st);
}
int
{
int st;
char tid[64];
char cmd[8192];
if (!reqID) {
return (MMS_MGMT_NOARG);
}
if (!mgmt_chk_auth("solaris.mms.request")) {
return (EACCES);
}
if (!session) {
if (st != 0) {
return (st);
}
}
if (!textp) {
textp = "rejected";
}
/* accept responsibility for this request, then respond to it */
(void) mms_gen_taskid(tid);
"accept task['%s'] reqid['%s'];",
&response);
if (st == 0) {
(void) mms_gen_taskid(tid);
"respond task['%s'] reqid['%s'] "
"message[id ['SUNW' 'MMS' '1000'] loctext ['EN' '%s']];",
&response);
}
if (sess) {
(void) mms_goodbye(sess, 0);
}
return (st);
}