DataMuseum.dk

Presents historical artifacts from the history of:

DKUUG/EUUG Conference tapes

This is an automatic "excavation" of a thematic subset of
artifacts from Datamuseum.dk's BitArchive.

See our Wiki for more about DKUUG/EUUG Conference tapes

Excavated with: AutoArchaeologist - Free & Open Source Software.


top - metrics - download
Index: T c

⟦9cf3af80c⟧ TextFile

    Length: 12105 (0x2f49)
    Types: TextFile
    Names: »cmis.c«

Derivation

└─⟦2d1937cfd⟧ Bits:30007241 EUUGD22: P.P 5.0
    └─⟦e83f91978⟧ »EurOpenD22/isode/osimis-2.0.tar.Z« 
        └─⟦d846658bd⟧ 
            └─⟦this⟧ »osimis/sma/cmis.c« 

TextFile

/*
 * Copyright (c) 1988 University College London
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms are permitted
 * provided that the above copyright notice and this paragraph are
 * duplicated in all such forms and that any documentation,
 * advertising materials, and other materials related to such
 * distribution and use acknowledge that the software was developed
 * by the Department of Computer Science, University College London.
 * The name of the University may not be used to
 * endorse or promote products derived from this software without
 * specific prior written permission.
 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
 * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
 * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
 */

/* handle the CMIP/S side of the SMA */

/*
 * By George Pavlou, April 1990
 */

#include <stdio.h>
#include <varargs.h>
#include "isode/rosap.h"
#include "msap.h"
#include "smi.h"

#define	MAXCONNS 6	/* max mgmt connections */

static int NofConns;	/* no of current mgmt connections */


extern struct ManagedObject * MIBroot;
extern struct ManagedObject * findcomp(), * forccomp();
extern OID oid_copy();
int M_This_Con;         /* for report dests */
int doGetMyId();
int doGetMySubords();
char * alloca();


int cmip_init (vecp, vec)
int vecp;
char ** vec;
{
    int sd, status;
    struct MSAPstart mss, * ms = &mss;
    struct MSAPindication mis, * mi = &mis;
    struct MSAPabort * ma = &mi -> mi_abort;

    if (M_Init(vecp, vec, ms, mi) == NOTOK) {
        warn("initialization fails: %s\n", ma -> ma_data);
        return NOTOK;
    }

    sd = ms -> ms_sd;
    status = NofConns < MAXCONNS ? ACS_ACCEPT : ACS_TRANSIENT;

    if (M_InitialiseResp(ms, status, NULLAEI, &ms->ms_start.ps_called,
    		NULLOID, 0x1, 0x0, NULLEXTERN, NULLEXTERN, mi) == NOTOK) {
        warn("A-ASSOCIATE.RESPONSE: %s\n", ma -> ma_data);
        return NOTOK;
    }

    NofConns++;
    return sd;
}


/* VARARGS1 */
warn (s, a, b, c, d, e)
char * s;
caddr_t a, b, c, d, e;
{
    fprintf(stderr, s, a, b, c, d, e);
    fputc('\n',stderr);
}


cmip_work (fd)
int fd;
{
    struct MSAPindication mis;

    M_WaitReq(fd, OK, &mis);
    switch (mis.mi_type) {
    case MI_PREJECT:
	switch (mis.mi_preject.mr_reason) {
	case ROS_TIMER:
	    return OK;
	case ROS_ACS:		/* ACS disconnect */
	    NofConns--;
	    break;
	default:
	    break;
	}
	break;

    case MI_GET:  (void)
        doGet(fd, mis.mi_getv.id,
	    &mis.mi_getv.args.ga_class, &mis.mi_getv.args.ga_inst,
	    mis.mi_getv.args.ga_access, mis.mi_getv.args.ga_sync,
	    mis.mi_getv.args.ga_nattrs, mis.mi_getv.args.ga_attrs);
        break;

    case MI_SET:  (void)
        doSet(fd, 0, mis.mi_setv.id,
	    &mis.mi_setv.args.sa_class, &mis.mi_setv.args.sa_inst,
	    mis.mi_setv.args.sa_access, mis.mi_setv.args.sa_sync,
	    mis.mi_setv.args.sa_nattrs, mis.mi_setv.args.sa_attrs);
        break;

    case MI_SETC:  (void)
        doSet(fd, 1, mis.mi_setv.id,
	    &mis.mi_setv.args.sa_class, &mis.mi_setv.args.sa_inst,
	    mis.mi_setv.args.sa_access, mis.mi_setv.args.sa_sync,
	    mis.mi_setv.args.sa_nattrs, mis.mi_setv.args.sa_attrs);
        break;

    case MI_EVENT_REP:
    case MI_EVENT_REPC:
    case MI_EVENT_REP_RES:
    case MI_GET_RES:
    case MI_SET_RES:
       fprintf(stderr, "Illegal indication type %d\n", mis.mi_type);
       break;

    case MI_TERM:
#ifdef DEBUG
        fprintf(stderr, "Connection released - %d\n", mis.mi_term.mt_reason);
#endif DEBUG
        M_TerminateResp(fd, ACS_ACCEPT, ACR_NORMAL, NULLPE, &mis);
        NofConns--;
        return NOTOK;

    default:
        fprintf(stderr, "Unknown indication type %d\n", mis.mi_type);
        break;
    }
    return OK;
}


/* ARGSUSED */
static  doGet (fd, id, class, instance, access, sync, nattrs, attrs)
int fd, id;
MID class;
MN  instance;
PE  access;
CMISsync sync;
int  nattrs;
MID  attrs;
{
    struct MSAPindication mis;
    struct ManagedObject * m;
    CMISparam result[M_MAXATTRS];
    MO_ID * inst;
    CMISerrors error = m_noError;
    register int cur;

    dn_decode(instance -> mn_dn);
    inst = dn2moid(instance -> mn_dn);
    m = findcomp(MIBroot, inst);
    moid_free(inst);
    if (m == NULL)
        return doGetError(fd, id, NULLMID, instance, m_noSuchObjectInstance);
    if (oid_cmp(class -> mid_global, &m -> Class) == NOTOK)
        return doGetError(fd, id, class, instance, m_classInstanceConflict);

    for (cur = 0; cur < nattrs && cur < M_MAXATTRS; cur++) {
        register int curid;
        result[cur].mp_id.mid_type = MID_LOCAL;
        curid = result[cur].mp_id.mid_local = attrs[cur].mid_local;
        if (curid == 0) {
	    if (doGetMyId(&result[cur].mp_val, m) == 0)
	        return doGetError(fd, id, class, instance, m_processingFailure);
	    continue;
	}
        if (curid == 1) {
	    if (doGetMySubords(&result[cur].mp_val, m) == 0)
	        return doGetError(fd, id, class, instance, m_processingFailure);
	    continue;
	}
        if (m -> do_get == NULL)
	    return doGetError(fd, id, NULLMID, NULLMN, m_accessDenied);
        switch(result[cur].mp_error =
		(m -> do_get)(&result[cur].mp_val, m, curid)) {
        case m_noError:
	    break;
        case m_noSuchAttribute:
	    error = m_getListError;
	    result[cur].mp_val = NULLPE;
	    break;
        case m_processingFailure:
	    return doGetError(fd, id, class, instance, m_processingFailure);
        default:
	    break;
        }
    }

    if (M_GetRes(fd, id, NOLINKED, class, instance, NULLCP, cur, result,
			error, NULLMERRPARM, &mis) == NOTOK)
        warn("Get Result failed - %s\n", mis.mi_preject.mr_data);
    for (; cur;)
        if (result[--cur].mp_val)
	    pe_free(result[cur].mp_val);
    return OK;
}


/* ARGSUSED */
static  doSet (fd, conf, id, class, instance, access, sync, nattrs, attrs)
int fd, conf, id;
MID class;
MN  instance;
PE  access;
CMISsync sync;
int nattrs;
CMISparam * attrs;
{
    struct MSAPindication mis;
    struct ManagedObject * m;
    CMISparam result[M_MAXATTRS];
    MO_ID * inst;
    CMISerrors error = m_noError;
    register int cur;
    int (*curfunc)();

    dn_decode(instance -> mn_dn);
    inst = dn2moid(instance -> mn_dn);
    m = findcomp(MIBroot, inst);
    moid_free(inst);
    if (m == NULL)
        return doSetError(fd, conf, id, NULLMID, instance,
					m_noSuchObjectInstance);
    if (oid_cmp(class -> mid_global, &m -> Class) == NOTOK)
        return doSetError(fd, conf, id, class, instance,
					m_classInstanceConflict);
    if (m -> do_set == NULL && m -> do_add == NULL && m -> do_remove == NULL)	
        return doSetError(fd, conf, id, NULLMID, NULLMN, m_accessDenied);
    M_This_Con = fd;

    for (cur = 0; cur < nattrs && cur < M_MAXATTRS; cur++) {
        register int curid;
        result[cur].mp_id.mid_type = MID_LOCAL;
        curid = result[cur].mp_id.mid_local = attrs[cur].mp_id.mid_local;
        switch (attrs[cur].mp_modify) {
        case m_replace:
	    if ((curfunc = m -> do_set) == NULL) {
	        result[cur].mp_error = m_invalidOperation;
	        result[cur].mp_val = attrs[cur].mp_val;
	        error = m_setListError;
	        continue;
	    }
	    break;
        case m_addValue:
	    if ((curfunc = m -> do_add) == NULL) {
	        result[cur].mp_error = m_invalidOperation;
	        result[cur].mp_val = attrs[cur].mp_val;
	        error = m_setListError;
	        continue;
	    }
	    break;
        case m_removeValue:
	    if ((curfunc = m -> do_remove) == NULL) {
	        result[cur].mp_error = m_invalidOperation;
	        result[cur].mp_val = attrs[cur].mp_val;
	        error = m_setListError;
	        continue;
	    }
	    break;
        case m_setToDefault:
	    result[cur].mp_error = m_invalidOperation;
	    result[cur].mp_val = attrs[cur].mp_val;
	    error = m_setListError;
	    continue;
        default:
	    result[cur].mp_error = m_invalidOperator;
	    result[cur].mp_val = attrs[cur].mp_val;
	    error = m_setListError;
	    continue;
        }
        switch(result[cur].mp_error =
		(curfunc)(&result[cur].mp_val, m, curid, attrs[cur].mp_val)) {
        case m_noError:
	    break;
        case m_noSuchAttribute:
	    error = m_setListError;
	    result[cur].mp_val = attrs[cur].mp_val;
	    break;
        case m_invalidAttributeValue:
	    error = m_setListError;
	    result[cur].mp_val = attrs[cur].mp_val;
	    break;
        case m_processingFailure:
	    return doSetError(fd, conf, id, class, instance,
						m_processingFailure);
        default:
	    break;
        }
    }

    if (conf && M_SetRes(fd, id, NOLINKED, class, instance, NULLCP, cur, result,
			error, NULLMERRPARM, &mis) == NOTOK)
        warn("Set Result failed - %s\n", mis.mi_preject.mr_data);
    for (; cur;)
        if (result[--cur].mp_val)
	    pe_free(result[cur].mp_val);
    return OK;
}


static  doGetMyId (res, m)
PE * res;
struct ManagedObject * m;
{
    MO_ID name;
    RDN rdn;
    int s;

    (void) oid_copy(&m -> rdntype, &name.rdntype);
    bcopy(m -> rdnval, name.rdnval, name.rdnlen = m -> rdnlen);
    rdn = moid2rdn(&name);
    s = encode_IF_RelativeDistinguishedName(res, 1, 0, NULLCP, rdn);
    rdn_free(rdn);
    free((char*) name.rdntype.oid_elements);
    return (s == NOTOK ? 0 : 1);
}

static  doGetMySubords (res, m)
PE * res;
struct ManagedObject * m;
{
    int i, n, s;
    MO_ID * names = (MO_ID*) NULL;
    DN rdnseq;
    register struct ManagedObject * subs = m -> subordinate;

    for(n = 0; subs; n++)
        subs = subs -> sibling;

    if (n) {
        if ((names = (MO_ID*) malloc(n * sizeof(MO_ID))) == NULL)
	    return 0;
        subs = m -> subordinate;
        for(i = 0; i < n; i++) {
	    oid_copy(&subs -> rdntype, &names[i].rdntype);
	    bcopy(subs -> rdnval, names[i].rdnval,
				names[i].rdnlen = subs -> rdnlen);
	    if (i+1 < n)
	        names[i].Next = &names[i+1];
	    else
	        names[i].Next = (MO_ID*) NULL;
	    subs = subs -> sibling;
	}
    }
    rdnseq = moid2dn(names);
    s = encode_IF_RDNSequence(res, 1, 0, NULLCP, rdnseq);
    if (rdnseq)
        dn_free(rdnseq);
    for(i = 0; i < n; i++)
        free((char*) names[i].rdntype.oid_elements);
    if (names)
        free(names);
    return (s == NOTOK ? 0 : 1);
}


static int  doGetError (fd, id, class, instance, error)
int fd, id;
MID class;
MN  instance;
CMISerrors error;
{
    CMISerrparam err_info;
    struct MSAPindication mis;

#ifdef DEBUG
    fprintf(stderr, "SMA-CMIS: doGetError %d\n", (int) error);
#endif
    switch (error) {
    case m_accessDenied:
	break;
    case m_noSuchObjectInstance:
	err_info.me_inst = *instance;		/* struct copy */
	break;
    case m_classInstanceConflict:
	err_info.me_class = *class;		/*  .. */
	err_info.me_inst  = *instance;		/*  .. */
	break;
    case m_processingFailure:
	err_info.me_class = *class;		/*  .. */
	err_info.me_inst  = *instance;		/*  .. */
	err_info.me_val   = NULLPE;
	break;
    default:
	fprintf(stderr, "doGetError: invalid error value %d\n", (int) error);
	return NOTOK;
    }
    return M_GetRes(fd, id, NOLINKED, NULLMID, NULLMN, NULLCP, 0, NULLMPARM,
				error, &err_info, &mis);
}


static int  doSetError (fd, conf, id, class, instance, error)
int fd, conf, id;
MID class;
MN  instance;
CMISerrors error;
{
    CMISerrparam err_info;
    struct MSAPindication mis;

#ifdef DEBUG
    fprintf(stderr, "SMA-CMIS: doSetError %d\n", (int) error);
#endif
    if (!conf)
	return OK;
    switch (error) {
    case m_accessDenied:
	break;
    case m_noSuchObjectInstance:
	err_info.me_inst = *instance;		/* struct copy */
	break;
    case m_classInstanceConflict:
	err_info.me_class = *class;		/*  .. */
	err_info.me_inst  = *instance;		/*  .. */
	break;
    case m_processingFailure:
	err_info.me_class = *class;		/*  .. */
	err_info.me_inst  = *instance;		/*  .. */
	err_info.me_val   = NULLPE;
	break;
    default:
	fprintf(stderr, "doGetError: invalid error value %d\n", (int) error);
	return NOTOK;
    }
    return M_SetRes(fd, id, NOLINKED, NULLMID, NULLMN, NULLCP, 0, NULLMPARM,
				error, &err_info, &mis);
}