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 /*
23 * Copyright (c) 2006, 2010, Oracle and/or its affiliates. All rights reserved.
24 */
25
26 #include <assert.h>
27 #include <dirent.h>
28 #include <errno.h>
29 #include <fnmatch.h>
30 #include <signal.h>
31 #include <stdlib.h>
32 #include <unistd.h>
33 #include <strings.h>
34 #include <synch.h>
35 #include <sys/brand.h>
36 #include <sys/fcntl.h>
37 #include <sys/param.h>
38 #include <sys/stat.h>
39 #include <sys/systeminfo.h>
40 #include <sys/types.h>
41 #include <thread.h>
42 #include <zone.h>
43
54 #define DTD_ELEM_GLOBAL_MOUNT ((const xmlChar *) "global_mount")
55 #define DTD_ELEM_HALT ((const xmlChar *) "halt")
56 #define DTD_ELEM_INITNAME ((const xmlChar *) "initname")
57 #define DTD_ELEM_INSTALL ((const xmlChar *) "install")
58 #define DTD_ELEM_INSTALLOPTS ((const xmlChar *) "installopts")
59 #define DTD_ELEM_LOGIN_CMD ((const xmlChar *) "login_cmd")
60 #define DTD_ELEM_FORCELOGIN_CMD ((const xmlChar *) "forcedlogin_cmd")
61 #define DTD_ELEM_MODNAME ((const xmlChar *) "modname")
62 #define DTD_ELEM_MOUNT ((const xmlChar *) "mount")
63 #define DTD_ELEM_POSTATTACH ((const xmlChar *) "postattach")
64 #define DTD_ELEM_POSTCLONE ((const xmlChar *) "postclone")
65 #define DTD_ELEM_POSTINSTALL ((const xmlChar *) "postinstall")
66 #define DTD_ELEM_POSTSNAP ((const xmlChar *) "postsnap")
67 #define DTD_ELEM_POSTSTATECHG ((const xmlChar *) "poststatechange")
68 #define DTD_ELEM_PREDETACH ((const xmlChar *) "predetach")
69 #define DTD_ELEM_PRESNAP ((const xmlChar *) "presnap")
70 #define DTD_ELEM_PRESTATECHG ((const xmlChar *) "prestatechange")
71 #define DTD_ELEM_PREUNINSTALL ((const xmlChar *) "preuninstall")
72 #define DTD_ELEM_PRIVILEGE ((const xmlChar *) "privilege")
73 #define DTD_ELEM_QUERY ((const xmlChar *) "query")
74 #define DTD_ELEM_SYMLINK ((const xmlChar *) "symlink")
75 #define DTD_ELEM_SYSBOOT ((const xmlChar *) "sysboot")
76 #define DTD_ELEM_UNINSTALL ((const xmlChar *) "uninstall")
77 #define DTD_ELEM_USER_CMD ((const xmlChar *) "user_cmd")
78 #define DTD_ELEM_VALIDSNAP ((const xmlChar *) "validatesnap")
79 #define DTD_ELEM_VERIFY_CFG ((const xmlChar *) "verify_cfg")
80 #define DTD_ELEM_VERIFY_ADM ((const xmlChar *) "verify_adm")
81
82 #define DTD_ATTR_ALLOWEXCL ((const xmlChar *) "allow-exclusive-ip")
83 #define DTD_ATTR_ARCH ((const xmlChar *) "arch")
84 #define DTD_ATTR_DIRECTORY ((const xmlChar *) "directory")
85 #define DTD_ATTR_IPTYPE ((const xmlChar *) "ip-type")
86 #define DTD_ATTR_MATCH ((const xmlChar *) "match")
87 #define DTD_ATTR_MODE ((const xmlChar *) "mode")
88 #define DTD_ATTR_NAME ((const xmlChar *) "name")
89 #define DTD_ATTR_OPT ((const xmlChar *) "opt")
90 #define DTD_ATTR_PATH ((const xmlChar *) "path")
91 #define DTD_ATTR_SET ((const xmlChar *) "set")
92 #define DTD_ATTR_SOURCE ((const xmlChar *) "source")
93 #define DTD_ATTR_SPECIAL ((const xmlChar *) "special")
484 }
485
486 int
487 brand_get_detach(brand_handle_t bh, const char *zonename,
488 const char *zonepath, char *buf, size_t len)
489 {
490 struct brand_handle *bhp = (struct brand_handle *)bh;
491 return (brand_get_value(bhp, zonename, zonepath, NULL, NULL,
492 buf, len, DTD_ELEM_DETACH, B_TRUE, B_TRUE));
493 }
494
495 int
496 brand_get_halt(brand_handle_t bh, const char *zonename,
497 const char *zonepath, char *buf, size_t len)
498 {
499 struct brand_handle *bhp = (struct brand_handle *)bh;
500 return (brand_get_value(bhp, zonename, zonepath, NULL, NULL,
501 buf, len, DTD_ELEM_HALT, B_TRUE, B_TRUE));
502 }
503
504 int
505 brand_get_initname(brand_handle_t bh, char *buf, size_t len)
506 {
507 struct brand_handle *bhp = (struct brand_handle *)bh;
508 return (brand_get_value(bhp, NULL, NULL, NULL, NULL,
509 buf, len, DTD_ELEM_INITNAME, B_FALSE, B_FALSE));
510 }
511
512 int
513 brand_get_login_cmd(brand_handle_t bh, const char *username,
514 char *buf, size_t len)
515 {
516 struct brand_handle *bhp = (struct brand_handle *)bh;
517 const char *curr_zone = get_curr_zone();
518 return (brand_get_value(bhp, NULL, NULL, username, curr_zone,
519 buf, len, DTD_ELEM_LOGIN_CMD, B_TRUE, B_FALSE));
520 }
521
522 int
523 brand_get_forcedlogin_cmd(brand_handle_t bh, const char *username,
|
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 /*
23 * Copyright (c) 2006, 2010, Oracle and/or its affiliates. All rights reserved.
24 * Copyright 2014 Nexenta Systems, Inc. All rights reserved.
25 */
26
27 #include <assert.h>
28 #include <dirent.h>
29 #include <errno.h>
30 #include <fnmatch.h>
31 #include <signal.h>
32 #include <stdlib.h>
33 #include <unistd.h>
34 #include <strings.h>
35 #include <synch.h>
36 #include <sys/brand.h>
37 #include <sys/fcntl.h>
38 #include <sys/param.h>
39 #include <sys/stat.h>
40 #include <sys/systeminfo.h>
41 #include <sys/types.h>
42 #include <thread.h>
43 #include <zone.h>
44
55 #define DTD_ELEM_GLOBAL_MOUNT ((const xmlChar *) "global_mount")
56 #define DTD_ELEM_HALT ((const xmlChar *) "halt")
57 #define DTD_ELEM_INITNAME ((const xmlChar *) "initname")
58 #define DTD_ELEM_INSTALL ((const xmlChar *) "install")
59 #define DTD_ELEM_INSTALLOPTS ((const xmlChar *) "installopts")
60 #define DTD_ELEM_LOGIN_CMD ((const xmlChar *) "login_cmd")
61 #define DTD_ELEM_FORCELOGIN_CMD ((const xmlChar *) "forcedlogin_cmd")
62 #define DTD_ELEM_MODNAME ((const xmlChar *) "modname")
63 #define DTD_ELEM_MOUNT ((const xmlChar *) "mount")
64 #define DTD_ELEM_POSTATTACH ((const xmlChar *) "postattach")
65 #define DTD_ELEM_POSTCLONE ((const xmlChar *) "postclone")
66 #define DTD_ELEM_POSTINSTALL ((const xmlChar *) "postinstall")
67 #define DTD_ELEM_POSTSNAP ((const xmlChar *) "postsnap")
68 #define DTD_ELEM_POSTSTATECHG ((const xmlChar *) "poststatechange")
69 #define DTD_ELEM_PREDETACH ((const xmlChar *) "predetach")
70 #define DTD_ELEM_PRESNAP ((const xmlChar *) "presnap")
71 #define DTD_ELEM_PRESTATECHG ((const xmlChar *) "prestatechange")
72 #define DTD_ELEM_PREUNINSTALL ((const xmlChar *) "preuninstall")
73 #define DTD_ELEM_PRIVILEGE ((const xmlChar *) "privilege")
74 #define DTD_ELEM_QUERY ((const xmlChar *) "query")
75 #define DTD_ELEM_SHUTDOWN ((const xmlChar *) "shutdown")
76 #define DTD_ELEM_SYMLINK ((const xmlChar *) "symlink")
77 #define DTD_ELEM_SYSBOOT ((const xmlChar *) "sysboot")
78 #define DTD_ELEM_UNINSTALL ((const xmlChar *) "uninstall")
79 #define DTD_ELEM_USER_CMD ((const xmlChar *) "user_cmd")
80 #define DTD_ELEM_VALIDSNAP ((const xmlChar *) "validatesnap")
81 #define DTD_ELEM_VERIFY_CFG ((const xmlChar *) "verify_cfg")
82 #define DTD_ELEM_VERIFY_ADM ((const xmlChar *) "verify_adm")
83
84 #define DTD_ATTR_ALLOWEXCL ((const xmlChar *) "allow-exclusive-ip")
85 #define DTD_ATTR_ARCH ((const xmlChar *) "arch")
86 #define DTD_ATTR_DIRECTORY ((const xmlChar *) "directory")
87 #define DTD_ATTR_IPTYPE ((const xmlChar *) "ip-type")
88 #define DTD_ATTR_MATCH ((const xmlChar *) "match")
89 #define DTD_ATTR_MODE ((const xmlChar *) "mode")
90 #define DTD_ATTR_NAME ((const xmlChar *) "name")
91 #define DTD_ATTR_OPT ((const xmlChar *) "opt")
92 #define DTD_ATTR_PATH ((const xmlChar *) "path")
93 #define DTD_ATTR_SET ((const xmlChar *) "set")
94 #define DTD_ATTR_SOURCE ((const xmlChar *) "source")
95 #define DTD_ATTR_SPECIAL ((const xmlChar *) "special")
486 }
487
488 int
489 brand_get_detach(brand_handle_t bh, const char *zonename,
490 const char *zonepath, char *buf, size_t len)
491 {
492 struct brand_handle *bhp = (struct brand_handle *)bh;
493 return (brand_get_value(bhp, zonename, zonepath, NULL, NULL,
494 buf, len, DTD_ELEM_DETACH, B_TRUE, B_TRUE));
495 }
496
497 int
498 brand_get_halt(brand_handle_t bh, const char *zonename,
499 const char *zonepath, char *buf, size_t len)
500 {
501 struct brand_handle *bhp = (struct brand_handle *)bh;
502 return (brand_get_value(bhp, zonename, zonepath, NULL, NULL,
503 buf, len, DTD_ELEM_HALT, B_TRUE, B_TRUE));
504 }
505
506 int
507 brand_get_shutdown(brand_handle_t bh, const char *zonename,
508 const char *zonepath, char *buf, size_t len)
509 {
510 struct brand_handle *bhp = (struct brand_handle *)bh;
511 return (brand_get_value(bhp, zonename, zonepath, NULL, NULL,
512 buf, len, DTD_ELEM_SHUTDOWN, B_TRUE, B_TRUE));
513 }
514
515 int
516 brand_get_initname(brand_handle_t bh, char *buf, size_t len)
517 {
518 struct brand_handle *bhp = (struct brand_handle *)bh;
519 return (brand_get_value(bhp, NULL, NULL, NULL, NULL,
520 buf, len, DTD_ELEM_INITNAME, B_FALSE, B_FALSE));
521 }
522
523 int
524 brand_get_login_cmd(brand_handle_t bh, const char *username,
525 char *buf, size_t len)
526 {
527 struct brand_handle *bhp = (struct brand_handle *)bh;
528 const char *curr_zone = get_curr_zone();
529 return (brand_get_value(bhp, NULL, NULL, username, curr_zone,
530 buf, len, DTD_ELEM_LOGIN_CMD, B_TRUE, B_FALSE));
531 }
532
533 int
534 brand_get_forcedlogin_cmd(brand_handle_t bh, const char *username,
|