mgmt_util.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.
*/
/*
* various utility functions
*/
#include <stdlib.h>
#include <stdio.h>
#include <errno.h>
#include <unistd.h>
#include <string.h>
#include <stdarg.h>
#include <time.h>
#include <libgen.h>
#include <pwd.h>
#include <grp.h>
#include <ctype.h>
#include <fcntl.h>
#include <unistd.h>
#include <procfs.h>
#include <dirent.h>
#include <auth_attr.h>
#include <secdb.h>
#include "mgmt_util.h"
#include "mmp_defs.h"
#include "mms_cfg.h"
/* forward declarations */
char *group);
static void
/*
* mms_gen_taskid()
*
* Parameters:
* - tid unique task identifier.
*
* This function returns a task identifier (TID). All responses to an MMP
* command will include the TID of the initiating command. The TID will be
* unique in the context of a session so that the client can determine which
* responses go with which command.
*/
int
mms_gen_taskid(char *tid)
{
if (!tid) {
return (MMS_MGMT_NOARG);
}
return (0);
}
/*
* create the directory dir. This function will not fail if the directory
* already exists.
*/
int
{
int st = 0;
if (!dir) {
return (MMS_MGMT_NOARG);
}
if (perms == 0) {
/* make the dir rwx by owner, and rx by other and group */
}
errno = 0;
/* TBD: set errno and errmsg */
return (ENOTDIR);
}
errno = 0;
if (st != 0) {
return (errno);
}
}
if (uid == 0) {
} else {
}
return (st);
}
static int
{
char buf[1024];
int st;
return (MMS_MGMT_NOARG);
}
/* nothing to do */
return (0);
}
return (MMS_MGMT_ERR_USER);
}
return (MMS_MGMT_ERR_GROUP);
}
}
return (st);
}
static int
{
int st;
return (MMS_MGMT_NOARG);
}
/* nothing to do */
return (0);
}
/* nothing to do */
return (0);
}
return (st);
}
int cp_file(
const char *old,
const char *new)
{
int oldfd = -1;
int newfd = -1;
struct stat oldstatbuf;
struct stat newstatbuf;
int res;
int saverr = 0;
char buf[8192];
int wlen;
/* make sure old exists */
if (res != 0) {
return (errno);
}
/* if the target exists, remove it */
if (res == 0) {
}
/* save the access & mod times so they can be reset */
if (oldfd == -1) {
return (res);
}
if (newfd == -1) {
return (res);
}
/* finally, copy the file */
res = 0;
while (oldlen > 0) {
if (oldlen < 8192) {
} else {
wlen = 8192;
}
if (res == -1) {
break;
}
if (res == -1) {
break;
}
}
/* set acccess & modify times to match original file */
if (saverr == 0) {
res = 0;
} else {
}
return (res);
}
/* helper function to use read() correctly */
int
{
int numread = 0;
int ret;
char *bufp;
return (-1);
}
if (ret == 0) {
/* reached EOF */
break;
} else if (ret == -1) {
continue;
}
numread = -1;
break;
}
}
return (numread);
}
/* helper function to use write() correctly */
int
{
int written = 0;
int ret;
char *bufp;
return (-1);
}
if (ret == -1) {
continue;
}
written = -1;
break;
}
}
return (written);
}
/*
* mk_wc_path()
*
* Function to generate a path name for working copies of
* files and creates the file.
*/
int
char *original, /* IN - path to original file */
{
char *copypath;
char *fname;
int ret;
return (MMS_MGMT_NOARG);
}
/* make sure target directory exists */
if (ret != 0) {
return (ret);
}
/*
* not an error if the original doesn't exist. In this
* case, dummy up a mode to be used for the later mknod.
*/
if (ret != 0) {
}
/* create the template name */
return (-1);
} else {
}
/* make sure an old version isn't hanging around */
/* create the target file */
return (ret);
}
/*
* make_working_copy()
*
* Copies a file to the default temporary location and returns
* the pathname of the copy.
*
*/
int
{
int ret;
return (-1);
}
if (ret != 0) {
return (ret);
}
return (ret);
}
typedef struct proclist proclist_t;
struct proclist {
};
/*
* The find_process() function reads through /proc and finds all processes with
* the specified executable name.
*
* PARAM
* exename - INPUT - name of executable
* procs - OUTPUT - list of psinfo_t structs
*
* ERRORS
*/
int
{
char pname[MAXPATHLEN];
char *ptr;
int ret = 0;
return (MMS_MGMT_NOARG);
}
return (ret);
}
/* allocate the dirent structure */
return (ENOMEM);
}
/* find each active process --- */
break;
}
/* skip . and .. */
continue;
}
if (procfd == -1) {
/* process may have ended while we were processing */
continue;
}
/*
* Get the info structure for the process and close quickly.
*/
if (ret == -1) {
break;
}
continue;
/* ensure cmd buffers properly terminated */
/* is it the proc we're looking for? */
continue;
}
break;
}
}
return (ret);
}
/*
* exec_mgmt_cmd()
*
* Helper functino to exec an external program, optionally returning
*
* The 'cmd' array must have the executable as the first entry, and *must*
* have a NULL as the last entry.
*/
int
char *cmd[])
{
/* The path to the executable must be fully-qualified */
return (-1);
}
return (-1);
}
}
return (-1);
}
}
return (-1);
}
if (pid == 0) { /* child */
/* redirect stdout and stderr */
int ret;
if (!outstr) {
}
if (!errstr) {
}
exit(9);
}
(void) close(STDIN_FILENO);
(void) closefrom(3);
/* set UID if requested */
if (euid != 0) {
}
if (egid != 0) {
}
if (daemon) {
(void) setsid(); /* become session leader */
if (pid < 0) {
exit(1);
} else if (pid > 0) {
/* parent */
exit(0);
}
}
if (0 != ret) {
return (ret);
}
}
/* parent */
if (outstr) {
}
if (errstr) {
}
return (pid);
}
/* configuration functions */
void
mgmt_unsetall_cfgvar(void)
{
(void) mms_cfg_unsetvar(MMS_CFG_CONFIG_TYPE);
(void) mms_cfg_unsetvar(MMS_CFG_MGR_HOST);
(void) mms_cfg_unsetvar(MMS_CFG_MGR_PORT);
(void) mms_cfg_unsetvar(MMS_CFG_SSL_ENABLED);
(void) mms_cfg_unsetvar(MMS_CFG_SSL_CERT_FILE);
(void) mms_cfg_unsetvar(MMS_CFG_SSL_PASS_FILE);
(void) mms_cfg_unsetvar(MMS_CFG_SSL_DH_FILE);
(void) mms_cfg_unsetvar(MMS_CFG_SSL_CRL_FILE);
(void) mms_cfg_unsetvar(MMS_CFG_SSL_PEER_FILE);
(void) mms_cfg_unsetvar(MMS_CFG_SSL_CIPHER);
(void) mms_cfg_unsetvar(MMS_CFG_SSL_VERIFY);
(void) mms_cfg_unsetvar(MMS_CFG_DB_DATA);
(void) mms_cfg_unsetvar(MMS_CFG_DB_LOG);
(void) mms_cfg_unsetvar(MMS_CFG_MM_DB_HOST);
(void) mms_cfg_unsetvar(MMS_CFG_MM_DB_PORT);
(void) mms_cfg_unsetvar(MMS_CFG_MM_DB_NAME);
(void) mms_cfg_unsetvar(MMS_CFG_MM_DB_USER);
(void) mms_cfg_unsetvar(MMS_CFG_SSI_PATH);
}
int
char *fmri,
char **original)
{
char *startState = NULL;
int st = 0;
const char *cmpState;
int i;
return (MMS_MGMT_NOARG);
}
if (startState == NULL) {
/*
* Not an error if request to disable or degrade a
* non-existent svc
*/
if (st == SCF_ERROR_NOT_FOUND) {
st = 0;
}
}
return (st);
}
*original = startState;
}
switch (targetState) {
case ENABLE:
}
break;
case DISABLE:
/*
* can't go directly from maintenance to disabled,
* though I can't see why.
*/
}
}
break;
case REFRESH:
/* refresh shouldn't change the current state */
break;
case RESTART:
break;
case MAINTAIN:
break;
case DEGRADE:
/* only available if 'online' */
} else {
}
break;
case RESTORE:
/*
* if disabled, returns to online. If maintenance,
* returns to disabled.
*/
== 0) {
== 0) {
} else {
/* invalid operation */
break;
}
break;
default:
st = -1;
break;
}
if (st == 0) {
/*
* Changing state sometimes takes a while, so
* loop for up to 5 seconds.
*/
for (i = 1; i < 10; i++) {
st = 1;
break;
st = 0;
break;
}
}
} else {
}
}
}
return (st);
}
int
{
int pst;
return (st);
}
} else {
} else if (WIFSIGNALED(pst)) {
if (signo) {
}
if (signo) {
}
}
}
return (st);
}
/* Helper function for MMS lists */
void
{
return;
}
while (! mms_list_empty(list)) {
}
}
/* helper functions to validate option values */
int
val_numonly(char *val)
{
int st = 0;
char *bufp;
if (!val) {
return (MMS_MGMT_NOARG);
}
if (*bufp == '-') {
/* negative number */
continue;
}
break;
}
}
return (st);
}
int
val_passwd(char *val)
{
if (!val) {
return (MMS_MGMT_NOARG);
return (EINVAL);
} else {
return (0);
}
}
int
val_objtype(char *val)
{
if (!val) {
return (MMS_MGMT_NOARG);
}
return (0);
} else {
return (EINVAL);
}
}
int
{
if (!val) {
return (MMS_MGMT_NOARG);
}
if (*val != '/') {
return (EINVAL);
}
return (0);
}
int
{
if (!val) {
return (MMS_MGMT_NOARG);
}
return (0);
} else {
return (EINVAL);
}
}
int
{
if (!val) {
return (MMS_MGMT_NOARG);
}
return (0);
} else {
return (EINVAL);
}
}
int
val_truefalse(char *val)
{
if (!val) {
return (MMS_MGMT_NOARG);
}
return (0);
} else {
return (EINVAL);
}
}
int
val_mms_size(char *val)
{
}
int
{
if (!val) {
return (MMS_MGMT_NOARG);
}
return (EINVAL);
}
if (unit) {
switch (*unit) {
case 'b':
case 'B':
mult = 1;
break;
case 'k':
case 'K':
break;
case 'm':
case 'M':
break;
case 'g':
case 'G':
break;
case 't':
case 'T':
break;
case 'p':
case 'P':
break;
default:
return (EINVAL);
break;
}
}
if (bytes) {
}
return (0);
}
int
val_density(char *val)
{
if (!val) {
return (MMS_MGMT_NOARG);
}
return (0);
}
return (EINVAL);
}
int
{
int st = 0;
char *mpwp;
char *chkpw;
char buf[512];
int fd;
return (MMS_MGMT_NOARG);
}
if (fd == -1) {
if (errs) {
}
return (st);
}
sz--;
}
return (MMS_MGMT_PASSTOOSHORT);
}
} else {
return (MMS_MGMT_NOARG);
}
return (MMS_MGMT_GETPASS_FAILED);
return (MMS_MGMT_PASSTOOSHORT);
}
/* getpassphrase overwrites previous result, so save first */
/* verify entered password if required */
if (phrase[1]) {
return (MMS_MGMT_PASSWD_MISMATCH);
}
}
}
return (0);
}
/*
* Helper function to generate the MMP 'create' clause for the specified
* object.
*/
int
{
int st = 0;
int ost = 0;
char tid[64];
char buf[1024];
char *val;
int i;
return (MMS_MGMT_NOARG);
}
(void) mms_gen_taskid(tid);
objtype);
continue;
}
ost = 0;
}
} else {
ost = 0;
continue;
}
}
if (ost != 0) {
if (st == 0) {
}
continue;
}
}
return (st);
}
int
{
int st;
char tid[64];
char cmd[8192];
return (MMS_MGMT_NOARG);
}
if (st != 0) {
return (st);
}
}
if (st == 0) {
&response);
}
if (sess) {
(void) mms_goodbye(sess, 0);
}
return (st);
}
int
{
int st = 0;
return (MMS_MGMT_NOARG);
}
st);
} else {
}
}
return (st);
}
int
{
int st = 0;
int ost = 0;
int i;
return (MMS_MGMT_NOARG);
}
*count = 0;
continue;
}
if (ost == 0) {
if (opts[i].validate_func) {
if (ost != 0) {
if (st == 0) {
}
ost);
continue;
}
}
(*count)++;
}
}
return (st);
}
void
{
int i;
int ost;
char *val;
return;
}
continue;
}
if (ost != 0) {
continue;
}
/* value identical */
(*count)--;
}
}
}
void
{
int i;
char phrase[1024];
return;
}
continue;
}
" set[%s.'%s' '%s']",
}
}
char **
{
int st;
int i;
return (NULL);
}
*count = 0;
return (NULL);
}
if (nvt == DATA_TYPE_STRING) {
if (st == 0) {
*count = 1;
}
}
} else if (nvt == DATA_TYPE_STRING_ARRAY) {
for (i = 0; i < *count; i++) {
}
}
}
}
return (arr);
}
void
{
int i;
if (!inarr) {
return;
}
for (i = 0; i < count; i++) {
if (inarr[i]) {
}
}
}
int
{
int st;
char *bufp;
char *wstr;
return (MMS_MGMT_NOARG);
}
if (!wstr) {
return (ENOMEM);
}
if (!bufp) {
return (MMS_MGMT_NOARG);
}
*bufp++ = '\0';
if (st != 0) {
if (allow_empty) {
/* common for 'list' options */
st = 0;
}
}
}
return (st);
}
int
{
int st;
char *bufp;
int count;
char **tmparr;
return (MMS_MGMT_NOARG);
}
count = 1;
for (;;) {
break;
}
bufp++;
count++;
}
if (count == 1) {
} else {
return (ENOMEM);
}
/* set delimiter to comma */
}
return (st);
}
int
{
int st;
switch (in_err) {
case SCF_ERROR_NOT_SET:
case SCF_ERROR_NOT_FOUND:
case SCF_ERROR_DELETED:
break;
case SCF_ERROR_NO_MEMORY:
break;
case SCF_ERROR_TYPE_MISMATCH:
break;
default:
break;
}
return (st);
}
int
{
return (MMS_MGMT_NOARG);
}
return (EIO);
}
continue;
}
/* should never happen */
continue;
}
} else {
st = 0;
}
break;
}
}
return (st);
}
int
{
int st;
int a;
return (MMS_MGMT_NOARG);
}
if (st != 0) {
return (st);
}
if (st != 0) {
return (st);
}
sizeof (struct sockaddr));
if (a == 0) {
break;
}
sizeof (struct sockaddr)) == 0) {
break;
}
}
}
if (res1) {
}
if (res2) {
}
if (match) {
return (0);
}
return (1);
}
/* error messages */
static char *mms_mgmt_errs[] = {
NULL,
"Internal error; missing argument",
"Could not exec ACSLS ssi daemon",
"Could not communicate with ACSLS server",
"Received invalid response from ACSLS server",
"Could not parse response from ACSLS server",
"Missing required option",
"Could not determine MM host",
"Volume in use",
"Could not access database backup",
"Unknown response type",
"Request cancelled",
"Request not accepted",
"Could not determine group",
"Could not determine user",
"Option applies to MM server host only",
"Volume not unique",
"Partition not unique",
"Volume not labeled",
"No usable volume found",
"Could not find ACSLS client libraries",
"MMS is not initialized or not running",
"Drives on remote systems cannot be configured at this time",
"Operation requires a password",
"Volume not mounted",
"Not authorized. Use the correct application/password combination.",
"Password validation failed",
"Failed to get the password",
"Password must be 8 characters or longer.",
"Internal error: MMP parsing failed",
"Application is still using one or more volumes.",
"Not a valid MMS database backup file",
"Database Administrator user account not found"
};
const char *
{
int max_err = sizeof (mms_mgmt_errs) / sizeof (char *);
/* standard errors */
if (errcode < 256) {
}
/* SCF errors */
return (scf_strerror(errcode));
}
}
if (errcode >= MMS_ERR_BIAS) {
return (mms_sym_code_to_str(errcode));
}
return (NULL);
}
int
mgmt_chk_auth(char *authname)
{
int st;
char buf[1024];
if (!authname) {
return (1);
}
if (st != 0) {
/* fail if we can't determine the username */
return (0);
}
return (st);
}
void
{
int st;
int count;
char **varray;
char *key;
/* not a failure if nothing to do */
return;
}
return;
}
continue;
}
if ((nvt != DATA_TYPE_STRING_ARRAY) &&
(nvt != DATA_TYPE_STRING)) {
continue;
}
}
}
static void
{
int st;
char **arr;
char *val;
int i;
int j;
char *attrname;
return;
}
if (st != 0) {
continue;
}
if (st != 0) {
/* no match, remove it */
continue;
}
if (nvt == DATA_TYPE_STRING) {
if (val) {
for (i = 0; i < count; i++) {
/* a keeper */
break;
}
}
}
} else if (nvt == DATA_TYPE_STRING_ARRAY) {
if (st == 0) {
for (j = 0; j < vcount; j++) {
for (i = 0; i < count; i++) {
== 0) {
/* a keeper */
break;
}
}
if (keep) {
break;
}
}
}
}
if (keep) {
} else {
}
}
}