2 * Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved.
3 * Copyright 2014 Nexenta Systems, Inc. All rights reserved.
9 * Copyright (c) 2007, The Storage Networking Industry Association.
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
14 * - Redistributions of source code must retain the above copyright
15 * notice, this list of conditions and the following disclaimer.
17 * - Redistributions in binary form must reproduce the above copyright
18 * notice, this list of conditions and the following disclaimer in
19 * the documentation and/or other materials provided with the
22 * - Neither the name of The Storage Networking Industry Association (SNIA)
23 * nor the names of its contributors may be used to endorse or promote
24 * products derived from this software without specific prior written
27 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
28 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
29 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
30 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
31 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
32 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
33 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
34 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
35 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
36 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
37 * POSSIBILITY OF SUCH DAMAGE.
41 * NDMP configuration management
48 #include <ndmpd_prop.h>
52 typedef struct ndmpd_cfg_param
{
60 static int ndmpd_config_update(ndmpd_cfg_param_t
*cfg
, char *value
);
63 * IMPORTANT: any changes to the order of this table's entries
64 * need to be reflected in the enum ndmpd_cfg_id_t.
66 ndmpd_cfg_param_t ndmpd_cfg_table
[] =
68 {"dar-support", "", 0, NDMP_CF_NOTINIT
},
69 {"mover-nic", "", 0, NDMP_CF_NOTINIT
},
70 {"dump-pathnode", "", 0, NDMP_CF_NOTINIT
},
71 {"tar-pathnode", "", 0, NDMP_CF_NOTINIT
},
72 {"fh-inode", "", 0, NDMP_CF_NOTINIT
},
73 {"ignore-ctime", "", 0, NDMP_CF_NOTINIT
},
74 {"include-lmtime", "", 0, NDMP_CF_NOTINIT
},
75 {"token-maxseq", "", 0, NDMP_CF_NOTINIT
},
76 {"version", "", 0, NDMP_CF_NOTINIT
},
77 {"restore-fullpath", "", 0, NDMP_CF_NOTINIT
},
78 {"debug-path", "", 0, NDMP_CF_NOTINIT
},
79 {"plugin-path", "", 0, NDMP_CF_NOTINIT
},
80 {"socket-css", "", 0, NDMP_CF_NOTINIT
},
81 {"socket-crs", "", 0, NDMP_CF_NOTINIT
},
82 {"mover-recordsize", "", 0, NDMP_CF_NOTINIT
},
83 {"restore-wildcard-enable", "", 0, NDMP_CF_NOTINIT
},
84 {"cram-md5-username", "", 0, NDMP_CF_NOTINIT
},
85 {"cram-md5-password", "", 0, NDMP_CF_NOTINIT
},
86 {"cleartext-username", "", 0, NDMP_CF_NOTINIT
},
87 {"cleartext-password", "", 0, NDMP_CF_NOTINIT
},
88 {"tcp-port", "", 0, NDMP_CF_NOTINIT
},
89 {"backup-quarantine", "", 0, NDMP_CF_NOTINIT
},
90 {"restore-quarantine", "", 0, NDMP_CF_NOTINIT
},
91 {"overwrite-quarantine", "", 0, NDMP_CF_NOTINIT
},
92 {"zfs-force-override", "", 0, NDMP_CF_NOTINIT
},
93 {"drive-type", "", 0, NDMP_CF_NOTINIT
},
94 {"debug-mode", "", 0, NDMP_CF_NOTINIT
},
98 * Loads all the NDMP configuration parameters and sets up the
102 ndmpd_load_prop(void)
105 ndmpd_cfg_param_t
*cfg
;
108 for (id
= 0; id
< NDMP_MAXALL
; id
++) {
109 cfg
= &ndmpd_cfg_table
[id
];
110 if ((ndmp_get_prop(cfg
->sc_name
, &value
)) == -1) {
111 syslog(LOG_DEBUG
, "%s %s",
112 cfg
->sc_name
, ndmp_strerror(ndmp_errno
));
116 * enval == 0 could mean two things, either the
117 * config param is not defined, or it has been
118 * removed. If the variable has already been defined
119 * and now enval is 0, it should be removed, otherwise
120 * we don't need to do anything in this case.
122 if ((cfg
->sc_flags
& NDMP_CF_DEFINED
) || value
) {
123 if (ndmpd_config_update(cfg
, value
)) {
134 * ndmpd_config_update
136 * Updates the specified config param with the given value.
137 * This function is called both on (re)load and set.
140 ndmpd_config_update(ndmpd_cfg_param_t
*cfg
, char *value
)
149 curval
= realloc(cfg
->sc_value
, (len
+ 1));
151 curval
= ndmp_malloc(len
+ 1);
155 cfg
->sc_value
= curval
;
156 (void) strcpy(cfg
->sc_value
, value
);
157 cfg
->sc_flags
|= NDMP_CF_DEFINED
;
159 syslog(LOG_ERR
, "Out of memory.");
162 } else if (cfg
->sc_value
) {
165 cfg
->sc_flags
&= ~NDMP_CF_DEFINED
;
172 * Returns value of the specified config param.
173 * The return value is a string pointer to the locally
174 * allocated memory if the config param is defined
175 * otherwise it would be NULL.
178 ndmpd_get_prop(ndmpd_cfg_id_t id
)
182 if (id
< NDMP_MAXALL
) {
183 env_val
= ndmpd_cfg_table
[id
].sc_value
;
191 * Similar to ndmpd_get_prop except it will return dflt value
195 ndmpd_get_prop_default(ndmpd_cfg_id_t id
, char *dflt
)
199 env
= ndmpd_get_prop(id
);
201 if (env
&& *env
!= 0) {
209 * Returns the value of a yes/no config param.
210 * Returns 1 is config is set to "yes", otherwise 0.
213 ndmpd_get_prop_yorn(ndmpd_cfg_id_t id
)
217 val
= ndmpd_get_prop(id
);
219 if (strcasecmp(val
, "yes") == 0)