DOC HOME SITE MAP MAN PAGES GNU INFO SEARCH PRINT BOOK
 
Designing SCOadmin object service agents

Example helper functions and procedures (C/C++)

Get user data

/*---
 * These routines need to be supplied by the OSA writer, they return the
 * attribute value they are named after when given a specific object. They
 * are also given the ubiquitous errStatus stack pointer in case something
 * goes wrong.
 */

extern bool_t ValidateObject(errStatus_cl *, objectName_pt); extern long GetUserId(errStatus_cl *, objectName_pt); extern long *GetGroupIds(errStatus_cl *, objectName_pt); extern char *GetHome(errStatus_cl *, objectName_pt); extern char *GetShell(errStatus_cl *, objectName_pt); extern char *GetRealName(errStatus_cl *, objectName_pt);

/*--- * The following helper routines are provided by the Server Library. They * perform the following functions (and are defined in "osaStdDef.h" so they * are only defined here in this example for the reader's benefit): * * o OSAReturn*() - returns the given value type to the Server from the OSA. * This routine would be used by the "get" and "action" operations. * o OSAGet*() - returns the indexed (via the 3rd argument) value of the * given valueList. * o OSAFind*() - returns the index to which the given value was in the * given valueList. */

extern void OSAReturnLong(ofParameterList_cl *, attributeToken_t, long); extern void OSAReturnString(ofParameterList_cl *, attributeToken_t, char *); extern void OSAReturnDouble(ofParameterList_cl *, attributeToken_t, double); extern void OSAReturnBoolean(ofParameterList_cl *, bool_t);

/*--- * * The per attribute Execution Procedures example * * Guaranteed that the attribute is a "valid" attribute (thus in this case * it is one of "uid gid home shell name"). * */

void UserGet(errStatus_cl *errStatus, OSAArgDesc_t *argDesc) { objectName_pt object = argDesc->objectName; ofParameter_cl *retList = argDesc->retValues; attributeToken_t token = argDesc->attrToken;

/*--- * validation of objects themselves is left up to the OSA writer. */

if (ValidateObjectName(errStatus, object)) == FALSE) { ErrorPush(errStatus, USER_OBJECT_NON_EXISTENT, object); return; }

/*--- * If the "get" operation had some attribute that was required to be * in the list (unlikely, but could be a possibility with operations * like "create") then it would check the "attrList" for that ability * and Push and error onto the stack if it wasn't found. */

/*--- * If any of the attributes needed another "co-dependent" attribute * to be in the list of attributes while it was being operated on, * then that would be checked for here. For instance, the "create" * might require that if a "home" attribute was specified (instead * of the default value being used) then the command line would also * have to have the "shell" attribute set as well (I don't know why, * this is just an example.) */

switch (token) { case 1: /* the UID attribute */

OSAReturnLong(retList, token, GetUserId(errStatus, userIndex)); return;

case 2: /* the GID attribute */ { /*--- * As a user can belong to more than one GID and the gid * attribute is a "set"-values attribute, let's make sure * to add all the GIDs the user belongs to to the return * list. Out imaginary helper procedure get_group_ids() will * return a NULL terminated list of integers. */

int *tmp_gids, *GetGroupIds(); tmp_gids = GetGroupIds(errStatus, object); while (*tmp_gids != 0) { OSAReturnLong(retList, token, *tmp_gids++); } return; }

case 3: /* the HOME attribute */

OSAReturnString(retList, token, GetHome(errStatus, userIndex)); return;

case 4: /* the SHELL attribute */

OSAReturnString(retList, token, GetShell(errStatus, userIndex)); return;

case 5: /* the NAME attribute */

OSAReturnString(retList, token, GetRealName(errStatus, object)); return; } }

OSA filter

/*---
 *
 * The equivalence filter operator
 *
 * Guaranteed that the attribute is a "valid" attribute (thus in this case
 * it's one of "uid gid home shell name").
 *
 */

void user_filter(errStatus_cl *errStatus, OSAArgDesc_t *argDesc) { /*--- * validation of objects themselves is left up to the OSA writer. */

if (ValidateObject(errStatus, object) == 0) { ErrorPush(errStatus, USER_OBJECT_NON_EXISTENT, object); return; }

if (argDesc->filterToken != FILTER_EQ) { ErrorPush(errStatus, USER_OBJECT_UNRECOGNIZED_FILTER, object); return; }

/*--- * Each attribute's value is read in from an OSA helper routine that * supplies it and then its pushed on to the return stack. */

switch (argDesc->attrToken) {

case ATTR_UID: /* the UID attribute */

if (get_user_id(errStatus, userIndex) == argDesc->filterValueArray[0].longValue) OSAReturnBoolean(argDesc->retValues, TRUE); else OSAReturnBoolean(argDesc->retValues, FALSE); return;

case ATTR_GID: /* the GID attribute */ { /*--- * As a user can belong to more than one GID and the gid * attribute is a "set"-values attribute, let's make sure * to check for all the GIDs the user belongs to. * Out imaginary helper procedure GetGroupIds() will return * a -1 terminated list of integers. */

int *attrGids; int *filtGids = argDesc->filterValueArray; int gidMatches = 0; attrGids = GetGroupIds(errStatus, object); while (*attrGids != -1) { /*--- * If the value is in the valueList, this function returns * its position in the list. Otherwise a -1. We don't care * what place it is in the list, just as long as every value * is in the list. */

for (loop = 0; loop < argDesc->filterValueCount; ++loop) { if (filtGids[loop] == *attrGids) { gidMatches++; continue; } }

if (loop == argDesc->filterValueCount) { /* looped all through the given data and could not find * the current attribute GID (*attrGid). So there is a * miss-match. */

OSAReturnBoolean(argDesc->retValues, FALSE); }

attrGids++; }

if (gidMatches == argDesc->filterValueCount) OSAReturnBoolean(argDesc->retValues, TRUE); else OSAReturnBoolean(argDesc->retValues, FALSE);

return; }

case ATTR_HOME: /* the HOME attribute */

if (strcmp(get_home(errStatus, userIndex), argDesc->filterValueArray[0].stringValue) == 0) OSAReturnBoolean(argDesc->retValues, TRUE); else OSAReturnBoolean(argDesc->retValues, FALSE); return;

case ATTR_SHELL: /* the SHELL attribute */

if (strcmp(get_shell(errStatus, userIndex), argDesc->filterValueArray[0].stringValue) == 0) OSAReturnBoolean(argDesc->retValues, TRUE); else OSAReturnBoolean(argDesc->retValues, FALSE); return;

case ATTR_NAME: /* the NAME attribute */

if (strcmp(get_real_name(errStatus, argDesc->objectName), argDesc->filterValueArray[0].stringValue) == 0) OSAReturnBoolean(argDesc->retValues, TRUE); else OSAReturnBoolean(argDesc->retValues, FALSE); return;

} }

OSA list

/*===========================================================================
 * OSA List
 *
 *   This function returns the list of objects of the current (subordinate)
 * class that are contained by the named object instance (of the superior
 * class).
 *
 * Returns:
 *   This function should return the list of all objects of the current
 * (subordinate) class that are contained by the give object instance. In this
 * contrived example, as in many contained/list functions, the function does
 * not care what the object instance of the superior class was, this is just
 * a means of providing the caller with a list of all the object instances
 * of this class on this machine. In other examples there would be persistent
 * storage databases that would indicate what objects contained what objects.
 *
 *---------------------------------------------------------------------------
 */

void WorkingList(errStatus_cl *errStatusPtr, OSAArgDesc_t *argDescPtr) { /* * Purely made up routine GetAllObjects() * returns a static array of object * names which is NULL terminated. */

objectInstance_pt *objectList = GetAllObjects(errStatusPtr); int i = 0;

while (objectList[i] != NULL) { OSAReturnActionData(argDescPtr->returnList, (char *) objectList[i]); i++; } }


Next topic: Example helper functions and procedures (Tcl)
Previous topic: Example CDT (C/C++)

© 2003 Caldera International, Inc. All rights reserved.
SCO OpenServer Release 5.0.7 -- 11 February 2003