xref: /illumos-gate/usr/src/lib/libslp/clib/DAAdvert.c (revision 1da57d55)
1*7c478bd9Sstevel@tonic-gate /*
2*7c478bd9Sstevel@tonic-gate  * CDDL HEADER START
3*7c478bd9Sstevel@tonic-gate  *
4*7c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5*7c478bd9Sstevel@tonic-gate  * Common Development and Distribution License, Version 1.0 only
6*7c478bd9Sstevel@tonic-gate  * (the "License").  You may not use this file except in compliance
7*7c478bd9Sstevel@tonic-gate  * with the License.
8*7c478bd9Sstevel@tonic-gate  *
9*7c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10*7c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
11*7c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
12*7c478bd9Sstevel@tonic-gate  * and limitations under the License.
13*7c478bd9Sstevel@tonic-gate  *
14*7c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
15*7c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16*7c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
17*7c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
18*7c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
19*7c478bd9Sstevel@tonic-gate  *
20*7c478bd9Sstevel@tonic-gate  * CDDL HEADER END
21*7c478bd9Sstevel@tonic-gate  */
22*7c478bd9Sstevel@tonic-gate /*
23*7c478bd9Sstevel@tonic-gate  * Copyright (c) 1999 by Sun Microsystems, Inc.
24*7c478bd9Sstevel@tonic-gate  * All rights reserved.
25*7c478bd9Sstevel@tonic-gate  */
26*7c478bd9Sstevel@tonic-gate 
27*7c478bd9Sstevel@tonic-gate /*
28*7c478bd9Sstevel@tonic-gate  * DAAdvert functionality. For all normal UA calls, libslp queries
29*7c478bd9Sstevel@tonic-gate  * slpd for available DAs. This file contains functionality to handle
30*7c478bd9Sstevel@tonic-gate  * DAAdverts explicitly requested by a call to SLPFindSrvs()
31*7c478bd9Sstevel@tonic-gate  * or SLPFindAttrs() with service-type = "service:directory-agent".
32*7c478bd9Sstevel@tonic-gate  */
33*7c478bd9Sstevel@tonic-gate 
34*7c478bd9Sstevel@tonic-gate #include <stdio.h>
35*7c478bd9Sstevel@tonic-gate #include <slp-internal.h>
36*7c478bd9Sstevel@tonic-gate 
slp_unpackDAAdvert(char * reply,char ** surl,char ** scopes,char ** attrs,char ** spis,SLPError * errCode)37*7c478bd9Sstevel@tonic-gate SLPError slp_unpackDAAdvert(char *reply, char **surl, char **scopes,
38*7c478bd9Sstevel@tonic-gate 				char **attrs, char **spis, SLPError *errCode) {
39*7c478bd9Sstevel@tonic-gate 	unsigned short protoErrCode, dummy;
40*7c478bd9Sstevel@tonic-gate 	size_t len, off;
41*7c478bd9Sstevel@tonic-gate 	SLPError err = SLP_OK;
42*7c478bd9Sstevel@tonic-gate 	/* authentication components */
43*7c478bd9Sstevel@tonic-gate 	struct iovec iov[5];
44*7c478bd9Sstevel@tonic-gate 	size_t tmp_off;
45*7c478bd9Sstevel@tonic-gate 	int auth_cnt;
46*7c478bd9Sstevel@tonic-gate 	size_t abLen = 0;
47*7c478bd9Sstevel@tonic-gate 
48*7c478bd9Sstevel@tonic-gate 	*surl = *scopes = *attrs = *spis = NULL;
49*7c478bd9Sstevel@tonic-gate 
50*7c478bd9Sstevel@tonic-gate 	len = slp_get_length(reply);
51*7c478bd9Sstevel@tonic-gate 	off = SLP_HDRLEN + slp_get_langlen(reply);
52*7c478bd9Sstevel@tonic-gate 	/* err code */
53*7c478bd9Sstevel@tonic-gate 	if ((err = slp_get_sht(reply, len, &off, &protoErrCode)) != SLP_OK)
54*7c478bd9Sstevel@tonic-gate 		goto fail;
55*7c478bd9Sstevel@tonic-gate 	/* internal errors should have been filtered out by the net code */
56*7c478bd9Sstevel@tonic-gate 	*errCode = slp_map_err(protoErrCode);
57*7c478bd9Sstevel@tonic-gate 	if (*errCode != SLP_OK) {
58*7c478bd9Sstevel@tonic-gate 		return (SLP_OK);
59*7c478bd9Sstevel@tonic-gate 	}
60*7c478bd9Sstevel@tonic-gate 
61*7c478bd9Sstevel@tonic-gate 	/* skip timestamp (4 bytes) */
62*7c478bd9Sstevel@tonic-gate 	iov[0].iov_base = reply + off;
63*7c478bd9Sstevel@tonic-gate 	tmp_off = off;
64*7c478bd9Sstevel@tonic-gate 	if ((err = slp_get_sht(reply, len, &off, &dummy)) != SLP_OK) {
65*7c478bd9Sstevel@tonic-gate 		goto fail;
66*7c478bd9Sstevel@tonic-gate 	}
67*7c478bd9Sstevel@tonic-gate 	if ((err = slp_get_sht(reply, len, &off, &dummy)) != SLP_OK) {
68*7c478bd9Sstevel@tonic-gate 		goto fail;
69*7c478bd9Sstevel@tonic-gate 	}
70*7c478bd9Sstevel@tonic-gate 	iov[0].iov_len = off - tmp_off;
71*7c478bd9Sstevel@tonic-gate 
72*7c478bd9Sstevel@tonic-gate 	/* service URL */
73*7c478bd9Sstevel@tonic-gate 	iov[1].iov_base = reply + off;
74*7c478bd9Sstevel@tonic-gate 	tmp_off = off;
75*7c478bd9Sstevel@tonic-gate 	if ((err = slp_get_string(reply, len, &off, surl)) != SLP_OK) {
76*7c478bd9Sstevel@tonic-gate 		goto fail;
77*7c478bd9Sstevel@tonic-gate 	}
78*7c478bd9Sstevel@tonic-gate 	iov[1].iov_len = off - tmp_off;
79*7c478bd9Sstevel@tonic-gate 
80*7c478bd9Sstevel@tonic-gate 	/* scopes */
81*7c478bd9Sstevel@tonic-gate 	iov[3].iov_base = reply + off;
82*7c478bd9Sstevel@tonic-gate 	tmp_off = off;
83*7c478bd9Sstevel@tonic-gate 	if ((err = slp_get_string(reply, len, &off, scopes)) != SLP_OK) {
84*7c478bd9Sstevel@tonic-gate 		goto fail;
85*7c478bd9Sstevel@tonic-gate 	}
86*7c478bd9Sstevel@tonic-gate 	iov[3].iov_len = off - tmp_off;
87*7c478bd9Sstevel@tonic-gate 
88*7c478bd9Sstevel@tonic-gate 	/* attributes */
89*7c478bd9Sstevel@tonic-gate 	iov[2].iov_base = reply + off;
90*7c478bd9Sstevel@tonic-gate 	tmp_off = off;
91*7c478bd9Sstevel@tonic-gate 	if ((err = slp_get_string(reply, len, &off, attrs)) != SLP_OK) {
92*7c478bd9Sstevel@tonic-gate 		goto fail;
93*7c478bd9Sstevel@tonic-gate 	}
94*7c478bd9Sstevel@tonic-gate 	iov[2].iov_len = off - tmp_off;
95*7c478bd9Sstevel@tonic-gate 
96*7c478bd9Sstevel@tonic-gate 	/* SPIs */
97*7c478bd9Sstevel@tonic-gate 	iov[4].iov_base = reply + off;
98*7c478bd9Sstevel@tonic-gate 	tmp_off = off;
99*7c478bd9Sstevel@tonic-gate 	if ((err = slp_get_string(reply, len, &off, spis)) != SLP_OK) {
100*7c478bd9Sstevel@tonic-gate 		goto fail;
101*7c478bd9Sstevel@tonic-gate 	}
102*7c478bd9Sstevel@tonic-gate 	iov[4].iov_len = off - tmp_off;
103*7c478bd9Sstevel@tonic-gate 
104*7c478bd9Sstevel@tonic-gate 	/* auth blocks */
105*7c478bd9Sstevel@tonic-gate 	if ((err = slp_get_byte(reply, len, &off, &auth_cnt)) != SLP_OK) {
106*7c478bd9Sstevel@tonic-gate 	    goto fail;
107*7c478bd9Sstevel@tonic-gate 	}
108*7c478bd9Sstevel@tonic-gate 	if (slp_get_security_on() || auth_cnt > 0) {
109*7c478bd9Sstevel@tonic-gate 	    if ((err = slp_verify(iov, 5,
110*7c478bd9Sstevel@tonic-gate 				    reply + off,
111*7c478bd9Sstevel@tonic-gate 				    len - off,
112*7c478bd9Sstevel@tonic-gate 				    auth_cnt,
113*7c478bd9Sstevel@tonic-gate 				    &abLen)) != SLP_OK) {
114*7c478bd9Sstevel@tonic-gate 		goto fail;
115*7c478bd9Sstevel@tonic-gate 	    }
116*7c478bd9Sstevel@tonic-gate 	}
117*7c478bd9Sstevel@tonic-gate 
118*7c478bd9Sstevel@tonic-gate 	return (SLP_OK);
119*7c478bd9Sstevel@tonic-gate 
120*7c478bd9Sstevel@tonic-gate fail:
121*7c478bd9Sstevel@tonic-gate 	if (*surl) free (*surl);
122*7c478bd9Sstevel@tonic-gate 	if (*scopes) free (*scopes);
123*7c478bd9Sstevel@tonic-gate 	if (*attrs) free (*attrs);
124*7c478bd9Sstevel@tonic-gate 	if (*spis) free (*spis);
125*7c478bd9Sstevel@tonic-gate 
126*7c478bd9Sstevel@tonic-gate 	return (err);
127*7c478bd9Sstevel@tonic-gate }
128