xref: /titanic_41/usr/src/lib/libslp/clib/SAAdvert.c (revision 0a47c91c895e274dd0990009919e30e984364a8b)
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 #pragma ident	"%Z%%M%	%I%	%E% SMI"
28 
29 /*
30  * SAAdverts are used internally by libslp to discover scopes in the
31  * absence of configured scopes and scopes found by active and
32  * passive DA discovery. They can also be solicited by SLPFindSrv()
33  * and SLPFindAttr calls with the "service:service-agent" type.
34  * slp_unpackSAAdvert() unpacks a SAAdvert and returns SA info.
35  */
36 
37 #include <stdio.h>
38 #include <slp-internal.h>
39 
40 SLPError slp_unpackSAAdvert(char *reply, char **surl,
41 				char **scopes, char **attrs) {
42 	SLPError err = SLP_OK;
43 	size_t off, len;
44 	/* authentication components */
45 	struct iovec iov[3];
46 	size_t tmp_off;
47 	int auth_cnt;
48 	size_t abLen = 0;
49 
50 	*surl = *scopes = *attrs = NULL;
51 
52 	len = slp_get_length(reply);
53 	off = SLP_HDRLEN + slp_get_langlen(reply);
54 
55 	/* service URL */
56 	iov[0].iov_base = reply + off;
57 	tmp_off = off;
58 	if ((err = slp_get_string(reply, len, &off, surl)) != SLP_OK) {
59 	    goto fail;
60 	}
61 	iov[0].iov_len = off - tmp_off;
62 
63 	/* scope list */
64 	iov[2].iov_base = reply + off;
65 	tmp_off = off;
66 	if ((err = slp_get_string(reply, len, &off, scopes)) != SLP_OK) {
67 	    goto fail;
68 	}
69 	iov[2].iov_len = off - tmp_off;
70 
71 	/* attributes */
72 	iov[1].iov_base = reply + off;
73 	tmp_off = off;
74 	if ((err = slp_get_string(reply, len, &off, attrs)) != SLP_OK) {
75 	    goto fail;
76 	}
77 	iov[1].iov_len = off - tmp_off;
78 
79 	/* auth blocks */
80 	if ((err = slp_get_byte(reply, len, &off, &auth_cnt)) != SLP_OK) {
81 	    goto fail;
82 	}
83 	if (slp_get_security_on() || auth_cnt > 0) {
84 	    if ((err = slp_verify(iov, 3,
85 				    reply + off,
86 				    len - off,
87 				    auth_cnt,
88 				    &abLen)) != SLP_OK) {
89 		goto fail;
90 	    }
91 	}
92 
93 	return (SLP_OK);
94 
95 fail:
96 	if (*surl) free(*surl);
97 	if (*scopes) free(*scopes);
98 	if (*attrs) free(*attrs);
99 
100 	return (err);
101 }
102