/******************************************************************************* * Copyright (C) 2004-2006 Intel Corp. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * * - Redistributions of source code must retain the above copyright notice, * this list of conditions and the following disclaimer. * * - Redistributions in binary form must reproduce the above copyright notice, * this list of conditions and the following disclaimer in the documentation * and/or other materials provided with the distribution. * * - Neither the name of Intel Corp. nor the names of its * contributors may be used to endorse or promote products derived from this * software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS'' * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL Intel Corp. OR THE CONTRIBUTORS * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. *******************************************************************************/ /** * @author Anas Nashif * @author Vadim Revyakin * @author Liang Hou */ #ifdef HAVE_CONFIG_H #include "config.h" #endif #include #include #include #ifdef HAVE_UNISTD_H #include #endif #include #include #include #include #include #if __linux__ extern char *getpass (const char *__prompt); #endif static int server_port = 0; static char *cainfo = NULL; static char *cert = NULL; static char *sslkey = NULL; static char *endpoint = NULL; static char *username = NULL; static char *password = NULL; static char *server = "localhost"; static char *url_path = NULL; static char *authentication_method = NULL; static char noverify_peer = 0; static char noverify_host = 0; static int transport_timeout = 0; static char *proxy = NULL; static char *proxy_upwd = NULL; static int debug_level = -1; static char *encoding = NULL; char dump_request = 0; char request_only = 0; static char *wsm_filter = NULL; static char *wsm_dialect = NULL; static char *event_delivery_mode = NULL; static char *event_delivery_sec_mode = NULL; static char *event_delivery_uri = NULL; static int event_subscription_expire = 0; static int event_heartbeat = 0; static int event_sendbookmark =0; static char *event_subscription_id = NULL; static char *event_reference_properties = NULL; static char *event_username = NULL; static char *event_password = NULL; static char *event_thumbprint = NULL; static char *enum_context = NULL; static int eventsink_enabled = 0; static char *cim_namespace = NULL; static char *_action = NULL; static char *config_file = NULL; static char *output_file = NULL; static char *resource_uri_opt = NULL; struct _WsActions { char *action; int value; }; typedef struct _WsActions WsActions; WsActions action_data[] = { {"pull", WSMAN_ACTION_PULL}, {"subscribe", WSMAN_ACTION_SUBSCRIBE}, {"unsubscribe", WSMAN_ACTION_UNSUBSCRIBE}, {"renew", WSMAN_ACTION_RENEW}, {"test", WSMAN_ACTION_TEST}, {NULL, 0}, }; WsActions delivery_mode[] = { {"push", WSMAN_DELIVERY_PUSH}, {"pushwithack", WSMAN_DELIVERY_PUSHWITHACK}, {"events", WSMAN_DELIVERY_EVENTS}, {"pull", WSMAN_DELIVERY_PULL}, {NULL, 0} }; WsActions delivery_sec_mode[] = { {"httpbasic", WSMAN_DELIVERY_SEC_HTTP_BASIC}, {"httpdigest", WSMAN_DELIVERY_SEC_HTTP_DIGEST}, {"httpsbasic", WSMAN_DELIVERY_SEC_HTTPS_BASIC}, {"httpsdigest", WSMAN_DELIVERY_SEC_HTTPS_DIGEST}, {"httpsmutual", WSMAN_DELIVERY_SEC_HTTPS_MUTUAL}, {"httpsmutualbasic", WSMAN_DELIVERY_SEC_HTTPS_MUTUAL_BASIC}, {"httpsmutualdigest", WSMAN_DELIVERY_SEC_HTTPS_MUTUAL_DIGEST}, {NULL, 0} }; static int wsman_options_get_action(void) { int op = 0; int i; for (i = 0; action_data[i].action != NULL; i++) { if (strcmp(action_data[i].action, _action) == 0) { op = action_data[i].value; break; } } return op; } static char wsman_parse_options(int argc, char **argv) { char retval = 0; u_error_t *error = NULL; u_option_entry_t options[] = { {"debug", 'd', U_OPTION_ARG_INT, &debug_level, "Set the verbosity of debugging output.", "1-6"}, {"print-request", 'R', U_OPTION_ARG_NONE, &dump_request, "print request on stdout", NULL}, {"encoding", 'j', U_OPTION_ARG_STRING, &encoding, "Set request message encoding"}, {"cacert", 'c', U_OPTION_ARG_STRING, &cainfo, "Certificate file to verify the peer", ""}, {"cert", 'A', U_OPTION_ARG_STRING, &cert, "Certificate file. The certificate must be in PEM format.", ""}, {"sslkey", 'K', U_OPTION_ARG_STRING, &sslkey, "SSL Key.", ""}, {"username", 'u', U_OPTION_ARG_STRING, &username, "User name", ""}, {"path", 'g', U_OPTION_ARG_STRING, &url_path, "Path", ""}, {"password", 'p', U_OPTION_ARG_STRING, &password, "Password", ""}, {"hostname", 'h', U_OPTION_ARG_STRING, &server, "Host name", ""}, {"endpoint", 'b', U_OPTION_ARG_STRING, &endpoint, "End point", ""}, {"port", 'P', U_OPTION_ARG_INT, &server_port, "Server Port", ""}, {"proxy", 'X', U_OPTION_ARG_STRING, &proxy, "Proxy name", ""}, {"proxyauth", 'Y', U_OPTION_ARG_STRING, &proxy_upwd, "Proxy user:pwd", ""}, {"auth", 'y', U_OPTION_ARG_STRING, &authentication_method, "Authentication Method", ""}, {"config-file", 'C', U_OPTION_ARG_STRING, &config_file, "Alternate configuration file", ""}, {"out-file", 'O', U_OPTION_ARG_STRING, &output_file, "Write output to file", ""}, {"noverifypeer", 'V', U_OPTION_ARG_NONE, &noverify_peer, "Not to verify peer certificate", NULL}, {"noverifyhost", 'v', U_OPTION_ARG_NONE, &noverify_host, "Not to verify hostname", NULL}, {"transport-timeout", 'I', U_OPTION_ARG_INT, &transport_timeout, "Transport timeout in seconds", "