xref: /titanic_52/usr/src/lib/libslp/clib/DAAdvert.c (revision c7158ae983f5a04c4a998f468ecefba6d23ba721)
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  * DAAdvert functionality. For all normal UA calls, libslp queries
31  * slpd for available DAs. This file contains functionality to handle
32  * DAAdverts explicitly requested by a call to SLPFindSrvs()
33  * or SLPFindAttrs() with service-type = "service:directory-agent".
34  */
35 
36 #include <stdio.h>
37 #include <slp-internal.h>
38 
39 SLPError slp_unpackDAAdvert(char *reply, char **surl, char **scopes,
40 				char **attrs, char **spis, SLPError *errCode) {
41 	unsigned short protoErrCode, dummy;
42 	size_t len, off;
43 	SLPError err = SLP_OK;
44 	/* authentication components */
45 	struct iovec iov[5];
46 	size_t tmp_off;
47 	int auth_cnt;
48 	size_t abLen = 0;
49 
50 	*surl = *scopes = *attrs = *spis = NULL;
51 
52 	len = slp_get_length(reply);
53 	off = SLP_HDRLEN + slp_get_langlen(reply);
54 	/* err code */
55 	if ((err = slp_get_sht(reply, len, &off, &protoErrCode)) != SLP_OK)
56 		goto fail;
57 	/* internal errors should have been filtered out by the net code */
58 	*errCode = slp_map_err(protoErrCode);
59 	if (*errCode != SLP_OK) {
60 		return (SLP_OK);
61 	}
62 
63 	/* skip timestamp (4 bytes) */
64 	iov[0].iov_base = reply + off;
65 	tmp_off = off;
66 	if ((err = slp_get_sht(reply, len, &off, &dummy)) != SLP_OK) {
67 		goto fail;
68 	}
69 	if ((err = slp_get_sht(reply, len, &off, &dummy)) != SLP_OK) {
70 		goto fail;
71 	}
72 	iov[0].iov_len = off - tmp_off;
73 
74 	/* service URL */
75 	iov[1].iov_base = reply + off;
76 	tmp_off = off;
77 	if ((err = slp_get_string(reply, len, &off, surl)) != SLP_OK) {
78 		goto fail;
79 	}
80 	iov[1].iov_len = off - tmp_off;
81 
82 	/* scopes */
83 	iov[3].iov_base = reply + off;
84 	tmp_off = off;
85 	if ((err = slp_get_string(reply, len, &off, scopes)) != SLP_OK) {
86 		goto fail;
87 	}
88 	iov[3].iov_len = off - tmp_off;
89 
90 	/* attributes */
91 	iov[2].iov_base = reply + off;
92 	tmp_off = off;
93 	if ((err = slp_get_string(reply, len, &off, attrs)) != SLP_OK) {
94 		goto fail;
95 	}
96 	iov[2].iov_len = off - tmp_off;
97 
98 	/* SPIs */
99 	iov[4].iov_base = reply + off;
100 	tmp_off = off;
101 	if ((err = slp_get_string(reply, len, &off, spis)) != SLP_OK) {
102 		goto fail;
103 	}
104 	iov[4].iov_len = off - tmp_off;
105 
106 	/* auth blocks */
107 	if ((err = slp_get_byte(reply, len, &off, &auth_cnt)) != SLP_OK) {
108 	    goto fail;
109 	}
110 	if (slp_get_security_on() || auth_cnt > 0) {
111 	    if ((err = slp_verify(iov, 5,
112 				    reply + off,
113 				    len - off,
114 				    auth_cnt,
115 				    &abLen)) != SLP_OK) {
116 		goto fail;
117 	    }
118 	}
119 
120 	return (SLP_OK);
121 
122 fail:
123 	if (*surl) free (*surl);
124 	if (*scopes) free (*scopes);
125 	if (*attrs) free (*attrs);
126 	if (*spis) free (*spis);
127 
128 	return (err);
129 }
130