2N/A/*
2N/A * CDDL HEADER START
2N/A *
2N/A * The contents of this file are subject to the terms of the
2N/A * Common Development and Distribution License, Version 1.0 only
2N/A * (the "License"). You may not use this file except in compliance
2N/A * with the License.
2N/A *
2N/A * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
2N/A * or http://www.opensolaris.org/os/licensing.
2N/A * See the License for the specific language governing permissions
2N/A * and limitations under the License.
2N/A *
2N/A * When distributing Covered Code, include this CDDL HEADER in each
2N/A * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
2N/A * If applicable, add the following below this CDDL HEADER, with the
2N/A * fields enclosed by brackets "[]" replaced with your own identifying
2N/A * information: Portions Copyright [yyyy] [name of copyright owner]
2N/A *
2N/A * CDDL HEADER END
2N/A */
2N/A/*
2N/A * Copyright (c) 1999 by Sun Microsystems, Inc.
2N/A * All rights reserved.
2N/A */
2N/A
2N/A#pragma ident "%Z%%M% %I% %E% SMI"
2N/A
2N/A/*
2N/A * SAAdverts are used internally by libslp to discover scopes in the
2N/A * absence of configured scopes and scopes found by active and
2N/A * passive DA discovery. They can also be solicited by SLPFindSrv()
2N/A * and SLPFindAttr calls with the "service:service-agent" type.
2N/A * slp_unpackSAAdvert() unpacks a SAAdvert and returns SA info.
2N/A */
2N/A
2N/A#include <stdio.h>
2N/A#include <slp-internal.h>
2N/A
2N/ASLPError slp_unpackSAAdvert(char *reply, char **surl,
2N/A char **scopes, char **attrs) {
2N/A SLPError err = SLP_OK;
2N/A size_t off, len;
2N/A /* authentication components */
2N/A struct iovec iov[3];
2N/A size_t tmp_off;
2N/A int auth_cnt;
2N/A size_t abLen = 0;
2N/A
2N/A *surl = *scopes = *attrs = NULL;
2N/A
2N/A len = slp_get_length(reply);
2N/A off = SLP_HDRLEN + slp_get_langlen(reply);
2N/A
2N/A /* service URL */
2N/A iov[0].iov_base = reply + off;
2N/A tmp_off = off;
2N/A if ((err = slp_get_string(reply, len, &off, surl)) != SLP_OK) {
2N/A goto fail;
2N/A }
2N/A iov[0].iov_len = off - tmp_off;
2N/A
2N/A /* scope list */
2N/A iov[2].iov_base = reply + off;
2N/A tmp_off = off;
2N/A if ((err = slp_get_string(reply, len, &off, scopes)) != SLP_OK) {
2N/A goto fail;
2N/A }
2N/A iov[2].iov_len = off - tmp_off;
2N/A
2N/A /* attributes */
2N/A iov[1].iov_base = reply + off;
2N/A tmp_off = off;
2N/A if ((err = slp_get_string(reply, len, &off, attrs)) != SLP_OK) {
2N/A goto fail;
2N/A }
2N/A iov[1].iov_len = off - tmp_off;
2N/A
2N/A /* auth blocks */
2N/A if ((err = slp_get_byte(reply, len, &off, &auth_cnt)) != SLP_OK) {
2N/A goto fail;
2N/A }
2N/A if (slp_get_security_on() || auth_cnt > 0) {
2N/A if ((err = slp_verify(iov, 3,
2N/A reply + off,
2N/A len - off,
2N/A auth_cnt,
2N/A &abLen)) != SLP_OK) {
2N/A goto fail;
2N/A }
2N/A }
2N/A
2N/A return (SLP_OK);
2N/A
2N/Afail:
2N/A if (*surl) free(*surl);
2N/A if (*scopes) free(*scopes);
2N/A if (*attrs) free(*attrs);
2N/A
2N/A return (err);
2N/A}