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