/*
* 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
*/
/*
*/
/*
* ==============================================
* Name Service Switch libscf to python interface
* ==============================================
*/
/* Python specific includes */
#include <Python.h>
#include <structmember.h>
/* libscf and other includes */
#include <libscf.h>
#include <stdlib.h>
#include <string.h>
/*
* ===================================
* Nssscf Method structure definitions
* ===================================
*/
typedef struct {
/* Nssscf Type-specific fields go here. */
} Nssscf_t;
/*
* =======================
* Nssscf helper functions
* =======================
*/
static int __strlist_len(char **list);
static void __strlist_free(char **list);
/*
* ==========================
* Nssscf Instance management
* ==========================
*/
static void
{
/* libscf instance cleanup */
}
}
}
}
}
static PyObject *
{
scf_handle_t *h;
scf_scope_t *s;
scf_service_t *v;
scf_instance_t *i;
return (NULL);
}
}
/* libscf instance generic setup */
h = scf_handle_create(SCF_VERSION);
s = scf_scope_create(h);
v = scf_service_create(h);
i = scf_instance_create(h);
scf_handle_bind(h) == -1 ||
if (i != NULL)
if (v != NULL)
if (s != NULL)
if (h != NULL)
return (NULL);
}
}
static int
{
return (-1);
if (service) {
/* libscf instance specific init */
return (-1);
/* python specific */
}
return (0);
}
/*
* ================================
* Nssscf Instance member functions
* ================================
*/
static PyObject *
{
}
static int
{
"Cannot delete the service attribute");
return (-1);
}
if (! PyString_Check(value)) {
"The service attribute value must be a string");
return (-1);
}
/* libscf instance specific init */
return (-1);
}
/* re-set any libscf instance specific init */
return (0);
}
/*
* =======================
* Nssscf Instance methods
* =======================
*/
/* Get Operations */
/*
* Get all Service Property groups
* IN: nothing
* OUT: Tuple of property group names and types
*/
static PyObject *
{
return (NULL);
}
return (NULL);
}
return (NULL);
}
return (NULL);
}
return (NULL);
}
continue;
continue;
}
"Unable to build Property group tuple");
goto err;
}
for (l = 0; l < listlen; l++) {
"Unable to build Property group tuple");
goto err;
}
"Unable to build Property group tuple");
goto err;
}
}
} else {
}
err:
/* ErrStrings (if any) should be set by now */
if (pyobject)
if (pylist)
if (pgname)
if (pgtype)
return (ret);
}
/*
* Get all Properties for a Property group
* IN: arg1=pg
* OUT: Tuple of properties and types
*/
static PyObject *
{
char *instnm;
const char *pgname;
const char *tpname;
/* get args */
"Property group argument must be a string");
return (NULL);
}
/* alloc temp storage */
return (NULL);
}
return (NULL);
}
return (NULL);
}
return (NULL);
}
/* get property group from service */
"Property group does not exist");
goto err;
}
} else {
"Service is not an instance");
goto err;
}
instnm++;
"Service is not an instance");
goto err;
}
"Property group does not exist");
goto err;
}
}
"Cannot create property iterator");
goto err;
}
/* setup and iterate properties in property group */
continue;
continue;
}
"Unable to build Property tuple");
goto err;
}
for (l = 0; l < listlen; l++) {
"Unable to build Property tuple");
goto err;
}
"Unable to build Property tuple");
goto err;
}
}
} else {
}
err:
/* ErrStrings (if any) should be set by now */
if (pyobject)
if (pylist)
if (prname)
return (ret);
}
/*
* IN: arg1=pg, arg2=prop
* OUT: Tuple of properties and types
*/
static PyObject *
{
char *instnm;
int listlen, l;
int buflen;
/* get args */
"Property group and property names must be strings");
return (NULL);
}
/* alloc temp storage */
return (NULL);
}
return (NULL);
}
return (NULL);
}
return (NULL);
}
return (NULL);
}
/* Always get composed properties using instance name */
goto err;
} else {
"Instance name missing");
goto err;
}
instnm++;
"Could not get service instance");
goto err;
}
"Composed property group does not exist");
goto err;
}
}
/* get property from property group */
goto err;
}
"Cannot create property value iterator");
goto err;
}
/* setup and iterate properties in property group */
continue;
}
"Unable to build Property tuple");
goto err;
}
for (l = 0; l < listlen; l++) {
"Unable to build Property tuple");
goto err;
}
"Unable to build Property tuple");
goto err;
}
}
} else {
}
err:
/* ErrStrings (if any) should be set by now */
if (pyobject)
if (pylist)
if (buf)
return (ret);
}
/*
* Get Service Property state
* IN: nothing
* OUT: String of current property state
*/
static PyObject *
{
return (NULL);
}
return (pyobject);
}
/*
* Get Service instance fmri
* IN: nothing
* OUT: String of current instance fmri
*/
static PyObject *
{
return (NULL);
}
return (pyobject);
}
/* Test Operations */
/*
* Check Service state
* IN: nothing
*/
static PyObject *
{
int enabled = 0;
return (NULL);
}
enabled++;
if (enabled) {
}
}
/*
* Test to see if a property group exists in the service
* IN: args is a property group string
*/
static PyObject *
{
char *instnm;
const char *pg;
int ret;
"The argument must be a string");
return (NULL);
}
/* do work */
} else {
"Service is not an instance");
return (NULL);
}
instnm++;
"Service is not an instance");
return (NULL);
}
}
if (ret == 0) {
/* ensure we have the most recent pg */
(void) scf_pg_update(pg_handle);
}
if (ret == 0) {
}
}
/*
* Create a property group given a name and type
* IN: arg1 is a property group name, arg2 is the type
*/
static PyObject *
{
char *instnm;
int ret;
"The arguments must be strings");
return (NULL);
}
/* do work */
0, pg_handle);
} else {
"Service is not an instance");
return (NULL);
}
instnm++;
"Service is not an instance");
return (NULL);
}
0, pg_handle);
}
if (ret == 0) {
}
}
/*
* Delete a property group and it's contents
* IN: arg is a property group string
*/
static PyObject *
{
char *instnm;
const char *pg;
int ret;
"The argument must be a string");
return (NULL);
}
/* do work */
} else {
"Service is not an instance");
return (NULL);
}
instnm++;
"Service is not an instance");
return (NULL);
}
}
if (ret == 0) {
} else {
ret = 0; /* true if no property group exists */
}
if (ret == 0) {
}
}
/*
* Delcust (delete customizations) on a service and instance property group
* IN: arg is a property group string
*/
static PyObject *
{
const char *pg;
int ret;
"The argument must be a string");
return (NULL);
}
/* do instance work - for effect */
instnm++;
/* delete it if possible */
(void) scf_pg_delcust(pg_handle);
}
}
}
}
/* do service work */
if (ret == 0) {
} else {
ret = 0; /* true if no property group exists */
}
if (ret == 0) {
}
}
/*
* Create or add a property value given a name, type and value
* IN: arg1 is a property group name, arg2 is the property
* arg3 is the type and arg4 is the value. Value may be either
* created if it does not previously exist.
* OUT: True or Exception
*/
static PyObject *
{
char *instnm;
int n, i;
int badadd = 0;
int new_prop = 0;
return (NULL);
}
/* examine obj for string or sequence */
return (NULL);
} else if (PyString_Check(obj)) {
if ((n = PySequence_Length(obj)) > 0) {
for (i = 0; i < n; i++) {
"Invalid tuple");
badadd = -1;
break;
}
if (!PyString_Check(item)) {
"Tuple value not a string");
badadd = -1;
break;
}
}
}
} else {
"The value must be a string or tuple of strings");
return (NULL);
}
"The value must be a string or tuple of strings");
return (NULL);
}
/* do work */
return (NULL);
}
return (NULL);
}
/* get property group from service */
"Property group does not exist");
ret = -1;
goto err;
}
} else {
"Service is not an instance");
ret = -1;
goto err;
}
instnm++;
"Service is not an instance");
ret = -1;
goto err;
}
"Property group does not exist");
ret = -1;
goto err;
}
}
/* get property from property group */
if (scf_error() == SCF_ERROR_NOT_FOUND)
new_prop = 1;
else {
"Get property error");
ret = -1;
goto err;
}
}
/* setup transaction */
"Could not create transaction or transaction entry");
ret = -1;
goto err;
}
"Could not start transaction");
ret = -1;
goto err;
}
if (ptype == SCF_TYPE_INVALID) {
"Invalid property type");
ret = -1;
goto err;
}
if (new_prop) {
ptype) == -1) {
"Could not create new property transaction");
ret = -1;
goto err;
}
ptype) == -1) {
"Could not create change property transaction");
ret = -1;
goto err;
}
/* add value(s) */
"Cannot create value handle");
ret = -1;
goto err;
}
"Cannot create value string");
ret = -1;
goto err;
}
"Cannot add string to entry");
ret = -1;
goto err;
}
}
/* commit */
if (scf_transaction_commit(tx) > 0) {
ret = 0; /* Successful commit */
} else {
"Cannot commit values to property");
ret = -1;
}
"Property group update failure");
ret = -1;
}
err:
if (ret == 0) {
}
return (NULL);
}
/* Admin Operations */
/*
* Generic Service state changer
* IN: fmri and new state (fmri defaults to fmri:default if not an instance)
*/
typedef enum {
static PyObject *
{
int success;
return (NULL);
}
switch (state) {
case OP_ENABLE:
break;
case OP_DISABLE:
break;
case OP_REFRESH:
break;
case OP_RESTART:
break;
case OP_MAINTAIN:
break;
case OP_DEGRADE:
break;
case OP_RESTORE:
break;
default:
success = 0;
}
if (success == 0) {
}
}
static PyObject *
{
}
static PyObject *
{
}
static PyObject *
{
}
static PyObject *
{
}
static PyObject *
{
}
static PyObject *
{
}
static PyObject *
{
}
static PyObject *
{
int success;
return (NULL);
}
int ret;
0)) >= len) {
"Out of memory.\n");
}
}
}
}
if (success == 0) {
} else {
if (msg) {
} else {
"Unknown Validate Error.\n");
}
}
return (pytuple);
}
/*
* =====================================
* Nssscf Instance structure definitions
* =====================================
*/
"service name", NULL },
{NULL} /* Sentinel */
};
{NULL} /* Sentinel */
};
/* Get Operations */
"Get the list of the services property groups" },
"Get list of properties for a property group (arg1)" },
"Get values for property group, property (arg1, arg2)" },
"Get Service state" },
"Get Service instance FMRI. (May be identical to service name)" },
/* Test Operations */
"Check if service is enabled" },
"Add a property group given a pgname and pgtype (arg1,arg2)" },
"Delete a property group [and it's contents]. (arg1)" },
"Delete customizations on a service property group. (arg1)" },
/* Admin Operations */
"Enable service instance" },
"Disable service instance" },
"Refresh service instance" },
"Restart service instance" },
"Immediately send service instance to maintenance state" },
"Immediately send service instance to degraded state" },
"Restore service instance" },
"Validate current service instance configuration" },
{NULL} /* Sentinel */
};
0, /* ob_size */
"nssscf.Nssscf", /* tp_name */
sizeof (Nssscf_t), /* tp_basicsize */
0, /* tp_itemsize */
0, /* tp_print */
0, /* tp_getattr */
0, /* tp_setattr */
0, /* tp_compare */
0, /* tp_repr */
0, /* tp_as_number */
0, /* tp_as_sequence */
0, /* tp_as_mapping */
0, /* tp_hash */
0, /* tp_call */
0, /* tp_str */
0, /* tp_getattro */
0, /* tp_setattro */
0, /* tp_as_buffer */
"Nssscf objects", /* tp_doc */
0, /* tp_traverse */
0, /* tp_clear */
0, /* tp_richcompare */
0, /* tp_weaklistoffset */
0, /* tp_iter */
0, /* tp_iternext */
Nssscf_methods, /* tp_methods */
Nssscf_members, /* tp_members */
Nssscf_getseters, /* tp_getset */
0, /* tp_base */
0, /* tp_dict */
0, /* tp_descr_get */
0, /* tp_descr_set */
0, /* tp_dictoffset */
0, /* tp_alloc */
Nssscf_new, /* tp_new */
};
/*
* =============================
* Nssscf library Initialization
* =============================
*/
"SUNW Project Private" },
};
initnssscf(void)
{
PyObject *m;
if (PyType_Ready(&nssscf_NssscfType) < 0)
return;
if (m == NULL)
return;
/* Create Nsscf Exception */
/* Create Nssscf Module */
}
/*
* ===============================
* Nssscf library helper functions
* ===============================
*/
static int
{
int count = 0;
return (0);
;
return (count);
}
static char **
{
int len;
char *s, **nl;
return (list);
return (list);
free((void *)s);
return (NULL);
}
nl[0] = s;
return (nl);
}
return (NULL);
return (nl);
}
{
char **nl;
return;
}
/*
* Get the full AS-IS service name. [svc:/]service[:instance]
*/
static char *
{
char *svcn;
return (NULL);
if (*svcstr == '\0')
return (NULL);
return (NULL);
return (svcn);
}
/*
* Get the service name if it is an instance, NULL otherwise
* Caller must free string.
*/
static char *
{
return (NULL);
return (svcn); /* service has an instance name */
return (NULL);
}
/*
* Get the service name if it is not and instance, append :default
* to it's name. Caller must free string.
*/
static char *
{
int newlen;
return (NULL);
return (svcn); /* service is an instance name */
return (NULL); /* storage problem return NULL */
return (svcname);
}
/*
* Sets the Python instance's smf service handle
*/
static int
{
int ret;
return (-1);
}
return (ret);
}
/*
* Given a service name, if it is an instance, return the
* current state. If service is not aninstance try fmri:default'
* NULL otherwise
* Caller must free string.
*/
static char *
{
char *state;
return (NULL);
}
return (state);
}
/*
*/
#include "ns_crypt.c"
static PyObject *
{
const char *input;
char *output;
"Argument must be a string");
return (NULL);
}
} else { /* encode */
}
"Illegal value");
return (NULL);
}
return (ret);
}