Changeset 740 for vendor/current/source4/lib/wmi
- Timestamp:
- Nov 14, 2012, 12:59:34 PM (13 years ago)
- Location:
- vendor/current/source4/lib/wmi
- Files:
-
- 1 added
- 1 deleted
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
vendor/current/source4/lib/wmi/tools/wmic.c
r414 r740 36 36 37 37 struct program_args { 38 39 40 38 char *hostname; 39 char *query; 40 char *ns; 41 41 }; 42 42 43 43 static void parse_args(int argc, char *argv[], struct program_args *pmyargs) 44 44 { 45 poptContext pc; 46 int opt, i; 47 48 int argc_new; 49 char **argv_new; 50 51 struct poptOption long_options[] = { 52 POPT_AUTOHELP 53 POPT_COMMON_SAMBA 54 POPT_COMMON_CONNECTION 55 POPT_COMMON_CREDENTIALS 56 POPT_COMMON_VERSION 57 {"namespace", 0, POPT_ARG_STRING, &pmyargs->ns, 0, 58 "WMI namespace, default to root\\cimv2", 0}, 59 POPT_TABLEEND 60 }; 61 62 pc = poptGetContext("wmi", argc, (const char **) argv, 63 long_options, POPT_CONTEXT_KEEP_FIRST); 64 65 poptSetOtherOptionHelp(pc, "//host query\n\nExample: wmic -U [domain/]adminuser%password //host \"select * from Win32_ComputerSystem\""); 66 67 while ((opt = poptGetNextOpt(pc)) != -1) { 68 poptPrintUsage(pc, stdout, 0); 69 poptFreeContext(pc); 70 exit(1); 45 poptContext pc; 46 int opt, i; 47 48 int argc_new; 49 char **argv_new; 50 51 struct poptOption long_options[] = { 52 POPT_AUTOHELP 53 POPT_COMMON_SAMBA 54 POPT_COMMON_CONNECTION 55 POPT_COMMON_CREDENTIALS 56 POPT_COMMON_VERSION 57 {"namespace", 0, POPT_ARG_STRING, &pmyargs->ns, 0, 58 "WMI namespace, default to root\\cimv2", 0}, 59 POPT_TABLEEND 60 }; 61 62 pc = poptGetContext("wmi", argc, (const char **) argv, 63 long_options, POPT_CONTEXT_KEEP_FIRST); 64 65 poptSetOtherOptionHelp(pc, "//host query\n\nExample: wmic -U [domain/]adminuser%password //host \"select * from Win32_ComputerSystem\""); 66 67 while ((opt = poptGetNextOpt(pc)) != -1) { 68 poptPrintUsage(pc, stdout, 0); 69 poptFreeContext(pc); 70 exit(1); 71 } 72 73 argv_new = discard_const_p(char *, poptGetArgs(pc)); 74 75 argc_new = argc; 76 for (i = 0; i < argc; i++) { 77 if (argv_new[i] == NULL) { 78 argc_new = i; 79 break; 71 80 } 72 73 argv_new = discard_const_p(char *, poptGetArgs(pc)); 74 75 argc_new = argc; 76 for (i = 0; i < argc; i++) { 77 if (argv_new[i] == NULL) { 78 argc_new = i; 79 break; 80 } 81 } 82 83 if (argc_new != 3 || argv_new[1][0] != '/' 84 || argv_new[1][1] != '/') { 85 poptPrintUsage(pc, stdout, 0); 86 poptFreeContext(pc); 87 exit(1); 88 } 89 90 pmyargs->hostname = argv_new[1] + 2; 91 pmyargs->query = argv_new[2]; 81 } 82 83 if (argc_new != 3 || argv_new[1][0] != '/' 84 || argv_new[1][1] != '/') { 85 poptPrintUsage(pc, stdout, 0); 92 86 poptFreeContext(pc); 93 } 94 95 static void escape_string(const char *src, char *dst, int len) 96 { 97 char *p = dst, *end = dst + len - 1; 98 const char *q = src; 99 100 if ( q == NULL) { 101 strncpy( dst, "(null)", len); 102 return; 103 } 104 105 while ( *q && p <= end ) { 106 if ( strchr( "|\\(),", *q)) { 107 *p++ = '\\'; 108 *p++ = *q++; 109 } else if ( *q == '\n' ) { 110 *p++ = '\\'; 111 *p++ = 'n'; 112 q++; 113 } else if ( *q == '\r' ) { 114 *p++ = '\\'; 115 *p++ = 'r'; 116 q++; 117 } else { 118 *p++ = *q++; 119 } 120 } 121 122 *p++ = 0; 87 exit(1); 88 } 89 90 pmyargs->hostname = argv_new[1] + 2; 91 pmyargs->query = argv_new[2]; 92 poptFreeContext(pc); 123 93 } 124 94 … … 130 100 } 131 101 132 #define RETURN_CVAR_ARRAY_STR _START(arr) {\133 102 #define RETURN_CVAR_ARRAY_STR(fmt, arr) {\ 103 uint32_t i;\ 134 104 char *r;\ 135 105 \ 136 137 return talloc_strdup(mem_ctx, "(null)");\138 106 if (!arr) {\ 107 return talloc_strdup(mem_ctx, "NULL");\ 108 }\ 139 109 r = talloc_strdup(mem_ctx, "(");\ 140 for (i = 0; i < arr->count; ++i) { 141 142 143 #define RETURN_CVAR_ARRAY_STR_END(fmt, arr, item) \ 144 r = talloc_asprintf_append(r, fmt "%s", item, (i+1 == arr->count)?"":",");\ 145 }\ 146 return talloc_asprintf_append(r, ")");\ 147 } 148 149 #define RETURN_CVAR_ARRAY_STR(fmt, arr) \ 150 RETURN_CVAR_ARRAY_STR_START(arr) \ 151 RETURN_CVAR_ARRAY_STR_END(fmt, arr, arr->item[i]) 152 153 #define RETURN_CVAR_ARRAY_ESCAPED(fmt, arr) \ 154 RETURN_CVAR_ARRAY_STR_START(arr) \ 155 char buf[2048]; \ 156 escape_string( arr->item[i], buf, 2048); \ 157 RETURN_CVAR_ARRAY_STR_END(fmt, arr, buf) 110 for (i = 0; i < arr->count; ++i) {\ 111 r = talloc_asprintf_append(r, fmt "%s", arr->item[i], (i+1 == arr->count)?"":",");\ 112 }\ 113 return talloc_asprintf_append(r, ")");\ 114 } 158 115 159 116 char *string_CIMVAR(TALLOC_CTX *mem_ctx, union CIMVAR *v, enum CIMTYPE_ENUMERATION cimtype) … … 173 130 case CIM_STRING: 174 131 case CIM_DATETIME: 175 case CIM_REFERENCE: { 176 char buf[2048]; 177 escape_string((char*) v-> v_string, buf, 2048); 178 return talloc_asprintf(mem_ctx, "%s", buf); 179 } 132 case CIM_REFERENCE: return talloc_asprintf(mem_ctx, "%s", v->v_string); 180 133 case CIM_CHAR16: return talloc_asprintf(mem_ctx, "Unsupported"); 181 134 case CIM_OBJECT: return talloc_asprintf(mem_ctx, "Unsupported"); … … 191 144 case CIM_ARR_REAL64: RETURN_CVAR_ARRAY_STR("%f", v->a_real64); 192 145 case CIM_ARR_BOOLEAN: RETURN_CVAR_ARRAY_STR("%d", v->a_boolean); 193 case CIM_ARR_STRING: RETURN_CVAR_ARRAY_ ESCAPED("%s", v->a_string);194 case CIM_ARR_DATETIME: RETURN_CVAR_ARRAY_ ESCAPED("%s", v->a_datetime);195 case CIM_ARR_REFERENCE: RETURN_CVAR_ARRAY_ ESCAPED("%s", v->a_reference);146 case CIM_ARR_STRING: RETURN_CVAR_ARRAY_STR("%s", v->a_string); 147 case CIM_ARR_DATETIME: RETURN_CVAR_ARRAY_STR("%s", v->a_datetime); 148 case CIM_ARR_REFERENCE: RETURN_CVAR_ARRAY_STR("%s", v->a_reference); 196 149 default: return talloc_asprintf(mem_ctx, "Unsupported"); 197 150 }
Note:
See TracChangeset
for help on using the changeset viewer.