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/OPENSOLARIS.LICENSE
   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/OPENSOLARIS.LICENSE.
  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  * Copyright (c) 2009, 2010, Oracle and/or its affiliates. All rights reserved.
  23  */
  24 
  25 #include <ctype.h>
  26 #include <errno.h>
  27 #include <fcntl.h>
  28 #include <libgen.h>
  29 #include <limits.h>
  30 #include <stdarg.h>
  31 #include <stdio.h>
  32 #include <stdlib.h>
  33 #include <string.h>
  34 #include <strings.h>
  35 #include <stropts.h>
  36 #include <sys/ioccom.h>
  37 #include <sys/stat.h>
  38 #include <sys/systeminfo.h>
  39 #include <sys/types.h>
  40 #include <sys/varargs.h>
  41 #include <unistd.h>
  42 #include <libintl.h>
  43 #include <locale.h>
  44 
  45 #include <libzonecfg.h>
  46 
  47 static void usage_err(void) __NORETURN;
  48 
  49 static char *bname = NULL;
  50 
  51 #if !defined(TEXT_DOMAIN)               /* should be defined by cc -D */
  52 #define TEXT_DOMAIN     "SYS_TEST"      /* Use this only if it wasn't */
  53 #endif
  54 
  55 static void
  56 usage_err(void)
  57 {
  58         (void) printf(gettext("%s ipkg brand error: invalid usage\n"), bname);
  59 
  60         (void) fprintf(stderr,
  61             gettext("usage:\t%s verify <xml file>\n\n"), bname);
  62 
  63         exit(1);
  64 }
  65 
  66 static void
  67 err(char *msg, ...)
  68 {
  69         char    buf[1024];
  70         va_list ap;
  71 
  72         va_start(ap, msg);
  73         /*LINTED*/
  74         (void) vsnprintf(buf, sizeof (buf), msg, ap);
  75         va_end(ap);
  76 
  77         (void) printf(gettext("%s ipkg brand error: %s\n"), bname, buf);
  78 
  79         exit(1);
  80         /*NOTREACHED*/
  81 }
  82 
  83 static int
  84 do_verify(char *xmlfile)
  85 {
  86         zone_dochandle_t        handle;
  87 
  88         if ((handle = zonecfg_init_handle()) == NULL)
  89                 err(gettext("internal libzonecfg.so.1 error"), 0);
  90 
  91         if (zonecfg_get_xml_handle(xmlfile, handle) != Z_OK) {
  92                 zonecfg_fini_handle(handle);
  93                 err(gettext("zonecfg provided an invalid XML file"));
  94         }
  95 
  96         zonecfg_fini_handle(handle);
  97         return (0);
  98 }
  99 
 100 int
 101 main(int argc, char *argv[])
 102 {
 103         (void) setlocale(LC_ALL, "");
 104         (void) textdomain(TEXT_DOMAIN);
 105 
 106         bname = basename(argv[0]);
 107 
 108         if (argc < 3)
 109                 usage_err();
 110 
 111         if (strcmp(argv[1], "verify") == 0) {
 112                 if (argc != 3)
 113                         usage_err();
 114                 return (do_verify(argv[2]));
 115         }
 116 
 117         usage_err();
 118         /*NOTREACHED*/
 119 }