Ignore:
Timestamp:
Nov 14, 2012, 12:59:34 PM (13 years ago)
Author:
Silvan Scherrer
Message:

Samba Server: update vendor to 3.6.0

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  
    3636
    3737struct program_args {
    38         char *hostname;
    39         char *query;
    40         char *ns;
     38    char *hostname;
     39    char *query;
     40    char *ns;
    4141};
    4242
    4343static void parse_args(int argc, char *argv[], struct program_args *pmyargs)
    4444{
    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;
    7180        }
    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);
    9286        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);
    12393}
    12494
     
    130100                        }
    131101
    132 #define RETURN_CVAR_ARRAY_STR_START(arr) {\
    133         uint32_t i;\
     102#define RETURN_CVAR_ARRAY_STR(fmt, arr) {\
     103        uint32_t i;\
    134104        char *r;\
    135105\
    136         if (!arr) {\
    137                 return talloc_strdup(mem_ctx, "(null)");\
    138         }\
     106        if (!arr) {\
     107                return talloc_strdup(mem_ctx, "NULL");\
     108        }\
    139109        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}
    158115
    159116char *string_CIMVAR(TALLOC_CTX *mem_ctx, union CIMVAR *v, enum CIMTYPE_ENUMERATION cimtype)
     
    173130        case CIM_STRING:
    174131        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);
    180133        case CIM_CHAR16: return talloc_asprintf(mem_ctx, "Unsupported");
    181134        case CIM_OBJECT: return talloc_asprintf(mem_ctx, "Unsupported");
     
    191144        case CIM_ARR_REAL64: RETURN_CVAR_ARRAY_STR("%f", v->a_real64);
    192145        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);
    196149        default: return talloc_asprintf(mem_ctx, "Unsupported");
    197150        }
Note: See TracChangeset for help on using the changeset viewer.