Ejemplo n.º 1
0
/*
 * Create an LDAP server container entry.
 */
static void rpc_ns__ldap_export_server(LDAP *ld,
	char *dn,
	rpc_if_handle_t if_spec,
	unsigned32 *status
	)
{
	unsigned_char_p_t uuid = NULL;
	rpc_if_id_t if_id;
	LDAPMod *modV[4];
	LDAPMod modRpcNsObjectID, modObjectClass;
	char *valueRpcNsObjectID[2], *valueObjectClass[3];

	rpc_if_inq_id(if_spec, &if_id, status);
	if (*status != rpc_s_ok) {
		return;
	}

	uuid_to_string(&if_id.uuid, &uuid, status);
	if (*status != rpc_s_ok) {
		return;
	}

	valueRpcNsObjectID[0] = uuid;
	valueRpcNsObjectID[1] = NULL;

	modRpcNsObjectID.mod_op = LDAP_MOD_ADD;
	modRpcNsObjectID.mod_type = "rpcNsObjectID";
	modRpcNsObjectID.mod_values = valueRpcNsObjectID;

	valueObjectClass[0] = "rpcServer";
	valueObjectClass[1] = "rpcEntry";
	valueObjectClass[2] = "top";

	modObjectClass.mod_op = LDAP_MOD_ADD;
	modObjectClass.mod_type = "objectClass";
	modObjectClass.mod_values = valueObjectClass;

	modV[0] = &modRpcNsObjectID;
	modV[1] = &modObjectClass;
	modV[2] = NULL;

	if (ldap_add_s(ld, dn, modV) != LDAP_SUCCESS) {
		*status = rpc_s_update_failed;
	} else {
		*status = rpc_s_ok;
	}

	rpc_string_free(&uuid, status);
}
Ejemplo n.º 2
0
static void rpc_ns__ldap_import_server_element(LDAP *ld,
	unsigned_char_p_t serverDN,
	rpc_if_handle_t if_spec,
	rpc_ns_handle_t *ctx,
	unsigned32 *status
	)
{
	unsigned_char_p_t filter = NULL;
	unsigned_char_p_t uuid = NULL;
	rpc_if_id_t if_id;
	LDAPMessage *msg = NULL, *e;
	rpc_ns_handle_rep_t *rep;
	unsigned_char_p_t *bindings;
	size_t len;

	rpc_if_inq_id(if_spec, &if_id, status);
	if (*status != rpc_s_ok) {
		goto out;
	}

	/* Get the interface ID */
	uuid_to_string(&if_id.uuid, &uuid, status);
	if (*status != rpc_s_ok) {
		goto out;
	}

	len = strlen(uuid);
	len += sizeof("(&(objectClass=rpcServerElement)(rpcNsInterfaceID=,65535.65535))");
	RPC_MEM_ALLOC(filter, unsigned_char_p_t, len,
		RPC_C_MEM_NSRESOLUTION, RPC_C_MEM_WAITOK);

	sprintf(filter, "(&(objectClass=rpcServerElement)(rpcNsInterfaceID=%s,%hu.%hu))",
		uuid, if_id.vers_major, if_id.vers_minor);

	if (ldap_search_s(ld, serverDN, LDAP_SCOPE_ONELEVEL,
		filter, NULL, 0, &msg) != LDAP_SUCCESS) {
		*status = rpc_s_not_found;
		goto out;
	}

	e = ldap_first_entry(ld, msg);
	if (e == NULL) {
		*status = rpc_s_not_found;
		goto out;
	}

	bindings = (unsigned_char_p_t *)ldap_get_values(ld, e, "rpcNsBindings");
	if (bindings == NULL) {
		*status = rpc_s_not_found;
		goto out;
	}

	RPC_MEM_ALLOC(rep, rpc_ns_handle_rep_p_t,
		sizeof(*rep),
		RPC_C_MEM_NSRESOLUTION, RPC_C_MEM_WAITOK);

	rep->count = ldap_count_values((char **)bindings);
	rep->bindings = bindings;
	rep->cursor = 0;

	*ctx = (rpc_ns_handle_t)rep;
	*status = rpc_s_ok;

out:
	if (filter != NULL) {
		RPC_MEM_FREE(filter, RPC_C_MEM_NSRESOLUTION);
	}

	if (msg != NULL) {
		ldap_msgfree(msg);
	}
}
Ejemplo n.º 3
0
static void rpc_ns__ldap_lookup_server_element(LDAP *ld,
	unsigned_char_p_t serverDN,
	rpc_if_handle_t if_spec,
	unsigned_char_p_t *dn,
	unsigned32 *status)
{
	unsigned_char_p_t filter = NULL;
	unsigned_char_p_t uuid = NULL;
	rpc_if_id_t if_id;
	LDAPMessage *msg = NULL, *e;
	char *_dn;
	size_t len;

	rpc_if_inq_id(if_spec, &if_id, status);
	if (*status != rpc_s_ok) {
		goto out;
	}

	/* Get the interface ID */
	uuid_to_string(&if_id.uuid, &uuid, status);
	if (*status != rpc_s_ok) {
		goto out;
	}

	len = strlen(uuid);
	len += sizeof("(&(objectClass=rpcServerElement)(rpcNsInterfaceID=,65535.65535))");

	RPC_MEM_ALLOC(filter, unsigned_char_p_t, len,
		RPC_C_MEM_NSRESOLUTION, RPC_C_MEM_WAITOK);

	sprintf(filter, "(&(objectClass=rpcServerElement)(rpcNsInterfaceID=%s,%hu.%hu))",
		uuid, if_id.vers_major, if_id.vers_minor);

	if (ldap_search_s(ld, serverDN, LDAP_SCOPE_ONELEVEL,
		filter, NULL, 0, &msg) != LDAP_SUCCESS) {
		*status = rpc_s_not_found;
		goto out;
	}

	e = ldap_first_entry(ld, msg);
	if (e == NULL) {
		*status = rpc_s_not_found;
		goto out;
	}

	_dn = ldap_get_dn(ld, e);
	if (dn == NULL) {
		*status = rpc_s_not_found;
		goto out;
	}

	*dn = rpc_stralloc(_dn);
	ldap_memfree(_dn);

out:
	if (filter != NULL) {
		RPC_MEM_FREE(filter, RPC_C_MEM_NSRESOLUTION);
	}

	if (msg != NULL) {
		ldap_msgfree(msg);
	}

	if (uuid != NULL) {
		rpc_string_free(&uuid, status);
	}
}
Ejemplo n.º 4
0
/*
 * Create or update an LDAP server binding entry.
 */
static void rpc_ns__ldap_export_server_element_ext(LDAP *ld,
	char *dn,
	rpc_if_handle_t if_spec,
	rpc_binding_vector_p_t vec,
	int modop,
	unsigned32 *status
	)
{
	unsigned_char_p_t uuid = NULL;
	unsigned_char_p_t interfaceID = NULL;
	rpc_if_id_t if_id;
	LDAPMod *modV[4];
	LDAPMod modRpcNsInterfaceID, modRpcNsBindings, modObjectClass;
	char **valueRpcNsBindings = NULL;
	char *valueRpcNsInterfaceID[2], *valueObjectClass[3];
	int rc;
	unsigned i;

	rpc_if_inq_id(if_spec, &if_id, status);
	if (*status != rpc_s_ok) {
		goto out;
	}

	/* Get the interface ID */
	uuid_to_string(&if_id.uuid, &uuid, status);
	if (*status != rpc_s_ok) {
		goto out;
	}

	RPC_MEM_ALLOC(interfaceID, unsigned_char_p_t,
		strlen(uuid) + sizeof(",65535.65535"),
		RPC_C_MEM_NSRESOLUTION, RPC_C_MEM_WAITOK);

	sprintf(interfaceID, "%s,%hu.%hu", uuid,
		if_id.vers_major, if_id.vers_minor);

	valueRpcNsInterfaceID[0] = interfaceID;
	valueRpcNsInterfaceID[1] = NULL;

	modRpcNsInterfaceID.mod_op = LDAP_MOD_ADD;
	modRpcNsInterfaceID.mod_type = "rpcNsInterfaceID";
	modRpcNsInterfaceID.mod_values = valueRpcNsInterfaceID;

	RPC_MEM_ALLOC(valueRpcNsBindings, char **,
		(vec->count * sizeof(char *)),
		RPC_C_MEM_NSRESOLUTION, RPC_C_MEM_WAITOK);
	memset(valueRpcNsBindings, 0, (vec->count * sizeof(unsigned_char_p_t)));

	for (i = 0; i < vec->count; i++) {
		rpc_binding_to_string_binding(vec->binding_h[i],
			(unsigned_char_p_t *)&valueRpcNsBindings[i], status);
		if (*status != rpc_s_ok) {
			goto out;
		}
	}
	valueRpcNsBindings[vec->count] = NULL;

	modRpcNsBindings.mod_op = modop;
	modRpcNsBindings.mod_type = "rpcNsBindings";
	modRpcNsBindings.mod_values = valueRpcNsBindings;

	valueObjectClass[0] = "rpcServerElement";
	valueObjectClass[1] = "rpcEntry";
	valueObjectClass[2] = "top";

	modObjectClass.mod_op = modop;
	modObjectClass.mod_type = "objectClass";
	modObjectClass.mod_values = valueObjectClass;

	modV[0] = &modRpcNsInterfaceID;
	modV[1] = &modRpcNsBindings;
	modV[2] = &modObjectClass;
	modV[3] = NULL;

	if (modop == LDAP_MOD_ADD) {
		rc = ldap_add_s(ld, dn, modV);
	} else {
		rc = ldap_modify_s(ld, dn, modV);
	}
	*status = (rc == LDAP_SUCCESS) ? rpc_s_ok : rpc_s_update_failed;

out:
	if (uuid != NULL)
		free(uuid);
	if (interfaceID != NULL)
		free(interfaceID);
	if (valueRpcNsBindings != NULL) {
		char **p;

		for (p = valueRpcNsBindings; *valueRpcNsBindings != NULL; p++) {
			unsigned_char_p_t tmp = (unsigned_char_p_t)*p;

			rpc_string_free(&tmp, status);
		}
		RPC_MEM_FREE(valueRpcNsBindings, RPC_C_MEM_NSRESOLUTION);
	}
}
Ejemplo n.º 5
0
PRIVATE boolean rpc__tower_ref_is_compatible 
(
    rpc_if_rep_p_t          if_spec,
    rpc_tower_ref_p_t       tower_ref,
    unsigned32              *status
)
{
    boolean                 match;
    unsigned32              if_spec_syntax_count,
                            tower_vers_major,
                            tower_vers_minor,
                            version_major,
                            version_minor;
    rpc_if_id_t             if_id,
                            tower_if_id;
    rpc_syntax_id_t         *if_syntax_id,
                            tower_syntax_id;
    rpc_protseq_id_t        tower_protseq_id;
    rpc_protocol_id_t       tower_prot_id;
    unsigned8               temp_id;


    CODING_ERROR (status);


    /*
     * Obtain the protocol sequence from this tower.
     */
    rpc__tower_ref_inq_protseq_id (tower_ref, &tower_protseq_id, status);
    if (*status != rpc_s_ok)
    {
        *status = rpc_s_ok;	/* ignore towers we don't understand */
        return (false);
    }

    /*
     * Ensure the protocol sequence from the tower 
     * is supported by this client.  
     */
    if (!(RPC_PROTSEQ_INQ_SUPPORTED (tower_protseq_id)))
    {
        /*
         * Invalid protocol sequence, return status from call.
         */
        return (false);
    }

    /*
     * We have a valid protocol sequence.
     * Check the interface for compatibility if one is specified.
     */
    if (if_spec != NULL)
    {

        /*
         * Get the interface identifier.
         */
        rpc_if_inq_id ((rpc_if_handle_t) if_spec, &if_id, status);
        if (*status != rpc_s_ok)
        {
            return (false);
        }
        
        /*
         * Get the interface identifier from the tower
         */
        rpc__tower_flr_to_if_id (tower_ref->floor[0], &tower_if_id, status);
        if (*status != rpc_s_ok)
        {
            return (false);
        }

        /*
         * Compare the client's interface identifier to the
         * tower's interface id.  (Checks both the uuid and version.)
         */
        if (!(rpc__if_id_compare 
            (&if_id, &tower_if_id, rpc_c_vers_compatible, status)))
        {
            return (false);
        }

        /* 
         * See if any of the if_spec transfer syntaxes matches 
         * the tower transfer syntaxes. 
         *
         * Note an interface transfer syntax count of 0 is an internal error.
         */
         
         /*
          * Obtain the tower transfer syntax.
          */
        rpc__tower_flr_to_drep (tower_ref->floor[1], &tower_syntax_id, status);
        if (*status != rpc_s_ok)
        {
            return (false);
        }

        for (if_spec_syntax_count = 0, 
             match = false,
             if_syntax_id = if_spec->syntax_vector.syntax_id;
             ((match == false) && 
              (if_spec_syntax_count < if_spec->syntax_vector.count ));
             if_spec_syntax_count++,
             if_syntax_id++ )
        {
            /*
             * Check if a syntax id and version match.
             */
            match = dce_uuid_equal
                    (&(tower_syntax_id.id), &(if_syntax_id->id), status);

            if ((match == true) &&
                (tower_syntax_id.version != if_syntax_id->version))
            {
                match = false;
            }
        }

        /* 
         * if no match occurred, binding is not compatible - return false
         */
        if (match == false) 
        {
            *status = rpc_s_ok;
            return (false);
        }
    }

    /*
     * Obtain the RPC protocol id and version numbers of the tower.
     */
    rpc__tower_flr_to_rpc_prot_id (tower_ref->floor[2], &tower_prot_id,
        &tower_vers_major, &tower_vers_minor, status);
    if (*status != rpc_s_ok)
    {
        return (false);
    }

    /*
     * Obtain the clients' version numbers for the protocol sequence
     * specified in the tower.
     */
    rpc__network_inq_prot_version (
        tower_protseq_id, &temp_id, &version_major, 
        &version_minor, status);
    if (*status != rpc_s_ok)
    {
        return (false);
    }

    /*
     * Compare protocol versions, they are only 1 byte each.
     */
    if ((unsigned8) version_major != (unsigned8) tower_vers_major)
       /*
        * We don't do this so we can rev the minor protocol version.
        *  || ((unsigned8) version_minor >  (unsigned8) tower_vers_minor)
        */
    {
        return (false);
    }

    /*
     * Tower is compatible with the client's.
     */
    return (true);
}
Ejemplo n.º 6
0
PRIVATE void rpc__tower_ref_vec_from_binding 
(
    rpc_if_rep_p_t              if_spec,
    rpc_binding_handle_t        binding,
    rpc_tower_ref_vector_p_t    *tower_vector,
    unsigned32                  *status
)
{
    unsigned16              lower_flr_count;
    unsigned32              i,
                            temp_status;
    twr_p_t                 lower_floors;
    rpc_tower_ref_p_t       tower_copy;
    rpc_tower_floor_p_t     tower_floor;
    rpc_if_id_t             if_id;
    rpc_binding_rep_p_t     binding_rep;
    rpc_syntax_id_t         *if_syntax_id;


    CODING_ERROR (status);

    /*
     * Create the tower vector.
     */
    RPC_MEM_ALLOC ( 
        *tower_vector,
        rpc_tower_ref_vector_p_t,
        sizeof (rpc_tower_ref_vector_t) + 
        ((if_spec->syntax_vector.count -1) * (sizeof (rpc_tower_ref_p_t))) ,
        RPC_C_MEM_TOWER_REF_VECTOR,
        RPC_C_MEM_WAITOK );

    /*
     * Initialize tower count.
     */
    (*tower_vector)->count = 0;

    /*
     * Create the tower for the first transfer syntax 
     * in the interface specification.
     */

    /*
     * Obtain the rpc address of this binding.
     */
    binding_rep = (rpc_binding_rep_p_t) binding;

    /*
     * Create the lower tower floors.
     */
    rpc__naf_tower_flrs_from_addr (
        binding_rep->rpc_addr, &lower_floors, status);
    if (*status != rpc_s_ok)
    {
        RPC_MEM_FREE (*tower_vector, RPC_C_MEM_TOWER_REF_VECTOR);
        return;
    }

    /*
     * Initialize the tower vector with the pointer
     * to the lower floors.
     */
    (*tower_vector)->lower_flrs = lower_floors;

    /*
     * Get the number of lower tower floors returned and
     * convert to host's representation.
     */
    memcpy ((char *)&lower_flr_count, 
            (char *)lower_floors->tower_octet_string,
            RPC_C_TOWER_FLR_COUNT_SIZE);

    RPC_RESOLVE_ENDIAN_INT16 (lower_flr_count);

    /*
     * Allocate the tower reference structure to the first tower.
     * The number of floors is equal to the number of RPC (upper) floors
     * plus the number of network (lower) floors.
     */
    rpc__tower_ref_alloc (lower_floors->tower_octet_string, 
        RPC_C_NUM_RPC_FLOORS + lower_flr_count, 
        RPC_C_NUM_RPC_FLOORS+1, &((*tower_vector)->tower[0]), status);

    if (*status != rpc_s_ok)
    {
        goto CLEANUP;
    }

    /*
     * Get the interface identifier and create tower floor 1.
     */
    rpc_if_inq_id ((rpc_if_handle_t) if_spec, &if_id, status);
    if (*status != rpc_s_ok)
    {
        goto CLEANUP;
    }

    rpc__tower_flr_from_if_id (&if_id, &tower_floor, status);
    if (*status != rpc_s_ok)
    {
        goto CLEANUP;
    }

    /*
     * Add floor 1 to the tower.
     */
    rpc__tower_ref_add_floor (1, tower_floor, (*tower_vector)->tower[0], status);
    if (*status != rpc_s_ok)
    {
        goto CLEANUP;
    }

    /*
     * Create tower floor 2 from the transfer syntax from the ifspec.
     */
    if_syntax_id = if_spec->syntax_vector.syntax_id;
    rpc__tower_flr_from_drep (if_syntax_id, &tower_floor, status);
    if (*status != rpc_s_ok)
    {
        goto CLEANUP;
    }

    /*
     * Add floor 2 to the tower.
     */
    rpc__tower_ref_add_floor (2, tower_floor, (*tower_vector)->tower[0], status);
    if (*status != rpc_s_ok)
    {
        goto CLEANUP;
    }

    /*
     * Create tower floor 3 from the RPC protocol id.
     */
    rpc__tower_flr_from_rpc_prot_id (binding_rep->rpc_addr->rpc_protseq_id, 
        binding_rep->protocol_version, &tower_floor, status);
    if (*status != rpc_s_ok)
    {
        goto CLEANUP;
    }

    /*
     * Add floor 3 to the tower.
     */
    rpc__tower_ref_add_floor (3, tower_floor, (*tower_vector)->tower[0], status);
    if (*status != rpc_s_ok)
    {
        goto CLEANUP;
    }

    /*
     * Increment the number of towers in the vector.
     */
    (*tower_vector)->count++;

    /*
     * Create the towers for the remaining transfer syntaxes
     * in the interface specification.
     */
    if_syntax_id++;
    for (i=1; i < if_spec->syntax_vector.count; 
         i++, if_syntax_id++, (*tower_vector)->count++)
    {
        /*
         * Copy the initial tower created.
         */
        rpc__tower_ref_copy ((*tower_vector)->tower[0], &tower_copy, status);
        if (*status != rpc_s_ok)
        {
            goto CLEANUP;
        }

        /*
         * Create floor 2 for this tower from the next transfer syntax.
         */
        rpc__tower_flr_from_drep (if_syntax_id, &tower_floor, status);
        if (*status != rpc_s_ok)
        {
            goto CLEANUP;
        }

        /*
         * Add floor 2 to the tower.
         */
        rpc__tower_ref_add_floor (2, tower_floor, tower_copy, status);
        if (*status != rpc_s_ok)
        {
            goto CLEANUP;
        }

        (*tower_vector)->tower[i] = tower_copy;
        

    }
        
CLEANUP:
    /*
     * If status is anything other than successful,
     * free the tower vector.
     */
    if (*status != rpc_s_ok)
    {
        rpc__tower_ref_vec_free (tower_vector, &temp_status);
    }

    return;

}