1 /*
2 * CDDL HEADER START
3 *
4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License, Version 1.0 only
6 * (the "License"). You may not use this file except in compliance
7 * with the License.
8 *
9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 * or http://www.opensolaris.org/os/licensing.
11 * See the License for the specific language governing permissions
12 * and limitations under the License.
13 *
14 * When distributing Covered Code, include this CDDL HEADER in each
15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16 * If applicable, add the following below this CDDL HEADER, with the
17 * fields enclosed by brackets "[]" replaced with your own identifying
18 * information: Portions Copyright [yyyy] [name of copyright owner]
19 *
20 * CDDL HEADER END
21 */
22 /*
23 * Copyright (c) 1999 by Sun Microsystems, Inc.
24 * All rights reserved.
25 */
26
27 /*
28 * SAAdverts are used internally by libslp to discover scopes in the
29 * absence of configured scopes and scopes found by active and
30 * passive DA discovery. They can also be solicited by SLPFindSrv()
31 * and SLPFindAttr calls with the "service:service-agent" type.
32 * slp_unpackSAAdvert() unpacks a SAAdvert and returns SA info.
33 */
34
35 #include <stdio.h>
36 #include <slp-internal.h>
37
slp_unpackSAAdvert(char * reply,char ** surl,char ** scopes,char ** attrs)38 SLPError slp_unpackSAAdvert(char *reply, char **surl,
39 char **scopes, char **attrs) {
40 SLPError err = SLP_OK;
41 size_t off, len;
42 /* authentication components */
43 struct iovec iov[3];
44 size_t tmp_off;
45 int auth_cnt;
46 size_t abLen = 0;
47
48 *surl = *scopes = *attrs = NULL;
49
50 len = slp_get_length(reply);
51 off = SLP_HDRLEN + slp_get_langlen(reply);
52
53 /* service URL */
54 iov[0].iov_base = reply + off;
55 tmp_off = off;
56 if ((err = slp_get_string(reply, len, &off, surl)) != SLP_OK) {
57 goto fail;
58 }
59 iov[0].iov_len = off - tmp_off;
60
61 /* scope list */
62 iov[2].iov_base = reply + off;
63 tmp_off = off;
64 if ((err = slp_get_string(reply, len, &off, scopes)) != SLP_OK) {
65 goto fail;
66 }
67 iov[2].iov_len = off - tmp_off;
68
69 /* attributes */
70 iov[1].iov_base = reply + off;
71 tmp_off = off;
72 if ((err = slp_get_string(reply, len, &off, attrs)) != SLP_OK) {
73 goto fail;
74 }
75 iov[1].iov_len = off - tmp_off;
76
77 /* auth blocks */
78 if ((err = slp_get_byte(reply, len, &off, &auth_cnt)) != SLP_OK) {
79 goto fail;
80 }
81 if (slp_get_security_on() || auth_cnt > 0) {
82 if ((err = slp_verify(iov, 3,
83 reply + off,
84 len - off,
85 auth_cnt,
86 &abLen)) != SLP_OK) {
87 goto fail;
88 }
89 }
90
91 return (SLP_OK);
92
93 fail:
94 if (*surl) free(*surl);
95 if (*scopes) free(*scopes);
96 if (*attrs) free(*attrs);
97
98 return (err);
99 }
100