0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032
0033
0034 #include <string.h>
0035 #include <stdio.h>
0036 #include <stdlib.h>
0037 #include <memory.h>
0038 #include <unistd.h>
0039 #include <ctype.h>
0040
0041 #include <ndrstandard.h>
0042 #include <ndebug.h>
0043
0044 #include <ndrx.h>
0045 #include <ndrxdcmn.h>
0046 #include <atmi_int.h>
0047 #include <nclopt.h>
0048 #include <pscript.h>
0049 #include <errno.h>
0050 #include <userlog.h>
0051
0052
0053 extern const char ndrx_G_resource_Exfields[];
0054
0055
0056
0057
0058
0059
0060
0061
0062
0063
0064
0065 expublic char * ndrx_xadmin_nodeid(void)
0066 {
0067 static char nodeid[64];
0068 static int first = EXTRUE;
0069 char *p;
0070
0071 if (first)
0072 {
0073 if (NULL==(p = getenv(CONF_NDRX_NODEID)))
0074 {
0075 NDRX_STRCPY_SAFE(nodeid, "?");
0076 }
0077 else
0078 {
0079 NDRX_STRCPY_SAFE(nodeid, p);
0080 }
0081 }
0082
0083 return nodeid;
0084 }
0085
0086
0087
0088
0089
0090
0091
0092
0093 expublic int chk_confirm_clopt(char *message, int argc, char **argv)
0094 {
0095 int ret = EXSUCCEED;
0096 short confirm = EXFALSE;
0097
0098 ncloptmap_t clopt[] =
0099 {
0100 {'y', BFLD_SHORT, (void *)&confirm, 0,
0101 NCLOPT_OPT | NCLOPT_TRUEBOOL, "Confirm"},
0102 {0}
0103 };
0104
0105
0106 if (nstd_parse_clopt(clopt, EXTRUE, argc, argv, EXFALSE))
0107 {
0108 fprintf(stderr, XADMIN_INVALID_OPTIONS_MSG);
0109 EXFAIL_OUT(ret);
0110 }
0111
0112
0113 ret = ndrx_chk_confirm(message, confirm);
0114
0115 out:
0116 return ret;
0117 }
0118
0119 #ifndef NDRX_DISABLEPSCRIPT
0120
0121
0122
0123
0124
0125
0126 expublic void printfunc(HPSCRIPTVM v,const PSChar *s,...)
0127 {
0128 va_list vl;
0129 va_start(vl, s);
0130 vfprintf(stdout, s, vl);
0131 va_end(vl);
0132 }
0133
0134
0135
0136
0137
0138
0139
0140
0141 expublic void errorfunc(HPSCRIPTVM v,const PSChar *s,...)
0142 {
0143 va_list vl;
0144 va_start(vl, s);
0145 vfprintf(stderr, s, vl);
0146 va_end(vl);
0147 }
0148
0149
0150
0151
0152
0153
0154
0155
0156 expublic int load_value(HPSCRIPTVM v, char *key_val_string)
0157 {
0158 int ret = EXSUCCEED;
0159 char *p;
0160 int len = strlen(key_val_string);
0161
0162 p=strchr(key_val_string, '=');
0163
0164 if (!len)
0165 {
0166 fprintf(stderr, "Empty value string!\n");
0167 EXFAIL_OUT(ret);
0168 }
0169
0170 if (NULL==p)
0171 {
0172 fprintf(stderr, "Missing '=' in value [%s]!\n", key_val_string);
0173 EXFAIL_OUT(ret);
0174 }
0175
0176 if (p==key_val_string)
0177 {
0178 fprintf(stderr, "Missing value [%s]!\n", key_val_string);
0179 EXFAIL_OUT(ret);
0180 }
0181
0182 if (p==key_val_string)
0183 {
0184 fprintf(stderr, "Missing value [%s]!\n", key_val_string);
0185 EXFAIL_OUT(ret);
0186 }
0187
0188 *p = EXEOS;
0189 p++;
0190
0191
0192 ps_pushstring(v, key_val_string, -1);
0193 ps_pushstring(v, p, -1);
0194 ps_newslot(v, -3, PSFalse );
0195
0196 out:
0197 return ret;
0198 }
0199
0200
0201
0202
0203
0204
0205 expublic int add_defaults_from_config(HPSCRIPTVM v, char *section)
0206 {
0207 int ret = EXSUCCEED;
0208 ndrx_inicfg_section_keyval_t *val;
0209 char *ptr = NULL;
0210 char *p;
0211
0212 if (NULL!=(val=ndrx_keyval_hash_get(G_xadmin_config, section)))
0213 {
0214 userlog("Got config defaults for %s: [%s]", section, val->val);
0215
0216 if (NULL==(ptr = strdup(val->val)))
0217 {
0218 userlog("Malloc failed: %s", strerror(errno));
0219 EXFAIL_OUT(ret);
0220 }
0221
0222
0223
0224
0225 p = strtok (ptr, ARG_DEILIM);
0226 while (p != NULL)
0227 {
0228 if (0==strcmp(p, "-d"))
0229 {
0230 PSBool isDefaulted = EXTRUE;
0231 ps_pushstring(v, "isDefaulted", -1);
0232 ps_pushbool(v, isDefaulted);
0233 ps_newslot(v, -3, PSFalse );
0234 }
0235 else if (0==strncmp(p, "-v", 2)
0236 && 0!=strcmp(p, "-v"))
0237 {
0238 if (strlen(p) < 4)
0239 {
0240 userlog("Invalid default settings for provision command [%s]",
0241 val->val);
0242 EXFAIL_OUT(ret);
0243 }
0244
0245
0246
0247
0248 if (EXSUCCEED!=load_value(v, p+2))
0249 {
0250 userlog("Invalid value\n");
0251 EXFAIL_OUT(ret);
0252 }
0253 }
0254 else if (0==strncmp(p, "-v", 2))
0255 {
0256 p = strtok (NULL, ARG_DEILIM);
0257
0258
0259 if (NULL!=p)
0260 {
0261 if (EXSUCCEED!=load_value(v, p))
0262 {
0263 userlog("Invalid value on provision defaults [%s]",
0264 val->val);
0265 EXFAIL_OUT(ret);
0266 }
0267 }
0268 else
0269 {
0270 userlog("Invalid command line missing value at end [%s]",
0271 val->val);
0272 EXFAIL_OUT(ret);
0273 }
0274 }
0275
0276 p = strtok (NULL, ARG_DEILIM);
0277 }
0278 }
0279
0280 out:
0281
0282 if (NULL!=ptr)
0283 {
0284 free(ptr);
0285 }
0286
0287 if (EXSUCCEED!=ret)
0288 {
0289 fprintf(stderr, "Failed to process defaults - invalid config [%s], see ULOG\n",
0290 G_xadmin_config_file);
0291 }
0292
0293 return ret;
0294 }
0295
0296
0297
0298
0299
0300
0301 static PSInteger _xadmin_getExfields(HPSCRIPTVM v)
0302 {
0303
0304 ps_pushstring(v,ndrx_G_resource_Exfields,-1);
0305
0306 return 1;
0307 }
0308
0309
0310
0311
0312 expublic int register_getExfields(HPSCRIPTVM v)
0313 {
0314
0315 ps_pushstring(v,"getExfields",-1);
0316 ps_newclosure(v,_xadmin_getExfields,0);
0317 ps_setparamscheck(v,1,".s");
0318 ps_setnativeclosurename(v,-1,"getExfields");
0319 ps_newslot(v,-3,PSFalse);
0320
0321 return 1;
0322 }
0323
0324 #endif
0325