xref: /titanic_41/usr/src/cmd/cmd-inet/usr.sbin/bootconfchk/bootconfchk.c (revision eb0cc229f19c437a6b538d3ac0d0443268290b7e)
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, Version 1.0 only
6  * (the "License").  You may not use this file except in compliance
7  * with the License.
8  *
9  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10  * or http://www.opensolaris.org/os/licensing.
11  * See the License for the specific language governing permissions
12  * and limitations under the License.
13  *
14  * When distributing Covered Code, include this CDDL HEADER in each
15  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16  * If applicable, add the following below this CDDL HEADER, with the
17  * fields enclosed by brackets "[]" replaced with your own identifying
18  * information: Portions Copyright [yyyy] [name of copyright owner]
19  *
20  * CDDL HEADER END
21  */
22 /*
23  * Copyright 2003 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 #pragma ident	"%Z%%M%	%I%	%E% SMI"
27 
28 /*
29  * This program parses and validates a wanboot.conf(4) file, and reports
30  * any errors on standard error.
31  *
32  * Returns:
33  *	= 0	- success
34  *	> 0	- error (see exit codes below)
35  */
36 
37 #include <libintl.h>
38 #include <locale.h>
39 #include <stdio.h>
40 #include <wanbootutil.h>
41 #include <wanboot_conf.h>
42 
43 /*
44  * Exit codes:
45  */
46 #define	BOOTCONFCHK_OK		0
47 #define	BOOTCONFCHK_INVALID	1
48 #define	BOOTCONFCHK_USAGE	2
49 
50 int
51 main(int argc, char **argv)
52 {
53 	int		ret = BOOTCONFCHK_OK;
54 	char		*bootconf;
55 	bc_handle_t	bc_handle;
56 
57 	/*
58 	 * Do the necessary magic for localization support.
59 	 */
60 	(void) setlocale(LC_ALL, "");
61 #if	!defined(TEXT_DOMAIN)
62 #define	TEXT_DOMAIN "SYS_TEST"
63 #endif	/* !defined(TEXT_DOMAIN) */
64 	(void) textdomain(TEXT_DOMAIN);
65 
66 	/*
67 	 * Initialize program name for use by wbku_printerr().
68 	 */
69 	wbku_errinit(argv[0]);
70 
71 	/*
72 	 * Check usage is legal.
73 	 */
74 	if (argc != 2) {
75 		(void) fprintf(stderr,
76 		    gettext("Usage: %s bootconf_file\n"), argv[0]);
77 		return (BOOTCONFCHK_USAGE);
78 	}
79 	bootconf = argv[1];
80 
81 	/*
82 	 * Parse and validate the given wanboot.conf(4) file.
83 	 */
84 	if (bootconf_init(&bc_handle, bootconf) != BC_SUCCESS) {
85 		wbku_printerr("Error parsing/validating %s: %s\n",
86 		    bootconf, bootconf_errmsg(&bc_handle));
87 		ret = BOOTCONFCHK_INVALID;
88 	}
89 	bootconf_end(&bc_handle);
90 
91 	return (ret);
92 }
93