Home | History | Annotate | Download | only in dns
      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 (the License).
      6  * You may not use this file except in compliance with the License.
      7  *
      8  * You can obtain a copy of the license at usr/src/CDDL.txt
      9  * or http://www.opensolaris.org/os/licensing.
     10  * See the License for the specific language governing permissions
     11  * and limitations under the License.
     12  *
     13  * When distributing Covered Code, include this CDDL HEADER in each
     14  * file and include the License file at usr/src/CDDL.txt.
     15  * If applicable, add the following below this CDDL HEADER, with the
     16  * fields enclosed by brackets [] replaced with your own identifying
     17  * information: Portions Copyright [yyyy] [name of copyright owner]
     18  *
     19  * CDDL HEADER END
     20  */
     21 
     22 /*
     23  * Copyright 1998-2002 Sun Microsystems, Inc.  All rights reserved.
     24  * Use is subject to license terms.
     25  *
     26  * dns_validate.c - validate method for highly available DNS
     27  */
     28 
     29 #pragma ident	"@(#)dns_validate.c	1.16	07/06/06 SMI"
     30 
     31 #include <string.h>
     32 #include <stdio.h>
     33 #include <locale.h>
     34 #include <libintl.h>
     35 #include "dns.h"
     36 
     37 /*
     38  * Do some basic sanity check of the configuration here.
     39  */
     40 
     41 int
     42 main(int argc, char *argv[])
     43 {
     44 	scds_handle_t handle;
     45 	char *mode;
     46 	scha_extprop_value_t *mode_used;
     47 	int rc;
     48 
     49 	/* I18N stuff */
     50 	(void) setlocale(LC_ALL, "");
     51 	(void) textdomain(TEXT_DOMAIN);
     52 	(void) bindtextdomain(TEXT_DOMAIN, MESSAGE_DIR);
     53 
     54 	if ((rc = scds_initialize(&handle, argc, argv)) != SCHA_ERR_NOERR) {
     55 		scds_syslog(LOG_ERR, "Failed to retrieve the resource "
     56 			"handle: %s", scds_error_string(rc));
     57 		(void) fprintf(stderr, gettext("Failed to retrieve the "
     58 			"resource handle: %s\n"),
     59 			gettext(scds_error_string(rc)));
     60 		return (1);
     61 	}
     62 
     63 	if (scds_get_ext_property(handle, DNS_MODE_USED, SCHA_PTYPE_STRING,
     64 	    &mode_used) != SCHA_ERR_NOERR) {
     65 		scds_syslog(LOG_ERR, "Property %s is not set.", DNS_MODE_USED);
     66 		(void) fprintf(stderr, gettext("Property %s is not set.\n"),
     67 			DNS_MODE_USED);
     68 		scds_close(&handle);
     69 		return (1);
     70 	} else {
     71 		/* make a copy of the mode and free the ext property */
     72 		mode = strdup(mode_used->val.val_str);
     73 		scds_free_ext_property(mode_used);
     74 		if (mode == NULL) {
     75 			scds_syslog(LOG_ERR, "INTERNAL ERROR: %s.",
     76 				"Out of memory");
     77 			(void) fprintf(stderr, gettext("INTERNAL ERROR: %s.\n"),
     78 				gettext("Out of memory"));
     79 			scds_close(&handle);
     80 			return (1);
     81 		}
     82 	}
     83 
     84 	if (svc_validate(handle, mode, B_TRUE) != SCHA_ERR_NOERR) {
     85 		free(mode);
     86 		scds_syslog(LOG_ERR, "Failed to validate configuration.");
     87 		(void) fprintf(stderr, gettext("Failed to validate "
     88 			"configuration.\n"));
     89 		scds_close(&handle);
     90 		return (1);	/* Validation failure */
     91 	}
     92 
     93 	scds_syslog(LOG_INFO, "Completed successfully.");
     94 	free(mode);
     95 	scds_close(&handle);
     96 
     97 	return (0);
     98 }
     99