154925bf6Swillf /*
2*dd9ccd46S  * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
354925bf6Swillf  * Use is subject to license terms.
454925bf6Swillf  */
554925bf6Swillf 
654925bf6Swillf /*
754925bf6Swillf  * kadmin/ldap_util/kdb5_ldap_services.c
854925bf6Swillf  */
954925bf6Swillf 
1054925bf6Swillf /* Copyright (c) 2004-2005, Novell, Inc.
1154925bf6Swillf  * All rights reserved.
1254925bf6Swillf  *
1354925bf6Swillf  * Redistribution and use in source and binary forms, with or without
1454925bf6Swillf  * modification, are permitted provided that the following conditions are met:
1554925bf6Swillf  *
1654925bf6Swillf  *   * Redistributions of source code must retain the above copyright notice,
1754925bf6Swillf  *       this list of conditions and the following disclaimer.
1854925bf6Swillf  *   * Redistributions in binary form must reproduce the above copyright
1954925bf6Swillf  *       notice, this list of conditions and the following disclaimer in the
2054925bf6Swillf  *       documentation and/or other materials provided with the distribution.
2154925bf6Swillf  *   * The copyright holder's name is not used to endorse or promote products
2254925bf6Swillf  *       derived from this software without specific prior written permission.
2354925bf6Swillf  *
2454925bf6Swillf  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
2554925bf6Swillf  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
2654925bf6Swillf  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
2754925bf6Swillf  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
2854925bf6Swillf  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
2954925bf6Swillf  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
3054925bf6Swillf  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
3154925bf6Swillf  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
3254925bf6Swillf  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
3354925bf6Swillf  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
3454925bf6Swillf  * POSSIBILITY OF SUCH DAMAGE.
3554925bf6Swillf  */
3654925bf6Swillf 
3754925bf6Swillf /*
3854925bf6Swillf  * Create / Delete / Modify / View / List service objects.
3954925bf6Swillf  */
4054925bf6Swillf 
4154925bf6Swillf /*
4254925bf6Swillf  * Service objects have rights over realm objects and principals. The following
4354925bf6Swillf  * functions manage the service objects.
4454925bf6Swillf  */
4554925bf6Swillf 
4654925bf6Swillf #include <stdio.h>
4754925bf6Swillf #include <k5-int.h>
4854925bf6Swillf #include <libintl.h> /* Solaris Kerberos */
4954925bf6Swillf #include <locale.h> /* Solaris Kerberos */
5054925bf6Swillf #include "kdb5_ldap_util.h"
5154925bf6Swillf #include "kdb5_ldap_list.h"
5254925bf6Swillf 
5354925bf6Swillf #ifdef HAVE_EDIRECTORY
5454925bf6Swillf 
5554925bf6Swillf krb5_error_code
5654925bf6Swillf rem_service_entry_from_file(int argc,
5754925bf6Swillf 			    char *argv[],
5854925bf6Swillf 			    char *file_name,
5954925bf6Swillf 			    char *service_object);
6054925bf6Swillf 
6154925bf6Swillf extern char *yes;
6254925bf6Swillf extern krb5_boolean db_inited;
6354925bf6Swillf 
process_host_list(char ** host_list,int servicetype)6454925bf6Swillf static int process_host_list(char **host_list, int servicetype)
6554925bf6Swillf {
6654925bf6Swillf     krb5_error_code retval = 0;
6754925bf6Swillf     char *pchr = NULL;
6854925bf6Swillf     char host_str[MAX_LEN_LIST_ENTRY] = "", proto_str[PROTOCOL_STR_LEN + 1] = "", port_str[PORT_STR_LEN + 1] = "";
6954925bf6Swillf     int j = 0;
7054925bf6Swillf 
7154925bf6Swillf     /* Protocol and port number processing */
7254925bf6Swillf     for (j = 0; host_list[j]; j++) {
7354925bf6Swillf 	/* Look for one hash */
7454925bf6Swillf 	if ((pchr = strchr(host_list[j], HOST_INFO_DELIMITER))) {
7554925bf6Swillf 	    unsigned int hostname_len = pchr - host_list[j];
7654925bf6Swillf 
7754925bf6Swillf 	    /* Check input for buffer overflow */
7854925bf6Swillf 	    if (hostname_len >= MAX_LEN_LIST_ENTRY) {
7954925bf6Swillf 		retval = EINVAL;
8054925bf6Swillf 		goto cleanup;
8154925bf6Swillf 	    }
8254925bf6Swillf 
8354925bf6Swillf 	    /* First copy off the host name portion */
8454925bf6Swillf 	    strncpy (host_str, host_list[j], hostname_len);
8554925bf6Swillf 
8654925bf6Swillf 	    /* Parse for the protocol string and translate to number */
8754925bf6Swillf 	    strncpy (proto_str, pchr + 1, PROTOCOL_STR_LEN);
8854925bf6Swillf 	    if (!strcmp(proto_str, "udp"))
8954925bf6Swillf 		sprintf (proto_str, "%d", PROTOCOL_NUM_UDP);
9054925bf6Swillf 	    else if (!strcmp(proto_str, "tcp"))
9154925bf6Swillf 		sprintf (proto_str, "%d", PROTOCOL_NUM_TCP);
92