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