16ba597c5SAnurag S. Maskey /*
26ba597c5SAnurag S. Maskey  * CDDL HEADER START
36ba597c5SAnurag S. Maskey  *
46ba597c5SAnurag S. Maskey  * The contents of this file are subject to the terms of the
56ba597c5SAnurag S. Maskey  * Common Development and Distribution License (the "License").
66ba597c5SAnurag S. Maskey  * You may not use this file except in compliance with the License.
76ba597c5SAnurag S. Maskey  *
86ba597c5SAnurag S. Maskey  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
96ba597c5SAnurag S. Maskey  * or http://www.opensolaris.org/os/licensing.
106ba597c5SAnurag S. Maskey  * See the License for the specific language governing permissions
116ba597c5SAnurag S. Maskey  * and limitations under the License.
126ba597c5SAnurag S. Maskey  *
136ba597c5SAnurag S. Maskey  * When distributing Covered Code, include this CDDL HEADER in each
146ba597c5SAnurag S. Maskey  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
156ba597c5SAnurag S. Maskey  * If applicable, add the following below this CDDL HEADER, with the
166ba597c5SAnurag S. Maskey  * fields enclosed by brackets "[]" replaced with your own identifying
176ba597c5SAnurag S. Maskey  * information: Portions Copyright [yyyy] [name of copyright owner]
186ba597c5SAnurag S. Maskey  *
196ba597c5SAnurag S. Maskey  * CDDL HEADER END
206ba597c5SAnurag S. Maskey  */
216ba597c5SAnurag S. Maskey 
226ba597c5SAnurag S. Maskey /*
23ea408ca7SAnurag S. Maskey  * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
246ba597c5SAnurag S. Maskey  */
256ba597c5SAnurag S. Maskey 
266ba597c5SAnurag S. Maskey #include <assert.h>
276ba597c5SAnurag S. Maskey #include <ctype.h>
286ba597c5SAnurag S. Maskey #include <sys/param.h>
296ba597c5SAnurag S. Maskey #include <sys/types.h>
306ba597c5SAnurag S. Maskey #include <sys/stat.h>
316ba597c5SAnurag S. Maskey #include <stdio.h>
326ba597c5SAnurag S. Maskey #include <stdlib.h>
336ba597c5SAnurag S. Maskey #include <strings.h>
346ba597c5SAnurag S. Maskey #include <unistd.h>
356ba597c5SAnurag S. Maskey #include <libscf.h>
366ba597c5SAnurag S. Maskey 
376ba597c5SAnurag S. Maskey #include "libnwam_impl.h"
386ba597c5SAnurag S. Maskey #include <libnwam_priv.h>
396ba597c5SAnurag S. Maskey #include <libnwam.h>
406ba597c5SAnurag S. Maskey 
416ba597c5SAnurag S. Maskey /*
426ba597c5SAnurag S. Maskey  * Functions to support creating, modifying, destroying, querying the
436ba597c5SAnurag S. Maskey  * state of and changing the state of location objects. Locations
446ba597c5SAnurag S. Maskey  * represent the configuration to be applied once basic network configuration
456ba597c5SAnurag S. Maskey  * has been established - name services, IPsec config, etc, and can be enabled
466ba597c5SAnurag S. Maskey  * either manually or conditionally for a combination of the set of
476ba597c5SAnurag S. Maskey  * available conditions (an IP address is present, an ENM is active etc).
486ba597c5SAnurag S. Maskey  */
496ba597c5SAnurag S. Maskey 
506ba597c5SAnurag S. Maskey #define	NSSWITCH_PREFIX		"/etc/nsswitch."
516ba597c5SAnurag S. Maskey 
526ba597c5SAnurag S. Maskey typedef nwam_error_t (*nwam_loc_prop_validate_func_t)(nwam_value_t);
536ba597c5SAnurag S. Maskey 
546ba597c5SAnurag S. Maskey static nwam_error_t valid_loc_activation_mode(nwam_value_t);
556ba597c5SAnurag S. Maskey static nwam_error_t valid_loc_condition(nwam_value_t);
566ba597c5SAnurag S. Maskey static nwam_error_t valid_nameservices(nwam_value_t);
576ba597c5SAnurag S. Maskey static nwam_error_t valid_configsrc(nwam_value_t);
586ba597c5SAnurag S. Maskey 
596ba597c5SAnurag S. Maskey struct nwam_prop_table_entry loc_prop_table_entries[] = {
606ba597c5SAnurag S. Maskey 	{NWAM_LOC_PROP_ACTIVATION_MODE, NWAM_VALUE_TYPE_UINT64, B_FALSE, 1, 1,
616ba597c5SAnurag S. Maskey 	    valid_loc_activation_mode,
626ba597c5SAnurag S. Maskey 	    "specifies the location activation mode - valid values are:\n"
636ba597c5SAnurag S. Maskey 	    "\'manual\', \'conditional-any\' and \'conditional-all\'",
646ba597c5SAnurag S. Maskey 	    NWAM_TYPE_ANY, NWAM_CLASS_ANY},
656ba597c5SAnurag S. Maskey 	{NWAM_LOC_PROP_CONDITIONS, NWAM_VALUE_TYPE_STRING, B_FALSE, 0,
666ba597c5SAnurag S. Maskey 	    NWAM_MAX_NUM_VALUES, valid_loc_condition,
676ba597c5SAnurag S. Maskey 	    "specifies the activation condition. Conditions are of the form:\n"
686ba597c5SAnurag S. Maskey 	    "ncp|ncu|enm name is|is-not active\n"
696ba597c5SAnurag S. Maskey 	    "ip-address is|is-not|is-in-range|is-not-in-range| 1.2.3.4[/24]\n"
706ba597c5SAnurag S. Maskey 	    "advertised-domain is|is-not|contains|does-not-contain string\n"
716ba597c5SAnurag S. Maskey 	    "system-domain is|is-not|contains|does-not-contain string\n"
726ba597c5SAnurag S. Maskey 	    "essid is|is-not|contains|does-not-contain string\n"
736ba597c5SAnurag S. Maskey 	    "bssid is|is-not string",
746ba597c5SAnurag S. Maskey 	    NWAM_TYPE_ANY, NWAM_CLASS_ANY},
756ba597c5SAnurag S. Maskey 	{NWAM_LOC_PROP_ENABLED, NWAM_VALUE_TYPE_BOOLEAN, B_TRUE, 1, 1,
766ba597c5SAnurag S. Maskey 	    nwam_valid_boolean,
776ba597c5SAnurag S. Maskey 	    "specifies if location is to be enabled",
786ba597c5SAnurag S. Maskey 	    NWAM_TYPE_ANY, NWAM_CLASS_ANY},
796ba597c5SAnurag S. Maskey 	{NWAM_LOC_PROP_NAMESERVICES, NWAM_VALUE_TYPE_UINT64, B_FALSE, 1,
806ba597c5SAnurag S. Maskey 	    NWAM_MAX_NUM_VALUES, valid_nameservices,
816ba597c5SAnurag S. Maskey 	    "specifies name service(s) to be used - valid values are:\n"
826ba597c5SAnurag S. Maskey 	    "\'files\', \'dns\', \'nis\', and \'ldap\'",
836ba597c5SAnurag S. Maskey 	    NWAM_TYPE_ANY, NWAM_CLASS_ANY},
846ba597c5SAnurag S. Maskey 	{NWAM_LOC_PROP_NAMESERVICES_CONFIG_FILE, NWAM_VALUE_TYPE_STRING,
856ba597c5SAnurag S. Maskey 	    B_FALSE, 0, 1, nwam_valid_file,
866ba597c5SAnurag S. Maskey 	    "specifies path to configuration file for name services switch "
87*bbf21555SRichard Lowe 	    "for this location - see nsswitch.conf(5)",
886ba597c5SAnurag S. Maskey 	    NWAM_TYPE_ANY, NWAM_CLASS_ANY},
896ba597c5SAnurag S. Maskey 	{NWAM_LOC_PROP_DNS_NAMESERVICE_CONFIGSRC, NWAM_VALUE_TYPE_UINT64,
906ba597c5SAnurag S. Maskey 	    B_FALSE, 0, NWAM_MAX_NUM_VALUES, valid_configsrc,
916ba597c5SAnurag S. Maskey 	    "specifies sources of DNS configuration parameters - valid values "
926ba597c5SAnurag S. Maskey 	    "are:\n\'dhcp\', or \'manual\'",
936ba597c5SAnurag S. Maskey 	    NWAM_TYPE_ANY, NWAM_CLASS_ANY},
946ba597c5SAnurag S. Maskey 	{NWAM_LOC_PROP_DNS_NAMESERVICE_DOMAIN, NWAM_VALUE_TYPE_STRING, B_FALSE,
956ba597c5SAnurag S. Maskey 	    0, 1, nwam_valid_domain,
966ba597c5SAnurag S. Maskey 	    "specifies DNS domain name to be set for this location",
976ba597c5SAnurag S. Maskey 	    NWAM_TYPE_ANY, NWAM_CLASS_ANY},
986ba597c5SAnurag S. Maskey 	{NWAM_LOC_PROP_DNS_NAMESERVICE_SERVERS, NWAM_VALUE_TYPE_STRING, B_FALSE,
996ba597c5SAnurag S. Maskey 	    0, NWAM_MAX_NUM_VALUES, nwam_valid_host_any,
1006ba597c5SAnurag S. Maskey 	    "specifies DNS server host address(es)",
1016ba597c5SAnurag S. Maskey 	    NWAM_TYPE_ANY, NWAM_CLASS_ANY},
1026ba597c5SAnurag S. Maskey 	{NWAM_LOC_PROP_DNS_NAMESERVICE_SEARCH, NWAM_VALUE_TYPE_STRING, B_FALSE,
1036ba597c5SAnurag S. Maskey 	    0, NWAM_MAX_NUM_VALUES, nwam_valid_domain,
1046ba597c5SAnurag S. Maskey 	    "specifies DNS search list for host name lookup",
1056ba597c5SAnurag S. Maskey 	    NWAM_TYPE_ANY, NWAM_CLASS_ANY},
1066ba597c5SAnurag S. Maskey 	{NWAM_LOC_PROP_NIS_NAMESERVICE_CONFIGSRC, NWAM_VALUE_TYPE_UINT64,
1076ba597c5SAnurag S. Maskey 	    B_FALSE, 0, NWAM_MAX_NUM_VALUES, valid_configsrc,
1086ba597c5SAnurag S. Maskey 	    "specifies sources of NIS configuration parameters - valid values "
1096ba597c5SAnurag S. Maskey 	    "are:\n\'dhcp\', or \'manual\'",
1106ba597c5SAnurag S. Maskey 	    NWAM_TYPE_ANY, NWAM_CLASS_ANY},
1116ba597c5SAnurag S. Maskey 	{NWAM_LOC_PROP_NIS_NAMESERVICE_SERVERS, NWAM_VALUE_TYPE_STRING, B_FALSE,
1126ba597c5SAnurag S. Maskey 	    0, NWAM_MAX_NUM_VALUES, nwam_valid_host_any,
1136ba597c5SAnurag S. Maskey 	    "specifies NIS server host address(es)",
1146ba597c5SAnurag S. Maskey 	    NWAM_TYPE_ANY, NWAM_CLASS_ANY},
1156ba597c5SAnurag S. Maskey 	{NWAM_LOC_PROP_LDAP_NAMESERVICE_CONFIGSRC, NWAM_VALUE_TYPE_UINT64,
1166ba597c5SAnurag S. Maskey 	    B_FALSE, 0, NWAM_MAX_NUM_VALUES, valid_configsrc,
1176ba597c5SAnurag S. Maskey 	    "specifies sources of NIS configuration parameters - currently, "
1186ba597c5SAnurag S. Maskey 	    "the only valid value is \'manual\'",
1196ba597c5SAnurag S. Maskey 	    NWAM_TYPE_ANY, NWAM_CLASS_ANY},
1206ba597c5SAnurag S. Maskey 	{NWAM_LOC_PROP_LDAP_NAMESERVICE_SERVERS, NWAM_VALUE_TYPE_STRING,
1216ba597c5SAnurag S. Maskey 	    B_FALSE, 0, NWAM_MAX_NUM_VALUES, nwam_valid_host_or_domain,
1226ba597c5SAnurag S. Maskey 	    "specifies LDAP server host address(es)",
1236ba597c5SAnurag S. Maskey 	    NWAM_TYPE_ANY, NWAM_CLASS_ANY},
1246ba597c5SAnurag S. Maskey 	{NWAM_LOC_PROP_DEFAULT_DOMAIN, NWAM_VALUE_TYPE_STRING, B_FALSE, 0, 1,
1256ba597c5SAnurag S. Maskey 	    nwam_valid_domain,
126*bbf21555SRichard Lowe 	    "specifies the domainname(8) to be set for this location",
1276ba597c5SAnurag S. Maskey 	    NWAM_TYPE_ANY, NWAM_CLASS_ANY},
1286ba597c5SAnurag S. Maskey 	{NWAM_LOC_PROP_NFSV4_DOMAIN, NWAM_VALUE_TYPE_STRING, B_FALSE, 0, 1,
1296ba597c5SAnurag S. Maskey 	    nwam_valid_domain,
1306ba597c5SAnurag S. Maskey 	    "specifies an NFSv4 domain for this location",
1316ba597c5SAnurag S. Maskey 	    NWAM_TYPE_ANY, NWAM_CLASS_ANY},
1326ba597c5SAnurag S. Maskey 	{NWAM_LOC_PROP_IPFILTER_CONFIG_FILE, NWAM_VALUE_TYPE_STRING, B_FALSE,
1336ba597c5SAnurag S. Maskey 	    0, 1, nwam_valid_file,
134*bbf21555SRichard Lowe 	    "specifies an absolute path to an ipf.conf(5) file for this "
1356ba597c5SAnurag S. Maskey 	    "location",
1366ba597c5SAnurag S. Maskey 	    NWAM_TYPE_ANY, NWAM_CLASS_ANY},
1376ba597c5SAnurag S. Maskey 	{NWAM_LOC_PROP_IPFILTER_V6_CONFIG_FILE, NWAM_VALUE_TYPE_STRING,
1386ba597c5SAnurag S. Maskey 	    B_FALSE, 0, 1, nwam_valid_file,
1396ba597c5SAnurag S. Maskey 	    "specifies an absolute path to an ipf6.conf file for this "
1406ba597c5SAnurag S. Maskey 	    "location",
1416ba597c5SAnurag S. Maskey 	    NWAM_TYPE_ANY, NWAM_CLASS_ANY},
1426ba597c5SAnurag S. Maskey 	{NWAM_LOC_PROP_IPNAT_CONFIG_FILE, NWAM_VALUE_TYPE_STRING, B_FALSE, 0,
1436ba597c5SAnurag S. Maskey 	    1, nwam_valid_file,
144*bbf21555SRichard Lowe 	    "specifies an absolute path to an ipnat.conf(5) file for this "
1456ba597c5SAnurag S. Maskey 	    "location",
1466ba597c5SAnurag S. Maskey 	    NWAM_TYPE_ANY, NWAM_CLASS_ANY},
1476ba597c5SAnurag S. Maskey 	{NWAM_LOC_PROP_IPPOOL_CONFIG_FILE, NWAM_VALUE_TYPE_STRING, B_FALSE, 0,
1486ba597c5SAnurag S. Maskey 	    1, nwam_valid_file,
149*bbf21555SRichard Lowe 	    "specifies an absolute path to an ippool.conf(5) file for this "
1506ba597c5SAnurag S. Maskey 	    "location",
1516ba597c5SAnurag S. Maskey 	    NWAM_TYPE_ANY, NWAM_CLASS_ANY},
1526ba597c5SAnurag S. Maskey 	{NWAM_LOC_PROP_IKE_CONFIG_FILE, NWAM_VALUE_TYPE_STRING, B_FALSE, 0, 1,
1536ba597c5SAnurag S. Maskey 	    nwam_valid_file,
1546ba597c5SAnurag S. Maskey 	    "specifies an absolute path to an ike config file "
155*bbf21555SRichard Lowe 	    "(see ike.config(5))",
1566ba597c5SAnurag S. Maskey 	    NWAM_TYPE_ANY, NWAM_CLASS_ANY},
1576ba597c5SAnurag S. Maskey 	{NWAM_LOC_PROP_IPSECPOLICY_CONFIG_FILE, NWAM_VALUE_TYPE_STRING,
1586ba597c5SAnurag S. Maskey 	    B_FALSE, 0, 1, nwam_valid_file,
1596ba597c5SAnurag S. Maskey 	    "specifies an absolute path to an IPsec policy configuration file "
160*bbf21555SRichard Lowe 	    "(see ipsecconf(8)",
1616ba597c5SAnurag S. Maskey 	    NWAM_TYPE_ANY, NWAM_CLASS_ANY},
1626ba597c5SAnurag S. Maskey };
1636ba597c5SAnurag S. Maskey 
1646ba597c5SAnurag S. Maskey #define	NWAM_NUM_LOC_PROPS	(sizeof (loc_prop_table_entries) / \
1656ba597c5SAnurag S. Maskey 				sizeof (*loc_prop_table_entries))
1666ba597c5SAnurag S. Maskey 
1676ba597c5SAnurag S. Maskey struct nwam_prop_table loc_prop_table =
1686ba597c5SAnurag S. Maskey 	{ NWAM_NUM_LOC_PROPS, loc_prop_table_entries };
1696ba597c5SAnurag S. Maskey 
1706ba597c5SAnurag S. Maskey static uint64_t
nwam_loc_activation_to_flag(nwam_activation_mode_t activation)1716ba597c5SAnurag S. Maskey nwam_loc_activation_to_flag(nwam_activation_mode_t activation)
1726ba597c5SAnurag S. Maskey {
1736ba597c5SAnurag S. Maskey 	switch (activation) {
1746ba597c5SAnurag S. Maskey 	case NWAM_ACTIVATION_MODE_MANUAL:
1756ba597c5SAnurag S. Maskey 		return (NWAM_FLAG_ACTIVATION_MODE_MANUAL);
1766ba597c5SAnurag S. Maskey 	case NWAM_ACTIVATION_MODE_SYSTEM:
1776ba597c5SAnurag S. Maskey 		return (NWAM_FLAG_ACTIVATION_MODE_SYSTEM);
1786ba597c5SAnurag S. Maskey 	case NWAM_ACTIVATION_MODE_CONDITIONAL_ANY:
1796ba597c5SAnurag S. Maskey 		return (NWAM_FLAG_ACTIVATION_MODE_CONDITIONAL_ANY);
1806ba597c5SAnurag S. Maskey 	case NWAM_ACTIVATION_MODE_CONDITIONAL_ALL:
1816ba597c5SAnurag S. Maskey 		return (NWAM_FLAG_ACTIVATION_MODE_CONDITIONAL_ALL);
1826ba597c5SAnurag S. Maskey 	default:
1836ba597c5SAnurag S. Maskey 		return (0);
1846ba597c5SAnurag S. Maskey 	}
1856ba597c5SAnurag S. Maskey }
1866ba597c5SAnurag S. Maskey 
1876ba597c5SAnurag S. Maskey nwam_error_t
nwam_loc_read(const char * name,uint64_t flags,nwam_loc_handle_t * lochp)1886ba597c5SAnurag S. Maskey nwam_loc_read(const char *name, uint64_t flags, nwam_loc_handle_t *lochp)
1896ba597c5SAnurag S. Maskey {
1906ba597c5SAnurag S. Maskey 	return (nwam_read(NWAM_OBJECT_TYPE_LOC, NWAM_LOC_CONF_FILE, name,
1916ba597c5SAnurag S. Maskey 	    flags, lochp));
1926ba597c5SAnurag S. Maskey }
1936ba597c5SAnurag S. Maskey 
1946ba597c5SAnurag S. Maskey nwam_error_t
nwam_loc_create(const char * name,nwam_loc_handle_t * lochp)1956ba597c5SAnurag S. Maskey nwam_loc_create(const char *name, nwam_loc_handle_t *lochp)
1966ba597c5SAnurag S. Maskey {
1976ba597c5SAnurag S. Maskey 	nwam_error_t err;
1986ba597c5SAnurag S. Maskey 	nwam_value_t val = NULL;
1996ba597c5SAnurag S. Maskey 	char *nsswitch = NULL;
2006ba597c5SAnurag S. Maskey 
2016ba597c5SAnurag S. Maskey 	assert(lochp != NULL && name != NULL);
2026ba597c5SAnurag S. Maskey 
2036ba597c5SAnurag S. Maskey 	if ((err = nwam_create(NWAM_OBJECT_TYPE_LOC, NWAM_LOC_CONF_FILE, name,
2046ba597c5SAnurag S. Maskey 	    lochp)) != NWAM_SUCCESS)
2056ba597c5SAnurag S. Maskey 		return (err);
2066ba597c5SAnurag S. Maskey 
2076ba597c5SAnurag S. Maskey 	/* Create new object list for loc */
2086ba597c5SAnurag S. Maskey 	if ((err = nwam_alloc_object_list(&((*lochp)->nwh_data)))
2096ba597c5SAnurag S. Maskey 	    != NWAM_SUCCESS)
2106ba597c5SAnurag S. Maskey 		goto finish;
2116ba597c5SAnurag S. Maskey 
2126ba597c5SAnurag S. Maskey 	/* NWAM_LOC_PROP_ACTIVATION_MODE is mandatory */
2136ba597c5SAnurag S. Maskey 	if ((err = nwam_value_create_uint64(NWAM_ACTIVATION_MODE_MANUAL, &val))
2146ba597c5SAnurag S. Maskey 	    != NWAM_SUCCESS) {
2156ba597c5SAnurag S. Maskey 		goto finish;
2166ba597c5SAnurag S. Maskey 	}
2176ba597c5SAnurag S. Maskey 	if ((err = nwam_set_prop_value((*lochp)->nwh_data,
2186ba597c5SAnurag S. Maskey 	    NWAM_LOC_PROP_ACTIVATION_MODE, val)) != NWAM_SUCCESS) {
2196ba597c5SAnurag S. Maskey 		goto finish;
2206ba597c5SAnurag S. Maskey 	}
2216ba597c5SAnurag S. Maskey 	nwam_value_free(val);
2226ba597c5SAnurag S. Maskey 	val = NULL;
2236ba597c5SAnurag S. Maskey 
2246ba597c5SAnurag S. Maskey 	/*
2256ba597c5SAnurag S. Maskey 	 * NWAM_LOC_PROP_ENABLED defaults to false.
2266ba597c5SAnurag S. Maskey 	 */
2276ba597c5SAnurag S. Maskey 	if ((err = nwam_value_create_boolean(B_FALSE, &val)) != NWAM_SUCCESS)
2286ba597c5SAnurag S. Maskey 		goto finish;
2296ba597c5SAnurag S. Maskey 	if ((err = nwam_set_prop_value((*lochp)->nwh_data,
2306ba597c5SAnurag S. Maskey 	    NWAM_LOC_PROP_ENABLED, val)) != NWAM_SUCCESS)
2316ba597c5SAnurag S. Maskey 		goto finish;
2326ba597c5SAnurag S. Maskey 	nwam_value_free(val);
2336ba597c5SAnurag S. Maskey 	val = NULL;
2346ba597c5SAnurag S. Maskey 
2356ba597c5SAnurag S. Maskey 	/*
2366ba597c5SAnurag S. Maskey 	 * Initialize name service properties: use DNS, configured
2376ba597c5SAnurag S. Maskey 	 * via DHCP, with default nsswitch (/etc/nsswitch.dns).
2386ba597c5SAnurag S. Maskey 	 */
2396ba597c5SAnurag S. Maskey 	if ((err = nwam_value_create_uint64(NWAM_NAMESERVICES_DNS, &val)) !=
2406ba597c5SAnurag S. Maskey 	    NWAM_SUCCESS)
2416ba597c5SAnurag S. Maskey 		goto finish;
2426ba597c5SAnurag S. Maskey 	if ((err = nwam_set_prop_value((*lochp)->nwh_data,
2436ba597c5SAnurag S. Maskey 	    NWAM_LOC_PROP_NAMESERVICES, val)) != NWAM_SUCCESS)
2446ba597c5SAnurag S. Maskey 		goto finish;
2456ba597c5SAnurag S. Maskey 	nwam_value_free(val);
2466ba597c5SAnurag S. Maskey 	val = NULL;
2476ba597c5SAnurag S. Maskey 
2486ba597c5SAnurag S. Maskey 	if ((err = nwam_value_create_uint64(NWAM_CONFIGSRC_DHCP, &val)) !=
2496ba597c5SAnurag S. Maskey 	    NWAM_SUCCESS)
2506ba597c5SAnurag S. Maskey 		goto finish;
2516ba597c5SAnurag S. Maskey 	if ((err = nwam_set_prop_value((*lochp)->nwh_data,
2526ba597c5SAnurag S. Maskey 	    NWAM_LOC_PROP_DNS_NAMESERVICE_CONFIGSRC, val)) != NWAM_SUCCESS)
2536ba597c5SAnurag S. Maskey 		goto finish;
2546ba597c5SAnurag S. Maskey 	nwam_value_free(val);
2556ba597c5SAnurag S. Maskey 	val = NULL;
2566ba597c5SAnurag S. Maskey 
2576ba597c5SAnurag S. Maskey 	/* concatenate these two strings */
2586ba597c5SAnurag S. Maskey 	nsswitch = strdup(NSSWITCH_PREFIX NWAM_NAMESERVICES_DNS_STRING);
2596ba597c5SAnurag S. Maskey 	if (nsswitch == NULL) {
2606ba597c5SAnurag S. Maskey 		err = NWAM_NO_MEMORY;
2616ba597c5SAnurag S. Maskey 		goto finish;
2626ba597c5SAnurag S. Maskey 	}
2636ba597c5SAnurag S. Maskey 	if ((err = nwam_value_create_string(nsswitch, &val)) != NWAM_SUCCESS)
2646ba597c5SAnurag S. Maskey 		goto finish;
2656ba597c5SAnurag S. Maskey 	err = nwam_set_prop_value((*lochp)->nwh_data,
2666ba597c5SAnurag S. Maskey 	    NWAM_LOC_PROP_NAMESERVICES_CONFIG_FILE, val);
2676ba597c5SAnurag S. Maskey 
2686ba597c5SAnurag S. Maskey finish:
2696ba597c5SAnurag S. Maskey 	if (nsswitch != NULL)
2706ba597c5SAnurag S. Maskey 		free(nsswitch);
2716ba597c5SAnurag S. Maskey 	if (val != NULL)
2726ba597c5SAnurag S. Maskey 		nwam_value_free(val);
2736ba597c5SAnurag S. Maskey 	if (err != NWAM_SUCCESS) {
2746ba597c5SAnurag S. Maskey 		nwam_loc_free(*lochp);
2756ba597c5SAnurag S. Maskey 		*lochp = NULL;
2766ba597c5SAnurag S. Maskey 	}
2776ba597c5SAnurag S. Maskey 	return (err);
2786ba597c5SAnurag S. Maskey }
2796ba597c5SAnurag S. Maskey 
2806ba597c5SAnurag S. Maskey nwam_error_t
nwam_loc_get_name(nwam_loc_handle_t loch,char ** namep)2816ba597c5SAnurag S. Maskey nwam_loc_get_name(nwam_loc_handle_t loch, char **namep)
2826ba597c5SAnurag S. Maskey {
2836ba597c5SAnurag S. Maskey 	return (nwam_get_name(loch, namep));
2846ba597c5SAnurag S. Maskey }
2856ba597c5SAnurag S. Maskey 
2866ba597c5SAnurag S. Maskey nwam_error_t
nwam_loc_set_name(nwam_loc_handle_t loch,const char * name)2876ba597c5SAnurag S. Maskey nwam_loc_set_name(nwam_loc_handle_t loch, const char *name)
2886ba597c5SAnurag S. Maskey {
2896ba597c5SAnurag S. Maskey 	return (nwam_set_name(loch, name));
2906ba597c5SAnurag S. Maskey }
2916ba597c5SAnurag S. Maskey 
2926ba597c5SAnurag S. Maskey boolean_t
nwam_loc_can_set_name(nwam_loc_handle_t loch)2936ba597c5SAnurag S. Maskey nwam_loc_can_set_name(nwam_loc_handle_t loch)
2946ba597c5SAnurag S. Maskey {
2956ba597c5SAnurag S. Maskey 	return (!loch->nwh_committed);
2966ba597c5SAnurag S. Maskey }
2976ba597c5SAnurag S. Maskey 
2986ba597c5SAnurag S. Maskey /* ARGSUSED2 */
2996ba597c5SAnurag S. Maskey static int
loc_selectcb(struct nwam_handle * hp,uint64_t flags,void * data)3006ba597c5SAnurag S. Maskey loc_selectcb(struct nwam_handle *hp, uint64_t flags, void *data)
3016ba597c5SAnurag S. Maskey {
3026ba597c5SAnurag S. Maskey 	nwam_loc_handle_t loch = hp;
3036ba597c5SAnurag S. Maskey 	char *locname;
3046ba597c5SAnurag S. Maskey 	uint64_t activation, actflag, walkfilter;
3056ba597c5SAnurag S. Maskey 	nwam_value_t activationval;
3066ba597c5SAnurag S. Maskey 
3076ba597c5SAnurag S. Maskey 	/* Skip the Legacy location in all cases */
3086ba597c5SAnurag S. Maskey 	if (nwam_loc_get_name(loch, &locname) != NWAM_SUCCESS)
3096ba597c5SAnurag S. Maskey 		return (NWAM_INVALID_ARG);
3106ba597c5SAnurag S. Maskey 	if (strcmp(locname, NWAM_LOC_NAME_LEGACY) == 0) {
3116ba597c5SAnurag S. Maskey 		free(locname);
3126ba597c5SAnurag S. Maskey 		return (NWAM_INVALID_ARG);
3136ba597c5SAnurag S. Maskey 	}
3146ba597c5SAnurag S. Maskey 	free(locname);
3156ba597c5SAnurag S. Maskey 
3166ba597c5SAnurag S. Maskey 	/*
3176ba597c5SAnurag S. Maskey 	 * Get a bitmapped flag value corresponding to this loc's
3186ba597c5SAnurag S. Maskey 	 * activation.
3196ba597c5SAnurag S. Maskey 	 */
3206ba597c5SAnurag S. Maskey 	if (nwam_loc_get_prop_value(loch, NWAM_LOC_PROP_ACTIVATION_MODE,
3216ba597c5SAnurag S. Maskey 	    &activationval) != NWAM_SUCCESS) {
3226ba597c5SAnurag S. Maskey 		return (NWAM_INVALID_ARG);
3236ba597c5SAnurag S. Maskey 	}
3246ba597c5SAnurag S. Maskey 	if (nwam_value_get_uint64(activationval, &