openwsman-2.4.3/src/server/shttpd/shttpd.c000664 001750 001750 00000110323 12256012305 021052 0ustar00kentbkentb000000 000000 /* * Copyright (c) 2004-2005 Sergey Lyubka * All rights reserved * * "THE BEER-WARE LICENSE" (Revision 42): * Sergey Lyubka wrote this file. As long as you retain this notice you * can do whatever you want with this stuff. If we meet some day, and you think * this stuff is worth it, you can buy me a beer in return. */ /* * Small and portable HTTP server, http://shttpd.sourceforge.net * $Id: shttpd.c,v 1.18 2008/01/10 11:01:21 drozd Exp $ */ #include "shttpd_defs.h" /* from src/server/wsmand-daemon.h */ extern int wsmand_options_get_use_ipv4(void); #ifdef ENABLE_IPV6 extern int wsmand_options_get_use_ipv6(void); extern void wsmand_options_disable_use_ipv6(void); #endif time_t current_time; /* Current UTC time */ int tz_offset; /* Time zone offset from UTC */ static LL_HEAD(listeners); /* List of listening sockets */ const struct vec known_http_methods[] = { /* {"GET", 3}, */ {"POST", 4}, /* {"PUT", 3}, {"DELETE", 6}, {"HEAD", 4}, */ {NULL, 0} }; struct listener { struct llhead link; struct shttpd_ctx *ctx; /* Context that socket belongs */ int sock; /* Listening socket */ int is_ssl; /* Should be SSL-ed */ }; /* * This structure tells how HTTP headers must be parsed. * Used by parse_headers() function. */ #define OFFSET(x) offsetof(struct headers, x) static const struct http_header http_headers[] = { {16, HDR_INT, OFFSET(cl), "Content-Length: " }, {14, HDR_STRING, OFFSET(ct), "Content-Type: " }, {12, HDR_STRING, OFFSET(useragent), "User-Agent: " }, {19, HDR_DATE, OFFSET(ims), "If-Modified-Since: " }, {15, HDR_STRING, OFFSET(auth), "Authorization: " }, {9, HDR_STRING, OFFSET(referer), "Referer: " }, {8, HDR_STRING, OFFSET(cookie), "Cookie: " }, {10, HDR_STRING, OFFSET(location), "Location: " }, {8, HDR_INT, OFFSET(status), "Status: " }, {7, HDR_STRING, OFFSET(range), "Range: " }, {12, HDR_STRING, OFFSET(connection), "Connection: " }, {19, HDR_STRING, OFFSET(transenc), "Transfer-Encoding: " }, {0, HDR_INT, 0, NULL } }; struct shttpd_ctx *init_ctx(const char *config_file, int argc, char *argv[]); static void process_connection(struct conn *, int, int); int url_decode(const char *src, int src_len, char *dst, int dst_len) { int i, j, a, b; #define HEXTOI(x) (isdigit(x) ? x - '0' : x - 'W') for (i = j = 0; i < src_len && j < dst_len - 1; i++, j++) switch (src[i]) { case '%': if (isxdigit(((unsigned char *) src)[i + 1]) && isxdigit(((unsigned char *) src)[i + 2])) { a = tolower(((unsigned char *)src)[i + 1]); b = tolower(((unsigned char *)src)[i + 2]); dst[j] = (HEXTOI(a) << 4) | HEXTOI(b); i += 2; } else { dst[j] = '%'; } break; default: dst[j] = src[i]; break; } dst[j] = '\0'; /* Null-terminate the destination */ return (j); } void shttpd_add_mime_type(struct shttpd_ctx *ctx, const char *ext, const char *mime) { struct mime_type_link *e; const char *error_msg = "shttpd_add_mime_type: no memory"; if ((e = malloc(sizeof(*e))) == NULL) { elog(E_FATAL, 0, error_msg); } else if ((e->ext= strdup(ext)) == NULL) { elog(E_FATAL, 0, error_msg); } else if ((e->mime = strdup(mime)) == NULL) { elog(E_FATAL, 0, error_msg); } else { e->ext_len = strlen(ext); LL_TAIL(&ctx->mime_types, &e->link); } } static const char * is_alias(struct shttpd_ctx *ctx, const char *uri, struct vec *a_uri, struct vec *a_path) { const char *p, *s = ctx->aliases; size_t len; DBG(("is_alias: aliases [%s]", s == NULL ? "" : s)); FOR_EACH_WORD_IN_LIST(s, len) { if ((p = memchr(s, '=', len)) != NULL && memcmp(uri, s, p - s) == 0) { a_uri->ptr = s; a_uri->len = p - s; a_path->ptr = ++p; a_path->len = (s + len) - p; return (s); } } return (NULL); } void stop_stream(struct stream *stream) { if (stream->io_class != NULL && stream->io_class->close != NULL) stream->io_class->close(stream); stream->io_class= NULL; stream->flags |= FLAG_CLOSED; stream->flags &= ~(FLAG_R | FLAG_W | FLAG_ALWAYS_READY); DBG(("%d %s stopped. %lu of content data, %d now in a buffer", stream->conn->rem.chan.sock, stream->io_class ? stream->io_class->name : "(null)", (unsigned long) stream->io.total, io_data_len(&stream->io))); } /* * Setup listening socket on given port, return socket */ static int open_listening_port(int port) { int sock = -1, on = 1; struct usa sa; #ifdef _WIN32 {WSADATA data; WSAStartup(MAKEWORD(2,2), &data);} #endif /* _WIN32 */ #ifdef ENABLE_IPV6 sa.len = sizeof(sa.u.sin6); memset(&sa.u.sin6, 0, sa.len); sa.u.sin6.sin6_family = AF_INET6; sa.u.sin6.sin6_addr = in6addr_any; sa.u.sin6.sin6_port = htons((uint16_t) port); sa.u.sin6.sin6_flowinfo = 0; sa.u.sin6.sin6_scope_id = 0; if (!wsmand_options_get_use_ipv6() || (sock = socket(AF_INET6, SOCK_STREAM, 6)) == -1) { wsmand_options_disable_use_ipv6(); if (wsmand_options_get_use_ipv4()) { #endif sa.len = sizeof(sa.u.sin); memset(&sa.u.sin, 0, sa.len); sa.u.sin.sin_family = AF_INET; sa.u.sin.sin_addr.s_addr = htonl(INADDR_ANY); sa.u.sin.sin_port = htons((uint16_t) port); if ((sock = socket(PF_INET, SOCK_STREAM, 6)) == -1) goto fail; #ifdef ENABLE_IPV6 } else goto fail; } #endif if (set_non_blocking_mode(sock) != 0) goto fail; if (setsockopt(sock, SOL_SOCKET, SO_REUSEADDR,(char *) &on, sizeof(on)) != 0) goto fail; if (bind(sock, &sa.u.sa, sa.len) < 0) goto fail; if (listen(sock, 128) != 0) goto fail; #ifndef _WIN32 (void) fcntl(sock, F_SETFD, FD_CLOEXEC); #endif /* !_WIN32 */ return (sock); fail: if (sock != -1) (void) closesocket(sock); elog(E_LOG, NULL, "open_listening_port(%d): %s", port, strerror(errno)); return (-1); } /* * Check whether full request is buffered Return headers length, or 0 */ int get_headers_len(const char *buf, size_t buflen) { const char *s, *e; int len = 0; for (s = buf, e = s + buflen - 1; len == 0 && s < e; s++) /* Control characters are not allowed but >=128 is. */ if (!isprint(* (unsigned char *) s) && *s != '\r' && *s != '\n' && * (unsigned char *) s < 128) len = -1; else if (s[0] == '\n' && s[1] == '\n') len = s - buf + 2; else if (s[0] == '\n' && &s[1] < e && s[1] == '\r' && s[2] == '\n') len = s - buf + 3; return (len); } /* * Send error message back to a client. */ void send_server_error(struct conn *c, int status, const char *reason) { #ifdef EMBEDDED struct llhead *lp; struct error_handler *e; LL_FOREACH(&c->ctx->error_handlers, lp) { e = LL_ENTRY(lp, struct error_handler, link); if (e->code == status) { if (c->loc.io_class != NULL && c->loc.io_class->close != NULL) c->loc.io_class->close(&c->loc); io_clear(&c->loc.io); setup_embedded_stream(c, e->callback, e->callback_data); return; } } #endif /* EMBEDDED */ io_clear(&c->loc.io); c->loc.headers_len = c->loc.io.head = snprintf(c->loc.io.buf, c->loc.io.size, "HTTP/1.1 %d %s\r\nConnection: Close\r\n\r\n%d %s", status, reason, status, reason); c->status = status; stop_stream(&c->loc); } /* * Convert month to the month number. Return -1 on error, or month number */ static int montoi(const char *s) { static const char *ar[] = { "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" }; size_t i; for (i = 0; i < sizeof(ar) / sizeof(ar[0]); i++) if (!strcmp(s, ar[i])) return (i); return (-1); } /* * Parse date-time string, and return the corresponding time_t value */ static time_t date_to_epoch(const char *s) { struct tm tm, *tmp; char mon[32]; int sec, min, hour, mday, month, year; (void) memset(&tm, 0, sizeof(tm)); sec = min = hour = mday = month = year = 0; if (((sscanf(s, "%d/%3s/%d %d:%d:%d", &mday, mon, &year, &hour, &min, &sec) == 6) || (sscanf(s, "%d %3s %d %d:%d:%d", &mday, mon, &year, &hour, &min, &sec) == 6) || (sscanf(s, "%*3s, %d %3s %d %d:%d:%d", &mday, mon, &year, &hour, &min, &sec) == 6) || (sscanf(s, "%d-%3s-%d %d:%d:%d", &mday, mon, &year, &hour, &min, &sec) == 6)) && (month = montoi(mon)) != -1) { tm.tm_mday = mday; tm.tm_mon = month; tm.tm_year = year; tm.tm_hour = hour; tm.tm_min = min; tm.tm_sec = sec; } if (tm.tm_year > 1900) tm.tm_year -= 1900; else if (tm.tm_year < 70) tm.tm_year += 100; /* Set Daylight Saving Time field */ tmp = localtime(¤t_time); tm.tm_isdst = tmp->tm_isdst; return (mktime(&tm)); } static void remove_double_dots(char *s) { char *p = s; while (*s != '\0') { *p++ = *s++; if (s[-1] == '/' || s[-1] == '\\') while (*s == '.' || *s == '/' || *s == '\\') s++; } *p = '\0'; } void parse_headers(const char *s, int len, struct headers *parsed) { const struct http_header *h; union variant *v; const char *p, *e = s + len; DBG(("parsing headers (len %d): [%.*s]", len, len, s)); /* Loop through all headers in the request */ while (s < e) { /* Find where this header ends */ for (p = s; p < e && *p != '\n'; ) p++; /* Is this header known to us ? */ for (h = http_headers; h->len != 0; h++) if (e - s > h->len && !strncasecmp(s, h->name, h->len)) break; /* If the header is known to us, store its value */ if (h->len != 0) { /* Shift to where value starts */ s += h->len; /* Find place to store the value */ v = (union variant *) ((char *) parsed + h->offset); /* Fetch header value into the connection structure */ if (h->type == HDR_STRING) { v->v_vec.ptr = s; v->v_vec.len = p - s; if (p[-1] == '\r' && v->v_vec.len > 0) v->v_vec.len--; } else if (h->type == HDR_INT) { v->v_big_int = strtoul(s, NULL, 10); } else if (h->type == HDR_DATE) { v->v_time = date_to_epoch(s); } } s = p + 1; /* Shift to the next header */ } } /* * For given directory path, substitute it to valid index file. * Return 0 if index file has been found, -1 if not found */ static int find_index_file(struct conn *c, char *path, size_t maxpath, struct stat *stp) { char buf[FILENAME_MAX]; const char *s = c->ctx->index_files; int len; FOR_EACH_WORD_IN_LIST(s, len) { snprintf(buf, sizeof(buf), "%s%c%.*s",path, DIRSEP, len, s); if (my_stat(buf, stp) == 0) { my_strlcpy(path, buf, maxpath); c->mime_type = get_mime_type(c->ctx, s, len); return (0); } } return (-1); } /* * Try to open requested file, return 0 if OK, -1 if error. * If the file is given arguments using PATH_INFO mechanism, * initialize pathinfo pointer. */ static int get_path_info(struct conn *c, char *path, struct stat *stp) { char *p, *e; if (my_stat(path, stp) == 0) return (0); p = path + strlen(path); e = path + strlen(c->ctx->document_root) + 2; /* Strip directory parts of the path one by one */ for (; p > e; p--) if (*p == '/') { *p = '\0'; if (!my_stat(path, stp) && !S_ISDIR(stp->st_mode)) { c->path_info = p + 1; return (0); } else { *p = '/'; } } return (-1); } static void decide_what_to_do(struct conn *c) { char path[URI_MAX], buf[1024]; struct vec alias_uri, alias_path; struct stat st; int rc; #ifdef EMBEDDED struct registered_uri *ruri; #endif /* EMBEDDED */ DBG(("decide_what_to_do: [%s]", c->uri)); if ((c->query = strchr(c->uri, '?')) != NULL) *c->query++ = '\0'; url_decode(c->uri, strlen(c->uri), c->uri, strlen(c->uri) + 1); remove_double_dots(c->uri); if (strlen(c->uri) + strlen(c->ctx->document_root) >= sizeof(path)) { send_server_error(c, 400, "URI is too long"); return; } (void) snprintf(path, sizeof(path), "%s%s", c->ctx->document_root, c->uri); /* User may use the aliases - check URI for mount point */ if (is_alias(c->ctx, c->uri, &alias_uri, &alias_path) != NULL) { (void) snprintf(path, sizeof(path), "%.*s%s", alias_path.len, alias_path.ptr, c->uri + alias_uri.len); DBG(("using alias %.*s -> %.*s", alias_uri.len, alias_uri.ptr, alias_path.len, alias_path.ptr)); } #if !defined(NO_AUTH) rc = check_authorization(c, path); if(rc != 1) { if(rc != 2) /* 2 = multipass auth (GSS)*/ send_authorization_request(c); } else #endif /* NO_AUTH */ #ifdef EMBEDDED if ((ruri = is_registered_uri(c->ctx, c->uri)) != NULL) { setup_embedded_stream(c, ruri->callback, ruri->callback_data); } else #endif /* EMBEDDED */ if (strstr(path, HTPASSWD)) { /* Do not allow to view passwords files */ send_server_error(c, 403, "Forbidden"); } else #if !defined(NO_AUTH) if ((c->method == METHOD_PUT || c->method == METHOD_DELETE) && (c->ctx->put_auth_file == NULL || !is_authorized_for_put(c))) { send_authorization_request(c); } else #endif /* NO_AUTH */ if (c->method == METHOD_PUT) { c->status = my_stat(path, &st) == 0 ? 200 : 201; if (c->ch.range.v_vec.len > 0) { send_server_error(c, 501, "PUT Range Not Implemented"); } else if ((rc = put_dir(path)) == 0) { send_server_error(c, 200, "OK"); } else if (rc == -1) { send_server_error(c, 500, "PUT Directory Error"); } else if (c->rem.content_len == 0) { send_server_error(c, 411, "Length Required"); } else if ((c->loc.chan.fd = my_open(path, O_WRONLY | O_BINARY | O_CREAT | O_NONBLOCK | O_TRUNC, 0644)) == -1) { send_server_error(c, 500, "PUT Error"); } else { DBG(("PUT file [%s]", c->uri)); c->loc.io_class = &io_file; c->loc.flags |= FLAG_W | FLAG_ALWAYS_READY ; } } else if (c->method == METHOD_DELETE) { DBG(("DELETE [%s]", c->uri)); if (my_remove(path) == 0) send_server_error(c, 200, "OK"); else send_server_error(c, 500, "DELETE Error"); } else if (get_path_info(c, path, &st) != 0) { send_server_error(c, 404, "Not Found"); } else if (S_ISDIR(st.st_mode) && path[strlen(path) - 1] != '/') { (void) snprintf(buf, sizeof(buf), "Moved Permanently\r\nLocation: %s/", c->uri); send_server_error(c, 301, buf); } else if (S_ISDIR(st.st_mode) && find_index_file(c, path, sizeof(path) - 1, &st) == -1 && c->ctx->dirlist == 0) { send_server_error(c, 403, "Directory Listing Denied"); } else if (S_ISDIR(st.st_mode) && c->ctx->dirlist) { if ((c->loc.chan.dir.path = strdup(path)) != NULL) get_dir(c); else send_server_error(c, 500, "GET Directory Error"); } else if (S_ISDIR(st.st_mode) && c->ctx->dirlist == 0) { send_server_error(c, 403, "Directory listing denied"); #if !defined(NO_CGI) } else if (match_extension(path, c->ctx->cgi_extensions)) { if (c->method != METHOD_POST && c->method != METHOD_GET) { send_server_error(c, 501, "Bad method "); } else if ((run_cgi(c, path)) == -1) { send_server_error(c, 500, "Cannot exec CGI"); } else { do_cgi(c); } #endif /* NO_CGI */ #if !defined(NO_SSI) } else if (match_extension(path, c->ctx->ssi_extensions)) { if ((c->loc.chan.fd = my_open(path, O_RDONLY | O_BINARY, 0644)) == -1) { send_server_error(c, 500, "SSI open error"); } else { do_ssi(c); } #endif /* NO_CGI */ } else if (c->ch.ims.v_time && st.st_mtime <= c->ch.ims.v_time) { send_server_error(c, 304, "Not Modified"); } else if ((c->loc.chan.fd = my_open(path, O_RDONLY | O_BINARY, 0644)) != -1) { get_file(c, &st); } else { send_server_error(c, 500, "Internal Error"); } } static int set_request_method(struct conn *c) { const struct vec *v; assert(c->rem.io.head >= MIN_REQ_LEN); /* Set the request method */ for (v = known_http_methods; v->ptr != NULL; v++) if (!memcmp(c->rem.io.buf, v->ptr, v->len)) { c->method = v - known_http_methods; break; } return (v->ptr == NULL); } static void parse_http_request(struct conn *c) { char *s, *e, *p, *start; char *end_number; int uri_len, req_len; s = io_data(&c->rem.io);; req_len = c->rem.headers_len = get_headers_len(s, io_data_len(&c->rem.io)); if (req_len == 0 && io_space_len(&c->rem.io) == 0) send_server_error(c, 400, "Request is too big"); if (req_len == 0) return; else if (req_len < MIN_REQ_LEN) send_server_error(c, 400, "Bad request"); else if (set_request_method(c)) send_server_error(c, 501, "Method Not Implemented"); else if ((c->request = u_strndup(s, req_len)) == NULL) send_server_error(c, 500, "Cannot allocate request"); if (c->loc.flags & FLAG_CLOSED) return; DBG(("Conn %d: parsing request: [%.*s]", c->rem.chan.sock, req_len, s)); c->rem.flags |= FLAG_HEADERS_PARSED; /* Set headers pointer. Headers follow the request line */ c->headers = memchr(c->request, '\n', req_len); assert(c->headers != NULL); assert(c->headers < c->request + req_len); if (c->headers > c->request && c->headers[-1] == '\r') c->headers[-1] = '\0'; *c->headers++ = '\0'; /* * Now make a copy of the URI, because it will be URL-decoded, * and we need a copy of unmodified URI for the access log. * First, we skip the REQUEST_METHOD and shift to the URI. */ for (p = c->request, e = p + req_len; *p != ' ' && p < e; p++); while (p < e && *p == ' ') p++; /* Now remember where URI starts, and shift to the end of URI */ for (start = p; p < e && !isspace((unsigned char)*p); ) p++; uri_len = p - start; /* Skip space following the URI */ while (p < e && *p == ' ') p++; /* Now comes the HTTP-Version in the form HTTP/. */ if (strncmp(p, "HTTP/", 5) != 0) { send_server_error(c, 400, "Bad HTTP version"); return; } p += 5; /* Parse the HTTP major version number */ c->major_version = strtoul(p, &end_number, 10); if (end_number == p || *end_number != '.') { send_server_error(c, 400, "Bad HTTP major version"); return; } p = end_number + 1; /* Parse the minor version number */ c->minor_version = strtoul(p, &end_number, 10); if (end_number == p || *end_number != '\0') { send_server_error(c, 400, "Bad HTTP minor version"); return; } /* Version must be <=1.1 */ if (c->major_version > 1 || (c->major_version == 1 && c->minor_version > 1)) { send_server_error(c, 505, "HTTP version not supported"); return; } if (uri_len <= 0) { send_server_error(c, 400, "Bad URI"); } else if ((c->uri = malloc(uri_len + 1)) == NULL) { send_server_error(c, 500, "Cannot allocate URI"); } else { my_strlcpy(c->uri, (char *) start, uri_len + 1); parse_headers(c->headers, (c->request + req_len) - c->headers, &c->ch); /* Remove the length of request from total, count only data */ assert(c->rem.io.total >= (big_int_t) req_len); c->rem.io.total -= req_len; c->rem.content_len = c->ch.cl.v_big_int; io_inc_tail(&c->rem.io, req_len); decide_what_to_do(c); } } void shttpd_add_socket(struct shttpd_ctx *ctx, int sock, int is_ssl) { struct conn *c; struct usa sa; int l = ctx->inetd_mode ? E_FATAL : E_LOG; #if !defined(NO_SSL) SSL *ssl = NULL; #endif /* NO_SSL */ sa.len = sizeof(sa.u.sin); (void) set_non_blocking_mode(sock); if (getpeername(sock, &sa.u.sa, &sa.len)) { elog(l, NULL, "add_socket: %s", strerror(errno)); #if !defined(NO_SSL) } else if (is_ssl && (ssl = SSL_new(ctx->ssl_ctx)) == NULL) { elog(l, NULL, "add_socket: SSL_new: %s", strerror(ERRNO)); (void) closesocket(sock); } else if (is_ssl && SSL_set_fd(ssl, sock) == 0) { elog(l, NULL, "add_socket: SSL_set_fd: %s", strerror(ERRNO)); (void) closesocket(sock); SSL_free(ssl); #endif /* NO_SSL */ } else if ((c = calloc(1, sizeof(*c) + 2 * ctx->io_buf_size)) == NULL) { #if !defined(NO_SSL) if (ssl) SSL_free(ssl); #endif /* NO_SSL */ (void) closesocket(sock); elog(l, NULL, "add_socket: calloc: %s", strerror(ERRNO)); } else { ctx->nrequests++; c->rem.conn = c->loc.conn = c; c->ctx = ctx; c->sa = sa; c->birth_time = current_time; c->expire_time = current_time + EXPIRE_TIME; (void) getsockname(sock, &sa.u.sa, &sa.len); #ifdef ENABLE_IPV6 if (wsmand_options_get_use_ipv6()) { c->loc_port = sa.u.sin6.sin6_port; } else { #endif c->loc_port = sa.u.sin.sin_port; #ifdef ENABLE_IPV6 } #endif set_close_on_exec(sock); c->loc.io_class = NULL; c->rem.io_class = &io_socket; c->rem.chan.sock = sock; /* Set IO buffers */ c->loc.io.buf = (char *) (c + 1); c->rem.io.buf = c->loc.io.buf + ctx->io_buf_size; c->loc.io.size = c->rem.io.size = ctx->io_buf_size; #ifdef SHTTPD_GSS c->gss_ctx = GSS_C_NO_CONTEXT; #endif #if !defined(NO_SSL) if (is_ssl) { c->rem.io_class = &io_ssl; c->rem.chan.ssl.sock = sock; c->rem.chan.ssl.ssl = ssl; ssl_handshake(&c->rem); } #endif /* NO_SSL */ EnterCriticalSection(&ctx->mutex); LL_TAIL(&ctx->connections, &c->link); ctx->nactive++; LeaveCriticalSection(&ctx->mutex); #ifdef ENABLE_IPV6 if (wsmand_options_get_use_ipv6()) { char str[INET6_ADDRSTRLEN]; inet_ntop( AF_INET6,&sa.u.sin6.sin6_addr, str, sizeof(str)); DBG(("%s:%hu connected IPv6 (socket %d)", str , ntohs(sa.u.sin6.sin6_port), sock)); } else { #endif DBG(("%s:%hu connected IPv4 (socket %d)", inet_ntoa(* (struct in_addr *) &sa.u.sin.sin_addr.s_addr), ntohs(sa.u.sin.sin_port), sock)); #ifdef ENABLE_IPV6 } #endif } } int shttpd_active(struct shttpd_ctx *ctx) { return (ctx->nactive); } /* * Setup a listening socket on given port. Return opened socket or -1 */ int shttpd_listen(struct shttpd_ctx *ctx, int port, int is_ssl) { struct listener *l; int sock; if ((sock = open_listening_port(port)) == -1) { elog(E_FATAL, NULL, "cannot open port %d", port); } else if ((l = calloc(1, sizeof(*l))) == NULL) { (void) closesocket(sock); elog(E_FATAL, NULL, "cannot allocate listener"); } else if (is_ssl && ctx->ssl_ctx == NULL) { (void) closesocket(sock); elog(E_FATAL, NULL, "cannot add SSL socket, " "please specify certificate file"); } else { l->is_ssl = is_ssl; l->sock = sock; l->ctx = ctx; LL_TAIL(&listeners, &l->link); DBG(("shttpd_listen: added socket %d", sock)); } return (sock); } int shttpd_accept(int lsn_sock, int milliseconds) { struct timeval tv; struct usa sa; fd_set read_set; int sock = -1; tv.tv_sec = milliseconds / 1000; tv.tv_usec = milliseconds % 1000; sa.len = sizeof(sa.u.sin); FD_ZERO(&read_set); FD_SET(lsn_sock, &read_set); if (select(lsn_sock + 1, &read_set, NULL, NULL, &tv) == 1) sock = accept(lsn_sock, &sa.u.sa, &sa.len); return (sock); } static void read_stream(struct stream *stream) { int n, len; int sslerr = 0; len = io_space_len(&stream->io); assert(len > 0); /* Do not read more that needed */ if (stream->content_len > 0 && stream->io.total + len > stream->content_len) len = stream->content_len - stream->io.total; /* Read from underlying channel */ n = stream->nread_last = stream->io_class->read(stream, io_space(&stream->io), len); if (n > 0) { io_inc_head(&stream->io, n); stream->flags &= ~FLAG_SSL_SHOULD_SELECT_ON_WRITE; } else if (n == -1) { if(stream->chan.ssl.ssl) { sslerr = SSL_get_error(stream->chan.ssl.ssl, n); } /* Ignore SSL_ERROR_WANT_READ and SSL_ERROR_WANT_WRITE*/ if((stream->chan.ssl.ssl && sslerr == SSL_ERROR_SYSCALL && (ERRNO == EINTR || ERRNO == EWOULDBLOCK)) || (ERRNO == EINTR || ERRNO == EWOULDBLOCK)) { n = n; /* Ignore EINTR and EAGAIN */ } else if(sslerr == SSL_ERROR_WANT_READ) { n = n; } else if(sslerr == SSL_ERROR_WANT_WRITE) { stream->flags |= FLAG_SSL_SHOULD_SELECT_ON_WRITE; } else if (!(stream->flags & FLAG_DONT_CLOSE)) stop_stream(stream); } else if (!(stream->flags & FLAG_DONT_CLOSE)) stop_stream(stream); #if 0 DBG(("read_stream (%d %s): read %d/%d/%lu bytes (errno %d)", stream->conn->rem.chan.sock, stream->io_class ? stream->io_class->name : "(null)", n, len, (unsigned long) stream->io.total, ERRNO)); #endif /* * Close the local stream if everything was read * XXX We do not close the remote stream though! It may be * a POST data completed transfer, we do not want the socket * to be closed. */ if (stream->content_len > 0 && stream == &stream->conn->loc) { assert(stream->io.total <= stream->content_len); if (stream->io.total == stream->content_len) stop_stream(stream); } stream->conn->expire_time = current_time + EXPIRE_TIME; } static void write_stream(struct stream *from, struct stream *to) { int n, len; int sslerr = 0; len = io_data_len(&from->io); assert(len > 0); /* TODO: should be assert on CAN_WRITE flag */ n = to->io_class->write(to, io_data(&from->io), len); to->conn->expire_time = current_time + EXPIRE_TIME; /* DBG(("write_stream (%d %s): written %d/%d bytes (errno %d)", to->conn->rem.chan.sock, to->io_class ? to->io_class->name : "(null)", n, len, ERRNO)); */ if (n > 0) { io_inc_tail(&from->io, n); to->flags &= ~FLAG_SSL_SHOULD_SELECT_ON_READ; } else if (n == -1) { if(to->chan.ssl.ssl) { sslerr = SSL_get_error(to->chan.ssl.ssl, n); } /* Ignore SSL_ERROR_WANT_READ and SSL_ERROR_WANT_WRITE*/ if((to->chan.ssl.ssl && sslerr == SSL_ERROR_SYSCALL && (ERRNO == EINTR || ERRNO == EWOULDBLOCK)) || (ERRNO == EINTR || ERRNO == EWOULDBLOCK)) { n = n; /* Ignore EINTR and EAGAIN */ } else if(sslerr == SSL_ERROR_WANT_WRITE) { n = n; } else if(sslerr == SSL_ERROR_WANT_READ) { to->flags |= FLAG_SSL_SHOULD_SELECT_ON_READ; } else if (!(to->flags & FLAG_DONT_CLOSE)) stop_stream(to); } else if (!(to->flags & FLAG_DONT_CLOSE)) stop_stream(to); } static void disconnect(struct llhead *lp) { struct conn *c = LL_ENTRY(lp, struct conn, link); static const struct vec ka = {"keep-alive", 10}; int dont_close; DBG(("Disconnecting %d (%.*s)", c->rem.chan.sock, c->ch.connection.v_vec.len, c->ch.connection.v_vec.ptr)); #if !defined(_WIN32) || defined(NO_GUI) if (c->ctx->access_log != NULL) #endif /* _WIN32 */ // log_access(c->ctx->access_log, c); /* In inetd mode, exit if request is finished. */ if (c->ctx->inetd_mode) exit(0); if (c->loc.io_class != NULL && c->loc.io_class->close != NULL) c->loc.io_class->close(&c->loc); /* * Check the "Connection: " header before we free c->request * If it its 'keep-alive', then do not close the connection */ dont_close = c->ch.connection.v_vec.len >= ka.len && !strncasecmp(ka.ptr, c->ch.connection.v_vec.ptr, ka.len); dont_close = 0; if (c->request) free(c->request); if (c->uri) free(c->uri); /* Handle Keep-Alive */ if (dont_close) { c->loc.io_class = NULL; c->loc.flags = 0; c->rem.flags = FLAG_W | FLAG_R; c->query = c->request = c->uri = c->path_info = NULL; c->mime_type = NULL; (void) memset(&c->ch, 0, sizeof(c->ch)); io_clear(&c->loc.io); if (io_data_len(&c->rem.io) > 0) process_connection(c, 0, 0); } else { if (c->rem.io_class != NULL) c->rem.io_class->close(&c->rem); EnterCriticalSection(&c->ctx->mutex); LL_DEL(&c->link); c->ctx->nactive--; assert(c->ctx->nactive >= 0); LeaveCriticalSection(&c->ctx->mutex); #ifdef SHTTPD_GSS { OM_uint32 majStat, minStat; majStat = gss_delete_sec_context(&minStat, c->gss_ctx, 0); } #endif free(c); } } static int is_allowed(const struct shttpd_ctx *ctx, const struct usa *usa) { const struct acl *acl; const struct llhead *lp; int allowed = '+'; uint32_t ip; LL_FOREACH(&ctx->acl, lp) { acl = LL_ENTRY(lp, struct acl, link); #ifdef ENABLE_IPV6 if (wsmand_options_get_use_ipv6()) return allowed; #endif (void) memcpy(&ip, &usa->u.sin.sin_addr, sizeof(ip)); if (acl->ip == (ntohl(ip) & acl->mask)) allowed = acl->flag; } return (allowed == '+'); } static void add_to_set(int fd, fd_set *set, int *max_fd) { FD_SET(fd, set); if (fd > *max_fd) *max_fd = fd; } static void process_connection(struct conn *c, int remote_ready, int local_ready) { #if 0 DBG(("loc: %u [%.*s]", io_data_len(&c->loc.io), io_data_len(&c->loc.io), io_data(&c->loc.io))); DBG(("rem: %u [%.*s]", io_data_len(&c->rem.io), io_data_len(&c->rem.io), io_data(&c->rem.io))); DBG(("locf=%x,remf=%x", c->loc.flags,c->rem.flags)); #endif /* Read from remote end if it is ready */ if(c->loc.flags & FLAG_RESPONSE_COMPLETE) c->rem.flags &= ~ FLAG_HEADERS_PARSED; if (remote_ready && io_space_len(&c->rem.io)) read_stream(&c->rem); /* If the request is not parsed yet, do so */ if (!(c->rem.flags & FLAG_HEADERS_PARSED)) parse_http_request(c); /* Read from the local end if it is ready */ if (local_ready && io_space_len(&c->loc.io)) read_stream(&c->loc); if (io_data_len(&c->rem.io) > 0 && (c->loc.flags & FLAG_W) && c->loc.io_class != NULL && c->loc.io_class->write != NULL) write_stream(&c->rem, &c->loc); if (io_data_len(&c->loc.io) > 0 && c->rem.io_class != NULL) write_stream(&c->loc, &c->rem); if (c->rem.nread_last > 0) c->ctx->in += c->rem.nread_last; if (c->loc.nread_last > 0) c->ctx->out += c->loc.nread_last; /* Check whether we should close this connection */ if ((current_time > c->expire_time) || (c->rem.flags & FLAG_CLOSED) || ((c->loc.flags & FLAG_CLOSED) && !io_data_len(&c->loc.io))) disconnect(&c->link); } /* * One iteration of server loop. This is the core of the data exchange. */ void shttpd_poll(struct shttpd_ctx *ctx, int milliseconds) { struct llhead *lp, *tmp; struct listener *l; struct conn *c = NULL; struct timeval tv; /* Timeout for select() */ fd_set read_set, write_set; int sock, max_fd = -1, msec = milliseconds; struct usa sa; current_time = time(0); FD_ZERO(&read_set); FD_ZERO(&write_set); /* Add listening sockets to the read set */ LL_FOREACH(&listeners, lp) { l = LL_ENTRY(lp, struct listener, link); FD_SET(l->sock, &read_set); if (l->sock > max_fd) max_fd = l->sock; //DBG(("FD_SET(%d) (listening)", l->sock)); } /* Multiplex streams */ LL_FOREACH(&ctx->connections, lp) { c = LL_ENTRY(lp, struct conn, link); /* If there is a space in remote IO, check remote socket */ if (c->rem.flags & FLAG_SSL_SHOULD_SELECT_ON_READ) add_to_set(c->rem.chan.fd, &read_set, &max_fd); else if (io_space_len(&c->rem.io) && c->rem.flags & FLAG_SSL_SHOULD_SELECT_ON_WRITE) add_to_set(c->rem.chan.fd, &write_set, &max_fd); else if (io_space_len(&c->rem.io)) add_to_set(c->rem.chan.fd, &read_set, &max_fd); #if !defined(NO_CGI) /* * If there is a space in local IO, and local endpoint is * CGI, check local socket for read availability */ if (io_space_len(&c->loc.io) && (c->loc.flags & FLAG_R) && c->loc.io_class == &io_cgi) add_to_set(c->loc.chan.fd, &read_set, &max_fd); /* * If there is some data read from remote socket, and * local endpoint is CGI, check local for write availability */ if (io_data_len(&c->rem.io) && (c->loc.flags & FLAG_W) && c->loc.io_class == &io_cgi) add_to_set(c->loc.chan.fd, &write_set, &max_fd); #endif /* NO_CGI */ /* * If there is some data read from local endpoint, check the * remote socket for write availability */ if (io_data_len(&c->loc.io) && (c->rem.flags & FLAG_SSL_SHOULD_SELECT_ON_READ)) add_to_set(c->rem.chan.fd, &read_set, &max_fd); else if (io_data_len(&c->loc.io)) add_to_set(c->rem.chan.fd, &write_set, &max_fd); if (io_space_len(&c->loc.io) && (c->loc.flags & FLAG_R) && (c->loc.flags & FLAG_ALWAYS_READY)) msec = 0; if (io_data_len(&c->rem.io) && (c->loc.flags & FLAG_W) && (c->loc.flags & FLAG_ALWAYS_READY)) msec = 0; } tv.tv_sec = msec / 1000; tv.tv_usec = msec % 1000; /* Check IO readiness */ if (select(max_fd + 1, &read_set, &write_set, NULL, &tv) < 0) { #ifdef _WIN32 /* * On windows, if read_set and write_set are empty, * select() returns "Invalid parameter" error * (at least on my Windows XP Pro). So in this case, * we sleep here. */ Sleep(milliseconds); #endif /* _WIN32 */ DBG(("select: %d", ERRNO)); if(c->rem.chan.ssl.ssl == NULL) return; else if(!SSL_pending(c->rem.chan.ssl.ssl)) return; } /* Check for incoming connections on listener sockets */ LL_FOREACH(&listeners, lp) { l = LL_ENTRY(lp, struct listener, link); if (!FD_ISSET(l->sock, &read_set)) continue; do { sa.len = sizeof(sa.u.sin); if ((sock = accept(l->sock, &sa.u.sa, &sa.len)) != -1) { #if defined(_WIN32) shttpd_add_socket(ctx, sock, l->is_ssl); #else if (sock >= (int) FD_SETSIZE) { elog(E_LOG, NULL, "shttpd_poll: ctx %p: disarding " "socket %d, too busy", ctx, sock); (void) closesocket(sock); } else if (!is_allowed(ctx, &sa)) { //elog(E_LOG, NULL, "shttpd_poll: %s is not allowed to connect", inet_ntoa(sa.u.sin.sin_addr)); (void) closesocket(sock); } else { shttpd_add_socket(ctx, sock, l->is_ssl); } #endif /* _WIN32 */ } } while (sock != -1); } /* Process all connections */ LL_FOREACH_SAFE(&ctx->connections, lp, tmp) { c = LL_ENTRY(lp, struct conn, link); #ifndef NO_SSL process_connection(c, ((FD_ISSET(c->rem.chan.fd, &read_set) && !(c->rem.flags & FLAG_SSL_SHOULD_SELECT_ON_READ)) || (c->rem.chan.ssl.ssl && SSL_pending(c->rem.chan.ssl.ssl)) || (FD_ISSET(c->rem.chan.fd, &write_set) && (c->rem.flags & FLAG_SSL_SHOULD_SELECT_ON_WRITE))), ((c->loc.flags & FLAG_ALWAYS_READY) #else process_connection(c, FD_ISSET(c->rem.chan.fd, &read_set), ((c->loc.flags & FLAG_ALWAYS_READY) #endif #if !defined(NO_CGI) || (c->loc.io_class == &io_cgi && FD_ISSET(c->loc.chan.fd, &read_set)) #endif /* NO_CGI */ )); } } static void free_list(struct llhead *head, void (*dtor)(struct llhead *)) { struct llhead *lp, *tmp; LL_FOREACH_SAFE(head, lp, tmp) { LL_DEL(lp); dtor(lp); } } static void listener_desctructor(struct llhead *lp) { struct listener *listener = LL_ENTRY(lp, struct listener, link); (void) closesocket(listener->sock); free(listener); } static void mime_type_destructor(struct llhead *lp) { struct mime_type_link *mtl = LL_ENTRY(lp, struct mime_type_link, link); free(mtl->mime); free(mtl->ext); free(mtl); } static void registered_uri_destructor(struct llhead *lp) { struct registered_uri *ruri = LL_ENTRY(lp, struct registered_uri, link); free((void *) ruri->uri); free(ruri); } static void acl_destructor(struct llhead *lp) { struct acl *acl = LL_ENTRY(lp, struct acl, link); free(acl); } static void protected_uri_destructor(struct llhead *lp) { struct uri_auth *auth = LL_ENTRY(lp, struct uri_auth, link); free((void *) auth->file_name); free((void *) auth->uri); free(auth); } /* * Deallocate shttpd object, free up the resources */ void shttpd_fini(struct shttpd_ctx *ctx) { free_list(&ctx->mime_types, mime_type_destructor); free_list(&ctx->connections, disconnect); free_list(&ctx->registered_uris, registered_uri_destructor); free_list(&ctx->uri_auths, protected_uri_destructor); free_list(&ctx->acl, acl_destructor); free_list(&listeners, listener_desctructor); #if !defined(NO_SSI) if (ctx->ssi_extensions) free(ctx->ssi_extensions); free_list(&ctx->ssi_funcs, ssi_func_destructor); #endif /* NO_SSI */ if (ctx->access_log) (void) fclose(ctx->access_log); if (ctx->error_log) (void) fclose(ctx->error_log); if (ctx->put_auth_file) free(ctx->put_auth_file); if (ctx->document_root) free(ctx->document_root); if (ctx->index_files) free(ctx->index_files); if (ctx->aliases) free(ctx->aliases); #if !defined(NO_CGI) if (ctx->cgi_vars) free(ctx->cgi_vars); if (ctx->cgi_extensions) free(ctx->cgi_extensions); if (ctx->cgi_interpreter) free(ctx->cgi_interpreter); #endif /* NO_CGI */ if (ctx->auth_realm) free(ctx->auth_realm); if (ctx->global_passwd_file) free(ctx->global_passwd_file); if (ctx->uid) free(ctx->uid); if (ctx->mime_file) free(ctx->mime_file); if (ctx->ports) free(ctx->ports); /* TODO: free SSL context */ if(ctx->ssl_ctx) SSL_CTX_free(ctx->ssl_ctx); free(ctx); } void open_listening_ports(struct shttpd_ctx *ctx) { const char *p = ctx->ports; int len, is_ssl; FOR_EACH_WORD_IN_LIST(p, len) { is_ssl = p[len - 1] == 's' ? 1 : 0; if (shttpd_listen(ctx, atoi(p), is_ssl) == -1) elog(E_FATAL, NULL, "Cannot open socket on port %d", atoi(p)); } } openwsman-2.4.3/src/cpp/Makefile.am000664 001750 001750 00000001134 12256012305 017401 0ustar00kentbkentb000000 000000 wsmanincludedir = $(includedir)/openwsman/cpp INCLUDES = \ -I$(top_srcdir) \ -I$(top_srcdir)/include \ $(OPENSSL_CFLAGS) LIBS = \ $(XML_LIBS) \ $(top_builddir)/src/lib/libwsman.la \ $(top_builddir)/src/lib/libwsman_client.la wsmaninclude_HEADERS = \ OpenWsmanClient.h \ Exception.h \ WsmanClient.h \ WsmanEPR.h \ WsmanFilter.h lib_LTLIBRARIES=libwsman_clientpp.la libwsman_clientpp_la_SOURCES = \ OpenWsmanClient.cpp \ OpenWsmanClient.h \ WsmanEPR.h \ WsmanFilter.h \ Exception.h \ WsmanClient.h libwsman_clientpp_la_CPPFLAGS = openwsman-2.4.3/bindings/ruby/tests/cim_system_configuration.rb000664 001750 001750 00000002077 12256012305 025353 0ustar00kentbkentb000000 000000 # cim_system_configuration.rb # enumerate/pull/release for CIM_SystemConfiguration require 'test/unit' require 'rexml/document' require File.join(File.dirname(__FILE__),'_loadpath') require 'openwsman' require '_client' class WsmanTest < Test::Unit::TestCase def test_client client = Client.open assert client options = Openwsman::ClientOptions.new assert options classname = "CIM_SystemConfiguration" uri = Openwsman.epr_uri_for "root/cimv2", classname result = client.enumerate( options, nil, uri ) assert result # puts result count = 0 context = result.context while (context) count += 1 result = client.pull( options, nil, uri, context ) # puts "Response ##{count}" # puts "### #{result.to_xml}" result.body.PullResponse.Items.each do |child| puts "#{child.name}" child.each do |prop| puts "\t#{prop.name} = #{prop.text}" end end context = result.context end client.release( options, uri, context ) if context puts "Got #{count} responses" end end openwsman-2.4.3/tests/webinject/indication.xml000664 001750 001750 00000002707 12256012305 021762 0ustar00kentbkentb000000 000000 http://schemas.xmlsoap.org/ws/2004/08/eventing/Subscribe http://localhost:5985/wsman http://schemas.dmtf.org/wbem/wscim/1/* uuid:0716ac62-98a8-18a8-8002-f4e83f290c00 http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous root/interop http://127.0.0.1:80/eventsink PT2.000000S PT240.000000S SELECT * from CIM_ProcessIndication openwsman-2.4.3/src/lib/wsman-event-pool.c000664 001750 001750 00000014047 12256012305 020717 0ustar00kentbkentb000000 000000 /******************************************************************************* * Copyright (C) 2004-2007 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 Liang Hou */ #ifdef HAVE_CONFIG_H #include "wsman_config.h" #endif #include "u/libu.h" #include "wsman-event-pool.h" int MemEventPoolInit (void *opaqueData); int MemEventPoolFinalize (void *opaqueData); int MemEventPoolCount(char *uuid); int MemEventPoolAddEvent (char *uuid, WsNotificationInfoH notification); int MemEventPoolAddPullEvent (char *uuid, WsNotificationInfoH notification) ; int MemEventPoolGetAndDeleteEvent (char *uuid, WsNotificationInfoH *notification); int MemEventPoolClearEvent (char *uuid, clearproc proc); list_t *global_event_list = NULL; int max_pull_event_number = 16; struct __EventPoolOpSet event_pool_op_set ={MemEventPoolInit, MemEventPoolFinalize, MemEventPoolCount, MemEventPoolAddEvent, MemEventPoolAddPullEvent, MemEventPoolGetAndDeleteEvent, MemEventPoolClearEvent}; EventPoolOpSetH wsman_get_eventpool_opset() { return &event_pool_op_set; } int MemEventPoolInit (void *opaqueData) { global_event_list = list_create(-1); if(opaqueData) max_pull_event_number = *(int *)opaqueData; return 0; } int MemEventPoolFinalize (void *opaqueData) { return 0; } int MemEventPoolCount(char *uuid) { lnode_t *node = NULL; event_entryH entry = NULL; node = list_first(global_event_list); while(node) { entry = (event_entryH)node->list_data; if(!strcasecmp(entry->subscription_id, uuid)) break; node = list_next(global_event_list, node); } if(node) return list_count(entry->event_content_list); return 0; } int MemEventPoolAddEvent (char *uuid, WsNotificationInfoH notification) { lnode_t *node = NULL; event_entryH entry = NULL; if(notification == NULL) return 0; node = list_first(global_event_list); while(node) { entry = (event_entryH)node->list_data; if(!strcasecmp(entry->subscription_id, uuid)) break; node = list_next(global_event_list, node); } if(node == NULL) { //No event_entry for this subscription, create it entry = u_malloc(sizeof(*entry)); entry->event_content_list = list_create(-1); strcpy(entry->subscription_id, uuid); node = lnode_create(entry); list_append(global_event_list, node); } node = lnode_create(notification); list_append(entry->event_content_list, node); return 0; } int MemEventPoolAddPullEvent (char *uuid, WsNotificationInfoH notification) { lnode_t *node = NULL; event_entryH entry = NULL; if(notification == NULL) return 0; node = list_first(global_event_list); while(node) { entry = (event_entryH)node->list_data; if(!strcasecmp(entry->subscription_id, uuid)) break; node = list_next(global_event_list, node); } if(node == NULL) { //No event_entry for this subscription, create it entry = u_malloc(sizeof(*entry)); entry->event_content_list = list_create(-1); strcpy(entry->subscription_id, uuid); node = lnode_create(entry); list_append(global_event_list, node); } if(list_count(entry->event_content_list) > max_pull_event_number) return -1; node = lnode_create(notification); list_append(entry->event_content_list, node); return 0; } int MemEventPoolGetAndDeleteEvent (char *uuid, WsNotificationInfoH *notification) { lnode_t *node = NULL; event_entryH entry = NULL; *notification = NULL; node = list_first(global_event_list); while(node) { entry = (event_entryH)node->list_data; if(!strcasecmp(entry->subscription_id, uuid)) break; node = list_next(global_event_list, node); } if(node == NULL) { return -1; } node = list_first(entry->event_content_list); if(node == NULL) return -1; list_delete(entry->event_content_list, node); *notification = (WsNotificationInfoH)node->list_data; lnode_destroy(node); return 0; } int MemEventPoolClearEvent (char *uuid, clearproc proc) { lnode_t *node = NULL; lnode_t *tmp = NULL; event_entryH entry = NULL; WsNotificationInfoH notification; node = list_first(global_event_list); while(node) { entry = (event_entryH)node->list_data; if(!strcasecmp(entry->subscription_id, uuid)) break; node = list_next(global_event_list, node); } if(node == NULL) { return -1; } list_delete(global_event_list, node); lnode_destroy(node); node = list_first(entry->event_content_list); while(node) { notification = (WsNotificationInfoH)node->list_data; if(proc) proc(notification); tmp = list_next(entry->event_content_list, node); list_delete(entry->event_content_list, node); lnode_destroy(node); node = tmp; } list_destroy(entry->event_content_list); u_free(entry); return 0; } openwsman-2.4.3/tests/serialization/CMakeLists.txt000664 001750 001750 00000000575 12256012305 022563 0ustar00kentbkentb000000 000000 # # CMakeLists.txt for openwsman/tests/epr # ENABLE_TESTING() include_directories(${CMAKE_SOURCE_DIR}/include ${CMAKE_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR} ) SET( TEST_LIBS wsman wsman_client ${LIBXML2_LIBRARIES} ${CURL_LIBRARIES} "pthread") SET( ser1_SOURCES ser1.c ) ADD_EXECUTABLE( ser1 ${ser1_SOURCES} ) TARGET_LINK_LIBRARIES( ser1 ${TEST_LIBS} ) ADD_TEST( ser1 ser1 )openwsman-2.4.3/etc/Makefile.am000664 001750 001750 00000000461 12256012305 016605 0ustar00kentbkentb000000 000000 SUBDIRS = init pamdir = $(sysconfdir)/pam.d pam_DATA = pam/openwsman noinst_DATA = ssleay.cnf openwsman.conf openwsman_client.conf openwsmanconf_DATA = owsmangencert.sh openwsmanconfdir = $(sysconfdir)/openwsman EXTRA_DIST = $(noinst_DATA) $(openwsmanconf_DATA) $(pam_DATA) CLEANFILES = owsmangencert openwsman-2.4.3/src/server/shttpd/shttpd.h000664 001750 001750 00000013206 12256012305 021061 0ustar00kentbkentb000000 000000 /* * Copyright (c) 2004-2005 Sergey Lyubka * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), * to deal in the Software without restriction, including without limitation * the rights to use, copy, modify, merge, publish, distribute, sublicense, * and/or sell copies of the Software, and to permit persons to whom the * Software is furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included * in all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER * DEALINGS IN THE SOFTWARE. * * $Id: shttpd.h,v 1.6 2008/01/11 11:20:31 drozd Exp $ */ #ifndef SHTTPD_HEADER_INCLUDED #define SHTTPD_HEADER_INCLUDED #ifdef __cplusplus extern "C" { #endif /* __cplusplus */ struct ubuf { char *buf; /* Buffer pointer */ int len; /* Size of a buffer */ int num_bytes; /* Bytes processed by callback */ }; /* * This structure is passed to the user callback function */ struct shttpd_arg { void *priv; /* Private! Do not touch! */ void *state; /* User state */ void *user_data; /* User-defined data */ struct ubuf in; /* Input is here, POST data */ struct ubuf out; /* Output goes here */ unsigned int flags; #define SHTTPD_END_OF_OUTPUT 1 #define SHTTPD_CONNECTION_ERROR 2 #define SHTTPD_MORE_POST_DATA 4 #define SHTTPD_POST_BUFFER_FULL 8 #define SHTTPD_SSI_EVAL_TRUE 16 }; /* * User callback function. Called when certain registered URLs have been * requested. These are the requirements to the callback function: * * 1. it must copy data into 'out.buf' buffer, not more than 'out.len' bytes, * and record how many bytes are copied, into 'out.num_bytes' * 2. it must not block the execution * 3. it must set SHTTPD_END_OF_OUTPUT flag when finished * 4. for POST requests, it must process the incoming data (in.buf) of length * 'in.len', and set 'in.num_bytes', which is how many bytes of POST * data is read and can be discarded by SHTTPD. * 5. If callback allocates arg->state, to keep state, it must deallocate it * at the end of coonection SHTTPD_CONNECTION_ERROR or SHTTPD_END_OF_OUTPUT */ typedef void (*shttpd_callback_t)(struct shttpd_arg *); /* * shttpd_init Initialize shttpd context. Parameters: configuration * file name (may be NULL), then NULL-terminated * sequence of pairs "option_name", "option_value". * shttpd_init2 Same as shttpd_init, but the list of option/value * pairs is passed in arrays * shttpd_fini Dealocate the context * shttpd_register_uri Setup the callback function for specified URL. * shttpd_protect_uri Associate authorization file with an URL. * shttpd_add_mime_type Add mime type * shtppd_listen Setup a listening socket in the SHTTPD context * shttpd_poll Do connections processing * shttpd_version return string with SHTTPD version * shttpd_get_var Fetch POST/GET variable value by name. Return value len * shttpd_get_header return value of the specified HTTP header * shttpd_get_env return string values for the following * pseudo-variables: "REQUEST_METHOD", "REQUEST_URI", * "REMOTE_USER" and "REMOTE_ADDR". */ typedef int (*basic_auth_callback)(char *user, char *passwd); struct shttpd_ctx; struct shttpd_ctx *shttpd_init(const char *config_file, ...); struct shttpd_ctx *shttpd_init2(const char *config_file, char *names[], char *values[], size_t num_options); void shttpd_fini(struct shttpd_ctx *); void shttpd_add_mime_type(struct shttpd_ctx *, const char *extension, const char *mime_type); int shttpd_listen(struct shttpd_ctx *ctx, int port, int is_ssl); void shttpd_register_uri(struct shttpd_ctx *ctx, const char *uri, shttpd_callback_t callback, void *const user_data); void shttpd_protect_uri(struct shttpd_ctx *ctx, const char *uri, const char *password_file, basic_auth_callback cb, int type); void shttpd_poll(struct shttpd_ctx *, int milliseconds); const char *shttpd_version(void); int shttpd_get_var(const char *var, const char *buf, int buf_len, char *value, int value_len); const char *shttpd_get_header(struct shttpd_arg *, const char *header_name); const char *shttpd_get_env(struct shttpd_arg *, const char *name); void shttpd_get_http_version(struct shttpd_arg *, unsigned long *major, unsigned long *minor); size_t shttpd_printf(struct shttpd_arg *, const char *fmt, ...); void shttpd_handle_error(struct shttpd_ctx *ctx, int status, shttpd_callback_t func, void *const data); void shttpd_register_ssi_func(struct shttpd_ctx *ctx, const char *name, shttpd_callback_t func, void *const user_data); /* * The following three functions are for applications that need to * load-balance the connections on their own. Many threads may be spawned * with one SHTTPD context per thread. Boss thread may only wait for * new connections by means of shttpd_accept(). Then it may scan thread * pool for the idle thread by means of shttpd_active(), and add new * connection to the context by means of shttpd_add(). */ void shttpd_add_socket(struct shttpd_ctx *, int sock, int is_ssl); int shttpd_accept(int lsn_sock, int milliseconds); int shttpd_active(struct shttpd_ctx *); #ifdef __cplusplus } #endif /* __cplusplus */ #endif /* SHTTPD_HEADER_INCLUDED */ openwsman-2.4.3/src/lib/wsman-libxml2-binding.c000664 001750 001750 00000051101 12256012305 021600 0ustar00kentbkentb000000 000000 /******************************************************************************* * 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 */ #ifdef HAVE_CONFIG_H #include #endif #include #include #include #include #include #include #include #include #include #include #include "u/libu.h" #include "wsman-xml-api.h" #include "wsman-soap.h" #include "wsman-xml.h" #include "wsman-xml-binding.h" static void destroy_attr_private_data(void *data) { if (data) xmlFree(data); } static void destroy_node_private_data(void *_data) { iWsNode *data = (iWsNode *) _data; if (data) { // ??? TBD data->nsQNameList; if (data->valText) xmlFree(data->valText); u_free(data); } } static void destroy_tree_private_data(xmlNode * node) { while (node) { xmlAttrPtr attr = node->properties; if (node->_private) { destroy_node_private_data(node->_private); node->_private = NULL; } while (attr) { if (attr->_private) { destroy_attr_private_data(attr->_private); attr->_private = NULL; } attr = attr->next; } destroy_tree_private_data(node->children); node = node->next; } } static void myXmlErrorReporting (void *ctx, const char* msg, ...) { va_list args; char *string; va_start(args, msg); string = u_strdup_vprintf (msg, args); warning (string); va_end(args); u_free(string); } void xml_parser_initialize() { xmlSetGenericErrorFunc(NULL, myXmlErrorReporting); } void xml_parser_destroy() { } int xml_parser_utf8_strlen(char *buf) { return xmlUTF8Strlen(BAD_CAST buf); } void xml_parser_doc_to_memory(WsXmlDocH doc, char **buf, int *ptrSize, const char *encoding) { if (doc && buf && ptrSize) xmlDocDumpMemoryEnc(doc->parserDoc, (xmlChar **) buf, ptrSize, (!encoding) ? "UTF-8" : encoding); } void xml_parser_free_memory(void *ptr) { if (ptr) xmlFree(ptr); } int xml_parser_create_doc_by_import(WsXmlDocH wsDoc, WsXmlNodeH node) { xmlDocPtr doc; xmlNodePtr rootNode; if ((doc = xmlNewDoc(BAD_CAST "1.0")) == NULL) { if (doc) xmlFreeDoc(doc); return 0; } else { doc->_private = wsDoc; wsDoc->parserDoc = doc; rootNode = xmlDocCopyNode((xmlNodePtr) node, doc, 1); xmlDocSetRootElement(doc, rootNode); return 1; } } int xml_parser_create_doc(WsXmlDocH wsDoc, const char *rootName) { int retVal = 0; xmlDocPtr doc; xmlNodePtr rootNode; if ((doc = xmlNewDoc(BAD_CAST "1.0")) == NULL || (rootNode = xmlNewNode(NULL, BAD_CAST rootName)) == NULL) { if (doc) xmlFreeDoc(doc); } else { doc->_private = wsDoc; wsDoc->parserDoc = doc; xmlDocSetRootElement(doc, rootNode); retVal = 1; } return retVal; } void xml_parser_destroy_doc(WsXmlDocH wsDoc) { xmlDocPtr xmlDoc = (xmlDocPtr) wsDoc->parserDoc; if (xmlDoc != NULL) { destroy_tree_private_data(xmlDocGetRootElement(xmlDoc)); xmlFreeDoc(xmlDoc); } } WsXmlDocH xml_parser_get_doc(WsXmlNodeH node) { xmlDocPtr xmlDoc = ((xmlDocPtr) node)->doc; return (WsXmlDocH) (!xmlDoc ? NULL : xmlDoc->_private); } WsXmlNodeH xml_parser_get_root(WsXmlDocH doc) { if (doc->parserDoc != NULL) return (WsXmlNodeH) xmlDocGetRootElement((xmlDocPtr) doc-> parserDoc); return NULL; } WsXmlDocH xml_parser_file_to_doc( const char *filename, const char *encoding, unsigned long options) { xmlDocPtr xmlDoc; WsXmlDocH Doc = NULL; xmlDoc = xmlReadFile(filename, encoding, XML_PARSE_NONET | XML_PARSE_NSCLEAN); if (xmlDoc == NULL) { return NULL; } Doc = (WsXmlDocH) u_zalloc(sizeof(*Doc)); if (Doc == NULL) { xmlFreeDoc(xmlDoc); return NULL; } xmlDoc->_private = Doc; Doc->parserDoc = xmlDoc; return Doc; } WsXmlDocH xml_parser_memory_to_doc( const char *buf, size_t size, const char *encoding, unsigned long options) { WsXmlDocH Doc = NULL; xmlDocPtr xmlDoc; if (!buf || !size ) { return NULL; } xmlDoc = xmlReadMemory(buf, (int) size, NULL, encoding, XML_PARSE_NONET | XML_PARSE_NSCLEAN); if (xmlDoc == NULL) { return NULL; } Doc = (WsXmlDocH) u_zalloc(sizeof(*Doc)); if (Doc == NULL) { xmlFreeDoc(xmlDoc); return NULL; } xmlDoc->_private = Doc; Doc->parserDoc = xmlDoc; return Doc; } char *xml_parser_node_query(WsXmlNodeH node, int what) { char *ptr = NULL; xmlNodePtr xmlNode = (xmlNodePtr) node; iWsNode *wsNode = (iWsNode *) xmlNode->_private; switch (what) { case XML_TEXT_VALUE: if (wsNode == NULL) xmlNode->_private = wsNode = u_zalloc(sizeof(iWsNode)); if (wsNode != NULL) { if (wsNode->valText == NULL) { wsNode->valText = (char *) xmlNodeGetContent(xmlNode); } ptr = wsNode->valText; } break; case XML_LOCAL_NAME: ptr = (char *) xmlNode->name; break; case XML_NS_URI: if (xmlNode->ns != NULL) ptr = (char *) xmlNode->ns->href; break; case XML_NS_PREFIX: if (xmlNode->ns != NULL) ptr = (char *) xmlNode->ns->prefix; break; default: break; } return ptr; } int xml_parser_node_set(WsXmlNodeH node, int what, const char *str) { int retVal = -1; xmlNodePtr xmlNode = (xmlNodePtr) node; iWsNode *wsNode = (iWsNode *) xmlNode->_private; xmlNsPtr xmlNs; switch (what) { case XML_TEXT_VALUE: if (wsNode == NULL) xmlNode->_private = wsNode = u_zalloc(sizeof(iWsNode)); if (wsNode != NULL) { if (wsNode->valText != NULL) { xmlFree(wsNode->valText); wsNode->valText = NULL; } xmlNodeSetContent(xmlNode, BAD_CAST str); retVal = 0; } break; case XML_LOCAL_NAME: xmlNodeSetName(xmlNode, BAD_CAST str); retVal = 0; break; case XML_NS_URI: if ((xmlNs = (xmlNsPtr) xml_parser_ns_find(node, str, NULL, 1, 1)) != NULL) { xmlNode->ns = xmlNs; retVal = 0; } else retVal = 1; break; default: retVal = 1; break; } return retVal; } WsXmlNodeH xml_parser_node_get(WsXmlNodeH node, int which) { xmlNodePtr xmlNode = NULL; xmlNodePtr base = (xmlNodePtr) node; switch (which) { case XML_ELEMENT_PARENT: xmlNode = base->parent; break; case XML_ELEMENT_NEXT: if ((xmlNode = base->next) != NULL) { do { if (xmlNode->type == XML_ELEMENT_NODE) break; } while ((xmlNode = xmlNode->next) != NULL); } break; case XML_ELEMENT_PREV: if ((xmlNode = base->prev) != NULL) { do { if (xmlNode->type == XML_ELEMENT_NODE) break; } while ((xmlNode = xmlNode->prev) != NULL); } break; case XML_LAST_CHILD: default: if (which >= 0 || which == XML_LAST_CHILD) { int count = 0; xmlNode = base->children; while (xmlNode) { if (xmlNode->type == XML_ELEMENT_NODE) { if (which == XML_LAST_CHILD && xmlNode->next == NULL) break; if (count == which) break; count++; } xmlNode = xmlNode->next; } } else { assert(which >= 0); } break; } return (WsXmlNodeH) xmlNode; } /* check if namespace is defined (at document root) * and evtl. (bAddAtRootIfNotFound!=0) add it to the root node */ WsXmlNsH xml_parser_ns_find(WsXmlNodeH node, const char *uri, const char *prefix, int bWalkUpTree, int bAddAtRootIfNotFound) { xmlNodePtr xmlNode = (xmlNodePtr) node; xmlNsPtr xmlNs = NULL; while (xmlNode != NULL) { xmlNs = xmlNode->nsDef; while (xmlNs != NULL) { if (uri) { if (!strcmp((char *) xmlNs->href, uri)) break; } else if (prefix == NULL) { if (xmlNs->prefix == NULL) break; } else if (xmlNs->prefix && !strcmp((char *) xmlNs->prefix, prefix)) { break; } xmlNs = xmlNs->next; } if (xmlNs != NULL || !bWalkUpTree) break; xmlNode = xmlNode->parent; } if (xmlNs == NULL && bAddAtRootIfNotFound) { xmlNodePtr xmlRoot = xmlDocGetRootElement(((xmlDocPtr) node)->doc); char buf[12]; if (prefix == NULL) { ws_xml_make_default_prefix((WsXmlNodeH) xmlRoot, uri, buf, sizeof(buf)); prefix = buf; } xmlNs = (xmlNsPtr) xml_parser_ns_add((WsXmlNodeH) xmlRoot, uri, prefix); } return (WsXmlNsH) xmlNs; } char *xml_parser_ns_query(WsXmlNsH ns, int what) { xmlNsPtr xmlNs = (xmlNsPtr) ns; char *ptr = NULL; switch (what) { case XML_NS_URI: ptr = (char *) xmlNs->href; break; case XML_NS_PREFIX: ptr = (char *) xmlNs->prefix; break; default: assert(what == XML_NS_URI); break; } return ptr; } WsXmlNsH xml_parser_ns_add(WsXmlNodeH node, const char *uri, const char *prefix) { xmlNsPtr xmlNs = NULL; if (node && uri) { if ((xmlNs = (xmlNsPtr) xml_parser_ns_find(node, uri, NULL, 0, 0)) != NULL) { /* namespace is known */ if (xmlNs->prefix != NULL) { xmlFree((char *) xmlNs->prefix); xmlNs->prefix = NULL; } if (prefix != NULL) { xmlNs->prefix = xmlStrdup(BAD_CAST prefix); } } else { /* create new namespace entry */ xmlNs = xmlNewNs((xmlNodePtr) node, BAD_CAST uri, BAD_CAST prefix); /* since the 'xml:' name is supposed to be predefined, the above * function will return NULL when prefix == xml && uri == XML_XML_NAMESPACE. * Compensate for this here. */ if (xmlNs == NULL && strcmp(prefix,"xml") == 0 && strcmp(uri, (const char *)XML_XML_NAMESPACE) == 0) { xmlNs = (xmlNsPtr) u_zalloc(sizeof(xmlNs)); if (xmlNs == NULL) { error("Couldn't create a new Namespace structure"); return(NULL); } xmlNs->type = XML_LOCAL_NAMESPACE; xmlNs->href = xmlStrdup((const xmlChar *)uri); xmlNs->prefix = xmlStrdup((const xmlChar *)prefix); } } } return (WsXmlNsH) xmlNs; } int xml_parser_ns_remove(WsXmlNodeH node, const char *nsUri) { int retVal = -1; if (node && nsUri) { xmlNodePtr xmlNode = (xmlNodePtr) node; xmlNsPtr xmlNs = xmlNode->nsDef; xmlNsPtr prevNs = NULL; while (xmlNs != NULL) { if ((xmlStrEqual(xmlNs->href, BAD_CAST nsUri))) { break; } prevNs = xmlNs; xmlNs = xmlNs->next; } if (xmlNs != NULL) { retVal = 0; if (prevNs == NULL) xmlNode->nsDef = xmlNs->next; else prevNs->next = xmlNs->next; xmlFreeNs(xmlNs); } else retVal = 1; } return retVal; } WsXmlNsH xml_parser_ns_get(WsXmlNodeH node, int which) { xmlNodePtr xmlNode = (xmlNodePtr) node; xmlNsPtr xmlNs = NULL; if (which >= 0) { int count = 0; xmlNs = xmlNode->nsDef; while (xmlNs != NULL) { if (which == count) break; count++; xmlNs = xmlNs->next; } } else { assert(which >= 0); } return (WsXmlNsH) xmlNs; } static int get_ns_count_at_node(xmlNodePtr xmlNode) { int count = 0; xmlNsPtr xmlNs = xmlNode->nsDef; while (xmlNs != NULL) { count++; xmlNs = xmlNs->next; } return count; } int xml_parser_get_count(WsXmlNodeH node, int what, int bWalkUpTree) { int count = 0; xmlNodePtr xmlNode; xmlAttrPtr xmlAttr; switch (what) { case XML_COUNT_NODE: xmlNode = ((xmlNodePtr) node)->children; while (xmlNode) { if (xmlNode->type == XML_ELEMENT_NODE) count++; xmlNode = xmlNode->next; } break; case XML_COUNT_ATTR: xmlAttr = ((xmlNodePtr) node)->properties; while (xmlAttr) { count++; xmlAttr = xmlAttr->next; } break; case XML_COUNT_NS: xmlNode = (xmlNodePtr) node; while (xmlNode != NULL) { count += get_ns_count_at_node(xmlNode); if (!bWalkUpTree) break; xmlNode = xmlNode->parent; } break; default: assert(what == XML_COUNT_NODE || what == XML_COUNT_ATTR || what == XML_COUNT_NS); break; } return count; } static xmlNodePtr make_new_xml_node(xmlNodePtr base, const char *uri, const char *name, const char *value, int xmlescape) { xmlNodePtr newNode = NULL; xmlNsPtr ns = NULL; if (uri == NULL || (ns = (xmlNsPtr) xml_parser_ns_find((WsXmlNodeH) base, uri, NULL, 1, 1)) != NULL) { if ((newNode = xmlNewNode(ns, BAD_CAST name)) != NULL) { if (value != NULL){ if (xmlescape == 1) xmlNodeAddContent(newNode, BAD_CAST value); else xmlNodeSetContent(newNode, BAD_CAST value); } newNode->_private = u_zalloc(sizeof(iWsNode)); } } return newNode; } WsXmlNodeH xml_parser_node_add(WsXmlNodeH base, int where, const char *nsUri, const char *localName, const char *value, int xmlescape) { xmlNodePtr xmlBase = (xmlNodePtr) base; xmlNodePtr newNode = make_new_xml_node((where != XML_ELEMENT_NEXT && where != XML_ELEMENT_PREV) ? xmlBase : xmlBase->parent, nsUri, localName, value, xmlescape); if (newNode) { switch (where) { case XML_ELEMENT_NEXT: xmlAddNextSibling((xmlNodePtr) base, newNode); break; case XML_ELEMENT_PREV: xmlAddPrevSibling((xmlNodePtr) base, newNode); break; case XML_LAST_CHILD: default: xmlAddChild((xmlNodePtr) base, newNode); break; } } return (WsXmlNodeH) newNode; } int xml_parser_node_remove(WsXmlNodeH node) { destroy_node_private_data(((xmlNodePtr) node)->_private); xmlUnlinkNode((xmlNodePtr) node); xmlFreeNode((xmlNodePtr) node); return 0; } WsXmlAttrH xml_parser_attr_add(WsXmlNodeH node, const char *uri, const char *name, const char *value) { xmlNodePtr xmlNode = (xmlNodePtr) node; xmlNsPtr xmlNs = (xmlNsPtr) xml_parser_ns_find(node, uri, NULL, 1, 1); xmlAttrPtr xmlAttr = (xmlAttrPtr) ws_xml_find_node_attr(node, uri, name); if (xmlAttr != NULL) ws_xml_remove_node_attr((WsXmlAttrH) xmlAttr); if (xmlNs == NULL) xmlAttr = xmlNewProp(xmlNode, BAD_CAST name, BAD_CAST value); else xmlAttr = xmlNewNsProp(xmlNode, xmlNs, BAD_CAST name, BAD_CAST value); if (xmlAttr != NULL) { if (xmlNs == NULL) xmlAttr->_private = xmlGetProp(xmlNode, BAD_CAST name); else xmlAttr->_private = xmlGetNsProp(xmlNode, BAD_CAST name, xmlNs->href); } return (WsXmlAttrH) xmlAttr; } int xml_parser_attr_remove(WsXmlAttrH attr) { xmlAttrPtr xmlAttr = (xmlAttrPtr) attr; xmlNodePtr xmlNode = (xmlNodePtr) xmlAttr->parent; xmlAttrPtr xmlAttrPrev = (xmlNode->properties == xmlAttr) ? NULL : xmlNode->properties; while (xmlAttrPrev != NULL && xmlAttrPrev->next != xmlAttr) { xmlAttrPrev = xmlAttrPrev->next; } if (xmlAttrPrev != NULL) xmlAttrPrev->next = xmlAttr->next; else xmlNode->properties = xmlAttr->next; xmlNode->parent = NULL; xmlNode->next = NULL; destroy_attr_private_data((xmlAttrPtr) attr); xmlFreeProp((xmlAttrPtr) attr); return 0; } char *xml_parser_attr_query(WsXmlAttrH attr, int what) { char *ptr = NULL; xmlAttrPtr xmlAttr = (xmlAttrPtr) attr; switch (what) { case XML_LOCAL_NAME: ptr = (char *) xmlAttr->name; break; case XML_NS_URI: if (xmlAttr->ns != NULL) ptr = (char *) xmlAttr->ns->href; break; case XML_NS_PREFIX: if (xmlAttr->ns != NULL) ptr = (char *) xmlAttr->ns->prefix; break; case XML_TEXT_VALUE: if (xmlAttr->_private == NULL) { if (xmlAttr->ns == NULL) xmlAttr->_private = xmlGetProp(xmlAttr->parent, xmlAttr->name); else xmlAttr->_private = xmlGetNsProp(xmlAttr->parent, xmlAttr->name, xmlAttr->ns->href); } ptr = (char *) xmlAttr->_private; break; default: assert(what == XML_LOCAL_NAME); break; } return ptr; } WsXmlAttrH xml_parser_attr_get(WsXmlNodeH node, int which) { xmlNodePtr xmlNode = (xmlNodePtr) node; xmlAttrPtr xmlAttr = NULL; switch (which) { case XML_LAST_CHILD: default: if (which >= 0 || which == XML_LAST_CHILD) { int count = 0; xmlAttr = xmlNode->properties; while (xmlAttr) { if (which == XML_LAST_CHILD && xmlAttr->next == NULL) break; if (which == count) break; count++; xmlAttr = xmlAttr->next; } } else { assert(which >= 0 || which == XML_LAST_CHILD); } break; } return (WsXmlAttrH) xmlAttr; } void xml_parser_element_dump(FILE * f, WsXmlDocH doc, WsXmlNodeH node) { xmlNodePtr n = (xmlNodePtr) node; xmlDocPtr d = (xmlDocPtr) doc->parserDoc; xmlElemDump(f, d, n); } void xml_parser_doc_dump(FILE * f, WsXmlDocH doc) { xmlDocPtr d = (xmlDocPtr) doc->parserDoc; xmlDocFormatDump(f, d, 1); return; } void xml_parser_doc_dump_memory(WsXmlDocH doc, char **buf, int *ptrSize) { xmlDocPtr d = (xmlDocPtr) doc->parserDoc; xmlDocDumpFormatMemory(d, (xmlChar **) buf, ptrSize, 1); return; } void xml_parser_doc_dump_memory_enc(WsXmlDocH doc, char **buf, int *ptrSize, const char *encoding) { xmlDocPtr d = (xmlDocPtr) doc->parserDoc; xmlDocDumpFormatMemoryEnc(d, (xmlChar **) buf, ptrSize, encoding?encoding:"UTF-8", 1); return; } static void register_namespaces(xmlXPathContextPtr ctxt, WsXmlDocH doc, WsXmlNodeH node) { xmlNsPtr *nsList, *cur; xmlDocPtr d = (xmlDocPtr) doc->parserDoc; nsList = xmlGetNsList(d, (xmlNodePtr) node); if (nsList == NULL) { return; } for (cur = nsList; *cur != NULL; cur++) { if (xmlXPathRegisterNs(ctxt, (*cur)->prefix, (*cur)->href) != 0) { return; } } xmlFree(nsList); } int xml_parser_check_xpath(WsXmlDocH doc, const char *expression) { xmlXPathObject *obj; xmlNodeSetPtr nodeset; xmlXPathContextPtr ctxt; xmlDocPtr d = (xmlDocPtr) doc->parserDoc; int retval = 0; ctxt = xmlXPathNewContext(d); if (ctxt == NULL) { error("failed while creating xpath context"); return 0; } register_namespaces(ctxt, doc, xml_parser_get_root(doc)); obj = xmlXPathEvalExpression(BAD_CAST expression, ctxt); if (obj) { nodeset = obj->nodesetval; if (nodeset && nodeset->nodeNr > 0) { int size = nodeset->nodeNr; int i; xmlNodePtr cur; for(i = 0; i < size; ++i) { if(nodeset->nodeTab[i]->type == XML_ELEMENT_NODE) { cur = nodeset->nodeTab[i]; if(cur->ns) { fprintf(stdout, "= element node \"%s:%s\"\n", cur->ns->href, cur->name); } else { fprintf(stdout, "= element node \"%s\"\n", cur->name); } } } retval = 1; } xmlXPathFreeContext(ctxt); xmlXPathFreeObject(obj); } else { return 0; } return retval; } char *xml_parser_get_xpath_value(WsXmlDocH doc, const char *expression) { //int i; char *result = NULL; xmlXPathObject *obj; xmlNodeSetPtr nodeset; xmlXPathContextPtr ctxt; xmlDocPtr d = (xmlDocPtr) doc->parserDoc; WsXmlNodeH body; ctxt = xmlXPathNewContext(d); if (ctxt == NULL) { error("failed while creating xpath context"); return NULL; } body = ws_xml_get_soap_body(doc); register_namespaces(ctxt, doc, xml_parser_get_root(doc)); if (ws_xml_get_child(body, 0, NULL, NULL)) { register_namespaces(ctxt, doc, ws_xml_get_child(body, 0, NULL, NULL)); } obj = xmlXPathEvalExpression(BAD_CAST expression, ctxt); if (obj) { nodeset = obj->nodesetval; if (nodeset && nodeset->nodeNr > 0) result = (char *) xmlNodeListGetString(d, nodeset-> nodeTab[0]-> xmlChildrenNode, 1); xmlXPathFreeContext(ctxt); xmlXPathFreeObject(obj); } else { return NULL; } return result; } void xml_parser_unlink_node(WsXmlNodeH node) { xmlUnlinkNode((xmlNodePtr) node); xmlFreeNode((xmlNodePtr) node); return; } void xml_parser_node_set_lang(WsXmlNodeH node, const char *lang) { xmlNodeSetLang((xmlNodePtr) node, BAD_CAST lang); } void xml_parser_set_ns(WsXmlNodeH r, WsXmlNsH ns, const char *prefix) { xmlSetNs((xmlNodePtr) r, (xmlNsPtr) ns); } void xml_parser_copy_node(WsXmlNodeH src, WsXmlNodeH dst) { if (src && dst) { xmlNodePtr x = xmlDocCopyNode((xmlNodePtr) src, ((xmlDocPtr) src)->doc, 1); if (x) xmlAddChild((xmlNodePtr) dst, x); } } openwsman-2.4.3/src/lib/wsman-epr.c000664 001750 001750 00000035644 12256012305 017423 0ustar00kentbkentb000000 000000 /******************************************************************************* * 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, Intel Corp. * @author Liang Hou, Intel Corp. */ #ifdef HAVE_CONFIG_H #include #endif #define _GNU_SOURCE #include #include #include #include #include #include "u/libu.h" #include "wsman-xml-api.h" #include "wsman-client-api.h" #include "wsman-soap.h" #include "wsman-xml.h" #include "wsman-faults.h" #include "wsman-soap-envelope.h" #include "wsman-epr.h" char *wsman_epr_selector_by_name(epr_t *epr, const char* name) { int i; char *value = NULL; Selector *ss = (Selector *) epr->refparams.selectorset.selectors; if (ss == NULL) { debug("epr->refparams.selectors.data == NULL\n"); return NULL; } for (i = 0; i < epr->refparams.selectorset.count; i++) { Selector *s; s = ss + i; if (strcmp(s->name, name) == 0 && s->type == 0) { value = u_strdup(s->value); break; } } return value; } void wsman_epr_selector_cb(epr_t *epr, selector_callback cb, void *cb_data) { int i; Selector *ss = (Selector *) epr->refparams.selectorset.selectors; if (ss == NULL) { debug("epr->refparams.selectors == NULL\n"); return; } for (i = 0; i < epr->refparams.selectorset.count; i++) { Selector *s; s = ss + i; cb(cb_data, s->name, s->value); } } void wsman_selectorset_cb(SelectorSet *selectorset, selector_callback cb, void *cb_data) { int i; Selector *ss = selectorset->selectors; if (ss == NULL) { debug("epr->refparams.selectors == NULL"); return; } for (i = 0; i < selectorset->count; i++) { Selector *s; s = ss + i; cb(cb_data, s->name, s->value); } } epr_t *epr_create(const char *uri, hash_t * selectors, const char *address) { epr_t *epr = NULL; epr = u_malloc(sizeof(epr_t)); if (address == NULL) epr->address = u_strdup(WSA_TO_ANONYMOUS); else epr->address = u_strdup(address); epr->refparams.uri = u_strdup(uri); if (selectors) { hnode_t *hn; hscan_t hs; Selector *p; selector_entry *entry; epr->refparams.selectorset.count = hash_count(selectors); epr->refparams.selectorset.selectors = u_malloc(sizeof(Selector)* epr->refparams.selectorset.count); p = epr->refparams.selectorset.selectors; hash_scan_begin(&hs, selectors); while ((hn = hash_scan_next(&hs))) { p->name = u_strdup((char *)hnode_getkey(hn)); entry = (selector_entry *)hnode_get(hn); if(entry->type == 0) { p->type = 0; p->value = u_strdup(entry->entry.text); debug("key=%s value=%s", (char *) hnode_getkey(hn), p->value); } else { p->type = 1; p->value = (char *)epr_copy(entry->entry.eprp); debug("key=%s value=%p(nested epr)", (char *) hnode_getkey(hn), p->value); } p++; } } else { epr->refparams.selectorset.count = 0; epr->refparams.selectorset.selectors = NULL; } return epr; } epr_t *epr_from_string(const char* str) { char *p; char *uri; hash_t *selectors = NULL; hash_t *selectors_new = NULL; hnode_t *hn; hscan_t hs; selector_entry *entry; epr_t *epr; p = strchr(str, '?'); if (p) { uri = u_strndup(str, p - str); selectors = u_parse_query(p + 1); selectors_new = hash_create2(HASHCOUNT_T_MAX, 0, 0); hash_scan_begin(&hs, selectors); while ((hn = hash_scan_next(&hs))) { entry = u_malloc(sizeof(selector_entry)); entry->type = 0; entry->entry.text = (char *)hnode_get(hn); hash_alloc_insert(selectors_new, hnode_getkey(hn), entry); } } else { uri = u_strdup(str); } epr = epr_create(uri, selectors_new, NULL); if (selectors_new) { hash_free(selectors_new); hash_free(selectors); } u_free(uri); return epr; } static int epr_add_selector(epr_t *epr, const char *name, selector_entry *selector) { int i; Selector *p; if(epr == NULL) return 0; p = epr->refparams.selectorset.selectors; for(i = 0; i< epr->refparams.selectorset.count; i++) { if(p->name && ( strcmp(name, p->name) == 0 ) ) { return -1; } p++; } p = epr->refparams.selectorset.selectors; p = u_realloc(p, (epr->refparams.selectorset.count+1) * sizeof(Selector)); if(p == NULL) return -1; p[epr->refparams.selectorset.count].name = u_strdup(name); p[epr->refparams.selectorset.count].type = selector->type; if(selector->type == 0) { if (selector->entry.text) { p[epr->refparams.selectorset.count].value = u_strdup(selector->entry.text); } } else { p[epr->refparams.selectorset.count].value = (char *)epr_copy(selector->entry.eprp); } epr->refparams.selectorset.selectors = p; epr->refparams.selectorset.count++; return 0; } int epr_selector_count(epr_t *epr) { if(epr == NULL) return 0; return epr->refparams.selectorset.count; } int epr_add_selector_text(epr_t *epr, const char *name, const char *text) { int r; selector_entry *entry; entry = u_malloc(sizeof(selector_entry)); entry->type = 0; entry->entry.text = (char *)text; r = epr_add_selector(epr, name, entry); u_free(entry); return r; } int epr_add_selector_epr(epr_t *epr, const char *name, epr_t *added_epr) { int r; selector_entry *entry; entry = u_malloc(sizeof(selector_entry)); entry->type = 1; entry->entry.eprp = added_epr; r = epr_add_selector(epr, name, entry); u_free(entry); return r; } int epr_delete_selector(epr_t *epr, const char *name) { int i,k; int count; Selector *selectors; if(epr == NULL || name == NULL) return 0; count = epr->refparams.selectorset.count; selectors = epr->refparams.selectorset.selectors; for(i =0; i < count; i++) { if(strcmp(name, selectors[i].name) == 0) break; } if(i == count) return -1; u_free(selectors[i].name); if(selectors[i].type == 0) { u_free(selectors[i].value); } else { epr_destroy((epr_t *)selectors[i].value); } for(k = i; k < count-1; k++) { memcpy(&selectors[k], &selectors[k+1], sizeof(Selector)); } epr->refparams.selectorset.selectors = u_realloc(selectors, (count-1)*sizeof(Selector)); epr->refparams.selectorset.count--; return 0; } void epr_destroy(epr_t *epr) { int i; Selector *p; if(epr == NULL) return; u_free(epr->address); u_free(epr->refparams.uri); p = epr->refparams.selectorset.selectors; for(i = 0; i< epr->refparams.selectorset.count; i++) { u_free(p->name); if(p->type == 0) u_free(p->value); else epr_destroy((epr_t*)p->value); p++; } u_free(epr->refparams.selectorset.selectors); u_free(epr); } epr_t *epr_copy(epr_t *epr) { int i; Selector *p1; Selector *p2; epr_t *cpy_epr = NULL; if(epr == NULL) return cpy_epr; cpy_epr = u_malloc(sizeof(epr_t)); if (epr && epr->address) cpy_epr->address = u_strdup(epr->address); cpy_epr->refparams.uri = u_strdup(epr->refparams.uri); cpy_epr->refparams.selectorset.count = epr->refparams.selectorset.count; cpy_epr->refparams.selectorset.selectors = u_malloc(sizeof(Selector)* epr->refparams.selectorset.count); p1 = epr->refparams.selectorset.selectors; p2 = cpy_epr->refparams.selectorset.selectors; for(i = 0; i < epr->refparams.selectorset.count; i++) { p2->name = u_strdup(p1->name); p2->type = p1->type; if(p1->type == 0) p2->value = u_strdup(p1->value); else p2->value = (char *)epr_copy((epr_t*)p1->value); p1++; p2++; } return cpy_epr; } int epr_cmp(epr_t *epr1, epr_t *epr2) { int i, j; int matches = 0; Selector *p1; Selector *p2; assert(epr1 != NULL && epr2 != NULL); //if(strcmp(epr1->address, epr2->address)) return 1; if(strcmp(epr1->refparams.uri, epr2->refparams.uri)) return 1; if(epr1->refparams.selectorset.count != epr2->refparams.selectorset.count) return 1; p1 = epr1->refparams.selectorset.selectors; for(i = 0; i < epr1->refparams.selectorset.count; i++) { p2 = epr1->refparams.selectorset.selectors; for(j = 0; j < epr2->refparams.selectorset.count; j++, p2++) { if(strcmp(p1->name, p2->name)) continue; if(p1->type != p2->type) continue; if(p1->type == 0) { if(strcmp(p1->value, p2->value)) continue; } else { if (epr_cmp((epr_t*)p1->value, (epr_t*)p2->value) == 1) { continue; } } matches++; } p1++; } if (matches == epr1->refparams.selectorset.count) return 0; else return 1; } char *epr_to_string(epr_t *epr) { int i, len; char *buf, *ptr; Selector *p = NULL; if (epr == NULL) return NULL; /* calculate buffer size */ len = strlen(epr->refparams.uri); p = epr->refparams.selectorset.selectors; for(i = 0; i < epr->refparams.selectorset.count; i++) { len += (strlen(p->name) + 1); /* (?|&)key */ if (p->type == 0) len += (strlen(p->value) + 1); /* =value */ else { char *value = epr_to_string((epr_t *)p->value); if (value) { len += (strlen(value) + 1); /* =value */ u_free(value); } } p++; } buf = u_malloc(len + 1); strcpy(buf, epr->refparams.uri); ptr = buf + strlen(buf); p = epr->refparams.selectorset.selectors; for(i = 0; i < epr->refparams.selectorset.count; i++) { if (i == 0) *ptr++ = '?'; else *ptr++ = '&'; strcpy(ptr, p->name); ptr += strlen(p->name); *ptr++ = '='; if (p->type == 0) { strcpy(ptr, p->value); ptr += strlen(p->value); } else { char *value = epr_to_string((epr_t *)p->value); if (value) { strcpy(ptr, value); ptr += strlen(value); u_free(value); } } p++; } *ptr++ = 0; return buf; } char *epr_to_txt(epr_t *epr, const char *ns, const char*epr_node_name) { char *buf = NULL; int len; WsXmlDocH doc2; WsXmlDocH doc = ws_xml_create_doc(ns, epr_node_name); WsXmlNodeH rootNode = ws_xml_get_doc_root(doc); epr_serialize(rootNode, NULL, NULL, epr, 1); doc2 = ws_xml_create_doc_by_import( rootNode); ws_xml_dump_memory_node_tree(ws_xml_get_doc_root(doc), &buf, &len); ws_xml_destroy_doc(doc);; ws_xml_destroy_doc(doc2); return buf; } char *epr_get_resource_uri(epr_t *epr) { if (epr) return epr->refparams.uri; else return NULL; } int epr_serialize(WsXmlNodeH node, const char *ns, const char *epr_node_name, epr_t *epr, int embedded) { int i; WsXmlNodeH eprnode = NULL; WsXmlNodeH refparamnode = NULL; WsXmlNodeH selectorsetnode = NULL; Selector *p = NULL; if(epr == NULL) return 0; if(epr_node_name) { eprnode = ws_xml_add_child(node, ns, epr_node_name, NULL); } else eprnode = node; if(embedded) ws_xml_add_child(eprnode, XML_NS_ADDRESSING, WSA_ADDRESS, epr->address); else ws_xml_add_child(eprnode, XML_NS_ADDRESSING, WSA_TO, epr->address); if(embedded) refparamnode = ws_xml_add_child(eprnode, XML_NS_ADDRESSING, WSA_REFERENCE_PARAMETERS, NULL); else refparamnode = node; ws_xml_add_child(refparamnode, XML_NS_WS_MAN, WSM_RESOURCE_URI, epr->refparams.uri); selectorsetnode = ws_xml_add_child(refparamnode, XML_NS_WS_MAN, WSM_SELECTOR_SET, NULL); p = epr->refparams.selectorset.selectors; for(i = 0; i < epr->refparams.selectorset.count; i++) { WsXmlNodeH temp = NULL; if(p->type == 0) temp = ws_xml_add_child(selectorsetnode, XML_NS_WS_MAN, WSM_SELECTOR, p->value); else { temp = ws_xml_add_child(selectorsetnode, XML_NS_WS_MAN, WSM_SELECTOR, NULL); epr_serialize(temp, XML_NS_ADDRESSING, WSA_EPR, (epr_t *)p->value, 1); } ws_xml_add_node_attr(temp, NULL, WSM_NAME, p->name); p++; } return 0; } epr_t *epr_deserialize(WsXmlNodeH node, const char *ns, const char *epr_node_name, int embedded) { int i; epr_t *epr = u_malloc(sizeof(epr_t)); WsXmlNodeH eprnode = NULL; WsXmlNodeH refparamnode = NULL; WsXmlNodeH temp = NULL; WsXmlNodeH selectorsetnode = NULL; WsXmlAttrH attr = NULL; Selector *p = NULL; if(epr_node_name) { eprnode = ws_xml_get_child(node, 0, ns, epr_node_name); if(eprnode == NULL) goto CLEANUP; } else { eprnode = node; } if(embedded) { temp = ws_xml_get_child(eprnode, 0, XML_NS_ADDRESSING, WSA_ADDRESS); } else { temp = ws_xml_get_child(eprnode, 0, XML_NS_ADDRESSING, WSA_TO); } if(temp == NULL) goto CLEANUP; epr->address = u_strdup(ws_xml_get_node_text(temp)); if(embedded) { refparamnode = ws_xml_get_child(eprnode, 0, XML_NS_ADDRESSING, WSA_REFERENCE_PARAMETERS); } else { refparamnode = node; } if(refparamnode == NULL) goto CLEANUP; temp = ws_xml_get_child(refparamnode, 0, XML_NS_WS_MAN, WSM_RESOURCE_URI); if(temp == NULL) goto CLEANUP; epr->refparams.uri = u_strdup(ws_xml_get_node_text(temp)); selectorsetnode = ws_xml_get_child(refparamnode, 0, XML_NS_WS_MAN, WSM_SELECTOR_SET); epr->refparams.selectorset.count = ws_xml_get_child_count(selectorsetnode); epr->refparams.selectorset.selectors = u_malloc(epr->refparams.selectorset.count * sizeof(Selector)); p = epr->refparams.selectorset.selectors; for(i = 0; i < epr->refparams.selectorset.count; i++) { temp = ws_xml_get_child(selectorsetnode, i, XML_NS_WS_MAN, WSM_SELECTOR); attr = ws_xml_find_node_attr(temp, NULL, "Name"); if(attr) { p->name = u_strdup(ws_xml_get_attr_value(attr)); } if(ws_xml_get_child(temp, 0, XML_NS_ADDRESSING, WSA_EPR)) { p->type = 1; p->value = (char *)epr_deserialize(temp, XML_NS_ADDRESSING, WSA_EPR, 1); } else { p->type = 0; p->value = u_strdup(ws_xml_get_node_text(temp)); } p++; } return epr; CLEANUP: u_free(epr); return NULL; } char *get_cimnamespace_from_selectorset(SelectorSet *selectorset) { int i = 0; while(i < selectorset->count) { if(strcmp(selectorset->selectors[i].name, CIM_NAMESPACE_SELECTOR) == 0) return selectorset->selectors[i].value; i++; } return NULL; } openwsman-2.4.3/tests/client/requests/request.xml000664 001750 001750 00000001637 12256012305 022511 0ustar00kentbkentb000000 000000 http://schemas.xmlsoap.org/ws/2004/09/enumeration/Enumerate http://langley.home.planux.com:8889/wsman http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_ComputerSystem uuid:d02518a4-20c3-10c3-8002-7a36080c0e00 http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous openwsman-2.4.3/src/server/shttpd/llist.h000664 001750 001750 00000002623 12256012305 020703 0ustar00kentbkentb000000 000000 /* * Copyright (c) 2004-2005 Sergey Lyubka * All rights reserved * * "THE BEER-WARE LICENSE" (Revision 42): * Sergey Lyubka wrote this file. As long as you retain this notice you * can do whatever you want with this stuff. If we meet some day, and you think * this stuff is worth it, you can buy me a beer in return. */ #ifndef LLIST_HEADER_INCLUDED #define LLIST_HEADER_INCLUDED /* * Linked list macros. */ struct llhead { struct llhead *prev; struct llhead *next; }; #define LL_INIT(N) ((N)->next = (N)->prev = (N)) #define LL_HEAD(H) struct llhead H = { &H, &H } #define LL_ENTRY(P,T,N) ((T *)((char *)(P) - offsetof(T, N))) #define LL_ADD(H, N) \ do { \ ((H)->next)->prev = (N); \ (N)->next = ((H)->next); \ (N)->prev = (H); \ (H)->next = (N); \ } while (0) #define LL_TAIL(H, N) \ do { \ ((H)->prev)->next = (N); \ (N)->prev = ((H)->prev); \ (N)->next = (H); \ (H)->prev = (N); \ } while (0) #define LL_DEL(N) \ do { \ ((N)->next)->prev = ((N)->prev); \ ((N)->prev)->next = ((N)->next); \ LL_INIT(N); \ } while (0) #define LL_EMPTY(N) ((N)->next == (N)) #define LL_FOREACH(H,N) for (N = (H)->next; N != (H); N = (N)->next) #define LL_FOREACH_SAFE(H,N,T) \ for (N = (H)->next, T = (N)->next; N != (H); \ N = (T), T = (N)->next) #endif /* LLIST_HEADER_INCLUDED */ openwsman-2.4.3/bindings/ruby/tests/ruby19_threaded_enumerate.rb000664 001750 001750 00000004255 12256012305 025310 0ustar00kentbkentb000000 000000 # # Do parallel enumerate request via celluloid gem # # Tests Ruby 1.9 threading model and proper use of rb_thread_blocking_region by the bindings # # Written by https://github.com/thehappycoder # require 'openwsman' require 'celluloid' require 'open-uri' connection_credentials = [ { :host => '10.120.67.93', :port => 5985, :username => 'wsman', :password => 'secret' }, { :host => '10.120.4.11', :port => 5985, :username => 'wsman', :password => 'secret' } ] uris = [ # 'http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/root/dcim/DCIM_NICView' 'http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_ComputerSystem' #'http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/root/dcim/DCIM_SoftwareIdentity' ] class Downloader include Celluloid def download(host, port, username, password, uri) puts "Requesting #{host}/#{File.basename(uri)}" @wsman = Openwsman::Client.new(host, port, "/wsman", "http", username, password) #Openwsman::debug = 9 @wsman.transport.verify_peer=0 @options = Openwsman::ClientOptions.new @options.flags = Openwsman::FLAG_ENUMERATION_OPTIMIZATION @options.max_elements = 100 puts "Client #{host} prepared" request(uri) do |response| puts "#{host} responded" end end def download_http(*params) host = 'http://google.com' puts "Requesting #{host}" open(host).read puts "#{host} responded" end private def request(uri, &response_handler_block) puts "Enumerate..." response = @wsman.enumerate(@options, nil, uri) puts "...done" response_handler_block.call(response) context = response.context puts "Context #{context}" while (context) response = @wsman.pull( @options, nil, uri, context ) response_handler_block.call(response) context = response.context end end end downloaders = Downloader.pool(size: connection_credentials.size * uris.size) connection_credentials.each do |credential| uris.each do |uri| puts "Starting async" downloaders.async.download(credential[:host], credential[:port], credential[:username], credential[:password], uri) end end sleep openwsman-2.4.3/src/plugins/identify/identify_stubs.c000664 001750 001750 00000004416 12256012305 023264 0ustar00kentbkentb000000 000000 /******************************************************************************* * 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 */ #ifdef HAVE_CONFIG_H #include "wsman_config.h" #endif #include "stdlib.h" #include "stdio.h" #include "string.h" #include "ctype.h" #include "u/libu.h" #include "wsman-xml-api.h" #include "wsman-soap.h" #include "wsman-xml-serializer.h" #include "wsman-dispatcher.h" #include "identify.h" wsmid_identify g_wsmid_identify = { XML_NS_WS_MAN, "Openwsman Project" , PACKAGE_VERSION }; wsmid_identify* wsmid_identify_Identify_EP(WsContextH cntx) { wsmid_identify *buf = u_malloc(sizeof(wsmid_identify)); memcpy(buf, &g_wsmid_identify, sizeof(wsmid_identify)); return buf; } openwsman-2.4.3/bindings/ruby/tests/cimenum.rb000664 001750 001750 00000002562 12256012305 021704 0ustar00kentbkentb000000 000000 # cimenum.rb # enumerate/pull/release for any class require 'test/unit' require 'rexml/document' require File.join(File.dirname(__FILE__),'_loadpath') require 'openwsman' require '_client' def show_fault result return unless result.fault? fault = Openwsman::Fault.new result puts "Fault code #{fault.code}, subcode #{fault.subcode}" puts "\treason #{fault.reason}" puts "\tdetail #{fault.detail}" exit 1 end debug = nil namespace = "root/cimv2" classname = nil loop do opt = ARGV.shift break unless opt case opt when "-d" then debug = true when "-n" then namespace = ARGV.shift else classname = opt end end raise "No classname given" unless classname client = Client.open options = Openwsman::ClientOptions.new uri = Openwsman.epr_uri_for namespace, classname result = client.enumerate( options, nil, uri ) raise "Connection failed" unless result STDERR.puts result.to_xml if debug show_fault result count = 0 context = result.context while (context) count += 1 result = client.pull( options, nil, uri, context ) # puts "Response ##{count}" # puts "### #{result.to_xml}" result.body.PullResponse.Items.each do |child| puts "#{child.name}" child.each do |prop| puts "\t#{prop.name} = #{prop.text}" end end context = result.context end client.release( options, uri, context ) if context puts "Got #{count} responses" openwsman-2.4.3/include/u/pthreadx.h000664 001750 001750 00000005635 12256012305 017665 0ustar00kentbkentb000000 000000 /* Copyright (C) 2001 by First Peer, Inc. All rights reserved. ** ** Redistribution and use in source and binary forms, with or without ** modification, are permitted provided that the following conditions ** are met: ** 1. Redistributions of source code must retain the above copyright ** notice, this list of conditions and the following disclaimer. ** 2. 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. ** 3. The name of the author may not be used to endorse or promote products ** derived from this software without specific prior written permission. ** ** THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 THE AUTHOR OR 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. */ #ifndef PTHREADX_H_INCLUDED #define PTHREADX_H_INCLUDED #ifndef WIN32 # include #elif defined (WIN32) #include #define PTHREAD_MUTEX_RECURSIVE_NP 0 typedef HANDLE pthread_t; typedef CRITICAL_SECTION pthread_mutex_t; #define PTHREAD_MUTEX_INITIALIZER NULL //usage: pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER; typedef struct { int attrs; //currently unused. placeholder. } pthread_attr_t; typedef struct { int attrs; //currently unused. placeholder. int type; } pthread_mutexattr_t; //typedef void * (*pthread_func)(void *); typedef unsigned ( __stdcall *pthread_func )( void * ); extern int pthread_create(pthread_t *new_thread_ID, const pthread_attr_t *attr, pthread_func start_func, void *arg); extern int pthread_cancel(pthread_t target_thread); extern int pthread_join(pthread_t target_thread, void **status); extern int pthread_detach(pthread_t target_thread); extern int pthread_mutex_init(pthread_mutex_t *mp, const pthread_mutexattr_t *attr); extern int pthread_mutex_lock(pthread_mutex_t *mp); extern int pthread_mutex_unlock(pthread_mutex_t *mp); extern int pthread_mutex_destroy(pthread_mutex_t *mp); extern int pthread_mutexattr_settype(pthread_mutexattr_t *attr, int t); extern int pthread_mutex_trylock(pthread_mutex_t *m); extern int pthread_mutexattr_init(pthread_mutexattr_t *attr); #endif /* WIN32 */ #endif openwsman-2.4.3/tests/client/test_pull.c000664 001750 001750 00000017271 12256012305 020604 0ustar00kentbkentb000000 000000 /******************************************************************************* * 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 */ #include "wsman_config.h" #include #include #include #include #include #include #include "u/libu.h" #include "wsman-client-api.h" #include "wsman-client-transport.h" #include "wsman-debug.h" #define INVALID_RURI "wsa:DestinationUnreachablex" #define XPATH_V "/s:Envelope/s:Body/s:Fault/s:Code/s:Subcode/s:Value" //int facility = LOG_DAEMON; int errors = 0; unsigned char optimized_flags; typedef struct { const char *server; int port; const char *path; const char *scheme; const char *username; const char *password; } ServerData; typedef struct { /* Explanation of what you should see */ const char *explanation; /* Resource UR to test against */ const char *resource_uri; /* Selectors in the form of a URI query key=value&key2=value2 */ const char *selectors; const char* xpath_expression; const char* expected_value; /* What the final status code should be. */ unsigned int final_status; unsigned char flags; unsigned int max_elements; } TestData; ServerData sd[] = { {"localhost", 5985, "/wsman", "http", "wsman", "secret"} }; TestData tests[] = { { "Enumeration with non existent Resource URI", "http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_ComputerSystemxx", NULL, "/s:Envelope/s:Body/s:Fault/s:Code/s:Subcode/s:Value", "wsa:DestinationUnreachable", 500, FLAG_NONE, 0 }, { "Enumeration with valid Resource URI.", "http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_ComputerSystem", NULL, NULL, NULL, 200, FLAG_NONE, 0 }, { "Enumeration with valid Resource URI and additional invalid selectors.", "http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_ComputerSystem", NULL, NULL, NULL, 200, FLAG_NONE, 1 }, { "Enumeration with valid Resource URI/Count Estimation.", "http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_ComputerSystem", NULL, NULL, NULL, 200, FLAG_ENUMERATION_COUNT_ESTIMATION, 0 }, { "Enumeration with valid Resource URI/Optimization.", "http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_ComputerSystem", NULL, NULL, NULL, 200, FLAG_ENUMERATION_OPTIMIZATION, 0 }, { "Enumeration with Count Estimation/Optimzation and get all elements.", "http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_ComputerSystem", NULL, NULL, NULL, 200, FLAG_ENUMERATION_OPTIMIZATION | FLAG_ENUMERATION_COUNT_ESTIMATION, 10 }, { "Enumeration with Count Estimation/Optimzation/Epr and get all elements.", "http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_ComputerSystem", NULL, NULL, NULL, 200, FLAG_ENUMERATION_OPTIMIZATION | FLAG_ENUMERATION_COUNT_ESTIMATION | FLAG_ENUMERATION_ENUM_EPR, 10 }, { "Enumeration with Count Estimation/Optimzation/ObjAndEpr and get all elements.", "http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_ComputerSystem", NULL, NULL, NULL, 200, FLAG_ENUMERATION_OPTIMIZATION | FLAG_ENUMERATION_COUNT_ESTIMATION | FLAG_ENUMERATION_ENUM_OBJ_AND_EPR, 10 } }; int ntests = sizeof (tests) / sizeof (tests[0]); static void debug_message_handler (const char *str, debug_level_e level, void *user_data) { if (wsman_debug_level_debugged(level)) { struct tm *tm; time_t now; char timestr[128]; time (&now); tm = localtime (&now); strftime (timestr, 128, "%b %e %T", tm); fprintf (stderr, "%s %s\n", timestr, str); } } static void initialize_logging (void) { debug_add_handler (debug_message_handler, DEBUG_LEVEL_ALWAYS, NULL); } static void wsman_output(WsXmlDocH doc) { if (doc) ws_xml_dump_node_tree(stdout, ws_xml_get_doc_root(doc)); else printf("returned doc is null\n"); return; } int main(int argc, char** argv) { int i; WsManClient *cl; WsXmlDocH docp; client_opt_t *options = NULL; char *enumContext = NULL; //unsigned int id = 0; //wsman_debug_set_level(DEBUG_LEVEL_DEBUG); initialize_logging(); //wsmc_add_handler(wsmc_handler, NULL); for (i = 0; i < ntests; i++) { printf ("Test %d: %s:", i + 1, tests[i].explanation); //printf ("------------------------------------------------\n"); cl = wsmc_create( sd[0].server, sd[0].port, sd[0].path, sd[0].scheme, sd[0].username, sd[0].password); wsmc_transport_init(cl, NULL); options = wsmc_options_init(); options->flags = tests[i].flags; options->max_elements = tests[i].max_elements; if (tests[i].selectors != NULL) wsmc_add_selectors_from_str (options, tests[i].selectors); WsXmlDocH enum_response = wsmc_action_enumerate(cl, (char *)tests[i].resource_uri , options, NULL); if (!enum_response) { printf("\t\t\033[22;31mUNRESOLVED\033[m\n"); goto CONTINUE; } //wsman_output(enum_response); if ((char *)tests[i].expected_value != NULL) { char *xp = ws_xml_get_xpath_value(enum_response, (char *)tests[i].xpath_expression); if (xp) { if (strcmp(xp,(char *)tests[i].expected_value ) == 0) printf("\t\t\033[22;32mPASSED\033[m\n"); else printf("\t\t\033[22;31mFAILED\033[m\n"); u_free(xp); } } wsmc_free_enum_context(enumContext); enumContext = wsmc_get_enum_context(enum_response); ws_xml_destroy_doc(enum_response); while (enumContext != NULL) { docp = wsmc_action_pull(cl, (char *)tests[i].resource_uri, options, NULL, enumContext); if (!docp) { printf("\t\t\033[22;31mUNRESOLVED\033[m\n"); goto CONTINUE; } wsman_output(docp); wsmc_free_enum_context(enumContext); enumContext = wsmc_get_enum_context(docp); ws_xml_destroy_doc(docp); } CONTINUE: wsmc_options_destroy(options); wsmc_release(cl); } return 0; } openwsman-2.4.3/src/lib/wsman-session-client.c000664 001750 001750 00000000000 12256012305 021546 0ustar00kentbkentb000000 000000 openwsman-2.4.3/include/u/000775 001750 001750 00000000000 12256012305 015664 5ustar00kentbkentb000000 000000 openwsman-2.4.3/include/u/hash.h000664 001750 001750 00000024143 12256012305 016764 0ustar00kentbkentb000000 000000 /* * Hash Table Data Type * Copyright (C) 1997 Kaz Kylheku * * Free Software License: * * All rights are reserved by the author, with the following exceptions: * Permission is granted to freely reproduce and distribute this software, * possibly in exchange for a fee, provided that this copyright notice appears * intact. Permission is also granted to adapt this software to produce * derivative works, as long as the modified versions carry this copyright * notice and additional notices stating that the work has been modified. * This source code may be translated into executable form and incorporated * into proprietary software; there is no requirement for such software to * contain a copyright notice related to this source. * * $Id: hash.h,v 1.22.2.7 2000/11/13 01:36:45 kaz Exp $ * $Name: kazlib_1_20 $ */ #ifndef HASH_H #define HASH_H #include #ifdef KAZLIB_SIDEEFFECT_DEBUG #include "sfx.h" #endif /* * Blurb for inclusion into C++ translation units */ #ifdef __cplusplus extern "C" { #endif typedef unsigned long hashcount_t; #define HASHCOUNT_T_MAX ULONG_MAX typedef unsigned long hash_val_t; #define HASH_VAL_T_MAX ULONG_MAX extern int hash_val_t_bit; #ifndef HASH_VAL_T_BIT #define HASH_VAL_T_BIT ((int) hash_val_t_bit) #endif /* * Hash chain node structure. * Notes: * 1. This preprocessing directive is for debugging purposes. The effect is * that if the preprocessor symbol KAZLIB_OPAQUE_DEBUG is defined prior to the * inclusion of this header, then the structure shall be declared as having * the single member int __OPAQUE__. This way, any attempts by the * client code to violate the principles of information hiding (by accessing * the structure directly) can be diagnosed at translation time. However, * note the resulting compiled unit is not suitable for linking. * 2. This is a pointer to the next node in the chain. In the last node of a * chain, this pointer is null. * 3. The key is a pointer to some user supplied data that contains a unique * identifier for each hash node in a given table. The interpretation of * the data is up to the user. When creating or initializing a hash table, * the user must supply a pointer to a function for comparing two keys, * and a pointer to a function for hashing a key into a numeric value. * 4. The value is a user-supplied pointer to void which may refer to * any data object. It is not interpreted in any way by the hashing * module. * 5. The hashed key is stored in each node so that we don't have to rehash * each key when the table must grow or shrink. */ typedef struct hnode_t { #if defined(HASH_IMPLEMENTATION) || !defined(KAZLIB_OPAQUE_DEBUG) /* 1 */ struct hnode_t *hash_next; /* 2 */ const void *hash_key; /* 3 */ const void *hash_data; /* 4 */ hash_val_t hash_hkey; /* 5 */ #else int hash_dummy; #endif } hnode_t; /* * The comparison function pointer type. A comparison function takes two keys * and produces a value of -1 if the left key is less than the right key, a * value of 0 if the keys are equal, and a value of 1 if the left key is * greater than the right key. */ typedef int (*hash_comp_t)(const void *, const void *); /* * The hashing function performs some computation on a key and produces an * integral value of type hash_val_t based on that key. For best results, the * function should have a good randomness properties in *all* significant bits * over the set of keys that are being inserted into a given hash table. In * particular, the most significant bits of hash_val_t are most significant to * the hash module. Only as the hash table expands are less significant bits * examined. Thus a function that has good distribution in its upper bits but * not lower is preferrable to one that has poor distribution in the upper bits * but not the lower ones. */ typedef hash_val_t (*hash_fun_t)(const void *); /* * allocator functions */ typedef hnode_t *(*hnode_alloc_t)(void *); typedef void (*hnode_free_t)(hnode_t *, void *); /* * This is the hash table control structure. It keeps track of information * about a hash table, as well as the hash table itself. * Notes: * 1. Pointer to the hash table proper. The table is an array of pointers to * hash nodes (of type hnode_t). If the table is empty, every element of * this table is a null pointer. A non-null entry points to the first * element of a chain of nodes. * 2. This member keeps track of the size of the hash table---that is, the * number of chain pointers. * 3. The count member maintains the number of elements that are presently * in the hash table. * 4. The maximum count is the greatest number of nodes that can populate this * table. If the table contains this many nodes, no more can be inserted, * and the hash_isfull() function returns true. * 5. The high mark is a population threshold, measured as a number of nodes, * which, if exceeded, will trigger a table expansion. Only dynamic hash * tables are subject to this expansion. * 6. The low mark is a minimum population threshold, measured as a number of * nodes. If the table population drops below this value, a table shrinkage * will occur. Only dynamic tables are subject to this reduction. No table * will shrink beneath a certain absolute minimum number of nodes. * 7. This is the a pointer to the hash table's comparison function. The * function is set once at initialization or creation time. * 8. Pointer to the table's hashing function, set once at creation or * initialization time. * 9. The current hash table mask. If the size of the hash table is 2^N, * this value has its low N bits set to 1, and the others clear. It is used * to select bits from the result of the hashing function to compute an * index into the table. * 10. A flag which indicates whether the table is to be dynamically resized. It * is set to 1 in dynamically allocated tables, 0 in tables that are * statically allocated. */ typedef struct hash_t { #if defined(HASH_IMPLEMENTATION) || !defined(KAZLIB_OPAQUE_DEBUG) struct hnode_t **hash_table; /* 1 */ hashcount_t hash_nchains; /* 2 */ hashcount_t hash_nodecount; /* 3 */ hashcount_t hash_maxcount; /* 4 */ hashcount_t hash_highmark; /* 5 */ hashcount_t hash_lowmark; /* 6 */ hash_comp_t hash_compare; /* 7 */ hash_fun_t hash_function; /* 8 */ hnode_alloc_t hash_allocnode; hnode_free_t hash_freenode; void *hash_context; hash_val_t hash_mask; /* 9 */ int hash_dynamic; /* 10 */ #else int hash_dummy; #endif } hash_t; /* * Hash scanner structure, used for traversals of the data structure. * Notes: * 1. Pointer to the hash table that is being traversed. * 2. Reference to the current chain in the table being traversed (the chain * that contains the next node that shall be retrieved). * 3. Pointer to the node that will be retrieved by the subsequent call to * hash_scan_next(). */ typedef struct hscan_t { #if defined(HASH_IMPLEMENTATION) || !defined(KAZLIB_OPAQUE_DEBUG) hash_t *hash_table; /* 1 */ hash_val_t hash_chain; /* 2 */ hnode_t *hash_next; /* 3 */ #else int hash_dummy; #endif } hscan_t; extern hash_t *ow_hash_create(hashcount_t, hash_comp_t, hash_fun_t); extern hash_t *ow_hash_create2(hashcount_t, hash_comp_t, hash_fun_t); extern hash_t *ow_hash_create3(hashcount_t, hash_comp_t, hash_fun_t); extern void ow_hash_set_allocator(hash_t *, hnode_alloc_t, hnode_free_t, void *); extern void ow_hash_destroy(hash_t *); extern void ow_hash_free_nodes(hash_t *); extern void ow_hash_free(hash_t *); extern hash_t *ow_hash_init(hash_t *, hashcount_t, hash_comp_t, hash_fun_t, hnode_t **, hashcount_t); extern void ow_hash_insert(hash_t *, hnode_t *, const void *); extern hnode_t *ow_hash_lookup(hash_t *, const void *); extern hnode_t *ow_hash_delete(hash_t *, hnode_t *); extern int ow_hash_alloc_insert(hash_t *, const void *, const void *); extern void ow_hash_delete_free(hash_t *, hnode_t *); extern void ow_hnode_put(hnode_t *, const void *); extern const void *ow_hnode_get(hnode_t *); extern const void *ow_hnode_getkey(hnode_t *); extern hashcount_t ow_hash_count(hash_t *); extern hashcount_t ow_hash_size(hash_t *); extern int ow_hash_isfull(hash_t *); extern int ow_hash_isempty(hash_t *); extern void ow_hash_scan_begin(hscan_t *, hash_t *); extern hnode_t *ow_hash_scan_next(hscan_t *); extern hnode_t *ow_hash_scan_delete(hash_t *, hnode_t *); extern void ow_hash_scan_delfree(hash_t *, hnode_t *); extern int ow_hash_verify(hash_t *); extern hnode_t *ow_hnode_create(const void *); extern hnode_t *ow_hnode_init(hnode_t *, const void *); extern void ow_hnode_destroy(hnode_t *); #if defined(HASH_IMPLEMENTATION) || !defined(KAZLIB_OPAQUE_DEBUG) #ifdef KAZLIB_SIDEEFFECT_DEBUG #define hash_isfull(H) (SFX_CHECK(H)->hash_nodecount == (H)->hash_maxcount) #else #define hash_isfull(H) ((H)->hash_nodecount == (H)->hash_maxcount) #endif #define hash_isempty(H) ((H)->hash_nodecount == 0) #define hash_count(H) ((H)->hash_nodecount) #define hash_size(H) ((H)->hash_nchains) #define hnode_get(N) ((N)->hash_data) #define hnode_getkey(N) ((N)->hash_key) #define hnode_put(N, V) ((N)->hash_data = (V)) #define hash_create ow_hash_create #define hash_create2 ow_hash_create2 #define hash_create3 ow_hash_create3 #define hash_set_allocator ow_hash_set_allocator #define hash_destroy ow_hash_destroy #define hash_free_nodes ow_hash_free_nodes #define hash_free ow_hash_free #define hash_init ow_hash_init #define hash_insert ow_hash_insert #define hash_lookup ow_hash_lookup #define hash_delete ow_hash_delete #define hash_alloc_insert ow_hash_alloc_insert #define hash_delete_free ow_hash_delete_free #define hash_scan_begin ow_hash_scan_begin #define hash_scan_next ow_hash_scan_next #define hash_scan_delete ow_hash_scan_delete #define hash_scan_delfree ow_hash_scan_delfree #define hash_verify ow_hash_verify #define hnode_gekey ow_hnode_getkey #define hnode_create ow_hnode_create #define hnode_init ow_hnode_init #define hnode_destroy ow_hnode_destroy #endif #ifdef __cplusplus } #endif #endif openwsman-2.4.3/bindings/ruby/tests/xmlattr.rb000664 001750 001750 00000001710 12256012305 021734 0ustar00kentbkentb000000 000000 # test XmlAttr class require 'test/unit' require File.join(File.dirname(__FILE__),'_loadpath') require 'openwsman' class XmlAttrTest < Test::Unit::TestCase def test_attr_constructor doc = Openwsman::XmlDoc.new "test" assert doc root = doc.root assert root # root shouldn't have any attributes assert root.attr_count == 0 # so lets add one attr = root.attr_add( Openwsman::XML_NS_SOAP_1_2, "attr", "value" ) assert attr assert attr.ns == Openwsman::XML_NS_SOAP_1_2 assert attr.name == "attr" assert attr.value == "value" # if must be there assert root.attr_count == 1 # it must be findable attr = root.attr_find( Openwsman::XML_NS_SOAP_1_2, "attr" ) assert attr.value == "value" # it must be enumerable root.each_attr { |attr| # puts "Attr #{attr.ns}:#{attr.name}=#{attr.value}" assert attr assert attr.ns assert attr.name assert attr.value } end end openwsman-2.4.3/src/lib/wsman-dispatcher.c000664 001750 001750 00000071571 12256012305 020762 0ustar00kentbkentb000000 000000 /******************************************************************************* * 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 Eugene Yarmosh */ #ifdef HAVE_CONFIG_H #include #endif #define _GNU_SOURCE #include #include #include #include #include "u/libu.h" #include "wsman-xml-api.h" #include "wsman-client-api.h" #include "wsman-soap.h" #include "wsman-xml.h" #include "wsman-dispatcher.h" #include "wsman-xml-serialize.h" #include "wsman-faults.h" #include "wsman-soap-envelope.h" /** * @defgroup Dispatcher Dispatcher * @brief SOAP Dispatcher * * @{ */ struct __MuHeaderInfo { char *ns; char *name; }; static int is_mu_header(WsXmlNodeH header) { int i; char *name, *ns; static struct __MuHeaderInfo s_Info[] = { {XML_NS_ADDRESSING, WSA_TO}, {XML_NS_ADDRESSING, WSA_MESSAGE_ID}, {XML_NS_ADDRESSING, WSA_RELATES_TO}, {XML_NS_ADDRESSING, WSA_ACTION}, {XML_NS_ADDRESSING, WSA_REPLY_TO}, {XML_NS_ADDRESSING, WSA_FROM}, {XML_NS_WS_MAN, WSM_RESOURCE_URI}, {XML_NS_WS_MAN, WSM_SELECTOR_SET}, {XML_NS_WS_MAN, WSM_MAX_ENVELOPE_SIZE}, {XML_NS_WS_MAN, WSM_OPERATION_TIMEOUT}, {XML_NS_WS_MAN, WSM_FRAGMENT_TRANSFER}, {XML_NS_TRUST, WST_ISSUEDTOKENS}, {NULL, NULL} }; name = ws_xml_get_node_local_name(header); ns = ws_xml_get_node_name_ns(header); for (i = 0; s_Info[i].name != NULL; i++) { if ((ns == NULL && s_Info[i].ns == NULL) || (ns != NULL && s_Info[i].ns != NULL && !strcmp(ns, s_Info[i].ns))) { if (!strcmp(name, s_Info[i].name)) return 1; } } debug("mustUnderstand: %s:%s", !ns ? "null" : ns, name ? name : "NULL"); return 0; } static void generate_op_fault(op_t * op, WsmanFaultCodeType faultCode, WsmanFaultDetailType faultDetail) { if (op->out_doc) { ws_xml_destroy_doc(op->out_doc); op->out_doc = NULL; } if (op->in_doc == NULL) { return; } op->out_doc = wsman_generate_fault(op->in_doc, faultCode, faultDetail, NULL); return; } static void generate_notunderstood_fault(op_t * op, WsXmlNodeH notUnderstoodHeader) { WsXmlNodeH child; WsXmlNodeH header; if (op->in_doc == NULL) return; generate_op_fault(op, SOAP_FAULT_MUSTUNDERSTAND, 0); if (op->out_doc != NULL) { header = ws_xml_get_soap_header(op->out_doc); if (header) { child = ws_xml_add_child(header, XML_NS_SOAP_1_2, "NotUnderstood", NULL); ws_xml_add_qname_attr(child, NULL, "qname", ws_xml_get_node_name_ns (notUnderstoodHeader), ws_xml_get_node_local_name (notUnderstoodHeader)); } } else { error("cant generate fault"); } return; } static int check_for_duplicate_selectors(op_t * op) { WsXmlNodeH header, node, selector; int retval = 0, index = 0; hash_t *h; header = wsman_get_soap_header_element( op->in_doc, NULL, NULL); if ((node = ws_xml_get_child(header, 0, XML_NS_WS_MAN, WSM_SELECTOR_SET)) == NULL) { // No selectors return 0; } h = hash_create(HASHCOUNT_T_MAX, 0, 0); if (h == NULL) { generate_op_fault(op, WSMAN_INTERNAL_ERROR, OWSMAN_NO_DETAILS); error("could not create hash"); return 1; } while ((selector = ws_xml_get_child(node, index++, XML_NS_WS_MAN, WSM_SELECTOR))) { char *attrVal = ws_xml_find_attr_value(selector, NULL, WSM_NAME); if (!attrVal) continue; if (hash_lookup(h, attrVal)) { generate_op_fault(op, WSMAN_INVALID_SELECTORS, WSMAN_DETAIL_DUPLICATE_SELECTORS); debug("Selector %s duplicated", attrVal); retval = 1; break; } if (!hash_alloc_insert(h, attrVal, ws_xml_get_node_text(selector))) { generate_op_fault(op, WSMAN_INTERNAL_ERROR, OWSMAN_NO_DETAILS); retval = 1; error("hash_alloc_insert failed"); break; } } hash_free_nodes(h); hash_destroy(h); return retval; } static int validate_control_headers(op_t * op) { unsigned long size = 0; time_t duration; WsXmlNodeH header, child, maxsize; char *mu = NULL; header = wsman_get_soap_header_element( op->in_doc, NULL, NULL); maxsize = ws_xml_get_child(header, 0, XML_NS_WS_MAN, WSM_MAX_ENVELOPE_SIZE); mu = ws_xml_find_attr_value(maxsize, XML_NS_SOAP_1_2, SOAP_MUST_UNDERSTAND); if (mu != NULL && strcmp(mu, "true") == 0) { size = ws_deserialize_uint32(NULL, header, 0, XML_NS_WS_MAN, WSM_MAX_ENVELOPE_SIZE); if (size < WSMAN_MINIMAL_ENVELOPE_SIZE_REQUEST) { generate_op_fault(op, WSMAN_ENCODING_LIMIT, WSMAN_DETAIL_MINIMUM_ENVELOPE_LIMIT); return 0; } op->maxsize = size; } child = ws_xml_get_child(header, 0, XML_NS_WS_MAN, WSM_OPERATION_TIMEOUT); if (child != NULL) { char *text = ws_xml_get_node_text(child); char *nsUri = ws_xml_get_node_name_ns(header); if (text == NULL || ws_deserialize_duration(text, &duration)) { generate_op_fault(op, WSA_INVALID_MESSAGE_INFORMATION_HEADER, WSMAN_DETAIL_OPERATION_TIMEOUT); return 0; } if (duration <= 0) { generate_op_fault(op, WSMAN_TIMED_OUT, 0); return 0; } op->expires = duration; // Not supported now if (ws_xml_find_attr_bool (child, nsUri, SOAP_MUST_UNDERSTAND)) { generate_op_fault(op, WSMAN_UNSUPPORTED_FEATURE, WSMAN_DETAIL_OPERATION_TIMEOUT); return 0; } } return 1; } static WsXmlNodeH validate_mustunderstand_headers(op_t * op) { WsXmlNodeH child = NULL, header = NULL; int i; char *nsUri; header = wsman_get_soap_header_element(op->in_doc, NULL, NULL); nsUri = ws_xml_get_node_name_ns(header); for (i = 0;(child = ws_xml_get_child(header, i, NULL, NULL)) != NULL; i++) { if (ws_xml_find_attr_bool(child, nsUri, SOAP_MUST_UNDERSTAND)) { if (!is_mu_header(child)) { break; } } } if (child != NULL) { debug("Mustunderstand Fault: %s", ws_xml_get_node_text(child)); } return child; } static int check_supported_dialect(const char *dialect) { if (strcmp(dialect, WSM_ASSOCIATION_FILTER_DIALECT) == 0) return 0; else if (strcmp(dialect, WSM_XPATH_FILTER_DIALECT) == 0) return 0; else if (strcmp(dialect, WSM_WQL_FILTER_DIALECT) == 0) return 0; else if (strcmp(dialect, WSM_CQL_FILTER_DIALECT) == 0) return 0; else if (strcmp(dialect, WSM_SELECTOR_FILTER_DIALECT) == 0) return 0; return 1; } /** * Check for duplicate Message ID * @param op operation * @return status */ static int check_unsupported_features(op_t * op) { WsXmlNodeH enumurate; WsXmlNodeH subscribe; WsXmlNodeH header = wsman_get_soap_header_element( op->in_doc, NULL, NULL); WsXmlNodeH body = ws_xml_get_soap_body(op->in_doc); int retVal = 0; WsXmlNodeH n, m, k; char *resource_uri = NULL, *mu = NULL; WsXmlAttrH attr = NULL; n = ws_xml_get_child(header, 0, XML_NS_ADDRESSING, WSA_FAULT_TO); if (n != NULL) { debug("wsa:FaultTo is not supported"); retVal = 1; generate_op_fault(op, WSMAN_UNSUPPORTED_FEATURE, WSMAN_DETAIL_ADDRESSING_MODE); goto DONE; } n = ws_xml_get_child(header, 0, XML_NS_WS_MAN, WSM_LOCALE); if (n != NULL) { debug("Locale header found"); mu = ws_xml_find_attr_value(n, XML_NS_SOAP_1_2, SOAP_MUST_UNDERSTAND); if (mu != NULL && strcmp(mu, "true") == 0) { retVal = 1; generate_op_fault(op, WSMAN_UNSUPPORTED_FEATURE, WSMAN_DETAIL_LOCALE); goto DONE; } } #if 0 n = ws_xml_get_child(header, 0, XML_NS_WS_MAN, WSM_FRAGMENT_TRANSFER); if (n != NULL) { debug("FragmentTransfer header found"); mu = ws_xml_find_attr_value(n, XML_NS_SOAP_1_2, SOAP_MUST_UNDERSTAND); if (mu != NULL && strcmp(mu, "true") == 0) { retVal = 1; generate_op_fault(op, WSMAN_UNSUPPORTED_FEATURE, WSMAN_DETAIL_FRAGMENT_LEVEL_ACCESS); goto DONE; } } #endif enumurate = ws_xml_get_child(body, 0, XML_NS_ENUMERATION, WSENUM_ENUMERATE); if (enumurate) { n = ws_xml_get_child(enumurate, 0, XML_NS_ENUMERATION, WSENUM_END_TO); if (n != NULL) { retVal = 1; generate_op_fault(op, WSMAN_UNSUPPORTED_FEATURE, WSMAN_DETAIL_ADDRESSING_MODE); } n = ws_xml_get_child(enumurate, 0, XML_NS_ENUMERATION, WSENUM_FILTER); m = ws_xml_get_child(enumurate, 0, XML_NS_WS_MAN, WSM_FILTER); if (n != NULL && m != NULL) { retVal = 1; generate_op_fault(op, WSEN_CANNOT_PROCESS_FILTER, 0); goto DONE; } else if (n || m) { char *dia = NULL; if (n) { dia = ws_xml_find_attr_value(n, NULL, WSM_DIALECT); } else if (m) { dia = ws_xml_find_attr_value(m, NULL, WSM_DIALECT); } if (dia) retVal = check_supported_dialect(dia); else retVal = check_supported_dialect (WSM_XPATH_FILTER_DIALECT); if (retVal) { retVal = 1; generate_op_fault(op, WSEN_FILTER_DIALECT_REQUESTED_UNAVAILABLE, 0); goto DONE; } } k = ws_xml_get_child(header, 0, XML_NS_WS_MAN, WSM_RESOURCE_URI); if (k) resource_uri = ws_xml_get_node_text(k); if (resource_uri && (strcmp(resource_uri, CIM_ALL_AVAILABLE_CLASSES) == 0)) { if (!n && !m) { retVal = 1; generate_op_fault(op, WSMAN_UNSUPPORTED_FEATURE, WSMAN_DETAIL_FILTERING_REQUIRED); goto DONE; } } } subscribe = ws_xml_get_child(body, 0, XML_NS_EVENTING, WSEVENT_SUBSCRIBE); if(subscribe) { /* n = ws_xml_get_child(subscribe, 0, XML_NS_EVENTING, WSEVENT_ENDTO); if(n) { retVal = 1; generate_op_fault(op, WSMAN_UNSUPPORTED_FEATURE, WSMAN_DETAIL_ADDRESSING_MODE); goto DONE; } */ n = ws_xml_get_child(subscribe, 0, XML_NS_EVENTING, WSEVENT_DELIVERY); if(n == NULL) { retVal = 1; generate_op_fault(op, WSE_INVALID_MESSAGE, 0); goto DONE; } attr = ws_xml_find_node_attr(n, NULL,WSEVENT_DELIVERY_MODE); if(attr) { mu = ws_xml_get_attr_value(attr); if (strcasecmp(mu, WSEVENT_DELIVERY_MODE_PUSH) && strcasecmp(mu, WSEVENT_DELIVERY_MODE_PUSHWITHACK) && strcasecmp(mu, WSEVENT_DELIVERY_MODE_EVENTS) && strcasecmp(mu, WSEVENT_DELIVERY_MODE_PULL)) { debug("Unsupported delivery mode : %s",ws_xml_get_attr_value(attr)); retVal = 1; generate_op_fault(op, WSE_DELIVERY_MODE_REQUESTED_UNAVAILABLE, 0); goto DONE; } } m = ws_xml_get_child(n, 0, XML_NS_WS_MAN, WSM_CONNECTIONRETRY); if(m) { retVal = 1; generate_op_fault(op, WSMAN_UNSUPPORTED_FEATURE, WSMAN_DETAIL_DELIVERY_RETRIES); goto DONE; } } DONE: return retVal; } /** * Check for duplicate Message ID * @param op operation * @return status */ static int wsman_is_duplicate_message_id(op_t * op) { WsXmlNodeH header = wsman_get_soap_header_element(op->in_doc, NULL, NULL); int retVal = 0; SoapH soap; WsXmlNodeH msgIdNode; soap = op->dispatch->soap; msgIdNode = ws_xml_get_child(header, 0, XML_NS_ADDRESSING, WSA_MESSAGE_ID); if (msgIdNode != NULL) { lnode_t *node; char *msgId; msgId = ws_xml_get_node_text(msgIdNode); if (msgId[0] == 0 ) { generate_op_fault(op, WSA_INVALID_MESSAGE_INFORMATION_HEADER, 0 ); debug("MessageId missing"); return 1; } debug("Checking Message ID: %s", msgId); u_lock(soap); if (soap->processedMsgIdList == NULL) { soap->processedMsgIdList = list_create(LISTCOUNT_T_MAX); } #ifndef IGNORE_DUPLICATE_ID node = list_first(soap->processedMsgIdList); while (node != NULL) { if (!strcmp(msgId, (char *) node->list_data)) { debug("Duplicate Message ID: %s", msgId); retVal = 1; generate_op_fault(op, WSA_INVALID_MESSAGE_INFORMATION_HEADER, WSA_DETAIL_DUPLICATE_MESSAGE_ID); break; } node = list_next(soap->processedMsgIdList, node); } #endif if (!retVal) { while (list_count(soap->processedMsgIdList) >= PROCESSED_MSG_ID_MAX_SIZE) { node = list_del_first(soap->processedMsgIdList); u_free(node->list_data); u_free(node); } node = lnode_create(NULL); if (node) { node->list_data = u_str_clone(msgId); if (node->list_data == NULL) { u_free(node); } else { list_append(soap->processedMsgIdList, node); } } } u_unlock(soap); } else if (!wsman_is_identify_request(op->in_doc)) { generate_op_fault(op, WSA_MESSAGE_INFORMATION_HEADER_REQUIRED, 0); debug("No MessageId Header found"); return 1; } return retVal; } int soap_add_filter(SoapH soap, SoapServiceCallback callbackProc, void *callbackData, int inbound) { callback_t *entry = NULL; if (soap) { if (!inbound) { if (!soap->outboundFilterList) soap->outboundFilterList = list_create(LISTCOUNT_T_MAX); entry = make_callback_entry(callbackProc, callbackData, soap->outboundFilterList); } else { if (!soap->inboundFilterList) soap->inboundFilterList = list_create(LISTCOUNT_T_MAX); entry = make_callback_entry(callbackProc, callbackData, soap->inboundFilterList); } } if (entry == NULL) return 0; else return 1; } int outbound_control_header_filter(SoapOpH opHandle, void *data, void *opaqueData) { op_t *op = (op_t *)opHandle; WsmanMessage *msg = wsman_get_msg_from_op(opHandle); if(check_envelope_size(op->out_doc, op->maxsize, msg->charset)) { debug("****should not go here"); generate_op_fault(op, WSMAN_ENCODING_LIMIT, WSMAN_DETAIL_SERVICE_ENVELOPE_LIMIT); } return 0; } int outbound_addressing_filter(SoapOpH opHandle, void *data, void *opaqueData) { WsXmlDocH in_doc = soap_get_op_doc(opHandle, 1); WsXmlDocH out_doc = soap_get_op_doc(opHandle, 0); WsXmlNodeH outHeaders = wsman_get_soap_header_element(out_doc, NULL, NULL); if (!outHeaders) { return 0; } if (ws_xml_get_child(outHeaders, 0, XML_NS_ADDRESSING, WSA_MESSAGE_ID) == NULL && !wsman_is_identify_request(in_doc)) { char uuidBuf[100]; generate_uuid(uuidBuf, sizeof(uuidBuf), 0); ws_xml_add_child(outHeaders, XML_NS_ADDRESSING, WSA_MESSAGE_ID, uuidBuf); debug("Adding message id: %s", uuidBuf); } if (in_doc != NULL) { WsXmlNodeH inMsgIdNode; inMsgIdNode = wsman_get_soap_header_element(in_doc,XML_NS_ADDRESSING, WSA_MESSAGE_ID); if (inMsgIdNode != NULL && !ws_xml_get_child(outHeaders, 0, XML_NS_ADDRESSING, WSA_RELATES_TO)) { ws_xml_add_child(outHeaders, XML_NS_ADDRESSING, WSA_RELATES_TO, ws_xml_get_node_text(inMsgIdNode)); } } return 0; } static int process_filter_chain(op_t *op, list_t *list, void *opaqueData) { int retVal = 0; callback_t *filter = NULL; if (list != NULL) { filter = (callback_t *) list_first(list); while (!retVal && filter != NULL) { retVal = filter->proc((SoapOpH) op, filter->node.list_data, opaqueData); filter = (callback_t *) list_next(list, &filter->node); } } return retVal; } /** * Process Filters * @param op SOAP operation * @param inbound Direction of message, 0 for outbound and 1 for inbound. * @return 0 on success, 1 on error. **/ static int process_filters(op_t * op, int inbound, void *opaqueData) { int retVal = 0; list_t *list; debug("Processing Filters: %s", (!inbound) ? "outbound" : "inbound"); if (!(op->dispatch->flags & SOAP_SKIP_DEF_FILTERS)) { list = inbound ? op->dispatch->soap->inboundFilterList : op->dispatch->soap->outboundFilterList; retVal = process_filter_chain(op, list, opaqueData); } if (retVal) { debug("process_filter_chain returned 1 for DEF FILTERS"); return 1; } list = inbound ? op->dispatch->inboundFilterList : op->dispatch->outboundFilterList; retVal = process_filter_chain(op, list, opaqueData); if (retVal) { debug("process_filter_chain returned 1"); return 1; } if (inbound) { WsXmlNodeH notUnderstoodHeader; if (wsman_is_duplicate_message_id(op)) { debug("wsman_is_duplicate_message_id"); return 1; } if (check_unsupported_features(op)) { debug("check_unsupported_features"); return 1; } if ((notUnderstoodHeader = validate_mustunderstand_headers(op)) != 0) { generate_notunderstood_fault(op, notUnderstoodHeader); debug("validate_mustunderstand_headers"); return 1; } if (!validate_control_headers(op)) { debug("validate_control_headers"); return 1; } if (check_for_duplicate_selectors(op)) { debug("check_for_duplicate_selectors"); return 1; } } return 0; } static void dispatcher_create_fault(SoapH soap, WsmanMessage * msg, WsXmlDocH in_doc) { char *buf = NULL; int len; if (!soap) return; if (wsman_fault_occured(msg)) { wsman_generate_fault_buffer(in_doc, msg->charset, msg->status.fault_code, msg->status.fault_detail_code, msg->status.fault_msg, &buf, &len); u_buf_set(msg->response, buf, len); u_free(buf); msg->http_code = wsman_find_httpcode_for_fault_code( msg->status. fault_code); } return; } static int process_inbound_operation(op_t * op, WsmanMessage * msg, void *opaqueData) { int retVal = 1; char *buf = NULL; int len; msg->http_code = WSMAN_STATUS_OK; op->out_doc = NULL; if (op->dispatch->serviceCallback == NULL) { wsman_set_fault(msg, WSA_ACTION_NOT_SUPPORTED, OWSMAN_NO_DETAILS, NULL); debug("op service callback is null"); goto GENERATE_FAULT; } if (process_filters(op, 1, opaqueData)) { if (op->out_doc == NULL) { error("doc is null"); wsman_set_fault(msg, WSMAN_INTERNAL_ERROR, OWSMAN_NO_DETAILS, NULL); goto GENERATE_FAULT; } if (wsman_is_fault_envelope(op->out_doc)) { msg->http_code = wsman_find_httpcode_for_value(op->out_doc); } else { error("not fault envelope"); } ws_xml_dump_memory_enc(op->out_doc, &buf, &len, msg->charset); u_buf_set(msg->response, buf, len); ws_xml_destroy_doc(op->out_doc); op->out_doc = NULL; u_free(buf); return 1; } retVal = op->dispatch->serviceCallback((SoapOpH) op, op->dispatch->serviceData, opaqueData); if (op->out_doc == NULL) { // XXX (correct fault?) wsman_set_fault(msg, WSA_DESTINATION_UNREACHABLE, WSMAN_DETAIL_INVALID_RESOURCEURI, NULL); error("output doc is null"); goto GENERATE_FAULT; } process_filters(op, 0, opaqueData); if (op->out_doc == NULL) { error("doc is null"); wsman_set_fault(msg, WSMAN_INTERNAL_ERROR, OWSMAN_NO_DETAILS, NULL); goto GENERATE_FAULT; } if (wsman_is_fault_envelope(op->out_doc)) { msg->http_code = wsman_find_httpcode_for_value(op->out_doc); } else { wsman_add_fragement_for_header(op->in_doc, op->out_doc); } ws_xml_dump_memory_enc(op->out_doc, &buf, &len, msg->charset); u_buf_set(msg->response, buf, len); ws_xml_destroy_doc(op->out_doc); op->out_doc = NULL; u_free(buf); return 0; GENERATE_FAULT: return retVal; } static SoapDispatchH get_dispatch_entry(SoapH soap, WsXmlDocH doc) { SoapDispatchH dispatch = NULL; if (soap->dispatcherProc) { dispatch = soap->dispatcherProc(soap->cntx, soap->dispatcherData, doc); } if (dispatch == NULL) { error("Dispatcher Error"); } else { dispatch->usageCount++; } return dispatch; } void dispatch_inbound_call(SoapH soap, WsmanMessage * msg, void *opaqueData) { op_t *op = NULL; WsXmlDocH in_doc = wsman_build_inbound_envelope( msg); SoapDispatchH dispatch = NULL; debug("Inbound call..."); #if 0 /* debug incoming message */ int size; char *buf; ws_xml_dump_memory_node_tree_enc( ws_xml_get_soap_body(in_doc), &buf, &size, "UTF-8" ); debug(buf); #endif if (wsman_fault_occured(msg)) { error("document is null"); goto DONE; } dispatch = get_dispatch_entry(soap, in_doc); if (dispatch == NULL) { wsman_set_fault(msg, WSA_DESTINATION_UNREACHABLE, WSMAN_DETAIL_INVALID_RESOURCEURI, NULL); debug("dispatch == NULL"); goto DONE; } op = create_op_entry(soap, dispatch, msg); if (op == NULL) { wsman_set_fault(msg, WSA_DESTINATION_UNREACHABLE, WSMAN_DETAIL_INVALID_RESOURCEURI, NULL); destroy_dispatch_entry(dispatch); debug("dispatch == NULL"); goto DONE; } op->in_doc = in_doc; process_inbound_operation(op, msg, opaqueData); DONE: dispatcher_create_fault(soap, msg, in_doc); destroy_op_entry(op); ws_xml_destroy_doc(in_doc); debug("Inbound call completed"); return; } static char *wsman_dispatcher_match_ns(WsDispatchInterfaceInfo * r, char *uri) { char *ns = NULL; lnode_t *node = NULL; if (r->namespaces == NULL) { return NULL; } if (!uri) return NULL; node = list_first(r->namespaces); while (node) { WsSupportedNamespaces *sns = (WsSupportedNamespaces *) node->list_data; debug("namespace: %s", sns->ns); if (sns->ns != NULL && strstr(uri, sns->ns)) { ns = u_strdup(sns->ns); break; } node = list_next(r->namespaces, node); } return ns; } WsEndPointRelease wsman_get_release_endpoint(WsContextH cntx, WsXmlDocH doc) { WsManDispatcherInfo *dispInfo = (WsManDispatcherInfo *) cntx->soap->dispatcherData; lnode_t *node = NULL; WsDispatchInterfaceInfo *r = NULL; WsDispatchEndPointInfo *ep = NULL; char *ptr = ENUM_ACTION_RELEASE, *ns = NULL, *uri = NULL; int i; if (dispInfo->interfaces) { node = list_first((list_t *) dispInfo->interfaces); } uri = wsman_get_resource_uri(cntx, doc); while (node != NULL) { WsDispatchInterfaceInfo *ifc = (WsDispatchInterfaceInfo *) node->list_data; if (ifc->wsmanResourceUri == NULL && (ns = wsman_dispatcher_match_ns(ifc, uri))) { r = ifc; break; } if (ifc->wsmanResourceUri && !strcmp(uri, ifc->wsmanResourceUri)) { r = ifc; break; } node = list_next((list_t *) dispInfo->interfaces, node); } if (r == NULL) { u_free(ns); return NULL; } /* * See if the action is part of the namespace which means that * we are dealing with a custom action */ if (ns != NULL) { size_t len = strlen(ns); if (!strncmp(ptr, ns, len) && ptr[len] == '/') { ptr += len + 1; } } for (i = 0; r->endPoints[i].serviceEndPoint != NULL; i++) { if (r->endPoints[i].inAction != NULL && !strcmp(ptr, r->endPoints[i].inAction)) { ep = &r->endPoints[i]; break; } } u_free(ns); if (ep == NULL) { debug("no ep"); return NULL; } debug("Release endpoint: %p", ep->serviceEndPoint); return (WsEndPointRelease) ep->serviceEndPoint; } SoapDispatchH wsman_dispatcher(WsContextH cntx, void *data, WsXmlDocH doc) { SoapDispatchH disp = NULL; char *uri = NULL, *action; WsManDispatcherInfo *dispInfo = (WsManDispatcherInfo *) data; WsDispatchEndPointInfo *ep = NULL; WsDispatchEndPointInfo *ep_custom = NULL; WsXmlDocH notdoc = NULL; #ifdef ENABLE_EVENTING_SUPPORT WsXmlNodeH nodedoc = NULL; #endif /* FIXME: resUriMatch set but not used */ int i, resUriMatch = 0; char *ns = NULL; WsDispatchInterfaceInfo *r = NULL; lnode_t *node = list_first((list_t *) dispInfo->interfaces); if (doc == NULL) { error("doc is null"); u_free(data); goto cleanup; } uri = wsman_get_resource_uri(cntx, doc); action = wsman_get_action(cntx, doc); #ifdef ENABLE_EVENTING_SUPPORT if(wsman_is_event_related_request(doc)) { WsXmlNodeH temp = ws_xml_get_child( ws_xml_get_soap_header(doc), 0, XML_NS_EVENTING, WSEVENT_IDENTIFIER); char *uuid = ws_xml_get_node_text(temp); debug("Request uuid: %s", uuid ? uuid : "NULL"); if(uuid) { lnode_t *t = list_first(cntx->subscriptionMemList); while(t != NULL) { WsSubscribeInfo *subsInfo = (WsSubscribeInfo *)t->list_data; if(!strcmp(uuid+5, subsInfo->subsId)) { uri = subsInfo->uri; break; } else t = list_next(cntx->subscriptionMemList, t); } if(t == NULL) { unsigned char *buf = NULL; int len; if(cntx->soap->subscriptionOpSet->get_subscription(cntx->soap->uri_subsRepository, uuid+5, &buf, &len) == 0) { notdoc = ws_xml_read_memory( (char *)buf, len, "UTF-8", 0); if(notdoc) { nodedoc = ws_xml_get_soap_header(notdoc); if(nodedoc) { nodedoc = ws_xml_get_child(nodedoc, 0, XML_NS_WS_MAN, WSM_RESOURCE_URI); if(nodedoc) { uri = ws_xml_get_node_text(nodedoc); } } } u_free(buf); } } } } #endif debug("uri: %s, action: %s", uri ? uri : "NULL", action ? action : "NULL"); if ((!uri || !action) && !wsman_is_identify_request(doc)) { goto cleanup; } while (node != NULL) { WsDispatchInterfaceInfo *ifc = (WsDispatchInterfaceInfo *) node->list_data; if (wsman_is_identify_request(doc)) { if ((ns = wsman_dispatcher_match_ns(ifc, XML_NS_WSMAN_ID))) { r = ifc; resUriMatch = 1; break; } debug("ns did not match"); } /* * If Resource URI is null then most likely we are dealing * with a generic plugin supporting a namespace with * multiple Resource URIs (e.g. CIM) **/ else if (ifc->wsmanResourceUri == NULL && (ns = wsman_dispatcher_match_ns(ifc, uri))) { r = ifc; resUriMatch = 1; break; } else if (ifc->wsmanResourceUri && !strcmp(uri, ifc->wsmanResourceUri)) { r = ifc; resUriMatch = 1; break; } node = list_next((list_t *) dispInfo->interfaces, node); } if (wsman_is_identify_request(doc) && r != NULL) { ep = &r->endPoints[0]; } else if (r != NULL) { char *ptr = action; /* * See if the action is part of the namespace which means that * we are dealing with a custom action */ if (ns != NULL) { size_t len = strlen(ns); if (!strncmp(action, ns, len) && action[len] == '/') ptr = &action[len + 1]; } for (i = 0; r->endPoints[i].serviceEndPoint != NULL; i++) { if (r->endPoints[i].inAction != NULL && !strcmp(ptr, r->endPoints[i].inAction)) { ep = &r->endPoints[i]; break; } else if (r->endPoints[i].inAction == NULL) { /* * Just store it for later * in case no match is found for above condition */ ep_custom = &r->endPoints[i]; } } } ws_remove_context_val(cntx, WSM_RESOURCE_URI); if (ep != NULL) { for (i = 0; i < dispInfo->mapCount; i++) { if (dispInfo->map[i].ep == ep) { disp = dispInfo->map[i].disp; break; } } } else if (ep_custom != NULL) { for (i = 0; i < dispInfo->mapCount; i++) { if (dispInfo->map[i].ep == ep_custom) { disp = dispInfo->map[i].disp; break; } } } cleanup: if(notdoc) ws_xml_destroy_doc(notdoc); if (ns) u_free(ns); return disp; } /* * Create dispatch Entry * * @param soap Soap Framework Handle * @param inboundAction Inbound Action * @param outboundAction Outbound Action * @param role Role * @param proc Call back processor * @param data Callback Data * @param flags Flags * @return Dispatch Entry */ static SoapDispatchH create_dispatch_entry(SoapH soap, char *inboundAction, char *outboundAction, char *role, SoapServiceCallback proc, void *data, unsigned long flags) { SoapDispatchH entry = wsman_dispatch_entry_new(); if (entry) { entry->soap = soap; entry->flags = flags; entry->inboundAction = u_str_clone(inboundAction); entry->outboundAction = u_str_clone(outboundAction); entry->serviceCallback = proc; entry->serviceData = data; entry->usageCount = 1; } return entry; } /* * Create Dispatch Entry * @param soap Soap handle * @param inboundAction Inbound Action * @param outboundAction Outbound Action (optional) * @param role Role (reserved, must be NULL) * @param callbackProc Callback processor * @param callbackData Callback data * @param flags Flags * @return Dispatch Handle */ SoapDispatchH wsman_dispatch_create(SoapH soap, char *inboundAction, char *outboundAction, //optional char *role, //reserved, must be NULL SoapServiceCallback callbackProc, void *callbackData, unsigned long flags) { SoapDispatchH disp = NULL; if (soap && role == NULL) { disp = create_dispatch_entry(soap, inboundAction, outboundAction, role, callbackProc, callbackData, flags); } return disp; } /* * Start Dispatcher */ void wsman_dispatch_start(SoapDispatchH disp) { list_t *displist = NULL; if (disp) { displist = disp->soap->dispatchList; if (displist != NULL || ( displist = list_create(LISTCOUNT_T_MAX) )) { list_append(displist, &(disp)->node); } } } SoapDispatchH wsman_dispatch_entry_new(void) { return (SoapDispatchH) u_zalloc(sizeof(struct __dispatch_t)); } /** @} */ openwsman-2.4.3/src/lib/wsman-curl-client-transport.c000664 001750 001750 00000046635 12256012305 023112 0ustar00kentbkentb000000 000000 /******************************************************************************* * 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 Vadim Revyakin */ #ifdef HAVE_CONFIG_H #include #endif #include #include #include #include #ifdef HAVE_UNISTD_H #include #endif #include #include #include #include #include "u/libu.h" #include "wsman-types.h" #include "wsman-client.h" #include "wsman-soap.h" #include "wsman-xml.h" #include "wsman-debug.h" #include "wsman-client-transport.h" #define DEFAULT_TRANSFER_LEN 32000 #ifndef CURLOPT_CRLFILE #define CURLOPT_CRLFILE 10169 #endif #ifndef CURLE_SSL_CRL_BADFILE #define CURLE_SSL_CRL_BADFILE 82 #endif extern wsman_auth_request_func_t request_func; void wsmc_handler( WsManClient *cl, WsXmlDocH rqstDoc, void* user_data); static pthread_mutex_t curl_mutex = PTHREAD_MUTEX_INITIALIZER; static long reauthenticate(WsManClient *cl, long auth_set, long auth_avail, char **username, char **password) { long choosen_auth = 0; wsman_auth_type_t ws_auth = WS_NO_AUTH; if (auth_avail & CURLAUTH_GSSNEGOTIATE && wsman_is_auth_method(cl, WS_GSSNEGOTIATE_AUTH)) { choosen_auth = CURLAUTH_GSSNEGOTIATE; ws_auth = WS_GSSNEGOTIATE_AUTH; goto REQUEST_PASSWORD; } if (auth_avail & CURLAUTH_DIGEST && wsman_is_auth_method(cl, WS_DIGEST_AUTH)) { choosen_auth = CURLAUTH_DIGEST; ws_auth = WS_DIGEST_AUTH; goto REQUEST_PASSWORD; } if (auth_avail & CURLAUTH_NTLM && wsman_is_auth_method(cl, WS_NTLM_AUTH)) { choosen_auth = CURLAUTH_NTLM; ws_auth = WS_NTLM_AUTH; goto REQUEST_PASSWORD; } if (auth_avail & CURLAUTH_BASIC && wsman_is_auth_method(cl, WS_BASIC_AUTH)) { ws_auth = WS_BASIC_AUTH; choosen_auth = CURLAUTH_BASIC; goto REQUEST_PASSWORD; } debug("Client does not support authentication type 0x%04x" " acceptable by server\n", auth_avail); return 0; REQUEST_PASSWORD: message("%s authentication is used", wsmc_transport_get_auth_name(ws_auth)); if (auth_set == 0 && *username && *password) { // use existing username and password return choosen_auth; } if (cl->authentication.auth_request_func) { debug("Invoking Auth request callback"); /* free the username and password as these are OUT params to the auth_request_func * which the caller is expected to set */ if (*username) { u_free(*username); *username = NULL; } if (*password) { u_free(*password); *password = NULL; } cl->authentication.auth_request_func(cl, ws_auth, username, password); } else return 0; if (!(*username) || strlen(*username) == 0) { debug("No username. Authorization canceled"); return 0; } return choosen_auth; } static WS_LASTERR_Code convert_to_last_error(CURLcode r) { switch (r) { case CURLE_OK: return WS_LASTERR_OK; case CURLE_FAILED_INIT: return WS_LASTERR_FAILED_INIT; case CURLE_UNSUPPORTED_PROTOCOL: return WS_LASTERR_UNSUPPORTED_PROTOCOL; case CURLE_URL_MALFORMAT: return WS_LASTERR_URL_MALFORMAT; case CURLE_COULDNT_RESOLVE_PROXY: return WS_LASTERR_COULDNT_RESOLVE_PROXY; case CURLE_COULDNT_RESOLVE_HOST: return WS_LASTERR_COULDNT_RESOLVE_HOST; case CURLE_COULDNT_CONNECT: return WS_LASTERR_COULDNT_CONNECT; case CURLE_HTTP_RETURNED_ERROR: return WS_LASTERR_HTTP_RETURNED_ERROR; case CURLE_WRITE_ERROR: return WS_LASTERR_WRITE_ERROR; case CURLE_READ_ERROR: return WS_LASTERR_READ_ERROR; case CURLE_OUT_OF_MEMORY: return WS_LASTERR_OUT_OF_MEMORY; case CURLE_OPERATION_TIMEOUTED: return WS_LASTERR_OPERATION_TIMEOUTED; case CURLE_HTTP_POST_ERROR: return WS_LASTERR_HTTP_POST_ERROR; case CURLE_BAD_DOWNLOAD_RESUME: return WS_LASTERR_BAD_DOWNLOAD_RESUME; case CURLE_TOO_MANY_REDIRECTS: return WS_LASTERR_TOO_MANY_REDIRECTS; case CURLE_SSL_CONNECT_ERROR: return WS_LASTERR_SSL_CONNECT_ERROR; case CURLE_BAD_FUNCTION_ARGUMENT: return WS_LASTERR_CURL_BAD_FUNCTION_ARG; case CURLE_SSL_PEER_CERTIFICATE: return WS_LASTERR_SSL_PEER_CERTIFICATE; case CURLE_SSL_ENGINE_NOTFOUND: return WS_LASTERR_SSL_ENGINE_NOTFOUND; case CURLE_SSL_ENGINE_SETFAILED: return WS_LASTERR_SSL_ENGINE_SETFAILED; case CURLE_SSL_CERTPROBLEM: return WS_LASTERR_SSL_CERTPROBLEM; case CURLE_SSL_CACERT: return WS_LASTERR_SSL_CACERT; #if LIBCURL_VERSION_NUM > 0x70C01 case CURLE_SSL_ENGINE_INITFAILED: return WS_LASTERR_SSL_ENGINE_INITFAILED; #endif case CURLE_SEND_ERROR: return WS_LASTERR_SEND_ERROR; case CURLE_RECV_ERROR: return WS_LASTERR_RECV_ERROR; case CURLE_BAD_CONTENT_ENCODING: return WS_LASTERR_BAD_CONTENT_ENCODING; #if LIBCURL_VERSION_NUM >= 0x70D01 case CURLE_LOGIN_DENIED: return WS_LASTERR_LOGIN_DENIED; #else /* Map 67 (same as CURLE_LOGIN_DENIED) got from OS that has lower version of CURL in which * CURLE_LOGIN_DENIED is not defined. This way we get the same error code in case of login failure */ case 67: return WS_LASTERR_LOGIN_DENIED; #endif case CURLE_SSL_CRL_BADFILE: return WS_LASTERR_BAD_CRL_FILE; default: return WS_LASTERR_OTHER_ERROR; } return WS_LASTERR_OTHER_ERROR; } static size_t write_handler( void *ptr, size_t size, size_t nmemb, void *data) { u_buf_t *buf = data; size_t len; len = size * nmemb; u_buf_append(buf, ptr, len); debug("write_handler: recieved %d bytes, all = %d\n", len, u_buf_len(buf)); return len; } #ifdef ENABLE_EVENTING_SUPPORT static int ssl_certificate_thumbprint_verify_callback(X509_STORE_CTX *ctx, void *arg) { unsigned char *thumbprint = (unsigned char *)arg; X509 *cert = ctx->cert; EVP_MD *tempDigest; unsigned char tempFingerprint[EVP_MAX_MD_SIZE]; unsigned int tempFingerprintLen; tempDigest = (EVP_MD*)EVP_sha1( ); if ( X509_digest(cert, tempDigest, tempFingerprint, &tempFingerprintLen ) <= 0) return 0; if(!memcmp(tempFingerprint, thumbprint, tempFingerprintLen)) return 1; return 0; } static CURLcode sslctxfun(CURL *curl, void *sslctx, void *parm) { CURLcode r = CURLE_OK; SSL_CTX * ctx = (SSL_CTX *) sslctx ; SSL_CTX_set_verify(ctx, SSL_VERIFY_PEER | SSL_VERIFY_FAIL_IF_NO_PEER_CERT, 0 ); SSL_CTX_set_cert_verify_callback(ctx, ssl_certificate_thumbprint_verify_callback, parm); return r; } #endif static void * init_curl_transport(WsManClient *cl) { CURL *curl; CURLcode r = CURLE_OK; #define curl_err(str) debug("Error = %d (%s); %s", \ r, curl_easy_strerror(r), str); curl = curl_easy_init(); if (curl == NULL) { r = CURLE_FAILED_INIT; debug("Could not init easy curl"); goto DONE; } debug("cl->authentication.verify_peer: %d", cl->authentication.verify_peer ); // verify peer r = curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, wsman_transport_get_verify_peer(cl)?1:0); if (r != 0) { curl_err("curl_easy_setopt(CURLOPT_SSL_VERIFYPEER) failed"); goto DONE; } // verify host r = curl_easy_setopt(curl, CURLOPT_SSL_VERIFYHOST, wsman_transport_get_verify_host(cl)?2:0); if (r != 0) { curl_err("curl_easy_setopt(CURLOPT_SSL_VERIFYHOST) failed"); goto DONE; } r = curl_easy_setopt(curl, CURLOPT_PROXY, cl->proxy_data.proxy); if (r != 0) { curl_err("Could notcurl_easy_setopt(curl, CURLOPT_PROXY, ...)"); goto DONE; } r = curl_easy_setopt(curl, CURLOPT_TIMEOUT, cl->transport_timeout); if (r != 0) { curl_err("Could notcurl_easy_setopt(curl, CURLOPT_TIMEOUT, ...)"); goto DONE; } r = curl_easy_setopt(curl, CURLOPT_PROXYUSERPWD, cl->proxy_data.proxy_auth); if (r != 0) { curl_err("Could notcurl_easy_setopt(curl, CURLOPT_PROXYUSERPWD, ...)"); goto DONE; } if (0 != cl->authentication.verify_peer && 0 != cl->authentication.crl_check) { dictionary *ini = NULL; if (cl->authentication.crl_file == NULL) { ini = iniparser_new(cl->client_config_file); if (ini != NULL) { char *crlfile = iniparser_getstr(ini, "client:crlfile"); wsman_transport_set_crlfile(cl, crlfile); iniparser_free(ini); } } if (cl->authentication.crl_file != NULL) { debug("wsman-curl-client-transport.c: init_curl_transport() : CRL file = %s\n",cl->authentication.crl_file); r = curl_easy_setopt(curl, CURLOPT_CRLFILE, cl->authentication.crl_file); } } if (cl->authentication.capath) { r = curl_easy_setopt(curl, CURLOPT_CAPATH, cl->authentication.capath); if (r != 0) { curl_err("Could not curl_easy_setopt(curl, CURLOPT_CAPATH, ..)"); goto DONE; } } // cainfo if (cl->authentication.cainfo) { r = curl_easy_setopt(curl, CURLOPT_CAINFO, cl->authentication.cainfo); if (r != 0) { curl_err("Could not curl_easy_setopt(curl, CURLOPT_CAINFO, ..)"); goto DONE; } } // certificate thumbprint #ifdef ENABLE_EVENTING_SUPPORT /* Bug in e.g. Fedora: [ curl-Bugs-1924441 ] SSL callback option with NSS-linked libcurl */ #ifndef NO_SSL_CALLBACK else if (strlen((char *)cl->authentication.certificatethumbprint) > 0 && 0 != cl->authentication.verify_peer) { r = curl_easy_setopt(curl, CURLOPT_SSL_CTX_FUNCTION, sslctxfun); if(r != 0) { curl_err("Could not curl_easy_setopt(curl, CURLOPT_SSL_CTX_FUNCTION)"); goto DONE; } r = curl_easy_setopt(curl, CURLOPT_SSL_CTX_DATA, (void *)cl->authentication.certificatethumbprint); if(r != 0) { curl_err("Could not curl_easy_setopt(curl, CURLOPT_SSL_CTX_DATA)"); goto DONE; } } #endif #endif // sslkey r = curl_easy_setopt(curl, CURLOPT_SSLKEY, cl->authentication.sslkey); if (r != 0) { curl_err("Could not curl_easy_setopt(curl, CURLOPT_SSLKEY, ..)"); goto DONE; } // sslcert r = curl_easy_setopt(curl, CURLOPT_SSLCERT, cl->authentication.sslcert ); if (r != 0) { curl_err("Could not curl_easy_setopt(curl, CURLOPT_SSLCERT, ..)"); goto DONE; } return (void *)curl; DONE: cl->last_error = convert_to_last_error(r); curl_easy_cleanup(curl); return NULL; #undef curl_err } void wsmc_handler( WsManClient *cl, WsXmlDocH rqstDoc, void* user_data) { #define curl_err(str) debug("Error = %d (%s); %s", \ r, curl_easy_strerror(r), str); WsManConnection *con = cl->connection; CURL *curl = NULL; CURLcode r; char *upwd = NULL; char *usag = NULL; struct curl_slist *headers=NULL; char *buf = NULL; int len; char *soapact_header = NULL; long http_code; long auth_avail = 0; char *_user = NULL, *_pass = NULL; u_buf_t *response = NULL; //char *soapaction; if (!cl->initialized && wsmc_transport_init(cl, NULL)) { cl->last_error = WS_LASTERR_FAILED_INIT; return; } if (cl->transport == NULL) { cl->transport = init_curl_transport(cl); if (cl->transport == NULL) { return; } } curl = (CURL *)cl->transport; r = curl_easy_setopt(curl, CURLOPT_URL, cl->data.endpoint); if (r != CURLE_OK) { cl->fault_string = u_strdup(curl_easy_strerror(r)); curl_err("Could not curl_easy_setopt(curl, CURLOPT_URL, ...)"); goto DONE; } r = curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, write_handler); if (r != CURLE_OK) { cl->fault_string = u_strdup(curl_easy_strerror(r)); curl_err("Could not curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, ..)"); goto DONE; } u_buf_create(&response); r = curl_easy_setopt(curl, CURLOPT_WRITEDATA, response); if (r != CURLE_OK) { cl->fault_string = u_strdup(curl_easy_strerror(r)); curl_err("Could not curl_easy_setopt(curl, CURLOPT_WRITEDATA, ..)"); goto DONE; } char content_type[64]; snprintf(content_type, 64, "Content-Type: application/soap+xml;charset=%s", cl->content_encoding); headers = curl_slist_append(headers, content_type); usag = malloc(12 + strlen(wsman_transport_get_agent(cl)) + 1); if (usag == NULL) { r = CURLE_OUT_OF_MEMORY; cl->fault_string = u_strdup("Could not malloc memory"); curl_err("Could not malloc memory"); goto DONE; } sprintf(usag, "User-Agent: %s", wsman_transport_get_agent(cl)); headers = curl_slist_append(headers, usag); #if 0 soapaction = ws_xml_get_xpath_value(rqstDoc, "/s:Envelope/s:Header/wsa:Action"); if (soapaction) { soapact_header = malloc(12 + strlen(soapaction) + 1); if (soapact_header) { sprintf(soapact_header, "SOAPAction: %s", soapaction); headers = curl_slist_append(headers, soapact_header); } u_free(soapaction); } #endif r = curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers); if (r != CURLE_OK) { cl->fault_string = u_strdup(curl_easy_strerror(r)); curl_err("Could not curl_easy_setopt(curl, CURLOPT_HTTPHEADER, ..)"); goto DONE; } ws_xml_dump_memory_enc(rqstDoc, &buf, &len, cl->content_encoding); #if 0 int count = 0; while(count < len) { printf("%c",buf[count++]); } #endif debug("*****set post buf len = %d******",len); r = curl_easy_setopt(curl, CURLOPT_POSTFIELDS, buf); if (r != CURLE_OK) { cl->fault_string = u_strdup(curl_easy_strerror(r)); curl_err("Could not curl_easy_setopt(curl, CURLOPT_POSTFIELDS, ..)"); goto DONE; } r = curl_easy_setopt(curl, CURLOPT_POSTFIELDSIZE, len); if (r != CURLE_OK) { cl->fault_string = u_strdup(curl_easy_strerror(r)); curl_err("Could not curl_easy_setopt(curl, CURLOPT_POSTFIELDSIZE, ..)"); goto DONE; } int iDone = 0; while (1) { u_free(_user); u_free(_pass); _user = wsmc_get_user(cl); _pass = wsmc_get_password(cl); if (_user && _pass && cl->data.auth_set) { r = curl_easy_setopt(curl, CURLOPT_HTTPAUTH, cl->data.auth_set); if (r != CURLE_OK) { cl->fault_string = u_strdup(curl_easy_strerror(r)); curl_err("curl_easy_setopt(CURLOPT_HTTPAUTH) failed"); goto DONE; } u_free(upwd); upwd = u_strdup_printf( "%s:%s", _user , _pass); if (!upwd) { r = CURLE_OUT_OF_MEMORY; cl->fault_string = u_strdup("Could not malloc memory"); curl_err("Could not malloc memory"); goto DONE; } r = curl_easy_setopt(curl, CURLOPT_USERPWD, upwd); if (r != CURLE_OK) { cl->fault_string = u_strdup(curl_easy_strerror(r)); curl_err("curl_easy_setopt(curl, CURLOPT_USERPWD, ..) failed"); goto DONE; } } if (wsman_debug_level_debugged(DEBUG_LEVEL_MESSAGE)) { curl_easy_setopt(curl, CURLOPT_VERBOSE, 1); } r = curl_easy_perform(curl); if (r != CURLE_OK) { cl->fault_string = u_strdup(curl_easy_strerror(r)); curl_err("curl_easy_perform failed"); goto DONE; } r = curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &http_code); if (r != CURLE_OK) { cl->fault_string = u_strdup(curl_easy_strerror(r)); curl_err("curl_easy_getinfo(CURLINFO_RESPONSE_CODE) failed"); goto DONE; } switch (http_code) { case 200: case 400: case 500: // The resource was successfully retrieved or WSMan server // returned a HTTP status code. You can use WinHttpReadData to // read the contents of the server's response. iDone = 1; break; case 401: // The server requires authentication. break; default: // The status code does not indicate success. r = WS_LASTERR_OTHER_ERROR; iDone = 1; break; } if(iDone == 1) { break; } /* we are here because of authentication required */ r = curl_easy_getinfo(curl, CURLINFO_HTTPAUTH_AVAIL, &auth_avail); if (r != CURLE_OK) { cl->fault_string = u_strdup(curl_easy_strerror(r)); curl_err("curl_easy_getinfo(CURLINFO_HTTPAUTH_AVAIL) failed"); goto DONE; } cl->data.auth_set = reauthenticate(cl, cl->data.auth_set, auth_avail, &cl->data.user, &cl->data.pwd); u_buf_clear(response); if (cl->data.auth_set == 0) { /* FIXME: user wants to cancel authentication */ #if LIBCURL_VERSION_NUM >= 0x70D01 r = CURLE_LOGIN_DENIED; #else /* Map the login failure error to CURLE_LOGIN_DENIED (67) so that we * get the same error code in case of login failure */ r = 67; #endif curl_err("user/password wrong or empty."); break; } } #if 0 unsigned char *mbbuf = NULL; iconv_t cd; if(strcmp(cl->content_encoding, "UTF-8")) { cd = iconv_open("UTF-8", cl->content_encoding); if(cd == -1) { cl->last_error = WS_LASTERR_BAD_CONTENT_ENCODING; goto DONE2; } mbbuf = u_zalloc(u_buf_len(response)); size_t outbuf_len = u_buf_len(response); size_t inbuf_len = outbuf_len; char *inbuf = u_buf_ptr(response); char *outbuf = mbbuf; size_t coverted = iconv(cd, &inbuf, &inbuf_len, &outbuf, &outbuf_len); iconv_close(cd); if( coverted == -1) { cl->last_error = WS_LASTERR_BAD_CONTENT_ENCODING; goto DONE2; } u_buf_append(con->response, mbbuf, u_buf_len(response) - inbuf_len); } u_free(mbbuf); #endif u_buf_append(con->response, u_buf_ptr(response), u_buf_len(response)); DONE: curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &http_code); cl->response_code = http_code; cl->last_error = convert_to_last_error(r); debug("curl error code: %d.", r); debug("cl->response_code: %d.", cl->response_code); debug("cl->last_error code: %d.", cl->last_error); curl_slist_free_all(headers); u_buf_free(response); u_free(soapact_header); u_free(usag); u_free(upwd); u_free(_pass); u_free(_user); #ifdef _WIN32 ws_xml_free_memory(buf); #else u_free(buf); #endif return; #undef curl_err } int wsmc_transport_init(WsManClient *cl, void *arg) { CURLcode r; pthread_mutex_lock(&curl_mutex); if (cl->initialized) { pthread_mutex_unlock(&curl_mutex); return 0; } r = curl_global_init(CURL_GLOBAL_SSL | CURL_GLOBAL_WIN32); if (r == CURLE_OK) { cl->initialized = 1; } pthread_mutex_unlock(&curl_mutex); if (r != CURLE_OK) { debug("Error = %d (%s); Could not initialize curl globals", r, curl_easy_strerror(r)); } return (r == CURLE_OK ? 0 : 1); } void wsmc_transport_fini(WsManClient *cl) { pthread_mutex_lock(&curl_mutex); if (cl->initialized == 0 ) { pthread_mutex_unlock(&curl_mutex); return; } curl_global_cleanup(); cl->initialized = 0; pthread_mutex_unlock(&curl_mutex); return; } void wsman_transport_close_transport(WsManClient *cl) { if (cl->transport != NULL) { curl_easy_cleanup((CURL *)cl->transport); } cl->transport = NULL; } openwsman-2.4.3/.gitignore000664 001750 001750 00000001353 12256012305 015767 0ustar00kentbkentb000000 000000 core *~ Makefile Makefile.am Makefile.in aclocal.m4 autom4te.cache config.cache config.guess config.h config.h.in config.log config.status config.sub configure configure.in depcomp install-sh libtool ltconfig ltmain.sh missing mkinstalldirs stamp-h* *.pc *.pc.in Doxyfile .project .cdtproject wsman_config.h wsman_config.h.in openwsman.spec build *.bz2 m4 *.o *.lo *.la *.class .deps .libs bindings/perl/openwsman.pm bindings/perl/openwsman_wrap.c bindings/python/openwsman_wrap.c bindings/python/pywsman.py bindings/ruby/openwsman_wrap.c bindings/ruby/html bindings/ruby/mkmf.log bindings/java/openwsman_wrap.c bindings/java/*.java etc/init/openwsmand.sh etc/owsmangencert.sh src/server/openwsmand CMakeFiles CMakeCache.txt DartConfiguration.tcl openwsman-2.4.3/bindings/ruby/tests/anon-identify.rb000664 001750 001750 00000001431 12256012305 023005 0ustar00kentbkentb000000 000000 # test identify action require 'test/unit' require File.join(File.dirname(__FILE__),'_loadpath') require 'openwsman' require 'auth-callback' class IdentifyTest < Test::Unit::TestCase def test_identify client = Openwsman::Client.new( "http://wsman:secret@localhost:5985/wsman-anon/identify" ) assert client options = Openwsman::ClientOptions.new assert options doc = client.identify( options ) assert doc root = doc.root assert root prot_version = root.find( Openwsman::XML_NS_WSMAN_ID, "ProtocolVersion" ) prod_vendor = root.find( Openwsman::XML_NS_WSMAN_ID, "ProductVendor" ) prod_version = root.find( Openwsman::XML_NS_WSMAN_ID, "ProductVersion" ) puts "Protocol #{prot_version}, Vendor #{prod_vendor}, Version #{prod_version}" end end openwsman-2.4.3/src/plugins/wsman/Makefile.am000664 001750 001750 00000000017 12256012305 021424 0ustar00kentbkentb000000 000000 SUBDIRS = test openwsman-2.4.3/bindings/ruby/tests/enumerate.rb000664 001750 001750 00000001203 12256012305 022223 0ustar00kentbkentb000000 000000 # enumerate.rb require 'test/unit' require 'rexml/document' require File.join(File.dirname(__FILE__),'_loadpath') require 'openwsman' require '_client' class WsmanTest < Test::Unit::TestCase def test_client client = Client.open assert client options = Openwsman::ClientOptions.new assert options uri = "http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_ComputerSystem" result = client.enumerate( options, nil, uri ) assert result doc = REXML::Document.new result.to_xml doc.write( $stdout, 0 ) context = result.context assert context client.release( options, uri, context) end end openwsman-2.4.3/include/u/debug_internal.h000664 001750 001750 00000012225 12256012305 021021 0ustar00kentbkentb000000 000000 /******************************************************************************* * 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 */ #ifndef DEBUG_INTERNAL_H_ #define DEBUG_INTERNAL_H_ #include #include #include "u/debug.h" #ifdef __cplusplus extern "C" { #endif /* __cplusplus */ struct _debug_handler_t { debug_fn fn; debug_level_e level; void* user_data; unsigned int id; }; typedef struct _debug_handler_t debug_handler_t; void debug_full(debug_level_e level, const char *format, ...); void debug_full_verbose(debug_level_e level, char *file, int line, const char *proc, const char *format, ...); // #define ENABLE_TRACING #ifdef ENABLE_TRACING #if defined (__SUNPRO_C) || defined(__SUNPRO_CC) #define TRACE_ENTER printf("TRACE: Entering %s %s:%d\n", __func__, __FILE__, __LINE__ ); #define TRACE_DETAILS(format...) printf("TRACE: %s :%s:%d --- %s\n", __func__, __FILE__, __LINE__ , debug_helper (format)); #define TRACE_EXIT printf("TRACE: Leaving %s %s:%d\n", __func__, __FILE__, __LINE__ ); #else // __SUNPRO_C || __SUNPRO_CC #define TRACE_ENTER printf("TRACE: Entering %s %s:%d\n", __FUNCTION__, __FILE__, __LINE__ ); #define TRACE_DETAILS(format...) printf("TRACE: %s :%s:%d --- %s\n", __FUNCTION__, __FILE__, __LINE__ , debug_helper (format)); #define TRACE_EXIT printf("TRACE: Leaving %s %s:%d\n", __FUNCTION__, __FILE__, __LINE__ ); #endif // __SUNPRO_C || __SUNPRO_CC #else #define TRACE_ENTER #ifdef _WIN32 static __inline void TRACE_DETAILS(char* format, ...) { return; } #else #define TRACE_DETAILS(format...) #endif #define TRACE_EXIT #endif #ifdef WIN32 # ifdef WSMAN_DEBUG_VERBOSE #define debug(format, ...) \ debug_full_verbose(DEBUG_LEVEL_DEBUG, __FILE__, \ __LINE__,__FUNCTION__, format, __VA_ARGS__) #define error(format, ...) \ debug_full_verbose(DEBUG_LEVEL_ERROR, __FILE__, \ __LINE__,__FUNCTION__, format, __VA_ARGS__) #define message(format, ...) \ debug_full_verbose(DEBUG_LEVEL_MESSAGE, __FILE__, \ __LINE__,__FUNCTION__, format, __VA_ARGS__) # else // WSMAN_DEBUG_VERBOSE #define debug(format, ...) \ debug_full(DEBUG_LEVEL_DEBUG, format, __VA_ARGS__) #define error(format, ...) \ debug_full(DEBUG_LEVEL_ERROR, format, __VA_ARGS__) #define message(format, ...) \ debug_full(DEBUG_LEVEL_MESSAGE, format, __VA_ARGS__) # endif // WSMAN_DEBUG_VERBOSE #else // WIN32 #ifdef WSMAN_DEBUG_VERBOSE #if defined (__SUNPRO_C) || defined(__SUNPRO_CC) #define debug(format...) \ debug_full_verbose(DEBUG_LEVEL_DEBUG, __FILE__, __LINE__,__func__, format) #define error(format...) \ debug_full_verbose(DEBUG_LEVEL_ERROR, __FILE__, __LINE__,__func__, format) #define message(format...) \ debug_full_verbose(DEBUG_LEVEL_MESSAGE, __FILE__, __LINE__,__func__, format) #else // __SUNPRO_C || __SUNPRO_CC #define debug(format...) \ debug_full_verbose(DEBUG_LEVEL_DEBUG, __FILE__, __LINE__,__FUNCTION__, format) #define error(format...) \ debug_full_verbose(DEBUG_LEVEL_ERROR, __FILE__, __LINE__,__FUNCTION__, format) #define message(format...) \ debug_full_verbose(DEBUG_LEVEL_MESSAGE, __FILE__, __LINE__,__FUNCTION__, format) #endif // __SUNPRO_C || __SUNPRO_CC #else // WSMAN_DEBUG_VERBOSE #define debug(format...) \ debug_full(DEBUG_LEVEL_DEBUG, format) #define error(format...) \ debug_full(DEBUG_LEVEL_ERROR, format) #define message(format...) \ debug_full(DEBUG_LEVEL_MESSAGE, format) #endif // WSMAN_DEBUG_VERBOSE #endif // WIN32 #ifdef __cplusplus } #endif /* __cplusplus */ #endif /*DEBUG_INTERNAL_H_*/ openwsman-2.4.3/src/server/CMakeLists.txt000664 001750 001750 00000004065 12256012305 020637 0ustar00kentbkentb000000 000000 # # CMakeLists.txt for openwsman/src/server # include_directories(${CMAKE_SOURCE_DIR}/include ${CMAKE_SOURCE_DIR}/src/server/shttpd ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_BINARY_DIR} ) SET( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -g" ) SET(openwsmand_SOURCES shttpd/string.c shttpd/shttpd.c shttpd/auth.c shttpd/md5.c shttpd/adapter.c shttpd/cgi.c) SET(openwsmand_SOURCES ${openwsmand_SOURCES} shttpd/mime_type.c shttpd/config.c shttpd/io_socket.c) SET(openwsmand_SOURCES ${openwsmand_SOURCES} shttpd/io_ssl.c shttpd/io_emb.c shttpd/compat_unix.c shttpd/io_dir.c shttpd/io_file.c) SET(openwsmand_SOURCES ${openwsmand_SOURCES} shttpd/shttpd_defs.h shttpd/llist.h shttpd/shttpd.h shttpd/std_includes.h shttpd/io.h shttpd/md5.h shttpd/ssl.h) SET(openwsmand_SOURCES ${openwsmand_SOURCES} shttpd/compat_unix.h shttpd/compat_win32.h shttpd/compat_rtems.h shttpd/adapter.h) SET(openwsmand_SOURCES ${openwsmand_SOURCES} wsmand-listener.h wsmand-daemon.c wsmand-daemon.h wsmand-listener.c) SET(openwsmand_SOURCES ${openwsmand_SOURCES} gss.c wsmand.c) ADD_DEFINITIONS(-DEMBEDDED -DNO_CGI -DNO_SSI ) ADD_DEFINITIONS(-DPACKAGE_PLUGIN_DIR="\\\"${PACKAGE_PLUGIN_DIR}\\\"") ADD_DEFINITIONS(-DPACKAGE_AUTH_DIR="\\\"${PACKAGE_AUTH_DIR}\\\"") ADD_DEFINITIONS(-DPACKAGE_SUBSCRIPTION_DIR="\\\"${PACKAGE_SUBSCRIPTION_DIR}\\\"") ADD_EXECUTABLE(openwsmand ${openwsmand_SOURCES}) TARGET_LINK_LIBRARIES(openwsmand wsman_server wsman ${LIBXML2_LIBRARIES}) if( ENABLE_EVENTING_SUPPORT ) TARGET_LINK_LIBRARIES(openwsmand wsman_client) TARGET_LINK_LIBRARIES(openwsmand ${CURL_LIBRARIES}) endif( ENABLE_EVENTING_SUPPORT ) if( USE_OPENSSL ) include_directories(${OPENSSL_INCLUDE_DIR}) ADD_DEFINITIONS(-DHAVE_OPENSSL ) TARGET_LINK_LIBRARIES(openwsmand ${OPENSSL_LIBRARIES}) endif( USE_OPENSSL ) if( USE_PTHREAD ) TARGET_LINK_LIBRARIES(openwsmand ${CMAKE_THREAD_LIBS_INIT}) endif( USE_PTHREAD ) if( HAVE_LIBDL ) TARGET_LINK_LIBRARIES(openwsmand ${DL_LIBRARIES}) endif( HAVE_LIBDL ) INSTALL(TARGETS openwsmand DESTINATION ${CMAKE_INSTALL_PREFIX}/sbin) # # #install-data-local: # $(mkinstalldirs) $(DESTDIR)$(PACKAGE_SUBSCRIPTION_DIR) openwsman-2.4.3/src/lib/wsman-soap-message.c000664 001750 001750 00000006044 12256012305 021211 0ustar00kentbkentb000000 000000 /******************************************************************************* * 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,cl * 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 NEGLIGclE 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 */ #ifdef HAVE_CONFIG_H #include #endif #include #include #include #include #include "u/libu.h" #include "wsman-xml-api.h" #include "wsman-soap.h" #include "wsman-xml.h" #include "wsman-xml-serializer.h" #include "wsman-faults.h" #include "wsman-soap-envelope.h" #include "wsman-soap-message.h" void wsman_set_message_flags(WsmanMessage *msg, unsigned int flag) { msg->flags |= flag; return; } WsmanMessage* wsman_soap_message_new() { WsmanMessage *wsman_msg = u_zalloc(sizeof(WsmanMessage)); u_buf_create(&wsman_msg->request); u_buf_create(&wsman_msg->response); // wsman_msg->charset = "UTF-8"; wsman_msg->status.fault_code = 0; wsman_msg->status.fault_detail_code = 0; wsman_msg->status.fault_msg = NULL; return wsman_msg; } void wsman_soap_message_destroy(WsmanMessage* wsman_msg) { u_buf_free(wsman_msg->response); u_buf_free(wsman_msg->request); u_free(wsman_msg->charset); u_free(wsman_msg->auth_data.password); u_free(wsman_msg->auth_data.username); if (wsman_msg->status.fault_msg) { u_free(wsman_msg->status.fault_msg); } if (wsman_msg->http_headers) { hash_free(wsman_msg->http_headers); wsman_msg->http_headers = NULL; } u_free(wsman_msg); } openwsman-2.4.3/bindings/ruby/.cvsignore000664 001750 001750 00000000077 12256012305 020557 0ustar00kentbkentb000000 000000 Makefile Makefile.in *.o *.lo *.la .deps .libs *.pyc *_wrap.c openwsman-2.4.3/bindings/ruby/tests/README000664 001750 001750 00000002776 12256012305 020611 0ustar00kentbkentb000000 000000 Ruby bindings for OpenWsMan The bindings are defined as a module named 'WsMan' 1. Helper classes - attr_accessor debug DEBUG_LEVEL_ALWAYS = -1, DEBUG_LEVEL_NONE = 0, DEBUG_LEVEL_ERROR = 1, DEBUG_LEVEL_CRITICAL = 2, DEBUG_LEVEL_WARNING = 3, DEBUG_LEVEL_MESSAGE = 4, DEBUG_LEVEL_INFO = 5, DEBUG_LEVEL_DEBUG = 6, - class WsMan::XmlNode new() rawxml() to_s() - class WsMan::Action None TransferGet TransferPut Enumeration Pull Release Custom TransferCreate Identify Test to_s() - class WsMan::ClientOption attr_accessor flags, filter, dialect, fragment, cim_ns, attr_accessor selectors, properties, timeout, max_envelope_size, max_elements flags<< selectors<< properties<< 2. SOAP related WsMan::XmlDoc << WsMan::XmlNode header body element rawxml to_s() 3. WsMan::Identify << WsMan::XmlDoc attr_read product_vendor, product_version, protocol_version 4. WsMan::TransferCreate << WsMan::XmlDoc 5. WsMan::TransferPut << WsMan::XmlDoc 6. WsMan::TransferGet << WsMan::XmlDoc 7. WsMan::Enumerate << WsMan::XmlDoc 8. WsMan::Pull << WsMan::XmlDoc 9. WsMan::Release << WsMan::XmlDoc 10. WsMan::Invoke << WsMan::XmlDoc 11. Client connection - class WsMan::Client new( scheme, host, port, path, username, password ) attr_read scheme, host, port, path, username, password identify() transfer_create() transfer_get() transfer_put() enumerate() pull() release() invoke() openwsman-2.4.3/include/wsman-event-pool.h000664 001750 001750 00000006203 12256012305 021005 0ustar00kentbkentb000000 000000 /******************************************************************************* * Copyright (C) 2004-2007 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 Liang Hou */ #ifndef WSMAN_EVENT_SOURCE_H_ #define WSMAN_EVENT_SOURCE_H_ #ifdef __cplusplus extern "C" { #endif #include "u/list.h" #define EUIDLEN 64 struct _WsXmlDoc; struct __WsNotificationInfo { struct _WsXmlDoc *headerOpaqueData; //header content char *EventAction; //event action URL struct _WsXmlDoc *EventContent; //event content }; typedef struct __WsNotificationInfo * WsNotificationInfoH; /*to store events for a subscription*/ struct __event_entry { char subscription_id[EUIDLEN]; //to identify the event entry list_t *event_content_list; //a list holds __WsNotificationInfo }; typedef struct __event_entry *event_entryH; typedef void (*clearproc) (WsNotificationInfoH); typedef int (*EventPoolInit) (void *); typedef int (*EventPoolFinalize) (void *); typedef int (*EventPoolCount) (char *); typedef int (*EventPoolAddEvent) (char *, WsNotificationInfoH); typedef int (*EventPoolAddPullEvent) (char *, WsNotificationInfoH); typedef int (*EventPoolGetAndDeleteEvent) (char *, WsNotificationInfoH*); typedef int (*EventPoolClearEvent) (char *, clearproc); /*Event Source Function Table*/ struct __EventPoolOpSet { EventPoolInit init; EventPoolFinalize finalize; EventPoolCount count; EventPoolAddEvent add; EventPoolAddPullEvent addpull; EventPoolGetAndDeleteEvent remove; EventPoolClearEvent clear; }; typedef struct __EventPoolOpSet *EventPoolOpSetH; EventPoolOpSetH wsman_get_eventpool_opset(void); #ifdef __cplusplus } #endif #endif openwsman-2.4.3/tests/webinject/testcases.xml000664 001750 001750 00000002653 12256012305 021637 0ustar00kentbkentb000000 000000 openwsman-2.4.3/bindings/ruby/extconf.rb000664 001750 001750 00000001543 12256012305 020551 0ustar00kentbkentb000000 000000 # # extconf.rb for openwsman Gem # require 'mkmf' # $CFLAGS = "#{$CFLAGS} -Werror" # requires wsman, wsman_client, and libxml2 unless have_library('wsman', 'wsman_create_doc') STDERR.puts "Cannot find wsman_create_doc() in libwsman" STDERR.puts "Is openwsman-devel installed ?" exit 1 end find_header 'wsman-xml-api.h', '/usr/include/openwsman' unless have_library('wsman_client', 'wsmc_create') STDERR.puts "Cannot find wsmc_create() in libwsman_client" STDERR.puts "Is openwsman-devel installed ?" exit 1 end find_header 'wsman-client-api.h', '/usr/include/openwsman' unless have_library('xml2', 'xmlNewDoc') STDERR.puts "Cannot find xmlNewDoc() in libxml2" STDERR.puts "Is libxml2-devel installed ?" exit 1 end find_header 'libxml/parser.h', '/usr/include/libxml2' $CPPFLAGS = "-I/usr/include/openwsman -I.." create_makefile('_openwsman') openwsman-2.4.3/bindings/version.i.in000664 001750 001750 00000000436 12256012305 020041 0ustar00kentbkentb000000 000000 /* * version.i * version definitions for openwsman swig bindings * */ #define OPENWSMAN_MAJOR @OPENWSMAN_MAJOR@ #define OPENWSMAN_MINOR @OPENWSMAN_MINOR@ #define OPENWSMAN_PATCH @OPENWSMAN_PATCH@ #define OPENWSMAN_VERSION "@OPENWSMAN_MAJOR@.@OPENWSMAN_MINOR@.@OPENWSMAN_PATCH@" openwsman-2.4.3/bindings/ruby/tests/nsconsts.rb000664 001750 001750 00000000472 12256012305 022117 0ustar00kentbkentb000000 000000 # nsconsts.rb require 'test/unit' require File.join(File.dirname(__FILE__),'_loadpath') require 'openwsman' class NsConstsTest < Test::Unit::TestCase def test_consts assert Openwsman::XML_NS_WS_MAN == "http://schemas.dmtf.org/wbem/wsman/1/wsman.xsd" assert Openwsman::XML_NS_SCHEMA_INSTANCE end end openwsman-2.4.3/examples/Makefile.am000664 001750 001750 00000000441 12256012305 017646 0ustar00kentbkentb000000 000000 AM_CFLAGS = INCLUDES = \ $(XML_CFLAGS) \ -I$(top_srcdir) \ -I$(top_srcdir)/include LIBS = \ $(XML_LIBS) \ $(top_builddir)/src/lib/libwsman.la \ $(top_builddir)/src/lib/libwsman_client.la serialize_SOURCES = serialize.c noinst_PROGRAMS = \ serialize openwsman-2.4.3/tests/client/requests/action_001.xml000664 001750 001750 00000001641 12256012305 022651 0ustar00kentbkentb000000 000000 http://schemas.xmlsoap.org/ws/2004/09/enumeration/DeEnumerate http://langley.home.planux.com:8889/wsman http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_ComputerSystem uuid:d02518a4-20c3-10c3-8002-7a36080c0e00 http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous openwsman-2.4.3/src/authenticators/file/Makefile.am000664 001750 001750 00000000450 12256012305 022573 0ustar00kentbkentb000000 000000 authdir = @PACKAGE_AUTH_DIR@ LIBS = $(top_builddir)/src/lib/libwsman.la libwsman_file_auth_la_SOURCES = \ file_auth.c INCLUDES = -I$(top_srcdir)/include libwsman_file_auth_la_LIBADD = $(CRYPT_LIBS) auth_LTLIBRARIES= libwsman_file_auth.la libwsman_file_auth_la_LDFLAGS = -version-info 1:0 openwsman-2.4.3/doc/examples000664 001750 001750 00000000460 12256012305 016303 0ustar00kentbkentb000000 000000 ./src/client/wsman enumerate http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/OMC_InitdService --username wsman -p secret -h --port 8889 ./src/client/wsman enumerate http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_ComputerSystem --username wsman -p secret -h --port 8889 openwsman-2.4.3/tests/filter/test_filter.c000664 001750 001750 00000017013 12256012305 021116 0ustar00kentbkentb000000 000000 #include #include "u/libu.h" #include "wsman-filter.h" #include "wsman-names.h" #include "wsman-xml.h" static void serialize_filter1(void) { hash_t *selectors = hash_create(HASHCOUNT_T_MAX, 0, 0); selector_entry *entry1 = NULL; entry1 = u_malloc(sizeof(selector_entry)*5); entry1[0].type = 0; entry1[0].entry.text = "OperatingSystemFilter0"; entry1[1].type = 0; entry1[1].entry.text = "localhost.localdomain"; entry1[2].type = 0; entry1[2].entry.text = "CIM_IndicationFilter"; entry1[3].type = 0; entry1[3].entry.text = "CIM_ComputerSystem"; entry1[4].type = 0; entry1[4].entry.text = "root/interop"; hash_alloc_insert(selectors, "Name", &entry1[0]); hash_alloc_insert(selectors, "SystemName", &entry1[1]); hash_alloc_insert(selectors, "CreationClassName", &entry1[2]); hash_alloc_insert(selectors, "SystemCreationClassName", &entry1[3]); hash_alloc_insert(selectors, "__cimnamespace", &entry1[4]); epr_t *epr = epr_create("http://schema.omc-project.org/wbem/wscim/1/cim-schema/2/CIM_IndicationFilter",selectors,NULL); filter_t *filter = filter_create_assoc(epr, 0, "CIM_IndicationSubscription", NULL, NULL, NULL, NULL, 0); WsXmlDocH doc = ws_xml_create_envelope(); WsXmlNodeH body = ws_xml_get_soap_body(doc); WsXmlNodeH node = ws_xml_add_child(body, XML_NS_ENUMERATION, WSENUM_ENUMERATE, NULL); filter_t *filter_cpy = filter_copy(filter); //test filter_copy int r = filter_serialize(node, filter_cpy, XML_NS_EVENTING); if(r) { printf("\033[22;31mfilter serialize failed!\033[m\n"); return; } ws_xml_dump_doc(stdout, doc); ws_xml_destroy_doc(doc); hash_free(selectors); u_free(entry1); epr_destroy(epr); filter_destroy(filter); filter_destroy(filter_cpy); printf("\033[22;32m\"http://schemas.dmtf.org/wbem/wsman/1/cimbinding/associationFilter\" filter serialize successfully!\033[m\n\n"); } static void serialize_filter2(void) { filter_t *filter = filter_create_simple(WSM_WQL_FILTER_DIALECT, "select * from CIM_ComputerSystem"); WsXmlDocH doc = ws_xml_create_envelope(); WsXmlNodeH body = ws_xml_get_soap_body(doc); WsXmlNodeH node = ws_xml_add_child(body, XML_NS_ENUMERATION, WSENUM_ENUMERATE, NULL); filter_t *filter_cpy = filter_copy(filter); //test filter_copy int r = filter_serialize(node, filter_cpy, XML_NS_WS_MAN); if(r) { printf("\t\033[22;31mfilter serialize failed!\033[m\n"); return; } ws_xml_dump_doc(stdout, doc); ws_xml_destroy_doc(doc); filter_destroy(filter); filter_destroy(filter_cpy); printf("\033[22;32m\"http://schemas.microsoft.com/wbem/wsman/1/WQL\" filter serialize successfully!\033[m\n\n"); } static void serialize_filter3(void) { hash_t *selectors = hash_create(HASHCOUNT_T_MAX, 0, 0); selector_entry *entry1 = NULL; entry1 = u_malloc(sizeof(selector_entry)*4); entry1[0].type = 0; entry1[0].entry.text = "OperatingSystemFilter0"; entry1[1].type = 0; entry1[1].entry.text = "localhost.localdomain"; entry1[2].type = 0; entry1[2].entry.text = "CIM_IndicationFilter"; entry1[3].type = 0; entry1[3].entry.text = "CIM_ComputerSystem"; hash_alloc_insert(selectors, "Name", &entry1[0]); hash_alloc_insert(selectors, "SystemName", &entry1[1]); hash_alloc_insert(selectors, "CreationClassName", &entry1[2]); hash_alloc_insert(selectors, "SystemCreationClassName", &entry1[3]); filter_t *filter = filter_create_selector(selectors); WsXmlDocH doc = ws_xml_create_envelope(); WsXmlNodeH body = ws_xml_get_soap_body(doc); WsXmlNodeH node = ws_xml_add_child(body, XML_NS_ENUMERATION, WSENUM_ENUMERATE, NULL); filter_t *filter_cpy = filter_copy(filter); //test filter_copy int r = filter_serialize(node, filter_cpy, XML_NS_WS_MAN); if(r) { printf("\033[22;31mfilter serialize failed!\033[m\n"); return; } ws_xml_dump_doc(stdout, doc); ws_xml_destroy_doc(doc); filter_destroy(filter); filter_destroy(filter_cpy); hash_free(selectors); u_free(entry1); printf("\033[22;32m\"http://schemas.dmtf.org/wbem/wsman/1/wsman/SelectorFilter\" filter serialize successfully!\033[m\n\n"); } static void deserialize_filter1(void) { WsXmlDocH doc = ws_xml_read_file("./sample1.xml", "UTF-8", 0); WsXmlNodeH node = ws_xml_get_soap_body(doc); node = ws_xml_get_child(node, 0, XML_NS_ENUMERATION, WSENUM_ENUMERATE); filter_t *filter = filter_deserialize(node, XML_NS_WS_MAN); if(filter == NULL) { printf("\033[22;31mfilter deserialize failed!\033[m\n"); return; } ws_xml_destroy_doc(doc); doc = ws_xml_create_envelope(); WsXmlNodeH body = ws_xml_get_soap_body(doc); node = ws_xml_add_child(body, XML_NS_ENUMERATION, WSENUM_ENUMERATE, NULL); int r = filter_serialize(node, filter, XML_NS_WS_MAN); if(r) { printf("\033[22;31mfilter serialize failed!\033[m\n"); return; } ws_xml_dump_doc(stdout, doc); ws_xml_destroy_doc(doc); filter_destroy(filter); printf("\033[22;32m\"http://schemas.dmtf.org/wbem/wsman/1/cimbinding/associationFilter\" filter deserialize successfully!\033[m\n\n"); } static void deserialize_filter2(void) { WsXmlDocH doc = ws_xml_read_file("./sample2.xml", "UTF-8", 0); WsXmlNodeH node = ws_xml_get_soap_body(doc); node = ws_xml_get_child(node, 0, XML_NS_ENUMERATION, WSENUM_ENUMERATE); filter_t *filter = filter_deserialize(node, XML_NS_WS_MAN); if(filter == NULL) { printf("\033[22;31mfilter deserialize failed!\033[m\n"); return; } ws_xml_destroy_doc(doc); doc = ws_xml_create_envelope(); WsXmlNodeH body = ws_xml_get_soap_body(doc); node = ws_xml_add_child(body, XML_NS_ENUMERATION, WSENUM_ENUMERATE, NULL); int r = filter_serialize(node, filter, XML_NS_WS_MAN); if(r) { printf("\033[22;31mfilter serialize failed!\033[m\n"); return; } ws_xml_dump_doc(stdout, doc); ws_xml_destroy_doc(doc); filter_destroy(filter); printf("\033[22;32m\"http://schemas.microsoft.com/wbem/wsman/1/WQL\" filter deserialize successfully!\033[m\n\n"); } static void deserialize_filter3(void) { WsXmlDocH doc = ws_xml_read_file("./sample3.xml", "UTF-8", 0); WsXmlNodeH node = ws_xml_get_soap_body(doc); node = ws_xml_get_child(node, 0, XML_NS_ENUMERATION, WSENUM_ENUMERATE); filter_t *filter = filter_deserialize(node, XML_NS_WS_MAN); if(filter == NULL) { printf("\033[22;31mfilter deserialize failed!\033[m\n"); return; } filter_add_selector(filter, "__cimnamespace", "root/interop"); ws_xml_destroy_doc(doc); doc = ws_xml_create_envelope(); WsXmlNodeH body = ws_xml_get_soap_body(doc); node = ws_xml_add_child(body, XML_NS_ENUMERATION, WSENUM_ENUMERATE, NULL); int r = filter_serialize(node, filter, XML_NS_WS_MAN); if(r) { printf("\033[22;31mfilter serialize failed!\033[m\n"); return; } ws_xml_dump_doc(stdout, doc); ws_xml_destroy_doc(doc); filter_destroy(filter); printf("\033[22;32m\"http://schemas.dmtf.org/wbem/wsman/1/wsman/SelectorFilter\" filter deserialize successfully!\033[m\n\n"); } int main(void) { serialize_filter1(); serialize_filter2(); serialize_filter3(); deserialize_filter1(); deserialize_filter2(); deserialize_filter3(); return 0; } openwsman-2.4.3/bindings/ruby/tests/pull.rb000664 001750 001750 00000001157 12256012305 021222 0ustar00kentbkentb000000 000000 # enumerate.rb require 'test/unit' require 'rexml/document' require File.join(File.dirname(__FILE__),'_loadpath') require 'openwsman' require '_client' class WsmanTest < Test::Unit::TestCase def test_client client = Client.open assert client options = Openwsman::ClientOptions.new assert options uri = "http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_ComputerSystem" context = "924fcbcc-2410-1410-8005-050505050505" result = client.pull( options, nil, uri, context ) assert result doc = REXML::Document.new result.to_xml assert doc # doc.write( $stdout, 0 ) end end openwsman-2.4.3/include/wsman-dispatcher.h000664 001750 001750 00000006370 12256012305 021050 0ustar00kentbkentb000000 000000 /******************************************************************************* * 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 Eugene Yarmosh */ #ifndef WSMAN_DISPATCHER_H_ #define WSMAN_DISPATCHER_H_ #include "wsman-soap.h" /** * @addtogroup Dispatcher * * @{ */ struct __dispatch_t { lnode_t node; int usageCount; char *inboundAction; char *outboundAction; unsigned long flags; SoapH soap; SoapServiceCallback serviceCallback; void *serviceData; list_t *inboundFilterList; list_t *outboundFilterList; }; struct __op_t { SoapDispatchH dispatch; time_t expires; unsigned long maxsize; //max envelope size //unsigned long submittedTicks; WsContextH cntx; WsXmlDocH in_doc; //not deleted on destroy WsXmlDocH out_doc; //not deleted on destroy WsmanMessage *data; list_t *processed_headers; }; typedef struct __op_t op_t; void dispatch_inbound_call(SoapH soap, WsmanMessage * msg, void *opaqueData); SoapDispatchH wsman_dispatcher(WsContextH cntx, void *data, WsXmlDocH doc); void destroy_op_entry(op_t * entry); op_t *create_op_entry(SoapH soap, SoapDispatchH dispatch, WsmanMessage * data); int unlink_response_entry(SoapH soap, op_t * entry); void destroy_dispatch_entry(SoapDispatchH entry); WsEndPointRelease wsman_get_release_endpoint(WsContextH cntx, WsXmlDocH doc); void wsman_dispatch_start(SoapDispatchH disp); SoapDispatchH wsman_dispatch_create(SoapH soap, char *inboundAction, char *outboundAction, char *role, //reserved, must be NULL SoapServiceCallback callbackProc, void *callbackData, unsigned long flags); SoapDispatchH wsman_dispatch_entry_new(void); /** @} */ #endif /* WS_DISPATCHER_H_ */ openwsman-2.4.3/bindings/ruby/tests/EnumKey.xml000664 001750 001750 00000004250 12256012305 022015 0ustar00kentbkentb000000 000000 http://schemas.microsoft.com/wbem/wsman/1/wmi/root/default/StdRegProv/EnumKeyResponse uuid:39F0214C-6B6A-4EFC-B971-CC0BC34D8DA4 http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous uuid:357dee93-b5a1-15a1-8004-4b73f7201300 AddressBook Branding Connection Manager DirectAnimation DirectDrawEx DXM_Runtime Fontcore ICW IE40 IE4Data IE5BAKEX IEData InstallShield Uninstall Information InstallShield_{F8FBDC28-C265-4F0D-8B91-6E92913E19F6} KB968930 MobileOptionPack Mozilla Firefox 9.0.1 (x86 en-US) MPlayer2 NetMeeting OutlookExpress PCHealth SchedulingAgent Windows Server 2003 Service Pack {25A13826-8E4A-4FBF-AD2B-776447FE9646} {B508B3F1-A24A-32C0-B310-85786919EF28} {F8FBDC28-C265-4F0D-8B91-6E92913E19F6} 0 openwsman-2.4.3/tests/client/requests/000775 001750 001750 00000000000 12256012305 020270 5ustar00kentbkentb000000 000000 openwsman-2.4.3/tests/client/CMakeLists.txt000664 001750 001750 00000005445 12256012305 021165 0ustar00kentbkentb000000 000000 # # CMakeLists.txt for openwsman/tests/client # include_directories(${CMAKE_SOURCE_DIR}/include ${CMAKE_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_BINARY_DIR} ) SET( TEST_LIBS wsman wsman_client ${LIBXML2_LIBRARIES} ${CURL_LIBRARIES} "pthread") SET( test_references_SOURCES test_references.c ) SET( test_transfer_get_SOURCES test_transfer_get.c ) SET( test_transfer_put_SOURCES test_transfer_put.c ) SET( test_invoke_SOURCES test_invoke.c ) SET( test_identify_SOURCES test_identify.c ) SET( test_enumeration_SOURCES test_enumeration.c ) SET( test_pull_SOURCES test_pull.c ) SET( test_subscribe_SOURCES test_subscribe.c ) SET( test_unsubscribe_SOURCES test_unsubscribe.c ) SET( test_renew_SOURCES test_renew.c ) SET( test_associators_SOURCES test_associators.c ) SET( test_selectorfilter_SOURCES test_selectorfilter.c ) ADD_EXECUTABLE( test_references ${test_references_SOURCES} ) ADD_EXECUTABLE( test_transfer_get ${test_transfer_get_SOURCES} ) ADD_EXECUTABLE( test_transfer_put ${test_transfer_put_SOURCES} ) ADD_EXECUTABLE( test_identify ${test_identify_SOURCES} ) ADD_EXECUTABLE( test_invoke ${test_invoke_SOURCES} ) ADD_EXECUTABLE( test_enumeration ${test_enumeration_SOURCES} ) ADD_EXECUTABLE( test_associators ${test_associators_SOURCES} ) ADD_EXECUTABLE( test_selectorfilter ${test_selectorfilter_SOURCES} ) ADD_EXECUTABLE( test_pull ${test_pull_SOURCES} ) ADD_EXECUTABLE( test_subscribe ${test_subscribe_SOURCES} ) ADD_EXECUTABLE( test_unsubscribe ${test_unsubscribe_SOURCES} ) ADD_EXECUTABLE( test_renew ${test_renew_SOURCES} ) TARGET_LINK_LIBRARIES( test_references ${TEST_LIBS} ) TARGET_LINK_LIBRARIES( test_transfer_get ${TEST_LIBS} ) TARGET_LINK_LIBRARIES( test_transfer_put ${TEST_LIBS} ) TARGET_LINK_LIBRARIES( test_identify ${TEST_LIBS} ) TARGET_LINK_LIBRARIES( test_invoke ${TEST_LIBS} ) TARGET_LINK_LIBRARIES( test_enumeration ${TEST_LIBS} ) TARGET_LINK_LIBRARIES( test_associators ${TEST_LIBS} ) TARGET_LINK_LIBRARIES( test_selectorfilter ${TEST_LIBS} ) TARGET_LINK_LIBRARIES( test_pull ${TEST_LIBS} ) TARGET_LINK_LIBRARIES( test_subscribe ${TEST_LIBS} ) TARGET_LINK_LIBRARIES( test_unsubscribe ${TEST_LIBS} ) TARGET_LINK_LIBRARIES( test_renew ${TEST_LIBS} ) ENABLE_TESTING() # Disable references, requires FQDNs in filter # ADD_TEST( test_client_references test_references ) ADD_TEST( test_client_transfer_get test_transfer_get ) ADD_TEST( test_client_transfer_put test_transfer_put ) ADD_TEST( test_client_identify test_identify ) ADD_TEST( test_client_invoke test_invoke ) ADD_TEST( test_client_enumeration test_enumeration ) ADD_TEST( test_client_associators test_associators ) ADD_TEST( test_client_selectorfilter test_selectorfilter ) ADD_TEST( test_client_pull test_pull ) ADD_TEST( test_client_subscribe test_subscribe ) ADD_TEST( test_client_unsubscribe test_unsubscribe ) ADD_TEST( test_client_renew test_renew ) openwsman-2.4.3/src/plugins/redirect/redirect.h000664 001750 001750 00000005035 12256012305 022023 0ustar00kentbkentb000000 000000 /* * Copyright (c) 2006 Dell, Inc. * by Praveen K Paladugu * Licensed under the GNU General Public license, version 2. */ #include "wsman-declarations.h" #include "wsman-xml-serializer.h" #define XML_REDIRECT_NS "http://dummy.com/wbem/wscim/1/cim-schema/2" struct __RedirectResult { int result; }; typedef struct __RedirectResult Redirect; // Service endpoint declaration int Redirect_Enumerate_EP(WsContextH cntx, WsEnumerateInfo* enumInfo, WsmanStatus *status, void *opaqueData); int Redirect_Pull_EP(WsContextH cntx, WsEnumerateInfo* enumInfo, WsmanStatus *status, void *opaqueData); int Redirect_Get_EP( SoapOpH op, void* appData, void *opaqueData ); int Redirect_Create_EP( SoapOpH op, void* appData, void *opaqueData ); int Redirect_Delete_EP( SoapOpH op, void* appData, void *opaqueData ); int Redirect_Put_EP( SoapOpH op, void* appData, void *opaqueData ); int Redirect_Custom_EP( SoapOpH op, void* appData, void *opaqueData ); int Redirect_transfer_action ( SoapOpH op, void* appData, void *opaqueData); int Redirect_Release_EP(WsContextH cntx, WsEnumerateInfo* enumInfo, WsmanStatus *status, void *opaqueData); /*int Redirect_Subscribe_EP(WsContextH cntx, WsSubscribeInfo* subsInfo, WsmanStatus *status, void *opaqueData); int Redirect_Renew_EP(WsContextH cntx, WsSubscribeInfo* subsInfo, WsmanStatus *status, void *opaqueData); int Redirect_UnSubscribe_EP(WsContextH cntx, WsSubscribeInfo* subsInfo, WsmanStatus *status, void *opaqueData); int Redirect_Evt_Pull_EP(WsContextH cntx,WsSubscribeInfo* subsInfo, WsmanStatus *status, void *opaqueData); int Redirect_EventPoll_EP(WsEventThreadContextH threadcntx); */ SER_DECLARE_TYPE(Redirect); DECLARE_EP_ARRAY(Redirect); void get_endpoints(void *self, void **data); //int init (void *self, void **data ); //void cleanup( void *self, void *data ); //void set_config( void *self, dictionary *config ); static char* get_remote_server(); static char* get_remote_username(); static char* get_remote_password(); static char* get_remote_url_path(); static char* get_remote_authentication_method(); static char* get_remote_cim_namespace(); static char* get_remote_cainfo(); static int get_remote_server_port(); static int get_remote_noverifypeer(); static int get_remote_noverifyhost(); static char* get_remote_sslkey(); static char* get_remote_cl_cert(); WsManClient* setup_redirect_client (WsContextH cntx, char *username, char *password); openwsman-2.4.3/src/server/gss.c000664 001750 001750 00000027530 12256012305 017041 0ustar00kentbkentb000000 000000 /******************************************************************************* * Copyright (C) 2008 Centrify 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. *******************************************************************************/ #ifdef SHTTPD_GSS #include "shttpd_defs.h" #include #define THE_END "\tContent-Type: application/octet-stream" #define FAKE_CT "Content-Type: application/soap+xml\r\n" #define FAKE_CL "Content-Length: " #define ENCRYPTED_BOUNDARY "-- Encrypted Boundary\r\n" #define KERB_CONTENT_TYPE "\tContent-Type: application/HTTP-Kerberos-session-encrypted\r\n" #define ORIGINAL_CONTENT "\tOriginalContent: type=application/soap+xml;charset=UTF-16;Length=" #define STREAM_CONTENT_TYPE "\tContent-Type: application/octet-stream\r\n" void displayError(char *msg, OM_uint32 maj_stat, OM_uint32 min_stat); int getCreds(char *service_name, gss_cred_id_t *server_creds); int do_gss(struct conn *c); int gss_encrypt(struct shttpd_arg *arg, char *input, int inlen, char **output, int *outlen); char* gss_decrypt(struct shttpd_arg *arg, char *data, int len); void getGssName(struct conn *c, char **user); static void doDisplay(char *m,OM_uint32 code,int type) { OM_uint32 maj_stat, min_stat; gss_buffer_desc msg; OM_uint32 msg_ctx; msg_ctx = 0; while (1) { maj_stat = gss_display_status(&min_stat, code, type, GSS_C_NULL_OID, &msg_ctx, &msg); DBG(("GSS-API error %s: %s\n", m, (char *)msg.value)); (void) gss_release_buffer(&min_stat, &msg); if (!msg_ctx) break; } } void displayError(char *msg, OM_uint32 maj_stat, OM_uint32 min_stat) { doDisplay(msg, maj_stat, GSS_C_GSS_CODE); doDisplay(msg, min_stat, GSS_C_MECH_CODE); } int getCreds(char *service_name, gss_cred_id_t *server_creds) { gss_buffer_desc name_buf; gss_name_t server_name; OM_uint32 maj_stat, min_stat; name_buf.value = service_name; name_buf.length = strlen(name_buf.value) + 1; maj_stat = gss_import_name(&min_stat, &name_buf, (gss_OID) GSS_C_NT_HOSTBASED_SERVICE, &server_name); if (maj_stat != GSS_S_COMPLETE) { displayError("importing name", maj_stat, min_stat); return -1; } maj_stat = gss_acquire_cred(&min_stat, server_name, 0, GSS_C_NULL_OID_SET, GSS_C_ACCEPT, server_creds, NULL, NULL); if (maj_stat != GSS_S_COMPLETE) { displayError("acquiring credentials", maj_stat, min_stat); return -1; } (void) gss_release_name(&min_stat, &server_name); return 0; } static int connectContext( void *buff, int len, gss_cred_id_t server_creds, gss_ctx_id_t *context, gss_buffer_t client_name, gss_buffer_t reply, OM_uint32 *ret_flags) { gss_buffer_desc recv_tok; gss_name_t client; gss_OID doid; OM_uint32 maj_stat, min_stat, acc_sec_min_stat; recv_tok.length = len; recv_tok.value = buff; maj_stat = gss_accept_sec_context(&acc_sec_min_stat, context, server_creds, &recv_tok, GSS_C_NO_CHANNEL_BINDINGS, &client, &doid, reply, ret_flags, 0, 0); if (maj_stat != GSS_S_COMPLETE) { displayError("accept",maj_stat,min_stat); return maj_stat; } maj_stat = gss_display_name(&min_stat, client, client_name, &doid); if(maj_stat == 0) { DBG(("Accept principal = %.*s", client_name->length, client_name->value)); maj_stat = gss_release_name(&min_stat, &client); } return maj_stat; } int do_gss(struct conn *c) { gss_cred_id_t gsscreds; gss_buffer_desc client_name; gss_buffer_desc reply; OM_uint32 retflags; if(getCreds("host@localhost", &gsscreds) != 0) return 0; // now find the beginning and end of the base64 encoded stuff struct vec *auth_vec = &c->ch.auth.v_vec; char *p = (char *) auth_vec->ptr + 9; while ((*p == ' ') || (*p == '\t')) { p++; } char *pp = p; while ((*p != ' ') && (*p != '\t') && (*p != '\r') && (*p != '\n') && (*p != 0)) { p++; } if (pp == p) { return 0; } *p = 0; // pp = start, p = end. Now decode char decbuf[p - pp]; // this is too long but we dont care int l = ws_base64_decode(pp, p - pp, decbuf, 4095); int ret = connectContext(decbuf, l, gsscreds, &c->gss_ctx, &client_name, &reply, &retflags); if (ret != 0) { send_server_error(c, 400, "Bad request"); return 0; } // encode the reply char repbuf[reply.length * 2]; // again, too large but we dont care ws_base64_encode(reply.value, reply.length, repbuf); io_clear(&c->loc.io); c->loc.headers_len = c->loc.io.head = snprintf(c->loc.io.buf, c->loc.io.size, "HTTP/1.1 200 \r\nWWW-Authenticate: Kerberos %s\r\n\r\n", repbuf); c->status = 200; OM_uint32 min_stat; gss_release_buffer(&min_stat, &reply); c->loc.flags |= FLAG_RESPONSE_COMPLETE; return 2; } int gss_encrypt(struct shttpd_arg *arg, char *input, int inlen, char **output, int *outlen) { struct conn *c = (struct conn *)arg->priv; OM_uint32 min_stat; gss_buffer_desc in_buf; gss_buffer_desc out_buf; int state; // convert to UTF-16 char utf16[inlen * 2 + 2]; char *u = utf16; *u++ = '\xff'; *u++ = '\xfe'; int i; for (i = 0; i < inlen; i++) { *u++ = input[i]; *u++ = 0; } int msglen = inlen * 2 + 2; // the data converted to UTF16 msglen += sizeof(ENCRYPTED_BOUNDARY); msglen += sizeof(KERB_CONTENT_TYPE); msglen += sizeof(ORIGINAL_CONTENT); msglen += 10; // computed length msglen += sizeof(STREAM_CONTENT_TYPE); msglen += sizeof(ENCRYPTED_BOUNDARY); msglen += 200; // encryption overhead (checksums, flags, confounders etc char *payload = (char*)malloc(msglen); if(!payload) return -1; char *p = payload; memcpy(p, ENCRYPTED_BOUNDARY, sizeof(ENCRYPTED_BOUNDARY) - 1); p += sizeof(ENCRYPTED_BOUNDARY) - 1; memcpy(p, KERB_CONTENT_TYPE, sizeof(KERB_CONTENT_TYPE) -1 ); p += sizeof(KERB_CONTENT_TYPE) - 1; memcpy(p, ORIGINAL_CONTENT, sizeof(ORIGINAL_CONTENT) - 1); p += sizeof(ORIGINAL_CONTENT) - 1 ; p += snprintf(p, 30, "%d\r\n", inlen * 2 + 2 + 1); // windows wants this to be the size of the encrypted data // and gss adds an extra pad byte memcpy(p, ENCRYPTED_BOUNDARY, sizeof(ENCRYPTED_BOUNDARY) - 1); p += sizeof(ENCRYPTED_BOUNDARY) - 1; memcpy(p, STREAM_CONTENT_TYPE, sizeof(STREAM_CONTENT_TYPE) -1 ); p += sizeof(STREAM_CONTENT_TYPE) - 1; in_buf.value = utf16; in_buf.length = inlen * 2 + 2; OM_uint32 maj_stat = gss_wrap(&min_stat, c->gss_ctx, 1, GSS_C_QOP_DEFAULT, &in_buf, &state, &out_buf); if (maj_stat != GSS_S_COMPLETE) { displayError("wrapping message", maj_stat, min_stat); return -1; } // thsi is the encryption space overhead *p++ = out_buf.length - in_buf.length - 1; // not quite sure why I need -1 but I do. Its all to do with the gss pad byte *p++ = 0; *p++ = 0; *p++ = 0; memcpy(p, out_buf.value, out_buf.length); p += out_buf.length; gss_release_buffer(&min_stat, &out_buf); memcpy(p, ENCRYPTED_BOUNDARY, sizeof(ENCRYPTED_BOUNDARY) - 1); p += sizeof(ENCRYPTED_BOUNDARY) - 1; *output = payload; *outlen = p - payload; return 1; // OK } void getGssName(struct conn *c, char **user) { OM_uint32 majStat, minStat; gss_name_t client; gss_OID doid; gss_buffer_desc client_name; *user = 0; majStat = gss_inquire_context(&minStat, c->gss_ctx, &client, 0,0,0,0,0,0); if (majStat != GSS_S_COMPLETE) { displayError("inq context", majStat, minStat); return; } majStat = gss_display_name(&minStat, client, &client_name, &doid); if (majStat != GSS_S_COMPLETE) { displayError("get display name", majStat, minStat); return; } *user = u_strndup(client_name.value, client_name.length); majStat = gss_release_name(&minStat, &client); } char* gss_decrypt(struct shttpd_arg *arg, char *data, int len) { struct conn *c = (struct conn *)arg->priv; OM_uint32 maj_stat, min_stat; int conf_state; gss_buffer_desc enc; gss_buffer_desc plain; DBG(("Decypting message %d", len)); char line[1000]; char *in = data; int found = 0; while ((in - data) < len) { char *p = line; while ((*p++ = *in++) != '\n' && (p - line < sizeof(line) - 1)); *p = 0; //DBG(("->%s", line)); if (!memcmp(line, THE_END, sizeof(THE_END) - 1 )) { found = 1; break; } } if(!found) { DBG(("Bad enc message format")); return strdup(""); } in += 4; // skip 2f000000, this is the GSS coding overhead char *p = in; found = 0; while (p - data < len) { if (!memcmp(p,"-- Enc", 6)) { found = 1; break; } p++; } if(!found) { return strdup(""); } enc.length= p - in; enc.value = in; maj_stat = gss_unwrap(&min_stat, c->gss_ctx, &enc, &plain, &conf_state, (gss_qop_t *) NULL); if (maj_stat != GSS_S_COMPLETE) { displayError("unsealing message", maj_stat, min_stat); return strdup(""); } char * pl = plain.value; // naive UTF-16 to ascii conversion char utf8[plain.length / 2 + 1]; p = utf8; int j; pl += 2; // fffe utf-16 lead in for (j = 0; j < (plain.length - 2) / 2; j++) { *p++ = *pl++; pl++; } *p = 0; gss_release_buffer(&min_stat, &plain); return( strdup(utf8)); } #endif openwsman-2.4.3/src/lib/test/.gitignore000664 001750 001750 00000000036 12256012305 020300 0ustar00kentbkentb000000 000000 test_list test_md5 test_stringopenwsman-2.4.3/src/lib/u/hash.c000664 001750 001750 00000073444 12256012305 016701 0ustar00kentbkentb000000 000000 /* * Hash Table Data Type * Copyright (C) 1997 Kaz Kylheku * * Free Software License: * * All rights are reserved by the author, with the following exceptions: * Permission is granted to freely reproduce and distribute this software, * possibly in exchange for a fee, provided that this copyright notice appears * intact. Permission is also granted to adapt this software to produce * derivative works, as long as the modified versions carry this copyright * notice and additional notices stating that the work has been modified. * This source code may be translated into executable form and incorporated * into proprietary software; there is no requirement for such software to * contain a copyright notice related to this source. * * $Id: hash.c,v 1.36.2.11 2000/11/13 01:36:45 kaz Exp $ * $Name: kazlib_1_20 $ */ #include #include #include #include #include #define HASH_IMPLEMENTATION #include "u/hash.h" #ifdef KAZLIB_RCSID static const char rcsid[] = "$Id: hash.c,v 1.36.2.11 2000/11/13 01:36:45 kaz Exp $"; #endif #define INIT_BITS 6 #define INIT_SIZE (1UL << (INIT_BITS)) /* must be power of two */ #define INIT_MASK ((INIT_SIZE) - 1) #define next hash_next #define key hash_key #define data hash_data #define hkey hash_hkey #define table hash_table #define nchains hash_nchains #define nodecount hash_nodecount #define maxcount hash_maxcount #define highmark hash_highmark #define lowmark hash_lowmark #define compare hash_compare #define function hash_function #define allocnode hash_allocnode #define freenode hash_freenode #define context hash_context #define mask hash_mask #define dynamic hash_dynamic #define table hash_table #define chain hash_chain static hnode_t *hnode_alloc(void *context); static void hnode_free(hnode_t *node, void *context); static void hnode_free2(hnode_t *node, void *context); static void hnode_free3(hnode_t *node, void *context); static hash_val_t hash_fun_default(const void *key); static int hash_comp_default(const void *key1, const void *key2); int hash_val_t_bit; /* * Compute the number of bits in the hash_val_t type. We know that hash_val_t * is an unsigned integral type. Thus the highest value it can hold is a * Mersenne number (power of two, less one). We initialize a hash_val_t * object with this value and then shift bits out one by one while counting. * Notes: * 1. HASH_VAL_T_MAX is a Mersenne number---one that is one less than a power * of two. This means that its binary representation consists of all one * bits, and hence ``val'' is initialized to all one bits. * 2. While bits remain in val, we increment the bit count and shift it to the * right, replacing the topmost bit by zero. */ static void compute_bits(void) { hash_val_t val = HASH_VAL_T_MAX; /* 1 */ int bits = 0; while (val) { /* 2 */ bits++; val >>= 1; } hash_val_t_bit = bits; } /* * Verify whether the given argument is a power of two. */ static int is_power_of_two(hash_val_t arg) { if (arg == 0) return 0; while ((arg & 1) == 0) arg >>= 1; return (arg == 1); } /* * Compute a shift amount from a given table size */ static hash_val_t compute_mask(hashcount_t size) { assert (is_power_of_two(size)); assert (size >= 2); return size - 1; } /* * Initialize the table of pointers to null. */ static void clear_table(hash_t *hash) { hash_val_t i; for (i = 0; i < hash->nchains; i++) hash->table[i] = NULL; } /* * Double the size of a dynamic table. This works as follows. Each chain splits * into two adjacent chains. The shift amount increases by one, exposing an * additional bit of each hashed key. For each node in the original chain, the * value of this newly exposed bit will decide which of the two new chains will * receive the node: if the bit is 1, the chain with the higher index will have * the node, otherwise the lower chain will receive the node. In this manner, * the hash table will continue to function exactly as before without having to * rehash any of the keys. * Notes: * 1. Overflow check. * 2. The new number of chains is twice the old number of chains. * 3. The new mask is one bit wider than the previous, revealing a * new bit in all hashed keys. * 4. Allocate a new table of chain pointers that is twice as large as the * previous one. * 5. If the reallocation was successful, we perform the rest of the growth * algorithm, otherwise we do nothing. * 6. The exposed_bit variable holds a mask with which each hashed key can be * AND-ed to test the value of its newly exposed bit. * 7. Now loop over each chain in the table and sort its nodes into two * chains based on the value of each node's newly exposed hash bit. * 8. The low chain replaces the current chain. The high chain goes * into the corresponding sister chain in the upper half of the table. * 9. We have finished dealing with the chains and nodes. We now update * the various bookeeping fields of the hash structure. */ static void grow_table(hash_t *hash) { hnode_t **newtable; assert (2 * hash->nchains > hash->nchains); /* 1 */ newtable = realloc(hash->table, sizeof *newtable * hash->nchains * 2); /* 4 */ if (newtable) { /* 5 */ hash_val_t mask = (hash->mask << 1) | 1; /* 3 */ hash_val_t exposed_bit = mask ^ hash->mask; /* 6 */ hash_val_t chain; assert (mask != hash->mask); for (chain = 0; chain < hash->nchains; chain++) { /* 7 */ hnode_t *low_chain = 0, *high_chain = 0, *hptr, *next; for (hptr = newtable[chain]; hptr != 0; hptr = next) { next = hptr->next; if (hptr->hkey & exposed_bit) { hptr->next = high_chain; high_chain = hptr; } else { hptr->next = low_chain; low_chain = hptr; } } newtable[chain] = low_chain; /* 8 */ newtable[chain + hash->nchains] = high_chain; } hash->table = newtable; /* 9 */ hash->mask = mask; hash->nchains *= 2; hash->lowmark *= 2; hash->highmark *= 2; } assert (hash_verify(hash)); } /* * Cut a table size in half. This is done by folding together adjacent chains * and populating the lower half of the table with these chains. The chains are * simply spliced together. Once this is done, the whole table is reallocated * to a smaller object. * Notes: * 1. It is illegal to have a hash table with one slot. This would mean that * hash->shift is equal to hash_val_t_bit, an illegal shift value. * Also, other things could go wrong, such as hash->lowmark becoming zero. * 2. Looping over each pair of sister chains, the low_chain is set to * point to the head node of the chain in the lower half of the table, * and high_chain points to the head node of the sister in the upper half. * 3. The intent here is to compute a pointer to the last node of the * lower chain into the low_tail variable. If this chain is empty, * low_tail ends up with a null value. * 4. If the lower chain is not empty, we simply tack the upper chain onto it. * If the upper chain is a null pointer, nothing happens. * 5. Otherwise if the lower chain is empty but the upper one is not, * If the low chain is empty, but the high chain is not, then the * high chain is simply transferred to the lower half of the table. * 6. Otherwise if both chains are empty, there is nothing to do. * 7. All the chain pointers are in the lower half of the table now, so * we reallocate it to a smaller object. This, of course, invalidates * all pointer-to-pointers which reference into the table from the * first node of each chain. * 8. Though it's unlikely, the reallocation may fail. In this case we * pretend that the table _was_ reallocated to a smaller object. * 9. Finally, update the various table parameters to reflect the new size. */ static void shrink_table(hash_t *hash) { hash_val_t chain, nchains; hnode_t **newtable, *low_tail, *low_chain, *high_chain; assert (hash->nchains >= 2); /* 1 */ nchains = hash->nchains / 2; for (chain = 0; chain < nchains; chain++) { low_chain = hash->table[chain]; /* 2 */ high_chain = hash->table[chain + nchains]; for (low_tail = low_chain; low_tail && low_tail->next; low_tail = low_tail->next) ; /* 3 */ if (low_chain != 0) /* 4 */ low_tail->next = high_chain; else if (high_chain != 0) /* 5 */ hash->table[chain] = high_chain; else assert (hash->table[chain] == NULL); /* 6 */ } newtable = realloc(hash->table, sizeof *newtable * nchains); /* 7 */ if (newtable) /* 8 */ hash->table = newtable; hash->mask >>= 1; /* 9 */ hash->nchains = nchains; hash->lowmark /= 2; hash->highmark /= 2; assert (hash_verify(hash)); } /* * Create a dynamic hash table. Both the hash table structure and the table * itself are dynamically allocated. Furthermore, the table is extendible in * that it will automatically grow as its load factor increases beyond a * certain threshold. * Notes: * 1. If the number of bits in the hash_val_t type has not been computed yet, * we do so here, because this is likely to be the first function that the * user calls. * 2. Allocate a hash table control structure. * 3. If a hash table control structure is successfully allocated, we * proceed to initialize it. Otherwise we return a null pointer. * 4. We try to allocate the table of hash chains. * 5. If we were able to allocate the hash chain table, we can finish * initializing the hash structure and the table. Otherwise, we must * backtrack by freeing the hash structure. * 6. INIT_SIZE should be a power of two. The high and low marks are always set * to be twice the table size and half the table size respectively. When the * number of nodes in the table grows beyond the high size (beyond load * factor 2), it will double in size to cut the load factor down to about * about 1. If the table shrinks down to or beneath load factor 0.5, * it will shrink, bringing the load up to about 1. However, the table * will never shrink beneath INIT_SIZE even if it's emptied. * 7. This indicates that the table is dynamically allocated and dynamically * resized on the fly. A table that has this value set to zero is * assumed to be statically allocated and will not be resized. * 8. The table of chains must be properly reset to all null pointers. */ hash_t *hash_create(hashcount_t maxcount, hash_comp_t compfun, hash_fun_t hashfun) { hash_t *hash; if (hash_val_t_bit == 0) /* 1 */ compute_bits(); hash = malloc(sizeof *hash); /* 2 */ if (hash) { /* 3 */ hash->table = malloc(sizeof *hash->table * INIT_SIZE); /* 4 */ if (hash->table) { /* 5 */ hash->nchains = INIT_SIZE; /* 6 */ hash->highmark = INIT_SIZE * 2; hash->lowmark = INIT_SIZE / 2; hash->nodecount = 0; hash->maxcount = maxcount; hash->compare = compfun ? compfun : hash_comp_default; hash->function = hashfun ? hashfun : hash_fun_default; hash->allocnode = hnode_alloc; hash->freenode = hnode_free; hash->context = NULL; hash->mask = INIT_MASK; hash->dynamic = 1; /* 7 */ clear_table(hash); /* 8 */ assert (hash_verify(hash)); return hash; } free(hash); } return NULL; } hash_t *hash_create2(hashcount_t maxcount, hash_comp_t compfun, hash_fun_t hashfun) { hash_t *hash; if (hash_val_t_bit == 0) /* 1 */ compute_bits(); hash = malloc(sizeof *hash); /* 2 */ if (hash) { /* 3 */ hash->table = malloc(sizeof *hash->table * INIT_SIZE); /* 4 */ if (hash->table) { /* 5 */ hash->nchains = INIT_SIZE; /* 6 */ hash->highmark = INIT_SIZE * 2; hash->lowmark = INIT_SIZE / 2; hash->nodecount = 0; hash->maxcount = maxcount; hash->compare = compfun ? compfun : hash_comp_default; hash->function = hashfun ? hashfun : hash_fun_default; hash->allocnode = hnode_alloc; hash->freenode = hnode_free2; hash->context = NULL; hash->mask = INIT_MASK; hash->dynamic = 1; /* 7 */ clear_table(hash); /* 8 */ assert (hash_verify(hash)); return hash; } free(hash); } return NULL; } hash_t *hash_create3(hashcount_t maxcount, hash_comp_t compfun, hash_fun_t hashfun) { hash_t *hash; if (hash_val_t_bit == 0) /* 1 */ compute_bits(); hash = malloc(sizeof *hash); /* 2 */ if (hash) { /* 3 */ hash->table = malloc(sizeof *hash->table * INIT_SIZE); /* 4 */ if (hash->table) { /* 5 */ hash->nchains = INIT_SIZE; /* 6 */ hash->highmark = INIT_SIZE * 2; hash->lowmark = INIT_SIZE / 2; hash->nodecount = 0; hash->maxcount = maxcount; hash->compare = compfun ? compfun : hash_comp_default; hash->function = hashfun ? hashfun : hash_fun_default; hash->allocnode = hnode_alloc; hash->freenode = hnode_free3; hash->context = NULL; hash->mask = INIT_MASK; hash->dynamic = 1; /* 7 */ clear_table(hash); /* 8 */ assert (hash_verify(hash)); return hash; } free(hash); } return NULL; } /* * Select a different set of node allocator routines. */ void hash_set_allocator(hash_t *hash, hnode_alloc_t al, hnode_free_t fr, void *context) { assert (hash_count(hash) == 0); // assert ((al == 0 && fr == 0) || (al != 0 && fr != 0)); hash->allocnode = al ? al : hnode_alloc; hash->freenode = fr ? fr : hnode_free; hash->context = context; } /* * Free every node in the hash using the hash->freenode() function pointer, and * cause the hash to become empty. */ void hash_free_nodes(hash_t *hash) { hscan_t hs; hnode_t *node; hash_scan_begin(&hs, hash); while ((node = hash_scan_next(&hs))) { hash_scan_delete(hash, node); hash->freenode(node, hash->context); } hash->nodecount = 0; clear_table(hash); } /* * Obsolescent function for removing all nodes from a table, * freeing them and then freeing the table all in one step. */ void hash_free(hash_t *hash) { #ifdef KAZLIB_OBSOLESCENT_DEBUG assert ("call to obsolescent function hash_free()" && 0); #endif hash_free_nodes(hash); hash_destroy(hash); } /* * Free a dynamic hash table structure. */ void hash_destroy(hash_t *hash) { assert (hash_val_t_bit != 0); assert (hash_isempty(hash)); free(hash->table); free(hash); } /* * Initialize a user supplied hash structure. The user also supplies a table of * chains which is assigned to the hash structure. The table is static---it * will not grow or shrink. * 1. See note 1. in hash_create(). * 2. The user supplied array of pointers hopefully contains nchains nodes. * 3. See note 7. in hash_create(). * 4. We must dynamically compute the mask from the given power of two table * size. * 5. The user supplied table can't be assumed to contain null pointers, * so we reset it here. */ hash_t *hash_init(hash_t *hash, hashcount_t maxcount, hash_comp_t compfun, hash_fun_t hashfun, hnode_t **table, hashcount_t nchains) { if (hash_val_t_bit == 0) /* 1 */ compute_bits(); assert (is_power_of_two(nchains)); hash->table = table; /* 2 */ hash->nchains = nchains; hash->nodecount = 0; hash->maxcount = maxcount; hash->compare = compfun ? compfun : hash_comp_default; hash->function = hashfun ? hashfun : hash_fun_default; hash->dynamic = 0; /* 3 */ hash->mask = compute_mask(nchains); /* 4 */ clear_table(hash); /* 5 */ assert (hash_verify(hash)); return hash; } /* * Reset the hash scanner so that the next element retrieved by * hash_scan_next() shall be the first element on the first non-empty chain. * Notes: * 1. Locate the first non empty chain. * 2. If an empty chain is found, remember which one it is and set the next * pointer to refer to its first element. * 3. Otherwise if a chain is not found, set the next pointer to NULL * so that hash_scan_next() shall indicate failure. */ #include "stdio.h" void hash_scan_begin(hscan_t *scan, hash_t *hash) { hash_val_t nchains = hash->nchains; hash_val_t chain; scan->table = hash; /* 1 */ for (chain = 0; chain < nchains && hash->table[chain] == 0; chain++) ; if (chain < nchains) { /* 2 */ scan->chain = chain; scan->next = hash->table[chain]; } else { /* 3 */ scan->next = NULL; } } /* * Retrieve the next node from the hash table, and update the pointer * for the next invocation of hash_scan_next(). * Notes: * 1. Remember the next pointer in a temporary value so that it can be * returned. * 2. This assertion essentially checks whether the module has been properly * initialized. The first point of interaction with the module should be * either hash_create() or hash_init(), both of which set hash_val_t_bit to * a non zero value. * 3. If the next pointer we are returning is not NULL, then the user is * allowed to call hash_scan_next() again. We prepare the new next pointer * for that call right now. That way the user is allowed to delete the node * we are about to return, since we will no longer be needing it to locate * the next node. * 4. If there is a next node in the chain (next->next), then that becomes the * new next node, otherwise ... * 5. We have exhausted the current chain, and must locate the next subsequent * non-empty chain in the table. * 6. If a non-empty chain is found, the first element of that chain becomes * the new next node. Otherwise there is no new next node and we set the * pointer to NULL so that the next time hash_scan_next() is called, a null * pointer shall be immediately returned. */ hnode_t *hash_scan_next(hscan_t *scan) { hnode_t *next = scan->next; /* 1 */ hash_t *hash = scan->table; hash_val_t chain = scan->chain + 1; hash_val_t nchains = hash->nchains; assert (hash_val_t_bit != 0); /* 2 */ if (next) { /* 3 */ if (next->next) { /* 4 */ scan->next = next->next; } else { while (chain < nchains && hash->table[chain] == 0) /* 5 */ chain++; if (chain < nchains) { /* 6 */ scan->chain = chain; scan->next = hash->table[chain]; } else { scan->next = NULL; } } } return next; } /* * Insert a node into the hash table. * Notes: * 1. It's illegal to insert more than the maximum number of nodes. The client * should verify that the hash table is not full before attempting an * insertion. * 2. The same key may not be inserted into a table twice. * 3. If the table is dynamic and the load factor is already at >= 2, * grow the table. * 4. We take the bottom N bits of the hash value to derive the chain index, * where N is the base 2 logarithm of the size of the hash table. */ void hash_insert(hash_t *hash, hnode_t *node, const void *key) { hash_val_t hkey, chain; assert (hash_val_t_bit != 0); assert (node->next == NULL); assert (hash->nodecount < hash->maxcount); /* 1 */ assert (hash_lookup(hash, key) == NULL); /* 2 */ if (hash->dynamic && hash->nodecount >= hash->highmark) /* 3 */ grow_table(hash); hkey = hash->function(key); chain = hkey & hash->mask; /* 4 */ node->key = key; node->hkey = hkey; node->next = hash->table[chain]; hash->table[chain] = node; hash->nodecount++; assert (hash_verify(hash)); } /* * Find a node in the hash table and return a pointer to it. * Notes: * 1. We hash the key and keep the entire hash value. As an optimization, when * we descend down the chain, we can compare hash values first and only if * hash values match do we perform a full key comparison. * 2. To locate the chain from among 2^N chains, we look at the lower N bits of * the hash value by anding them with the current mask. * 3. Looping through the chain, we compare the stored hash value inside each * node against our computed hash. If they match, then we do a full * comparison between the unhashed keys. If these match, we have located the * entry. */ hnode_t *hash_lookup(hash_t *hash, const void *key) { hash_val_t hkey, chain; hnode_t *nptr; hkey = hash->function(key); /* 1 */ chain = hkey & hash->mask; /* 2 */ for (nptr = hash->table[chain]; nptr; nptr = nptr->next) { /* 3 */ if (nptr->hkey == hkey && hash->compare(nptr->key, key) == 0) return nptr; } return NULL; } /* * Delete the given node from the hash table. Since the chains * are singly linked, we must locate the start of the node's chain * and traverse. * Notes: * 1. The node must belong to this hash table, and its key must not have * been tampered with. * 2. If this deletion will take the node count below the low mark, we * shrink the table now. * 3. Determine which chain the node belongs to, and fetch the pointer * to the first node in this chain. * 4. If the node being deleted is the first node in the chain, then * simply update the chain head pointer. * 5. Otherwise advance to the node's predecessor, and splice out * by updating the predecessor's next pointer. * 6. Indicate that the node is no longer in a hash table. */ hnode_t *hash_delete(hash_t *hash, hnode_t *node) { hash_val_t chain; hnode_t *hptr; assert (hash_lookup(hash, node->key) == node); /* 1 */ assert (hash_val_t_bit != 0); if (hash->dynamic && hash->nodecount <= hash->lowmark && hash->nodecount > INIT_SIZE) shrink_table(hash); /* 2 */ chain = node->hkey & hash->mask; /* 3 */ hptr = hash->table[chain]; if (hptr == node) { /* 4 */ hash->table[chain] = node->next; } else { while (hptr->next != node) { /* 5 */ assert (hptr != 0); hptr = hptr->next; } assert (hptr->next == node); hptr->next = node->next; } hash->nodecount--; assert (hash_verify(hash)); node->next = NULL; /* 6 */ return node; } int hash_alloc_insert(hash_t *hash, const void *key, const void *data) { hnode_t *node = hash->allocnode(hash->context); if (node) { hnode_init(node, data); hash_insert(hash, node, key); return 1; } return 0; } void hash_delete_free(hash_t *hash, hnode_t *node) { hash_delete(hash, node); hash->freenode(node, hash->context); } /* * Exactly like hash_delete, except does not trigger table shrinkage. This is to be * used from within a hash table scan operation. See notes for hash_delete. */ hnode_t *hash_scan_delete(hash_t *hash, hnode_t *node) { hash_val_t chain; hnode_t *hptr; assert (hash_lookup(hash, node->key) == node); assert (hash_val_t_bit != 0); chain = node->hkey & hash->mask; hptr = hash->table[chain]; if (hptr == node) { hash->table[chain] = node->next; } else { while (hptr->next != node) hptr = hptr->next; hptr->next = node->next; } hash->nodecount--; assert (hash_verify(hash)); node->next = NULL; return node; } /* * Like hash_delete_free but based on hash_scan_delete. */ void hash_scan_delfree(hash_t *hash, hnode_t *node) { hash_scan_delete(hash, node); hash->freenode(node, hash->context); } /* * Verify whether the given object is a valid hash table. This means * Notes: * 1. If the hash table is dynamic, verify whether the high and * low expansion/shrinkage thresholds are powers of two. * 2. Count all nodes in the table, and test each hash value * to see whether it is correct for the node's chain. */ int hash_verify(hash_t *hash) { hashcount_t count = 0; hash_val_t chain; hnode_t *hptr; if (hash->dynamic) { /* 1 */ if (hash->lowmark >= hash->highmark) return 0; if (!is_power_of_two(hash->highmark)) return 0; if (!is_power_of_two(hash->lowmark)) return 0; } for (chain = 0; chain < hash->nchains; chain++) { /* 2 */ for (hptr = hash->table[chain]; hptr != 0; hptr = hptr->next) { if ((hptr->hkey & hash->mask) != chain) return 0; count++; } } if (count != hash->nodecount) return 0; return 1; } /* * Test whether the hash table is full and return 1 if this is true, * 0 if it is false. */ #undef hash_isfull int ow_hash_isfull(hash_t *hash) { return hash->nodecount == hash->maxcount; } /* * Test whether the hash table is empty and return 1 if this is true, * 0 if it is false. */ #undef hash_isempty int ow_hash_isempty(hash_t *hash) { return hash->nodecount == 0; } static hnode_t *hnode_alloc(void *context) { return malloc(sizeof *hnode_alloc(NULL)); } static void hnode_free(hnode_t *node, void *context) { free(node); } static void hnode_free2(hnode_t *node, void *context) { free((void *)node->data); free(node); } static void hnode_free3(hnode_t *node, void *context) { free((void *)node->data); free((void *)node->key); free(node); } /* * Create a hash table node dynamically and assign it the given data. */ hnode_t *hnode_create(const void *data) { hnode_t *node = malloc(sizeof *node); if (node) { node->data = data; node->next = NULL; } return node; } /* * Initialize a client-supplied node */ hnode_t *hnode_init(hnode_t *hnode, const void *data) { hnode->data = data; hnode->next = NULL; return hnode; } /* * Destroy a dynamically allocated node. */ void hnode_destroy(hnode_t *hnode) { free(hnode); } #undef hnode_put void ow_hnode_put(hnode_t *node, const void *data) { node->data = data; } #undef hnode_get const void *ow_hnode_get(hnode_t *node) { return node->data; } #undef hnode_getkey const void *ow_hnode_getkey(hnode_t *node) { return node->key; } #undef hash_count hashcount_t ow_hash_count(hash_t *hash) { return hash->nodecount; } #undef hash_size hashcount_t ow_hash_size(hash_t *hash) { return hash->nchains; } static hash_val_t hash_fun_default(const void *key) { static unsigned long randbox[] = { 0x49848f1bU, 0xe6255dbaU, 0x36da5bdcU, 0x47bf94e9U, 0x8cbcce22U, 0x559fc06aU, 0xd268f536U, 0xe10af79aU, 0xc1af4d69U, 0x1d2917b5U, 0xec4c304dU, 0x9ee5016cU, 0x69232f74U, 0xfead7bb3U, 0xe9089ab6U, 0xf012f6aeU, }; const unsigned char *str = key; hash_val_t acc = 0; while (*str) { acc ^= randbox[(*str + acc) & 0xf]; acc = (acc << 1) | (acc >> 31); acc &= 0xffffffffU; acc ^= randbox[((*str++ >> 4) + acc) & 0xf]; acc = (acc << 2) | (acc >> 30); acc &= 0xffffffffU; } return acc; } static int hash_comp_default(const void *key1, const void *key2) { return strcmp(key1, key2); } #ifdef KAZLIB_TEST_MAIN #include #include #include typedef char input_t[256]; static int tokenize(char *string, ...) { char **tokptr; va_list arglist; int tokcount = 0; va_start(arglist, string); tokptr = va_arg(arglist, char **); while (tokptr) { while (*string && isspace((unsigned char) *string)) string++; if (!*string) break; *tokptr = string; while (*string && !isspace((unsigned char) *string)) string++; tokptr = va_arg(arglist, char **); tokcount++; if (!*string) break; *string++ = 0; } va_end(arglist); return tokcount; } static char *dupstring(char *str) { int sz = strlen(str) + 1; char *new = malloc(sz); if (new) memcpy(new, str, sz); return new; } static hnode_t *new_node(void *c) { static hnode_t few[5]; static int count; if (count < 5) return few + count++; return NULL; } static void del_node(hnode_t *n, void *c) { } int main(void) { input_t in; hash_t *h = hash_create(HASHCOUNT_T_MAX, 0, 0); hnode_t *hn; hscan_t hs; char *tok1, *tok2, *val; const char *key; int prompt = 0; char *help = "a add value to hash table\n" "d delete value from hash table\n" "l lookup value in hash table\n" "n show size of hash table\n" "c show number of entries\n" "t dump whole hash table\n" "+ increase hash table (private func)\n" "- decrease hash table (private func)\n" "b print hash_t_bit value\n" "p turn prompt on\n" "s switch to non-functioning allocator\n" "q quit"; if (!h) puts("hash_create failed"); for (;;) { if (prompt) putchar('>'); fflush(stdout); if (!fgets(in, sizeof(input_t), stdin)) break; switch(in[0]) { case '?': puts(help); break; case 'b': printf("%d\n", hash_val_t_bit); break; case 'a': if (tokenize(in+1, &tok1, &tok2, (char **) 0) != 2) { puts("what?"); break; } key = dupstring(tok1); val = dupstring(tok2); if (!key || !val) { puts("out of memory"); free((void *) key); free(val); } if (!hash_alloc_insert(h, key, val)) { puts("hash_alloc_insert failed"); free((void *) key); free(val); break; } break; case 'd': if (tokenize(in+1, &tok1, (char **) 0) != 1) { puts("what?"); break; } hn = hash_lookup(h, tok1); if (!hn) { puts("hash_lookup failed"); break; } val = hnode_get(hn); key = hnode_getkey(hn); hash_scan_delfree(h, hn); free((void *) key); free(val); break; case 'l': if (tokenize(in+1, &tok1, (char **) 0) != 1) { puts("what?"); break; } hn = hash_lookup(h, tok1); if (!hn) { puts("hash_lookup failed"); break; } val = hnode_get(hn); puts(val); break; case 'n': printf("%lu\n", (unsigned long) hash_size(h)); break; case 'c': printf("%lu\n", (unsigned long) hash_count(h)); break; case 't': hash_scan_begin(&hs, h); while ((hn = hash_scan_next(&hs))) printf("%s\t%s\n", (char*) hnode_getkey(hn), (char*) hnode_get(hn)); break; case '+': grow_table(h); /* private function */ break; case '-': shrink_table(h); /* private function */ break; case 'q': exit(0); break; case '\0': break; case 'p': prompt = 1; break; case 's': hash_set_allocator(h, new_node, del_node, NULL); break; default: putchar('?'); putchar('\n'); break; } } return 0; } #endif openwsman-2.4.3/bindings/python/tests/Makefile.am000664 001750 001750 00000000022 12256012305 022303 0ustar00kentbkentb000000 000000 EXTRA_DIST = *.py openwsman-2.4.3/src/server/shttpd/std_includes.h000664 001750 001750 00000002046 12256012305 022233 0ustar00kentbkentb000000 000000 /* * Copyright (c) 2004-2005 Sergey Lyubka * All rights reserved * * "THE BEER-WARE LICENSE" (Revision 42): * Sergey Lyubka wrote this file. As long as you retain this notice you * can do whatever you want with this stuff. If we meet some day, and you think * this stuff is worth it, you can buy me a beer in return. */ #ifndef STD_HEADERS_INCLUDED #define STD_HEADERS_INCLUDED #ifndef _WIN32_WCE /* Some ANSI #includes are not available on Windows CE */ #include #include #include #include #include #include #endif /* _WIN32_WCE */ #include #include #include #include #include #include #include #include #include #if defined(_WIN32) /* Windows specific */ #include "compat_win32.h" #elif defined(__rtems__) /* RTEMS specific */ #include "compat_rtems.h" #else /* UNIX specific */ #include "compat_unix.h" #endif /* _WIN32 */ #endif /* STD_HEADERS_INCLUDED */ openwsman-2.4.3/src/cpp/000775 001750 001750 00000000000 12256012305 015346 5ustar00kentbkentb000000 000000 openwsman-2.4.3/doc/README.memory-usage000664 001750 001750 00000013234 12256012305 020036 0ustar00kentbkentb000000 000000 A couple of days ago, I had sent in an email with the following observation: >Memory consumption: >=================== > >In case of stress test involving lots of clients doing enumeration at >the same time, the memory consumption starts growing at an alarming >rate. This is understandable, since Openwsman has to cache the >enumeration results till the client actually pulls them or they expire. >This might not be a problem under normal systems where the memory is not >at a premium but on embedded systems, this will definitely cause problems. > >Actually, let me take that back. It will cause problems on normal >systems as well. Somewhere between 1.5.0 and 2.0.0 we got rid of the >max_thread parameter. Currently, I believe each listener thread is setup >to handle 20 clients. In case there is a 21st simultaneous client, >another listener thread is spawned. > >Now if one were to look at compat_unix.h, we see this: > > >#define InitializeCriticalSection(x) /* FIXME UNIX version is not MT >safe */ >#define EnterCriticalSection(x) >#define LeaveCriticalSection(x) > > >Seems like mutex locking code is def'ed to nothing on unix systems. If >that is the case then the moment the system spawns another listener >thread, there will be problems and since you cannot contain the number >of threads spawned, you have no control over another thread being spawned. > >I tried to fix compat_unix.h but that just leads to deadlocks that >Helgrind can't seem to identify. > >This seems like a limitation of the spec and the way Openwsman is >engineered. I have a working fix for this albeit in the Openwsman 2.1.0 >codebase. Let me try and port it over to 2.2.0 and I shall send the fix >along. Might take me a day or two to get to this. > >The fix is not conventional but it is config file driven so it can be >turned on or off on the fly. I'm sending in the patch to fix this problem. The patch reintroduces the max_thread config file parameter and introduces two new parameters: * max_connections_per_thread * thread_stack_size Explanation for the patch: ================ 1. wsmand-daemon.c & wsmand-daemon.h: The changes here are to read in the config file parameters. 2. wsmand-listener.c: As I had mentioned earlier, the multithreading capabilities in Openwsman seem to be busted, since compat_unix.c defines all the locking/unlocking primitives to blanks. Since we got rid of the max_thread parameter this makes it quite dangerous since if we have a thread serving 20 clients and a 21st client sends in a request another thread is spawned which is dangerous without the concurrency primitives in place. The change in this file first of all reintroduces the max_thread parameter. I usually keep this to 1, since I don't want more than 1 listener thread running if there is no concurrency support. It also uses the max_connections_per_thread parameter to optimize how many clients you wish to serve by that thread. If more than max_thread * max_connections_per_thread client comes in it is blocked till one of the threads is free. I also modified find_not_busy thread to count how many threads are active. After some profiling it was also a pleasant surprise that Openwsman does not utilize a lot of stack space. Since each thread by default is given about 2Mb if I am not wrong, which seems wasteful, so I introduced the thread_stack_size to optimize the thread stack space. This parameter takes in stack size in bytes and is used as the input to pthread_attr_setstacksize(). I've tested with as low as 256k(262144 bytes) and Openwsman works just fine even under stress. Your mileage may vary depending on the OS. When max_thread is set to 0, Openwsman behaves as it used to. The only caveat is when max_thread is non-zero, max_connections_per_thread cannot be zero, since that would effectively mean that the threads cannot serve any clients. In the case of thread_stack_size set to 0, Openwsman again behaves like it used to. So set both these parameters to zero to turn off these optimizations. 3. wsman-soap.c: This is to tackle the problem of Openwsman using lots of memory when there are too many clients doing Enumerations. Enumerations require Openwsman to keep the results in memory till they expire or till they are pulled by the client. On an embedded system, where the memory constraints are stringent, this could cause problems. To get around this problem, if there are already max_threads*max_connections_ per_thread number of enumeration results in memory and another enumeration request is encountered, I return an error saying "Insufficient Resource.......", till one of the enumerations is pulled or one of them expires. max_threads*max_connections_per_thread means that all the available listeners have been utilized to do enumerations, therefore there could be that many clients making pull requests. I do not block the pull operations or any other operations since those do not require Openwsman to cache the results. This optimization can again be turned off by setting max_threads to 0 which is the default. Testing: ===== Before these changes, the idle Openwsman memory usage was about 8MB and with 10 clients doing simultaneous enumearations would climb up to about 50-60MB. With the following parameters in place: max_threads=1 max_connections_per_thread=8 thread_stack_size=262144 the idle memory usage was about 4MB and with 10 clients doing enumearation, it went up to about 19MB. NOTE: ------- I could get the idle usage down a lot more with setting the main stack even lower than the thread stack using `ulimit -s` in the wsman init file. I could set it down to about 64K and Openwsman worked just fine. Your mileage may again vary but feel free to play around with that if you are on a memory starved system. -- Suresh openwsman-2.4.3/openwsman++.pc.in000664 001750 001750 00000000464 12256012305 017067 0ustar00kentbkentb000000 000000 prefix=@prefix@ exec_prefix=@prefix@ libdir=@libdir@ includedir=@includedir@ Name: @PACKAGE@++ Description: Opensource Implementation of WS-Management Client Version: @VERSION@ Requires: Libs: -L${libdir} -l@WSMAN_PKG@ -l@WSMAN_CLIENTPP_PKG@ Cflags: -I${includedir}/@PACKAGE@ -I${includedir}/@PACKAGE@/cpp openwsman-2.4.3/include/cim/.cvsignore000664 001750 001750 00000000060 12256012305 020164 0ustar00kentbkentb000000 000000 Makefile Makefile.in *.o *.lo *.la .deps .libs openwsman-2.4.3/etc/000775 001750 001750 00000000000 12256012305 014550 5ustar00kentbkentb000000 000000 openwsman-2.4.3/src/plugins/redirect/redirect.c000664 001750 001750 00000020612 12256012305 022014 0ustar00kentbkentb000000 000000 /* * Copyright (c) 2006 Dell, Inc. * by Praveen K Paladugu * Licensed under the GNU General Public license, version 2. */ #include "wsman_config.h" #include "stdlib.h" #include "stdio.h" #include "string.h" #include "ctype.h" #include "u/libu.h" #include "wsman-xml-api.h" #include "wsman-soap.h" #include "wsman-xml-serializer.h" #include "wsman-dispatcher.h" #include "wsman-client-api.h" #include "redirect.h" #include "../../server/wsmand-daemon.h" struct __Redirect_Data { char *server; char *username; char *password; char *url_path; char *authentication_method; char *cim_namespace; char *cainfo, *sslkey, *cl_cert; char *namespace; int noverifypeer, noverifyhost; int server_port; }; static struct __Redirect_Data *redirect_data; SER_START_ITEMS(Redirect) SER_END_ITEMS(Redirect); /*As the data value in endPoints is not used, setting it to NULL for now*/ START_END_POINTS(Redirect) END_POINT_TRANSFER_DIRECT_GET(Redirect, NULL), END_POINT_TRANSFER_DIRECT_PUT(Redirect, NULL), END_POINT_TRANSFER_DIRECT_CREATE(Redirect, NULL), END_POINT_TRANSFER_DIRECT_DELETE(Redirect, NULL), END_POINT_ENUMERATE(Redirect, NULL), END_POINT_DIRECT_PULL(Redirect, NULL), END_POINT_PULL(Redirect, NULL), END_POINT_RELEASE(Redirect, NULL), END_POINT_CUSTOM_METHOD(Redirect, NULL), FINISH_END_POINTS(Redirect); static list_t * set_namespaces(void) { int i; list_t *l = list_create(LISTCOUNT_T_MAX); WsSupportedNamespaces *ns = (WsSupportedNamespaces *)u_malloc( sizeof(WsSupportedNamespaces)); ns->class_prefix = NULL; ns->ns = redirect_data->namespace; lnode_t *node = lnode_create(ns); list_append(l, node); return l; } void get_endpoints(void *self, void **data) { WsDispatchInterfaceInfo *ifc =(WsDispatchInterfaceInfo *)data; ifc->flags = 0; ifc->actionUriBase = NULL; ifc->version = "2.2"; ifc->vendor = "Dell"; ifc->displayName = "Redirect"; ifc->notes = "Redirect Plugin"; ifc->compliance = XML_NS_WS_MAN; ifc->wsmanResourceUri = NULL; ifc->extraData = NULL; ifc->namespaces = set_namespaces(); ifc->endPoints = Redirect_EndPoints; } int init( void *self, void **data ) { char* filename; dictionary *ini, *inc_ini; filename = (char *) wsmand_options_get_config_file(); ini = iniparser_new(filename); redirect_data = malloc (sizeof(struct __Redirect_Data)); if (redirect_data == NULL){ error("Failed while allocating memory for redirect_data"); return 0; } /*Check if the conf file has the required fields populated.*/ if ( iniparser_getstring(ini, "redirect:server", NULL) ==NULL || iniparser_getstring(ini, "redirect:resource", NULL) ==NULL ){ /*if the redirection details are not provided in the core config file, check for an include tag, and check file in the include tag*/ filename=iniparser_getstring(ini,"redirect:include",NULL); if (filename == NULL) goto err_out; inc_ini=iniparser_new(filename); if (inc_ini == NULL) goto err_out; if ( iniparser_getstring(inc_ini, ":server",NULL) != NULL && iniparser_getstring(inc_ini,":resource",NULL) != NULL ) return 1; /*the inputs are fine */ err_out: error("Redirect Plugin: The required inputs are not provided in the config file"); return 0; } return 1; } void cleanup( void *self, void *data ) { free(redirect_data); return; } void set_config( void *self, dictionary *config ) { if (config == NULL) return; char *inc_filename; dictionary *inc_ini; /*Check for include tag first, if exists, only use the included file*/ if ( (inc_filename=iniparser_getstring(config,"redirect:include",NULL)) != NULL ){ inc_ini = iniparser_new(inc_filename); redirect_data->server = iniparser_getstr (inc_ini, ":server"); redirect_data->namespace = iniparser_getstr (inc_ini, ":resource"); redirect_data->username = iniparser_getstring (inc_ini, ":username",NULL); redirect_data->password = iniparser_getstring (inc_ini, ":password",NULL); redirect_data->url_path = iniparser_getstring (inc_ini, ":url_path","/wsman"); redirect_data->authentication_method = iniparser_getstring (inc_ini, ":authentication_method", "basic"); redirect_data->cim_namespace = iniparser_getstring (inc_ini, ":cim_namespace","root/cimv2"); redirect_data->cainfo = iniparser_getstring (inc_ini, ":cacert",NULL); redirect_data->server_port = iniparser_getint (inc_ini, ":port",5895); redirect_data->noverifypeer = iniparser_getint (inc_ini, ":noverifypeer", 0); redirect_data->noverifyhost = iniparser_getint (inc_ini, ":noverifyhost", 0); redirect_data->sslkey = iniparser_getstring (inc_ini, ":sslkey", NULL); redirect_data->cl_cert = iniparser_getstring (inc_ini, ":cl_cert", NULL); return; } /*No Include file, read the main configuration file */ redirect_data->server = iniparser_getstr (config, "redirect:server"); redirect_data->namespace = iniparser_getstr (config, "redirect:resource"); redirect_data->username = iniparser_getstring (config, "redirect:username",NULL); redirect_data->password = iniparser_getstring (config, "redirect:password",NULL); redirect_data->url_path = iniparser_getstring (config, "redirect:url_path","/wsman"); redirect_data->authentication_method = iniparser_getstring (config, "redirect:authentication_method", "basic"); redirect_data->cim_namespace = iniparser_getstring (config, "redirect:cim_namespace","root/cimv2"); redirect_data->cainfo = iniparser_getstring (config, "redirect:cacert",NULL); redirect_data->server_port = iniparser_getint (config, "redirect:port",5895); redirect_data->noverifypeer = iniparser_getint (config, "redirect:noverifypeer", 0); redirect_data->noverifyhost = iniparser_getint (config, "redirect:noverifyhost", 0); redirect_data->sslkey = iniparser_getstring (config, "redirect:sslkey", NULL); redirect_data->cl_cert = iniparser_getstring (config, "redirect:cl_cert", NULL); } static char *get_remote_cl_cert() { return redirect_data->cl_cert; } static char *get_remote_sslkey() { return redirect_data->sslkey; } static char* get_remote_server() { return redirect_data->server; } static int get_remote_noverifypeer() { return redirect_data->noverifypeer; } static int get_remote_noverifyhost() { return redirect_data->noverifyhost; } static char* get_remote_username() { return redirect_data->username; } static char* get_remote_password() { return redirect_data->password; } static char* get_remote_url_path() { return redirect_data->url_path; } static char* get_remote_namespace() { return redirect_data->namespace; } static char* get_remote_authentication_method() { return redirect_data->authentication_method; } static char* get_remote_cim_namespace() { return redirect_data->cim_namespace; } static char* get_remote_cainfo() { return redirect_data->cainfo; } static int get_remote_server_port() { return redirect_data->server_port; } WsManClient* setup_redirect_client(WsContextH cntx, char *ws_username, char *ws_password) { WsManClient *cl = malloc(sizeof(cl)); if (cl == NULL){ error("Error while allocating memory for client in redirect plugin"); return NULL; } cl = wsmc_create( get_remote_server() , get_remote_server_port() , get_remote_url_path(), get_remote_cainfo() ? "https" : "http", get_remote_username() ? get_remote_username() : strdup(ws_username), get_remote_password() ? get_remote_password() : strdup(ws_password) ); wsman_transport_set_auth_method(cl, get_remote_authentication_method()); if ( get_remote_cainfo() ) { wsman_transport_set_cainfo(cl, get_remote_cainfo() ); } if (get_remote_cl_cert()){ wsman_transport_set_cert(cl, get_remote_cl_cert()); if (!get_remote_cainfo()) debug("Warning: cainfo not set to enable SSL operation in Redirect Plugin\n"); } if ( get_remote_sslkey()) { wsman_transport_set_cert(cl, get_remote_sslkey()); if (!get_remote_cainfo()) { debug("Warning: cainfo not set to enable SSL operation in Redirect Plugin\n"); } } wsman_transport_set_verify_peer(cl, get_remote_cainfo()? !get_remote_noverifypeer() : 0); wsman_transport_set_verify_host(cl, get_remote_cainfo() ? !get_remote_noverifyhost(): 0 ); return cl; } openwsman-2.4.3/bindings/python/tests/run000755 001750 001750 00000000231 12256012305 021001 0ustar00kentbkentb000000 000000 #!/bin/bash # # run script for Python tests # # Usage: run # (cd $1; f=`dirname $0`; LD_LIBRARY_PATH=$f/../../../build/src/lib python $2) openwsman-2.4.3/include/u/os.h000664 001750 001750 00000004511 12256012305 016457 0ustar00kentbkentb000000 000000 /* * Copyright (c) 2005, 2006 by KoanLogic s.r.l. - All rights reserved. */ #ifndef _LIBU_OS_H_ #define _LIBU_OS_H_ #include #include #include #if defined (__FreeBSD__) || defined (__OpenBSD__) || defined (__NetBSD__) || defined (__APPLE__) struct __timezone { int tz_minuteswest; /* minutes W of Greenwich */ int tz_dsttime; /* type of dst correction */ }; #endif #if defined WIN32 && ! defined __CYGWIN__ #define strcasecmp stricmp #define strncasecmp strnicmp #include #include typedef DWORD pid_t; #ifdef __cplusplus extern "C" { #endif pid_t getpid(void); #ifdef __cplusplus } #endif #define dlclose(handle) FreeLibrary(handle) #define strtoull(nptr, endptr, base) _strtoul_l(nptr, endptr, base, NULL) #define strtoll(nptr, endptr, base) _strtol_l(nptr, endptr, base, NULL) #define sleep(secs) Sleep( (secs) * 1000 ) #define snprintf _snprintf /*!< The snprintf is called _snprintf() in Win32 */ #define popen _popen #define getpid GetCurrentProcessId #define pclose _pclose #ifndef ssize_t typedef int ssize_t; #endif #define bzero(p, l) memset(p, 0, l) #endif // WIN32 /* Define VA_COPY() to do the right thing for copying va_list variables. */ #ifdef WIN32 # if defined (__GNUC__) && defined (__PPC__) && (defined (_CALL_SYSV) || defined (_WIN32)) # define VA_COPY(ap1, ap2) (*(ap1) = *(ap2)) # elif defined (VA_COPY_AS_ARRAY) # define VA_COPY(ap1, ap2) i_memmove ((ap1), (ap2), sizeof (va_list)) # else /* va_list is a pointer */ # define VA_COPY(ap1, ap2) ((ap1) = (ap2)) # endif /* va_list is a pointer */ #else # define VA_COPY va_copy #endif #ifdef __GNUC__ #define __INLINE__ __inline__ #elif _WIN32 #define __INLINE__ __inline #elif __SUNPRO_C || __SUNPRO_CC #define __INLINE__ inline # endif #ifndef _PASSWORD_LEN #define _PASSWORD_LEN 128 #endif #if defined(__vxworks) || defined(__VXWORKS__) /* on VxWorks/DCC there's not extern declaration (even if the var is available into library files) */ extern char *optarg; extern int optind; #endif #ifdef WIN32 #ifdef __cplusplus extern "C" { #endif #ifndef HAVE_STRSEP char * strsep(char **, const char *); #endif char *strtok_r(char *s, const char *delim, char **last); const char * getpass (const char *); #ifdef __cplusplus } #endif #endif #endif openwsman-2.4.3/ChangeLog000664 001750 001750 00000053553 12256012305 015562 0ustar00kentbkentb000000 000000 2.4.3 - Bugfixes - Fix bindings for Java 1.5 - Raise exception if client creation fails (bindings) 2.4.2 - Standards compliance - Honor WS-Management 1.1.1 standard (line 739) Disable multiple MessageID checks - Bugfixes - Fix crash in redirect module (typo) 2.4.1 - Build fixes - Builds now on SLES11 (cmake 2.4), Fedora 18 - Fedora 19 - needs rubypick package - has empty ruby_version in CONFIG - fix Ruby gem, include version.rb 2.4.0 - Features - Add support for OptionSet in SOAP header (breaks ABI) - Increase soversion of libwsman_client to 2.0.0 - new function wsmc_add_option - Redirect plugin: Added facilities to import the redirection details from an included file (Praveen K Paladugu) - Bugfixes - wsman_transport_set_verify_host passed wrong values to CURL - recognize 'Msvc' (Hyper V) and 'DCIM' (Dell Drac) CIM schemata - xml_parser_element_dump: fix pointer (github issue #8) - Bindings - Ruby: Fix Ruby 1.9 threading locks for wsmc_action_* functions - Ruby: API change: Transport.verify_{host,peer}? return Boolean now Transport.verify_peer -> Transport.verify_peer? Transport.verify_host -> Transport.verify_host? - Support for OptionSet - ClientOptions#add_option - ClientOptions#options= (Ruby) - XmlDoc#to_s returns non-indented xml representation - Ruby: Accessors for OptionSet, Selectors, and Properties - ClientOptions#options - ClientOptions#properties - ClientOptions#selectors - Define security delivery modes (WSMAN_DELIVERY_SEC_*) - Vastly improved bindings documentation - Generate documenation with rdoc 1.9 - Windows Remote Shell client implementation (see ruby/tests/winrs.rb) 2.3.7 - Bugfixes - Generate pkgconfig (.pc) files correctly - Require SWIG > 2.0.4 for building 2.3.6 - Features - Plugins: Ability to redirect requests to a different WS-Management server (Praveen Paladugu) - Bugfixes - Fix xml namespace in Fault message (Praveen Paladugu) - Pass correct key values when creating a Cim_IndicationSubscription (Santosh Bidaralli) - verify_class_namespace: properly check for 'CIM' class schema (Mayur Bhosle) - Fix MaxElements namespace in Pull context (Praveen Paladugu) - Bindings - Ruby: fix crash in Options destructor - Ruby: mark passing arrays via invoke as unsupported - Building - new cmake option: BUILD_BINDINGS (defaults to yes) - honor BUILD_TESTS for all test directories - fix MaxcOS build (Dan Villiom Podlaski Christiansen) 2.3.5 - Bugfixes - Release serializer lock only after use (Satya Chittidi) 2.3.4 - Bugfixes - Adapt to Swig 2.0.5 bugfix for renamed construtors/destructors. - Bindings - SwigClass.. variables are static now 2.3.3 - Bugfixes - Assume 'XPath' as default filter dialect, not 'WQL' (Zoltan Micskei) - Fixed enumeration with selector filter returning only one instance. (Zoltan Micskei) - mark XPath filtering as not supported (in sfcc) - Bindings - Adapt to Ruby 1.9 - Disable RDoc for Ruby 1.9 - WsXmlDoc.to_xml - enforce utf-8 encoding - Properly create AssociationInstances(CIM References) / AssociatedInstances(CIM Associations) filter 2.3.2 - Bugfixes - Assume 'XPath' as default filter dialect, not 'WQL' (Zoltan Micskei) - Bindings - Add ClientOptions#flags() (read) and ClientOptions#reset_flags() - Add Openwsman#uri_prefix - Add Openwsman#create_doc_from_string - Provide full EndPointReference handling 2.3.1 - Features - switch default CIMOM connection to https on port 5989 with PAM authentication (this now reflects the default sfcb config) - Bindings - Ruby: Add Openwsman#epr_uri_for - Bugfixes - Fix build issues in .spec file 2.3.0 - Features - openSUSE: support systemd - provider getter functions for all client and client option string values - Add ssl-related config options in [cim] section, see openwsman.conf ssl = yes/no verify_cert = yes/no trust_store = /etc/ssl/certs - Bugfixes - Enum/Pull: Fix envelope maxsize handling, return partial result - Fix memleaks in client and client option string setters (Matthias Bolte) - All string value getters (for client and client_opt) return copies now (found by Matthias Bolte) - Define and use PLUGIN_API_VERSION for the server-side plugins - Handle optional arguments propertly during client endpoint URI creation (Matthias Bolte) - Make calls to 'identify' repeatable - Destroy serializer lock and client mutex at exit (Bing Liu) - Fix leak in wsmc_release (Sanjeev Putta) - Allow to reset transport credentials to NULL (Matthias Bolte) - Plug memory leaks in wsman-client-transport (Found by Suneet Chandok, improved by Matthias Bolte) - print warning if event delivery fails - Bindings - Provide Ruby bindings also as GEM (-> https://rubygems.org/gems/openwsman) - Add Openwsman#create_doc_from_file to read xml files - Add XmlNode#next to iterate over children with identical name - Add Openwsman#erb_prefix_for to return EPR uri prefixes for different CIM schema - Ruby: Provide a default implementation of auth_request_callback - Ruby: Support Ruby 1.9 - Expose Openwsman version as OPENWSMAN_VERSION, OPENWSMAN_MAJOR, OPENWSMAN_MINOR, OPENWSMAN_PATCH - Ruby: expand XmlNode#each to iterate over multiple children of same name - new test tool: winenum.rb, to enumerate WINRM instances - update documentation: Add note about escaping selector values 2.2.7 - Features - Rename openwsman-client to libwsman_clientpp since it only includes C++ bindings. Split off libwsman_clientpp-devel. Move openwsman_client.conf to libwsman1. - Performance improvements for Enum (optimized) and Pull requests (Srinivas Thirumalaa) - Bindings - Fix all tests - Enhance client function documentation - Add max_elements, max_envelope_size, fragment, and timeout to Options - Use optimized enumeration in tests - Bugfixes - Fix memory leaks in wsmc_action_enumerate_and_pull and wsmc_release (Matthias Bolte) - Fix possible corruption in ws_serializer_free_mem (Matthias Bolte) - Fix recognition of ntlm and gss-negotiate auth methods when checking server-requested vs. client-offered methods. - Developer - Enable client tests - Improve Windows build (Matthias Bolte) - Reduce libu exposure in the public API (Matthias Bolte) 2.2.6 - Features - Add array support for indications (Suresh Sundriyal) - Add indication_baseclass_namespace (Till Steinbach, Suresh Sundriyal) - Bugfix - Correctly prefix /etc when CMAKE_INSTALL_PREFIX is not /usr (Chris Poblete) 2.2.5 - Features - Clean up cmake variable names (kkaempf) - Add --version option to display version and build timestamp (Chris Poblete) - Support array representation in XML bindings (multiple children with same name) (kkaempf) - Support array type in PUT operation (Chris Poblete) - Bindings - more Ruby examples to access winrm (kkaempf) - replace to_s with to_xml when a XML representation is returned (kkaempf) - Bugfixes - Always return the current instance representation after PUT (Chris Poblete) - Issue wsman:MaxElements only for Enumerate and OptimizeEnumeration (Chris Poblete) - Ensure all array elements have same type on invoke (Chris Poblete) - Compile with -DNO_SSL_CALLBACK on Fedora [curl-Bugs-1924441] (Vitezslav Crhonek) 2.2.4 - Features - Build with cmake (kkaempf) building with 'autotools' is now deprecated and will be removed in future versions - Java client bindings (kkaempf) - enforce manual creation of certificate (to get sufficient entropy for randomness) (Praveen Paladugu) - Bugfixes - fix pam config on RHEL/Fedora (kkaempf 2.2.3.9 - Bugfix release: - bindings (kkaempf) - make all constants uppercase - optionally pass code, code_detail, and message to WsmanStatus() constructor - Pass XmlDoc to Fault() constructor - Fix exceptions for Perl and Python - Ruby: Alias XmlDoc.foo to XmlDoc.body.foo - Ruby: Create bindings documentation - Java: Enable and fix for jdk 1.6.0 (unpackaged) - fix pam config on RHEL/Fedora - Fix Fedora/RH build (kkaempf) - Use floor() instead of round() (Suresh Sundriyal) - Reuse username/password if auth_request_func is not set (Arun Venkatachalam) - Catch invalid reference parameters (report bad EPR values) (kkaempf) - fix Windows build (Trevor Witten) - fix ssl (certificate thumbprint) callback check (Arun Venkatachalam) 2.2.3 final - Bugfix release: - cleanup: access CMPIString by macro, not by casted direct member access - fix connection error msg: rc.msg is a CMPIString, not a char* (kkaempf) - fix for OperationTimeout parsing (Chris Poblete) 2.2.3pre - Bugfix release: - fix Windows build (forum.openwsman.org) - fix to build with non-standard subscriptions dir (Chris Poblete) - accept OperationTimeout values as outlined in Section 3.2.6.1 of http://www.w3.org/TR/xmlschema-2 (Chris Poblete) - fall back to IPv4 if IPv6 unsupported (Arun Venkatachalam) - make IPv4 vs. IPv6 configurable (kkaempf) - support invoking a method with array type parameter/arguments (Chris Poblete, bnc#581414) - include instance namespace in the EPR response (Chris Poblete) - fix crash in (unhandled) Array argument (Suresh Sundriyal) - handle MaxElements in Pull operations (Chris Poblete, kkaempf, bnc#581731) - fix building with ssl when openssl/ssl.h is available (Chris Poblete) - make plugin directory configurable (Chris Poblete) - fix "WXF Invalid Representation" error when sending a Create instance request using the WinRm client (Trevor Witten) - add ExcludeNilProperties option to suppress nil properties per request (Chris Poblete, kkaempf) 2.2.2 - Bugfix release: - fix init.d script to run on non-LSB systems (bnc#571873, Chandrasekhar_R@Dell.com) - Clean up CMake build (kkaempf) - Fix build for RHEL5, Fedora 11+12, CentOS 5 - Fix host certificate check in eventing, enable only if the verify_host flag is set (bnc#569611, A_Venkatachalam@Dell.com) - adapt bindings/ruby/helpers.c to Swig 1.3.40 class variable name change - fix bindings to accept ints (enums can't be expressed) 2.2.1-1 - fix NULL pointer dereference in PullResponse (bnc#572553, Suresh Sundriyal) 2.2.1 - Major changes: - Enumeration timeout fixed, resulting in --enum-idle-timeout option to openwsmand taking seconds (instead of miliseconds) now - Client side CRL (certificate revocation list) support (Arun Venkatachalam) - split off client config as /etc/openwsman/openwsman_client.conf - Fix upper limit check for threads and their stack usage (Suresh Sundriyal) (Allowing to confine memory usage in the 10-20MB range!) Reintroduce max_thread config file parameter and two new parameters * max_connections_per_thread * thread_stack_size - Minor changes: - require swig 1.3.30 or later (rhel5 users: upgrade !) - clean up fault generation in CIM backend (Suresh Sundriyal) - fix various memory leaks (Suresh Sundriyal) - fix Python bindings build (kkaempf) - Fix security risk when listing indication subscriptions (Suresh Sundriyal) - Fix xml namespace for enumeration and subscription filters (kkaempf) - Fix class names for swig bindings, makes Python bindings operational (kkaempf) - Use same encoding for faults as in incoming msg (bug305, kkaempf) - Make WS-Enumeration pull response comply to WS-Enumeration sequence ordering (Suresh Sundriyal) 2.2.0 - Major changes: - Adapt IANA ports of 5985 (http) and 5986 (https) - Change the Ruby bindings module name to 'Openwsman' - Change the Ruby plugin module name to 'Openwsman' - IPv6 support (A_Venkatachalam@Dell.com) - preliminary support for wbem intrinsic operations 'EnumerateClassNames' and 'GetClass' (kkaempf@suse.de) (needs fixed sblim-sfcc, see www.openwsman.org for details) - Minor changes: - Perl example code added (by warptrosse@gmail.com) - Fixes to the CMake build environment - Fixes to the sfcc backend (argument handling, xml escaping) - Fix segfault when HTTP Content-Type not set (ssundriy@vmware.com) - Many other bug fixes, e.g. 297: More detailed http status codes 309: Use correct namespace for detecting Filter node 288: CIM Provider Faults not getting propagated to client 279: Openwsman server is adding extra CRLF 2.1.1 - Support SUNpro C compiler - Add SWIG server-side plugin support (Klaus Kaempf) - Add Perl client bindings (Klaus Kaempf) - Client bindings cleanup and improvements (Klaus Kaempf) 2.1.0 - Security related fixes - Many bug fixes related to http stack - GSSAPI support (thanks to Paul Moore) 2.0.1 - Added Java bindings - Set proxy in C++ bindings - Fixed SelectorSet Filter - Added SelectorSet filter support to C++ interface - SelecorFilter does not need __cimnamespace 2.0.0 - minor bug fixes 2.0.0b2 * Support SelectorSet Dialect * Improved Filter API * Improved EPR API * Enahnced bindings to support filters * Initial cmake support (Thanks to Klaus Kaempf) * Many other bug fixes 2.0.0b1 * Use latest shttpd code base * Fixed SSL related issues with shttpd. * Ruby bindings using swig now and part of openwsman * Python bindings update * serialize/de-serialize APIs updated. Make serialize/de-serialize APIs independent of server related structure; New APIs of do_serialize_real32, do_serialize_real64, do_serialize_int8 , do_serialize_int16, do_serialize_int32 and do_serialize_int64 added. * secure eventing delivery support in WS-Eventing server code and related options added in client code. * WS-Eventing client interfaces updated to make it more general. * Source indication namespace configuration supported so that the namespace of subscription related classes can be different from that of indication class. * Anonymous identify and custom identify file supported. * Many other bug fixings. 1.5.1 * Fixed compilation client library on windows * Fixed crash in CIM plugin * Fixed serialization in client library 1.5.0 Openwsman 1.5 is an interim stable release toward 2.0 with all completed features since 1.0. This release serves as a checkpoint to evaluate implemented and outstanding features and to take care of bugs instead of waiting until the beta phase of 2.0. * Structure Improvements o New file structure. Header files separated from source file o wsman_util library integrated into main library o CIM client library (relying on SFCC) is part of the CIM plugin now * Openwsman Server: o Rename server binary to openwsmand to avoid conflicts (wsmand is very generic) o Accept indications * Openwsman Client: o Added --encoding options to choose encoding type of sent and received messages o Added options to support eventing o Load custom method parameters from external file * WS-Eventing Phase 1 o Subscribe, Unsubscribe, Renew commands supported o Heartbeat message supported. The granularity is 1 second. o Four kinds of delivery modes supported: Push, PushWithAck, Pull, Events o Extensible subscription storage mechanism and local subscription storage implemented o If the delivery mode is PushWithAck or Events and there is no acknowledgment response from the event sink, the subscription will be terminated. o Expired subscription will be deleted from the storage. o Subscription with no expiry time will be kept until the service restarts. When the service restarts, all expired and non-expiry subscriptions will be deleted. o If the delivery mode is set to Pull, the number of events kept in the service is limited. Any events over that limit will be discarded. o Initial CIM indication support in the CIM plugin * XML abstraction layer and parser improvements * Language Bindings: o Python * Better support for windows authentication and client API support on windows * Windows Client-side WS-Eventing support: * C++ Bindings (Interface use mostly on windows) o Connect using proxy server. o Support replacing user name without the need to call constructor. Added api - void SetUserName?(const char *user_name) o Support replacing password without the need to call constructor. Added api - void SetPassword?(const char *password) o Add mechanism to extract error message (as string) using the error code inside the GeneralWsmanExeption?. o Fixed bugs related to Kerberos communication in windows transport client * Integration with CIMOMs: o Sfc Broker (Support local and CIMXML communication): Now it is possible to choose backend in the configuration file o Openwbem (External Request handler) * Many many other fixes and improvements 1.2.0 * Fixed memory leaks in client, cpp client * cleanup API to support external plugins and openwbem request handler * General cleanup and minor fixes 1.1.0 Thread saftey: Moved static variables to client struct TLS Support: Support mutual authentication on Linux and Windows C++ client improvements API changes: Fixed long names and modified prefix of client API function Filtering: Assoc./References Support improved 1.0.0 First major release 0.7.5 Bug fix release 0.7.4 Bug fix release 0.7.3 Bug fix release 0.7.2 Bug fix release 0.7.1 Bug fix release 0.7.0 * Enumeration Expiry support and timeout handler added * C++ Wrapper library added * Enhanced low-level API to support different types of data, now operations and actions requiring input (payload) accept: o Text o XML o Serialized data * Simple C API with Sessions support added * Serialization, Reworked and enhanced, added the following: o Date/Time Serialization o EPR Serialization * Create and Delete are now supported on the server level and the CIM plugin * Namespace and resource URI handling is now stricter now allowing the use of random namespaces (they have to be defined in the configuration file) * Transport using native interface on windows (not curl) * Unified error handling for Windows and Linux * Enahncements to make client compile and work on Windows * Single Client API header * Many bugs and spec conformance issues fixed 0.6.1 The updates in this version of Openwsman have been focused on WS-CIM and WS-Management specification compliance. Interoperability with other WS-Management implementations was done at the Management Developers Conference (MDC) 2006. The issues found at the MDC have been corrected in this release. 0.6.0 0.5.1 0.5.0 0.4.2 * Removed env_t and replaced it with SoapH * removing iWsDoc. Using WsXmlDocH everywhere * improved create request routine for transfer put 0.4.1 * 0.4.0 * Standalone http server (replace libsoup), libsoup server still available using config options, however it will no longer be supported * Support for both Basic and Diegst at the same time * Command line client * Client now uses curl * Added additional debuging options( save output to file, step operatings) * WS-CIM Compliance - Added support for namespaces as selectors - Full polymorphism support * CIM Plugin - Authentication with CIMOM using basic authentication - Multiple vendor namespace now supported - Vendor namespaces are configured in master config file - Default CIM namespace configurable in master config file * PAM Support * Removed dependency on Glib2 * New command line parser for client and server * Improved client interface * Test clients added * CUnit testing added (more tests to follow) * Functional testing scripts added (more comliance tests to follow) * Compliance with WS-Management specification - Authenticate with same credentials when enumerating - More Header checks * Updated Fault table * Many memory leak fixes * Plugin reads configuration data from master config file 0.3.2 * Parse SSL port correctly * Invoke CIM methods with right variables. 0.3.1 * fixed bug with null array value in cim access library: #24 0.3.0 * Code Cleanup * Optimize code size * RPM Support using SUSE build services * Further modularization * More WS-Management specification conformance * Utility Library (glib replacement in core library) * Basic CIM Binding support (Polymorphism) * Many bug fixes, see report for more details. 0.2.0 * This is a cleanup release with many bug fixes and the following additional features: * RPM support * Core library split into functional sub libraries for server, client and utility functions. 0.1.0 * This is the first release defaulting to support the WS-management specification from the DMTF (version 1.0, currently draft). Support for the June 2005 specification has been disabled. You will not be able to send requests to Windows 2003 R2 or Vista with WS-Man support unless those have the new WS-Management stack from Microsoft. * This release also added some new options to the client and removed many command line options from the service. Those options are now part of the configuration file used for the service. 0.09: * Support DMTF draft specification (Work in Progress) * Optimized enumeration * EPR enumeration * EPR And Object Enumeration * Estimate Item Count in Enumeration 0.07: * Various fixes to generic CIM plugin * Eliminated memory leaks in various location * Removed obsolete code which was inherited from the reference implementation this project is based on * Added support for custom methods: It is now possible to invoke custom methods (Extrinsic CIM operations). * Capture errors and status codes from the CIM library as WS-Management faults * Moved all CIM client library dependencies to the cim client interface library to be able to support other client libraries (i.e. OpenWBEM client interface ) in the future. * Changed command line options for the client to accomodate new actions and custom methods. openwsman-2.4.3/src/plugins/.cvsignore000664 001750 001750 00000000025 12256012305 020242 0ustar00kentbkentb000000 000000 Makefile.in Makefile openwsman-2.4.3/doc/CMakeLists.txt000664 001750 001750 00000000145 12256012305 017302 0ustar00kentbkentb000000 000000 # # CMakeLists.txt for openwsman/doc # add_subdirectory(specs) # #EXTRA_DIST = plugin-framwork.txt openwsman-2.4.3/package/openwsman.pam000664 001750 001750 00000000411 12256012305 020072 0ustar00kentbkentb000000 000000 #%PAM-1.0 auth required pam_unix2.so nullok auth required pam_nologin.so account required pam_unix2.so password required pam_pwcheck.so nullok password required pam_unix2.so nullok use_first_pass use_authtok session required pam_unix2.so none openwsman-2.4.3/include/u/base64.h000664 001750 001750 00000003533 12256012305 017125 0ustar00kentbkentb000000 000000 /******************************************************************************* * 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 Vadim Revyakin */ extern void ws_base64_encode(const char *from, int len, char *to); extern int ws_base64_decode(const char *from, int len, char *to, int to_len); openwsman-2.4.3/AUTHORS000664 001750 001750 00000001563 12256012305 015052 0ustar00kentbkentb000000 000000 Maintainer: Klaus Kaempf, SUSE, Developers: Anas Nashif, Intel Corp., Hou Liang, Intel Corp. Vadim Revyakin, Intel Corp., Denis Sadykov, Intel Corp., Code originally from: Eugene Yarmosh, Intel Corp. Contributions and Patches by: Jan Blunck, Novell, Matthias Bolte Vitezslav Crhonek, Redhat, Klaus Kaempf, Novell, Viktor Mihajlovski, IBM, Praveen Paladugu, Dell, Chris Poblete, Dell, Till Steinbach Suresh Sundriyal, VMware, Srinivas Thirumalaa If you think you name should be here and I forgot it, please let me know. openwsman-2.4.3/tests/client/requests/from_002.xml000664 001750 001750 00000001742 12256012305 022342 0ustar00kentbkentb000000 000000 http://schemas.xmlsoap.org/ws/2004/09/enumeration/Enumerate http://langley.home.planux.com:8889/wsman http://langley.home.planux.com:8889/wsman http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_ComputerSystem uuid:d02518a4-20c3-10c3-8002-7a36080c0e01 http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous openwsman-2.4.3/src/lib/u/uoption.c000664 001750 001750 00000042201 12256012305 017436 0ustar00kentbkentb000000 000000 /******************************************************************************* * Copyright (C) 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 Denis Sadykov */ #ifdef HAVE_CONFIG_H #include #endif #include "u/libu.h" /* ---------------------------------------------------------------------------- Misc ----------------------------------------------------------------------------- */ struct tmp_buf { long int lint; char *ptr; char **pptr; u_option_entry_t *entry; }; typedef struct tmp_help_buf { char *part1; char *part2; } tmp_help_buf_t; typedef struct help_buf { tmp_help_buf_t *buf; unsigned int num; size_t maxlen; } help_buf_t; static void put_to_help_buf(help_buf_t *help_buf, char count, const char *format, ...) { va_list ap; tmp_help_buf_t *buf = &(help_buf->buf[help_buf->num]); buf->part2 = NULL; va_start(ap, format); buf->part1 = u_strdup_vprintf(format, ap); va_end(ap); if (count) help_buf->maxlen = (strlen(buf->part1) > help_buf->maxlen) ? strlen(buf->part1) : help_buf->maxlen; help_buf->num += 1; } static void print_help_buf(help_buf_t *help_buf) { unsigned int i, j; size_t align; tmp_help_buf_t *buf = help_buf->buf; for (i = 0; i < help_buf->num; i++) { printf("%s", buf[i].part1); if (buf[i].part2) { align = (help_buf->maxlen > 50) ? help_buf->maxlen + 5 - strlen(buf[i].part1) : 50 - strlen(buf[i].part1); for (j = 0; j < align; j++) { printf(" "); } printf("%s", buf[i].part2); } printf("\n"); } } static void free_help_buf(help_buf_t *help_buf) { unsigned int i; tmp_help_buf_t *buf = help_buf->buf; for (i = 0; i < help_buf->num; i++) { u_free(buf[i].part1); if (buf[i].part2) u_free(buf[i].part2); } } static void print_help_header(u_option_context_t *ctx, help_buf_t *help_buf) { lnode_t *node; u_option_group_t *grp; tmp_help_buf_t *buf = help_buf->buf; put_to_help_buf(help_buf, 0, "Usage:"); put_to_help_buf(help_buf, 0, " %s [Option...] %s", ctx->prog_name, ctx->usage); put_to_help_buf(help_buf, 0, ""); put_to_help_buf(help_buf, 0, "Help Options"); put_to_help_buf(help_buf, 1, " -?, --help"); node = list_first(ctx->groups); if (node && list_next(ctx->groups, node)) { put_to_help_buf(help_buf, 1, " --help-all"); buf[help_buf->num - 1].part2 = u_strdup("Show help options"); } node = list_next(ctx->groups, node); while (node) { grp = (u_option_group_t *)node->list_data; put_to_help_buf(help_buf, 1, " --help-%s", grp->name); if (grp->help_descr) { buf[help_buf->num - 1].part2 = u_strdup(grp->help_descr); } node = list_next(ctx->groups, node); } put_to_help_buf(help_buf, 0, ""); } static void print_help_group(u_option_group_t *group, help_buf_t *help_buf) { unsigned int i; tmp_help_buf_t *buf = help_buf->buf; if (group->ismain) { put_to_help_buf(help_buf, 0, "Application Options"); } else { if (group->descr) put_to_help_buf(help_buf, 0, "%s", group->descr); else put_to_help_buf(help_buf, 0, "%s", group->name); } for (i = 0; i < group->num_entries; i++) { if (group->entries[i].short_name && group->entries[i].arg_descr) { put_to_help_buf(help_buf, 1, " -%c, --%s=%s", group->entries[i].short_name, group->entries[i].name, group->entries[i].arg_descr); } else if (group->entries[i].short_name) { put_to_help_buf(help_buf, 1, " -%c, --%s", group->entries[i].short_name, group->entries[i].name); } else if (group->entries[i].arg_descr){ put_to_help_buf(help_buf, 1, " --%s=%s", group->entries[i].name, group->entries[i].arg_descr); } else { put_to_help_buf(help_buf, 1, " --%s", group->entries[i].name); } if (group->entries[i].descr) { buf[help_buf->num - 1].part2 = u_strdup_printf("%s", group->entries[i].descr); } } put_to_help_buf(help_buf, 0, ""); } static void print_short_help(u_option_context_t *ctx) { help_buf_t help_buf; tmp_help_buf_t buf[1024]; lnode_t *node; help_buf.buf = buf; help_buf.maxlen = 0; help_buf.num = 0; node = list_first(ctx->groups); print_help_header(ctx, &help_buf); print_help_group((u_option_group_t *)node->list_data, &help_buf); print_help_buf(&help_buf); free_help_buf(&help_buf); exit (0); } static void print_long_help(u_option_context_t *ctx, char *hoption) { lnode_t *node, *first; u_option_group_t *grp; char *help_str; help_buf_t help_buf; tmp_help_buf_t buf[1024]; help_buf.buf = buf; help_buf.maxlen = 0; help_buf.num = 0; first = list_first(ctx->groups); node = list_next(ctx->groups, first); while (node) { grp = (u_option_group_t *)node->list_data; help_str = u_strdup_printf("help-%s", grp->name); if (!strncmp(hoption, help_str, strlen(help_str))) { u_free(help_str); break; } u_free(help_str); node = list_next(ctx->groups, node); } if (!node) { if (!strncmp(hoption, "help-all", strlen("help-all")) && strlen(hoption) == strlen("help-all")) { grp = (u_option_group_t *)first->list_data; } else if (!strncmp(hoption, "help", strlen("help")) && strlen(hoption) == strlen("help")) { grp = NULL; } else { return; } } print_help_header(ctx, &help_buf); if (grp == NULL) { grp = (u_option_group_t *)first->list_data; print_help_group(grp, &help_buf); } else if (grp == (u_option_group_t *)first->list_data) { node = list_next(ctx->groups, first); while (node) { grp = (u_option_group_t *)node->list_data; print_help_group(grp, &help_buf); node = list_next(ctx->groups, node); } grp = (u_option_group_t *)first->list_data; print_help_group(grp, &help_buf); } else { print_help_group(grp, &help_buf); } print_help_buf(&help_buf); free_help_buf(&help_buf); exit (0); } static unsigned int context_get_number_entries(u_option_context_t *ctx) { lnode_t *node; u_option_group_t *grp; unsigned int num_entr = 0; if (!ctx) { return 0; } node = list_first(ctx->groups); while (node) { grp = (u_option_group_t *)node->list_data; num_entr += grp->num_entries; node = list_next(ctx->groups, node); } return num_entr; } static char fill_tmp_data(struct tmp_buf *data, int *filled, char *optptr, char *argptr, u_option_entry_t *entry, u_error_t **error) { int nd; unsigned int count; char **pptr; long int val; for (nd = 0; nd < *filled; nd++) { if (data[nd].entry == entry) { break; } } switch(entry->arg) { case U_OPTION_ARG_INT: if (!isstrdigit(argptr)) { u_error_new(error, 0, "Cannot parse integer value \'%s\' for -%s\n", argptr, optptr); return 0; } val = strtol(argptr, (char **)NULL, 10); if (val == LONG_MIN || val == LONG_MAX) { u_error_new(error, 0, "Integer value \'%s\'for -%s out of range\n", argptr, optptr); return 0; } data[nd].lint = val; break; case U_OPTION_ARG_STRING: data[nd].ptr = u_strdup(argptr); break; case U_OPTION_ARG_STRING_ARRAY: count = 0; pptr = data[nd].pptr; while (pptr != NULL && pptr[count] != NULL) { ++count; } data[nd].pptr = u_malloc(sizeof(char *) * (count + 2)); data[nd].pptr[count] = u_strdup(argptr); data[nd].pptr[count + 1] = NULL; while (count != 0) { count--; data[nd].pptr[count] = pptr[count]; } if (pptr) u_free(pptr); break; case U_OPTION_ARG_NONE: data[nd].lint = 1; break; default: u_error_new(error, 0, "Unknown argument data type for -%s\n", optptr); return 0; } if (nd == *filled) { data[nd].entry = entry; *filled += 1; } return 1; } static void free_tmp_data(struct tmp_buf *data, int nd) { int i, count; for (i = 0; i < nd; i++) { switch (data[i].entry->arg) { case U_OPTION_ARG_STRING: if (data[i].ptr) { u_free(data[i].ptr); } break; case U_OPTION_ARG_STRING_ARRAY: count = 0; while (data[i].pptr != NULL && data[i].pptr[count] != NULL) { u_free(data[i].pptr[count]); count++; } if (data[i].pptr) { u_free(data[i].pptr); } break; } } } static void get_tmp_data(struct tmp_buf *data, int nd) { int i; u_option_entry_t *entry; for (i = 0; i < nd; i++) { entry = data[i].entry; switch (entry->arg) { case U_OPTION_ARG_INT: *(long int *)entry->arg_data = data[i].lint; break; case U_OPTION_ARG_STRING: *(char **)entry->arg_data = data[i].ptr; break; case U_OPTION_ARG_STRING_ARRAY: *(char ***)entry->arg_data = data[i].pptr; break; case U_OPTION_ARG_NONE: *(char *)entry->arg_data = (char)data[i].lint; } } } static u_option_entry_t* find_long_opt(u_option_context_t *ctx, char *option) { lnode_t *node; u_option_group_t *grp; unsigned int e; size_t nlen; if (!ctx) { return NULL; } if (!strncmp(option, "help", strlen("help")) ) { if (ctx->mode & U_OPTION_CONTEXT_HELP_ENABLED) { print_long_help(ctx, option); } } node = list_first(ctx->groups); while (node) { grp = (u_option_group_t *)node->list_data; for (e = 0; e < grp->num_entries; e++) { nlen = strlen(grp->entries[e].name); if (!strncmp(option, grp->entries[e].name, nlen)) { if (strlen(option) != nlen && *(option + nlen) != '=') { continue; } return &(grp->entries[e]); } } node = list_next(ctx->groups, node); } return NULL; } static u_option_entry_t* find_short_opt(u_option_context_t *ctx, char option) { lnode_t *node; u_option_group_t *grp; unsigned int e; if (!ctx) { return NULL; } if (option == '?') { if (ctx->mode & U_OPTION_CONTEXT_HELP_ENABLED) { print_short_help(ctx); } } node = list_first(ctx->groups); while (node) { grp = (u_option_group_t *)node->list_data; for (e = 0; e < grp->num_entries; e++) { if (option == grp->entries[e].short_name) { return &(grp->entries[e]); } } node = list_next(ctx->groups, node); } return NULL; } /* ---------------------------------------------------------------------------- Group ----------------------------------------------------------------------------- */ u_option_group_t* u_option_group_new(const char *name, const char *descr, const char *help_descr) { u_option_group_t *grp; grp = u_zalloc(sizeof(u_option_group_t)); if (name) { grp->name = u_strdup(name); } if (descr) { grp->descr = u_strdup(descr); } if (help_descr) { grp->help_descr = u_strdup(help_descr); } return grp; } void u_option_group_free(u_option_group_t *group) { if (!group) return; if (group->name) u_free(group->name); if (group->descr) u_free(group->descr); if(group->help_descr) u_free(group->help_descr); u_free(group); } void u_option_group_add_entries(u_option_group_t *group, u_option_entry_t *entries) { unsigned int i; if (!group || !entries) { return; } for (i = 0; entries[i].name; i++); group->entries = entries; group->num_entries = i; } /* ---------------------------------------------------------------------------- Context ----------------------------------------------------------------------------- */ u_option_context_t* u_option_context_new(const char *usage) { u_option_context_t *ctx; ctx = (u_option_context_t *) u_zalloc(sizeof(u_option_context_t)); if (usage) { ctx->usage = u_strdup(usage); } ctx->groups = list_create(LISTCOUNT_T_MAX); ctx->mode |= U_OPTION_CONTEXT_HELP_ENABLED; return ctx; } void u_option_context_free(u_option_context_t *ctx) { lnode_t *node, *tmp; if (!ctx) return; node = list_first(ctx->groups); while (node) { tmp = list_next(ctx->groups, node); u_option_group_free((u_option_group_t *)node->list_data); list_delete (ctx->groups, node); lnode_destroy(node); node = tmp; } list_destroy(ctx->groups); if (ctx->usage) u_free(ctx->usage); if (ctx->prog_name) u_free(ctx->prog_name); u_free(ctx); } void u_option_context_add_group(u_option_context_t *ctx, u_option_group_t *group) { lnode_t *node; if (!ctx || !group) return; node = lnode_create((void *)group); list_append(ctx->groups, node); } void u_option_context_add_main_entries(u_option_context_t *ctx, u_option_entry_t *options, const char *name) { u_option_group_t *grp; lnode_t *node; if (!ctx || !options) { return; } grp = u_option_group_new(name, NULL, NULL); u_option_group_add_entries(grp, options); grp->ismain = 1; node = lnode_create((void *)grp); list_prepend(ctx->groups, node); } void u_option_context_set_ignore_unknown_options(u_option_context_t *ctx, char ignore) { if (!ctx) return; if (ignore == 1) ctx->mode |= U_OPTION_CONTEXT_IGNORE_UNKNOWN; else ctx->mode &= ~U_OPTION_CONTEXT_IGNORE_UNKNOWN; } void u_option_context_set_help_enabled(u_option_context_t *ctx, char help_enabled) { if (!ctx) return; if (help_enabled == 1) ctx->mode |= U_OPTION_CONTEXT_HELP_ENABLED; else ctx->mode &= ~U_OPTION_CONTEXT_HELP_ENABLED; } /* ---------------------------------------------------------------------------- Parse ----------------------------------------------------------------------------- */ char u_option_context_parse(u_option_context_t *ctx, int *argc, char ***argv, u_error_t **error) { char **tmp_argv, **largv; int arg_ind = 0, noopt = 0; char *optptr = NULL, *argptr = NULL; char next_shopt = '\0'; int nd = 0; size_t nlen; int i, j; char retval = 0; u_option_entry_t *found; struct tmp_buf *tmp_data; if (!ctx) return 0; tmp_argv = u_zalloc(sizeof(char *) * (*argc)); largv = u_zalloc(sizeof(char *) * (*argc)); optptr = (*argv)[0]; while (*optptr != '\0') { if (*optptr == '/') argptr = optptr; optptr++; } if (argptr) { ctx->prog_name = u_strdup(argptr + 1); } else { ctx->prog_name = u_strdup((*argv)[0]); } for (i = 1; i < *argc; i++) { largv[i] = strdup((*argv)[i]); } tmp_data = u_zalloc(sizeof(struct tmp_buf) * context_get_number_entries(ctx)); for(i = 1; i < *argc;) { if (*largv[i] != '-') { tmp_argv[noopt] = largv[i]; noopt++; goto cont; } argptr = NULL; if (next_shopt != '\0') { optptr += 1; *optptr = next_shopt; next_shopt = '\0'; } else { optptr = largv[i] + 1; } if (*optptr == '-' && optptr == largv[i] + 1) { found = find_long_opt(ctx, optptr + 1); if (found) { nlen = strlen(found->name); if (strlen(optptr + 1) != nlen) { argptr = optptr + nlen + 2; *(optptr + 1 + nlen) = '\0'; } else { if (i + 1 < *argc) { argptr = largv[i + 1]; arg_ind++; } } } } else { found = find_short_opt(ctx, *optptr); if (found) { if (arg_ind + i + 1 < *argc) { arg_ind++; argptr = largv[arg_ind + i]; } next_shopt = *(optptr + 1); *(optptr + 1) = '\0'; } } if (!found) { u_error_new(error, 0, "Unknown option %s\n", (*argv)[i]); goto ret; } if (found->arg == U_OPTION_ARG_NONE) { if (argptr) { arg_ind--; argptr = NULL; } if (found->arg_data) { if (!fill_tmp_data(tmp_data, &nd, NULL, NULL, found, error)) { goto ret; } } goto cont; } if (argptr == NULL) { u_error_new(error, 0, "Missing argument for -%s\n", optptr); goto ret; } if (found->arg_data == NULL) { goto cont; } if (!fill_tmp_data(tmp_data, &nd, optptr, argptr, found, error)) { goto ret; } cont: if (next_shopt == '\0') { i = (argptr == largv[i + arg_ind] || !argptr) ? i + arg_ind + 1 : i + 1; arg_ind = 0; } } ret: if (*error) { free_tmp_data(tmp_data, nd); } else { for (i = 1; i < *argc; i++) { for (j = 0; j < noopt; j++) { if (!strcmp((*argv)[i], tmp_argv[j])) { (*argv)[j + 1] = (*argv)[i]; break; } } } get_tmp_data(tmp_data, nd); retval = 1; } for (i = 1; i < *argc; i++) u_free(largv[i]); *argc = noopt + 1; u_free(largv); u_free(tmp_argv); u_free(tmp_data); return retval; } openwsman-2.4.3/src/server/wsmand.c000664 001750 001750 00000015544 12256012305 017540 0ustar00kentbkentb000000 000000 /******************************************************************************* * 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 */ #ifdef HAVE_CONFIG_H #include "wsman_config.h" #endif #ifdef HAVE_UNISTD_H #include #endif #include #include #include #include #include #include #include #include #include #include #include #include "u/libu.h" #include "wsman-xml-api.h" #include "wsman-soap.h" #include "wsman-xml.h" #include "wsman-xml-serializer.h" #include "wsman-dispatcher.h" #include "wsman-plugins.h" #include "wsmand-listener.h" #include "wsmand-daemon.h" static int log_pid = 0; static void debug_message_handler(const char *str, debug_level_e level, void *user_data) { if (log_pid == 0) log_pid = getpid(); if (level <= wsmand_options_get_debug_level() || wsmand_options_get_foreground_debug() > 0) { struct tm *tm; time_t now; char timestr[128]; char *log_msg; int p; time(&now); tm = localtime(&now); strftime(timestr, 128, "%b %e %T", tm); log_msg = u_strdup_printf("%s [%d] %s\n", timestr, log_pid, str); if ((p = write(STDERR_FILENO, log_msg, strlen(log_msg))) < 0) fprintf(stderr, "Failed writing to log file\n"); fsync(STDERR_FILENO); u_free(log_msg); } if (level <= wsmand_options_get_syslog_level()) { char *log_name = u_strdup_printf("wsmand[%d]", log_pid); openlog(log_name, 0, LOG_DAEMON); syslog(LOG_INFO, "%s", str); closelog(); u_free(log_name); } } static void initialize_logging(void) { debug_add_handler(debug_message_handler, DEBUG_LEVEL_ALWAYS, NULL); } /* initialize_logging */ static void signal_handler(int sig_num) { const char *sig_name = NULL; if (sig_num == SIGQUIT) sig_name = "SIGQUIT"; else if (sig_num == SIGTERM) sig_name = "SIGTERM"; else if (sig_num == SIGINT) sig_name = "SIGINT"; else assert(1 == 1); debug("Received %s... Shutting down.", sig_name); wsmand_shutdown(); } /* signal_handler */ static void sighup_handler(int sig_num) { debug("SIGHUP received; reloading data"); if (wsmand_options_get_debug_level() == 0) { int fd; close(STDOUT_FILENO); fd = open("/var/log/wsmand.log", O_WRONLY | O_CREAT | O_APPEND, S_IRUSR | S_IWUSR); assert(fd == STDOUT_FILENO); close(STDERR_FILENO); fd = dup(fd); /* dup fd to stderr */ assert(fd == STDERR_FILENO); } } /* sighup_handler */ static int rc_write(int fd, const char *buf, size_t count) { size_t bytes_remaining = count; const char *ptr = buf; while (bytes_remaining) { size_t bytes_written; bytes_written = write(fd, ptr, bytes_remaining); if (bytes_written == -1) { if (errno == EAGAIN || errno == EINTR) { continue; } else { break; } } bytes_remaining -= bytes_written; ptr += bytes_written; } if (bytes_remaining) { return (FALSE); } return (TRUE); } static void daemonize(void) { int fork_rv; int i; int fd; char *pid; if (wsmand_options_get_foreground_debug() > 0) { return; } fork_rv = fork(); if (fork_rv < 0) { fprintf(stderr, "wsmand: fork failed!\n"); } if (fork_rv > 0) { exit(0); } log_pid = 0; setsid(); /* Change our CWD to / */ i=chdir("/"); assert(i == 0); /* Close all file descriptors. */ for (i = getdtablesize(); i >= 0; --i) close(i); fd = open("/dev/null", O_RDWR); /* open /dev/null as stdin */ assert(fd == STDIN_FILENO); /* Open a new file for our logging file descriptor. This will be the fd 1, stdout. */ fd = open("/var/log/wsmand.log", O_WRONLY | O_CREAT | O_APPEND, S_IRUSR | S_IWUSR); assert(fd == STDOUT_FILENO); fd = dup(fd); /* dup fd to stderr */ assert(fd == STDERR_FILENO); fd = open(wsmand_options_get_pid_file(), O_WRONLY | O_CREAT | O_TRUNC, 0644); pid = u_strdup_printf("%d", getpid()); rc_write(fd, pid, strlen(pid)); u_free(pid); close(fd); // TODO // remove /var/run/wsmand.pid // remove /var/lock/subsys/wsmand } int main(int argc, char **argv) { struct sigaction sig_action; dictionary *ini; char *filename; WsManListenerH *listener = NULL; if (!wsmand_parse_options(argc, argv)) { fprintf(stderr, "Failed to parse command line options\n"); exit(EXIT_FAILURE); } filename = (char *) wsmand_options_get_config_file(); ini = iniparser_new(filename); debug("Using conf file: %s", filename); if (ini == NULL) { fprintf(stderr, "Cannot parse file [%s]\n", filename); return 1; } else if (!wsmand_read_config(ini)) { fprintf(stderr, "Configuration file not found\n"); exit(EXIT_FAILURE); } daemonize(); /* Set up SIGTERM and SIGQUIT handlers */ sig_action.sa_handler = signal_handler; sigemptyset(&sig_action.sa_mask); sig_action.sa_flags = 0; sigaction(SIGINT, &sig_action, NULL); sigaction(SIGTERM, &sig_action, NULL); sigaction(SIGQUIT, &sig_action, NULL); /* Set up SIGHUP handler. */ sig_action.sa_handler = sighup_handler; sigemptyset(&sig_action.sa_mask); sig_action.sa_flags = 0; sigaction(SIGHUP, &sig_action, NULL); initialize_logging(); listener = wsmand_start_server(ini); if (listener) { wsman_plugins_unload(listener); u_free(listener); } debug_destroy_handlers(); iniparser_free(ini); if (!listener) { exit(EXIT_FAILURE); } return 0; } openwsman-2.4.3/include/wsman-client-transport.h000664 001750 001750 00000013726 12256012305 022235 0ustar00kentbkentb000000 000000 /******************************************************************************* * 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 Vadim Revyakin * @author Anas Nashif */ #ifndef WSMAN_CLIENT_TRANSPORT_H_ #define WSMAN_CLIENT_TRANSPORT_H_ #ifdef _WIN32 #include /* for BOOL */ #endif #ifdef __cplusplus extern "C" { #endif #include "wsman-client-api.h" #ifdef PACKAGE_STRING #define DEFAULT_USER_AGENT PACKAGE_STRING #else #define DEFAULT_USER_AGENT "Openwsman" #endif #define _WS_NO_AUTH "No Auth" #define _WS_BASIC_AUTH "Basic" #define _WS_DIGEST_AUTH "Digest" #define _WS_PASS_AUTH "Passport" #define _WS_NTLM_AUTH "NTLM" #define _WS_GSSNEGOTIATE_AUTH "GSS-Negotiate" int wsman_send_request(WsManClient *cl, WsXmlDocH request); /* * Set callback function to ask for username/password on authentication failure (http-401 returned) * If the callback returns an empty (or NULL) username, authentication is aborted. */ extern void wsmc_transport_set_auth_request_func(WsManClient *cl, wsman_auth_request_func_t f); extern int wsman_is_auth_method(WsManClient *cl, int method); extern int wsmc_transport_init(WsManClient *cl, void *arg); extern void wsman_transport_close_transport(WsManClient *cl); extern void wsmc_transport_fini(WsManClient *cl); extern void wsman_transport_set_agent(WsManClient *cl, const char *agent); extern char * wsman_transport_get_agent (WsManClient *cl); extern void wsman_transport_set_userName(WsManClient *cl, const char *user_name); extern char *wsman_transport_get_userName(WsManClient *cl); extern void wsman_transport_set_password(WsManClient *cl, const char *password); extern char *wsman_transport_get_password(WsManClient *cl); extern void wsman_transport_set_proxy_username(WsManClient *cl, const char *proxy_username ); extern char *wsman_transport_get_proxy_username(WsManClient *cl ); extern void wsman_transport_set_proxy_password(WsManClient *cl, const char *proxy_password ); extern char *wsman_transport_get_proxy_password(WsManClient *cl ); extern void wsman_transport_set_auth_method(WsManClient *cl, const char *am); extern char * wsman_transport_get_auth_method (WsManClient *cl); extern const char *wsmc_transport_get_auth_name(wsman_auth_type_t auth); extern wsman_auth_type_t wsmc_transport_get_auth_value(WsManClient *cl); char *wsman_transport_get_last_error_string(WS_LASTERR_Code err); extern void wsman_transport_set_timeout(WsManClient *cl, unsigned long timeout); extern unsigned long wsman_transport_get_timeout(WsManClient *cl); extern void wsman_transport_set_verify_peer(WsManClient *cl, unsigned int value); extern unsigned int wsman_transport_get_verify_peer(WsManClient *cl); extern void wsman_transport_set_verify_host(WsManClient *cl, unsigned int value); extern unsigned int wsman_transport_get_verify_host(WsManClient *cl); extern void wsman_transport_set_crlcheck(WsManClient * cl, unsigned int value); extern unsigned int wsman_transport_get_crlcheck(WsManClient * cl); extern void wsman_transport_set_crlfile(WsManClient *cl, const char *arg); extern char *wsman_transport_get_crlfile(WsManClient *cl); extern void wsman_transport_set_proxy(WsManClient *cl, const char *proxy); extern char *wsman_transport_get_proxy(WsManClient *cl); extern void wsman_transport_set_proxyauth(WsManClient *cl, const char *pauth); extern char *wsman_transport_get_proxyauth(WsManClient *cl); extern void wsman_transport_set_cainfo(WsManClient *cl, const char *cainfo); extern char *wsman_transport_get_cainfo(WsManClient *cl); extern void wsman_transport_set_certhumbprint(WsManClient *cl, const char *arg); extern char *wsman_transport_get_certhumbprint(WsManClient *cl); extern void wsman_transport_set_capath(WsManClient *cl, const char *capath); extern char *wsman_transport_get_capath(WsManClient *cl); extern void wsman_transport_set_caoid(WsManClient *cl, const char *oid); extern char *wsman_transport_get_caoid(WsManClient *cl); #ifdef _WIN32 extern void wsman_transport_set_calocal(WsManClient *cl, BOOL local); extern BOOL wsman_transport_get_calocal(WsManClient *cl); #endif extern void wsman_transport_set_cert(WsManClient *cl, const char *cert); extern char *wsman_transport_get_cert(WsManClient *cl); extern void wsman_transport_set_key(WsManClient *cl, const char *key); extern char *wsman_transport_get_key(WsManClient *cl); #ifdef DEBUG_VERBOSE long long get_transfer_time(void); #endif #ifdef __cplusplus } #endif #endif /* WSMAN_CLIENT_TRANSPORT_H_ */ openwsman-2.4.3/bindings/ruby/Makefile.am000664 001750 001750 00000002563 12256012305 020615 0ustar00kentbkentb000000 000000 # # Makefile.am for openwsman/bindings/ruby # SUBDIRS = openwsman tests rubyarchdir = $(shell ruby -r rbconfig -e "vad = Config::CONFIG['vendorarchdir']; print(vad ? vad : Config::CONFIG['sitearchdir'])") rubydir = $(shell ruby -r rbconfig -e "vd = Config::CONFIG['vendorlibdir']; print(vd ? vd : Config::CONFIG['sitelibdir'])") rubyincdir = $(shell ruby -r rbconfig -e "print(Config::CONFIG['archdir'])") INCLUDES = \ -I$(top_srcdir) \ -I$(top_srcdir)/include \ -I$(top_srcdir)/bindings \ $(OPENSSL_CFLAGS) \ -DSYSCONFDIR=\""$(sysconfdir)/openwsman"\" \ -I${rubyincdir} LIBS = \ $(OPENSSL_LIBS) \ $(top_builddir)/src/lib/libwsman.la \ $(top_builddir)/src/lib/libwsman_client.la \ $(top_builddir)/src/lib/libwsman_curl_client_transport.la GENERATED = openwsman_wrap.c SWIG_INPUT = ../openwsman.i openwsman_la_SOURCES = ../openwsman.c $(SWIG_INPUT) $(GENERATED) openwsman_la_LIBADD = $(LIBS) -lpthread $(CURL_LIBS) openwsman_la_CFLAGS = $(RUBY_CFLAGS) openwsman_la_LDFLAGS = -module -avoid-version $(NO_UNDEFINED) rubyarch_LTLIBRARIES = openwsman.la $(GENERATED): $(SWIG_INPUT) $(SWIG) -ruby -I$(top_srcdir)/include -I$(top_srcdir)/bindings -o $@ $< install-data-hook: rm -f $(DESTDIR)${rubyarchdir}/$(rubyarch_LTLIBRARIES) CLEANFILES= $(GENERATED) dist-hook: rm -f $(distdir)/openwsman_wrap.c EXTRA_DIST=helpers.h openwsman-2.4.3/package/openwsman.spec.in000664 001750 001750 00000034274 12256012305 020672 0ustar00kentbkentb000000 000000 # # spec file for package openwsman # # Copyright (c) 2013 SUSE LINUX Products GmbH, Nuernberg, Germany. # # All modifications and additions to the file contributed by third parties # remain the property of their copyright owners, unless otherwise agreed # upon. The license for this file, and modifications and additions to the # file, is the same license as for the pristine package itself (unless the # license for the pristine package is not an Open Source License, in which # case the license is the MIT License). An "Open Source License" is a # license that conforms to the Open Source Definition (Version 1.9) # published by the Open Source Initiative. # Please submit bugfixes or comments via http://bugs.opensuse.org/ # %if 0%{?suse_version} > 1140 || 0%{?fedora_version} > 14 %define has_systemd 1 %else %define has_systemd 0 %endif Name: openwsman BuildRequires: cmake BuildRequires: gcc-c++ BuildRequires: libxml2-devel BuildRequires: pam-devel BuildRequires: sblim-sfcc-devel BuildRequires: swig >= 2.0.5 BuildRequires: perl BuildRequires: python-devel %if 0%{?rhel_version} > 0 BuildRequires: -vim %endif %if 0%{?fedora_version} || 0%{?centos_version} || 0%{?rhel_version} || 0%{?fedora} || 0%{?rhel} BuildRequires: curl-devel %if 0%{?fedora} == 16 || (0%{?centos_version}>=500 && 0%{?centos_version}<700) || (0%{?rhel_version}>=500 && 0%{?rhel_version}<700) BuildRequires: java-1.6.0-openjdk-devel %else %if 0%{?fedora} >= 17 BuildRequires: java-1.7.0-openjdk-devel %else BuildRequires: java-devel %endif %endif BuildRequires: openssl-devel BuildRequires: pkgconfig BuildRequires: ruby BuildRequires: ruby-devel %if 0%{?fedora} == 0 BuildRequires: ruby-rdoc %endif %if 0%{?fedora} == 19 BuildRequires: rubypick %endif %if 0%{?fedora} > 0 || 0%{?rhel_version} >= 600 || 0%{?centos_version} >= 600 BuildRequires: perl-devel %endif %endif %if 0%{?suse_version} > 0 BuildRequires: java-devel # No jni_md.h on SLE10 :-/ #%if 0%{?suse_version} < 1100 #BuildRequires: java-1_5_0-ibm-devel #BuildRequires: libgcj-devel #BuildRequires: update-alternatives #%endif %if 0%{?suse_version} > 1010 BuildRequires: fdupes BuildRequires: libcurl-devel BuildRequires: libopenssl-devel %else # SLE10 BuildRequires: curl-devel BuildRequires: libidn-devel BuildRequires: openssl-devel %endif %if 0%{?suse_version} > 910 %if 0%{?suse_version} < 1110 # SLE 10 has Ruby 1.8.6 and runs into http://help.rubygems.org/discussions/problems/859-trying-to-install-rubygems BuildRequires: rubygems <= 1.3.7 %else BuildRequires: rubygems %endif BuildRequires: pkg-config BuildRequires: ruby-devel %else # SLE9 BuildRequires: pkgconfig BuildRequires: ruby %endif %endif %if 0%{?has_systemd} BuildRequires: systemd %{?systemd_requires} %endif Requires(pre): sed coreutils grep /bin/hostname Version: @VERSION@ Release: 0 # Mandriva: # Release %mkrel 1 Url: http://www.openwsman.org/ Summary: Opensource Implementation of WS-Management License: BSD-3-Clause Group: System/Management Source: %{name}-%{version}.tar.bz2 Source1: %{name}.rpmlintrc %if 0%{?fedora_version} || 0%{?centos_version} || 0%{?rhel_version} || 0%{?fedora} || 0%{?rhel} Source2: %{name}.pam.rh Patch1: openwsman-initscript.patch %else Source2: %{name}.pam %endif Source3: %{name}.SuSEfirewall2 BuildRoot: %{_tmppath}/%{name}-%{version}-build Source4: %{name}.service %description Opensource Implementation of WS-Management protocol stack %package -n libwsman1 Summary: Opensource Implementation of WS-Management Group: System/Management Provides: openwsman = %{version} Obsoletes: openwsman < %{version} %description -n libwsman1 Opensource Implementation of WS-Management protocol stack (Common libraries) %package -n libwsman-devel Summary: Opensource Implementation of WS-Management Group: Development/Libraries/C and C++ Provides: openwsman-devel = %{version} Obsoletes: openwsman-devel < %{version} Requires: %{name}-server = %{version} Requires: libwsman1 = %{version} Requires: libxml2-devel Requires: pam-devel Requires: sblim-sfcc-devel %description -n libwsman-devel Opensource Implementation of WS-Management stack (Development files) %package -n libwsman_clientpp1 Summary: C++ bindings to Openwsman Client libraries Group: System/Management Provides: openwsman-client = %{version} Obsoletes: openwsman-client < %{version} %description -n libwsman_clientpp1 An implementation of the WsmanClient interface using C++ %package -n libwsman_clientpp-devel Summary: C++ bindings to Openwsman Client libraries Group: Development/Libraries/C and C++ Requires: libwsman-devel = %{version} Requires: libwsman_clientpp1 = %{version} %description -n libwsman_clientpp-devel Development files for C++ interface to OpenWSMAN client library. %package server Requires(pre): sed coreutils grep diffutils /bin/hostname %if 0%{?suse_version} Requires(pre): fillup # for pam_unix2 and pam_pwcheck Requires: pam-modules %endif Summary: Openwsman Server and service libraries Group: System/Management %description server Openwsman Server and service libraries %package python Summary: Python bindings for openwsman client API Group: Development/Libraries/Python %{!?python_sitelib: %global python_sitelib %(%{__python} -c "from distutils.sysconfig import get_python_lib; print get_python_lib()")} %{!?python_sitearch: %global python_sitearch %(%{__python} -c "from distutils.sysconfig import get_python_lib; print get_python_lib(1)")} %{!?py_requires: %define py_requires Requires: python} %{py_requires} %description python This package provides Python bindings to access the openwsman client API. %package ruby Requires: ruby # RbConfig::CONFIG["ruby_version"] is empty in Fedora 19 !? %if 0%{?fedora} == 19 %{!?ruby_version: %global ruby_version %(ruby -r rbconfig -e 'print(RbConfig::CONFIG["RUBY_PROGRAM_VERSION"])')} %else %{!?ruby_version: %global ruby_version %(ruby -r rbconfig -e 'print(RbConfig::CONFIG["ruby_version"])')} %endif %if 0%{?fedora_version} || 0%{?centos_version} || 0%{?rhel_version} || 0%{?fedora} || 0%{?rhel} Requires: ruby(abi) = %{ruby_version} %endif %if 0%{?suse_version} > 1120 Requires: ruby(abi) = %{ruby_version} %endif %if 0%{?suse_version} == 1010 %{!?ruby_sitelib: %global ruby_sitelib %(ruby -r rbconfig -e 'vd = RbConfig::CONFIG["vendorlibdir"]; print(vd ? vd : RbConfig::CONFIG["sitelibdir"])')} %{!?ruby_sitearch: %global ruby_sitearch %(ruby -r rbconfig -e 'vad = RbConfig::CONFIG["vendorarchdir"]; print(vad ? vad : RbConfig::CONFIG["sitearchdir"])')} %else # SLES 10 can't parse this :-/ %if 0%{?ruby_sitelib} == 0 %if (0%{?fedora} && 0%{?fedora} < 16) || (0%{?centos_version} && 0%{?centos_version}<600) || (0%{?rhel_version} && 0%{?rhel_version}<500) # Fedora15, RHEL-5 and CentOS-5 don't have vendor lib # CMAKE checks for "ruby -r vendor-specific" and fails %{!?ruby_sitelib: %global ruby_sitelib %(ruby -r rbconfig -e 'print(RbConfig::CONFIG["sitelibdir"])')} %{!?ruby_sitearch: %global ruby_sitearch %(ruby -r rbconfig -e 'print(RbConfig::CONFIG["sitearchdir"])')} %else %{!?ruby_sitelib: %global ruby_sitelib %(ruby -r rbconfig -e 'vd = RbConfig::CONFIG["vendorlibdir"]; print(vd ? vd : RbConfig::CONFIG["sitelibdir"])')} %{!?ruby_sitearch: %global ruby_sitearch %(ruby -r rbconfig -e 'vad = RbConfig::CONFIG["vendorarchdir"]; print(vad ? vad : RbConfig::CONFIG["sitearchdir"])')} %endif %endif %endif Summary: Ruby bindings for openwsman client API Group: System/Management %description ruby This package provides Ruby bindings to access the openwsman client API. %package ruby-docs Summary: HTML documentation for Opendwsman Ruby bindings Group: Documentation/HTML %description ruby-docs This package provides HTML documentation for the Openwsman Ruby bindings. %package perl %if 0%{?fedora} %define perl_version %(eval "`%{__perl} -V:version`"; echo $version) %define perl_requires perl(:MODULE_COMPAT_%{perl_version}) Requires: %{perl_version} %else Requires: perl = %{perl_version} %endif Summary: Perl bindings for openwsman client API Group: System/Management %description perl This package provides Perl bindings to access the openwsman client API. %if 0%{?suse_version} == 0 || 0%{?suse_version} >= 1100 %package java Requires: java Requires: libwsman1 = %{version} Summary: Java bindings for openwsman client API Group: System/Management %description java This package provides Java bindings to access the openwsman client API. %endif %prep %setup -q %if 0%{?fedora_version} || 0%{?centos_version} || 0%{?rhel_version} || 0%{?fedora} || 0%{?rhel} %patch1 -p1 %endif %build rm -rf build mkdir build %if 0%{?fedora} # [ curl-Bugs-1924441 ] SSL callback option with NSS-linked libcurl # CURLOPT_SSL_CTX_FUNCTION is defined, but does not work on e.g. Fedora export RPM_OPT_FLAGS="$RPM_OPT_FLAGS -DNO_SSL_CALLBACK" %endif # SLES 10 needs explicit java bytecode target %if 0%{?suse_version} == 1010 || 0%{?suse_version} == 1110 export EXPLICIT_SOURCE=1.5 export EXPLICIT_TARGET=1.5 %endif export SSL_LIB=`readlink %{_libdir}/libssl.so` cd build cmake \ -DCMAKE_INSTALL_PREFIX=/usr \ -DCMAKE_VERBOSE_MAKEFILE=TRUE \ -DCMAKE_BUILD_TYPE=Release \ -DCMAKE_C_FLAGS_RELEASE:STRING="$RPM_OPT_FLAGS -fno-strict-aliasing" \ -DCMAKE_CXX_FLAGS_RELEASE:STRING="$RPM_OPT_FLAGS" \ -DCMAKE_SKIP_RPATH=1 \ -DPACKAGE_ARCHITECTURE=`uname -m` \ -DEXPLICIT_SOURCE="$EXPLICIT_SOURCE" \ -DEXPLICIT_TARGET="$EXPLICIT_TARGET" \ -DLIB=%{_lib} \ -DBUILD_RUBY_GEM=no \ .. make CFLAGS="-DSSL_LIB='\"$SSL_LIB\"'" %install cd build make DESTDIR=$RPM_BUILD_ROOT install mkdir -p $RPM_BUILD_ROOT%{_docdir} cp -a bindings/ruby/html $RPM_BUILD_ROOT%{_docdir}/openwsman-ruby-docs cd .. rm -f $RPM_BUILD_ROOT%{_libdir}/*.la rm -f $RPM_BUILD_ROOT%{_libdir}/openwsman/plugins/*.la rm -f $RPM_BUILD_ROOT%{_libdir}/openwsman/authenticators/*.la [ -d $RPM_BUILD_ROOT%{ruby_sitelib} ] && rm -f $RPM_BUILD_ROOT%{ruby_sitelib}/openwsmanplugin.rb [ -d $RPM_BUILD_ROOT%{ruby_vendorlib} ] && rm -f $RPM_BUILD_ROOT%{ruby_vendorlib}/openwsmanplugin.rb %if 0%{?suse_version} <= 1210 mkdir -p $RPM_BUILD_ROOT%{_sysconfdir}/init.d install -m 755 build/etc/init/openwsmand.sh $RPM_BUILD_ROOT%{_sysconfdir}/init.d/openwsmand ln -sf %{_sysconfdir}/init.d/openwsmand $RPM_BUILD_ROOT%{_sbindir}/rcopenwsmand %endif install -m 644 etc/openwsman.conf $RPM_BUILD_ROOT%{_sysconfdir}/openwsman install -m 644 etc/openwsman_client.conf $RPM_BUILD_ROOT%{_sysconfdir}/openwsman install -m 644 etc/ssleay.cnf $RPM_BUILD_ROOT%{_sysconfdir}/openwsman install -m 644 %{S:2} $RPM_BUILD_ROOT%{_sysconfdir}/pam.d/openwsman %if 0%{?suse_version} > 1010 install -D -m 644 %{S:3} $RPM_BUILD_ROOT%{_sysconfdir}/sysconfig/SuSEfirewall2.d/services/openwsman %endif %if 0%{?has_systemd} install -D -m 644 %{S:4} $RPM_BUILD_ROOT%{_unitdir}/%{name}.service %endif %post -n libwsman1 -p /sbin/ldconfig %postun -n libwsman1 /sbin/ldconfig exit 0 # follow http://en.opensuse.org/openSUSE:Systemd_packaging_guidelines %if 0%{?has_systemd} %pre server if [ -f /var/lib/systemd/migrated/%{name} ]; then %service_add_pre %{name}.service fi %endif %post server /sbin/ldconfig %if 0%{?has_systemd} %service_add_post %{name}.service %else %if 0%{?suse_version} %{fillup_and_insserv openwsmand} %else # FIXME: chkconfig?! %endif %endif %preun server %if 0%{?has_systemd} %service_del_preun %{name}.service %else %if 0%{?suse_version} %{stop_on_removal openwsmand} %else # FIXME: chkconfig?! %endif %endif %postun server rm -f /var/log/wsmand.log /sbin/ldconfig %if 0%{?has_systemd} %service_del_postun %{name}.service %else %if 0%{?suse_version} %{restart_on_update openwsmand} %{insserv_cleanup openwsmand} %else # FIXME: chkconfig?! %endif %endif %post -n libwsman_clientpp1 -p /sbin/ldconfig %postun -n libwsman_clientpp1 -p /sbin/ldconfig %files -n libwsman1 %defattr(-,root,root) %doc AUTHORS COPYING ChangeLog README.md TODO src/plugins/redirect/redirect-README %{_libdir}/libwsman.so.* %{_libdir}/libwsman_client.so.* %{_libdir}/libwsman_curl_client_transport.so.* %config(noreplace) %{_sysconfdir}/openwsman/openwsman_client.conf %files -n libwsman-devel %defattr(-,root,root) %{_includedir}/* %{_libdir}/pkgconfig/* %{_libdir}/*.so %exclude %{_includedir}/openwsman/cpp/*.h %exclude %{_libdir}/libwsman_clientpp.so %files python %defattr(-,root,root) %{python_sitearch}/*.so %{python_sitearch}/*.py* %files ruby %defattr(-,root,root) %if 0%{?mandriva_version} %{ruby_sitearchdir}/_openwsman.so %dir %{ruby_sitelibdir}/openwsman %{ruby_sitelibdir}/openwsman.rb %{ruby_sitelibdir}/openwsman/*.rb %else %{ruby_sitearch}/_openwsman.so %dir %{ruby_sitelib}/openwsman %{ruby_sitelib}/openwsman.rb %{ruby_sitelib}/openwsman/*.rb %endif %files ruby-docs %defattr(-,root,root) %dir %{_docdir}/openwsman-ruby-docs %{_docdir}/openwsman-ruby-docs %files perl %defattr(-,root,root) %{perl_vendorarch}/openwsman.so %{perl_vendorlib}/openwsman.pm %if 0%{?suse_version} == 0 || 0%{?suse_version} >= 1100 %files java %defattr(-,root,root) %{_javadir}/*jar %endif %files server %defattr(-,root,root) %dir %{_sysconfdir}/openwsman %config(noreplace) %{_sysconfdir}/openwsman/openwsman.conf %config(noreplace) %{_sysconfdir}/openwsman/ssleay.cnf %attr(0755,root,root) %{_sysconfdir}/openwsman/owsmangencert.sh %config %{_sysconfdir}/pam.d/openwsman %if 0%{?suse_version} > 1010 %config %{_sysconfdir}/sysconfig/SuSEfirewall2.d/services/openwsman %endif %if 0%{?suse_version} <= 1210 %attr(0755,root,root) %{_sysconfdir}/init.d/openwsmand %{_sbindir}/rcopenwsmand %endif %dir %{_libdir}/openwsman %dir %{_libdir}/openwsman/authenticators %{_libdir}/openwsman/authenticators/*.so %{_libdir}/openwsman/authenticators/*.so.* %dir %{_libdir}/openwsman/plugins %{_libdir}/openwsman/plugins/*.so %{_libdir}/openwsman/plugins/*.so.* %{_sbindir}/openwsmand %{_libdir}/libwsman_server.so.* %if 0%{?has_systemd} %{_unitdir}/%{name}.service %endif %files -n libwsman_clientpp1 %defattr(-,root,root) %{_libdir}/libwsman_clientpp.so.* %files -n libwsman_clientpp-devel %defattr(-,root,root) %{_libdir}/libwsman_clientpp.so %dir %{_includedir}/openwsman/cpp %{_includedir}/openwsman/cpp/*.h %changelog openwsman-2.4.3/bindings/perl/tests/CMakeLists.txt000664 001750 001750 00000010246 12256012305 022441 0ustar00kentbkentb000000 000000 # # CMakeLists.txt for openwsman/bindings/perl/test # ENABLE_TESTING() # loading wsman ADD_TEST(bindings_perl_loading ${CMAKE_CURRENT_SOURCE_DIR}/run ${CMAKE_CURRENT_SOURCE_DIR} loading.pl ) # predefined stuff # ADD_TEST(bindings_perl_constants ${CMAKE_CURRENT_SOURCE_DIR}/run ${CMAKE_CURRENT_SOURCE_DIR} constants.pl ) # Xml bindings # ADD_TEST(bindings_perl_xmldoc ${CMAKE_CURRENT_SOURCE_DIR}/run ${CMAKE_CURRENT_SOURCE_DIR} xmldoc.pl ) # ADD_TEST(bindings_perl_xmlnode ${CMAKE_CURRENT_SOURCE_DIR}/run ${CMAKE_CURRENT_SOURCE_DIR} xmlnode.pl ) # ADD_TEST(bindings_perl_xmlattr ${CMAKE_CURRENT_SOURCE_DIR}/run ${CMAKE_CURRENT_SOURCE_DIR} xmlattr.pl ) # Client # ADD_TEST(bindings_perl_client ${CMAKE_CURRENT_SOURCE_DIR}/run ${CMAKE_CURRENT_SOURCE_DIR} client.pl ) # ADD_TEST(bindings_perl_client_bad ${CMAKE_CURRENT_SOURCE_DIR}/run ${CMAKE_CURRENT_SOURCE_DIR} client_bad.pl ) # Transport # ADD_TEST(bindings_perl_transport ${CMAKE_CURRENT_SOURCE_DIR}/run ${CMAKE_CURRENT_SOURCE_DIR} transport.pl ) # ClientOptions # ADD_TEST(bindings_perl_options ${CMAKE_CURRENT_SOURCE_DIR}/run ${CMAKE_CURRENT_SOURCE_DIR} clientoptions.pl ) # ADD_TEST(bindings_perl_debug ${CMAKE_CURRENT_SOURCE_DIR}/run ${CMAKE_CURRENT_SOURCE_DIR} debug.pl ) # Identify ADD_TEST(bindings_perl_identify ${CMAKE_CURRENT_SOURCE_DIR}/run ${CMAKE_CURRENT_SOURCE_DIR} identify.pl ) # data types # ADD_TEST(bindings_perl_fault ${CMAKE_CURRENT_SOURCE_DIR}/run ${CMAKE_CURRENT_SOURCE_DIR} fault.pl ) # needs a CIMOM ADD_TEST(bindings_perl_computer_system ${CMAKE_CURRENT_SOURCE_DIR}/run ${CMAKE_CURRENT_SOURCE_DIR} CIM_ComputerSystem_EnumInstances.pl ) # ADD_TEST(bindings_perl_operating_system ${CMAKE_CURRENT_SOURCE_DIR}/run ${CMAKE_CURRENT_SOURCE_DIR} cim_operating_system.pl ) # ADD_TEST(bindings_perl_cim_process ${CMAKE_CURRENT_SOURCE_DIR}/run ${CMAKE_CURRENT_SOURCE_DIR} cim_process.pl ) # ADD_TEST(bindings_perl_system_configuration ${CMAKE_CURRENT_SOURCE_DIR}/run ${CMAKE_CURRENT_SOURCE_DIR} cim_system_configuration.pl ) # ADD_TEST(bindings_perl_create ${CMAKE_CURRENT_SOURCE_DIR}/run ${CMAKE_CURRENT_SOURCE_DIR} create.pl ) # ADD_TEST(bindings_perl_each_child ${CMAKE_CURRENT_SOURCE_DIR}/run ${CMAKE_CURRENT_SOURCE_DIR} each_child.pl ) ADD_TEST(bindings_perl_enumerate ${CMAKE_CURRENT_SOURCE_DIR}/run ${CMAKE_CURRENT_SOURCE_DIR} CIM_EnumClasses.pl ) # ADD_TEST(bindings_perl_get ${CMAKE_CURRENT_SOURCE_DIR}/run ${CMAKE_CURRENT_SOURCE_DIR} get.pl ) # ADD_TEST(bindings_perl_identify ${CMAKE_CURRENT_SOURCE_DIR}/run ${CMAKE_CURRENT_SOURCE_DIR} identify.pl ) # ADD_TEST(bindings_perl_invoke ${CMAKE_CURRENT_SOURCE_DIR}/run ${CMAKE_CURRENT_SOURCE_DIR} invoke.pl ) # ADD_TEST(bindings_perl_notepad ${CMAKE_CURRENT_SOURCE_DIR}/run ${CMAKE_CURRENT_SOURCE_DIR} notepad.pl ) # ADD_TEST(bindings_perl_nsconsts ${CMAKE_CURRENT_SOURCE_DIR}/run ${CMAKE_CURRENT_SOURCE_DIR} nsconsts.pl ) # ADD_TEST(bindings_perl_processes ${CMAKE_CURRENT_SOURCE_DIR}/run ${CMAKE_CURRENT_SOURCE_DIR} processes.pl ) # ADD_TEST(bindings_perl_pull ${CMAKE_CURRENT_SOURCE_DIR}/run ${CMAKE_CURRENT_SOURCE_DIR} pull.pl ) # ADD_TEST(bindings_perl_put ${CMAKE_CURRENT_SOURCE_DIR}/run ${CMAKE_CURRENT_SOURCE_DIR} put.pl ) # ADD_TEST(bindings_perl_release ${CMAKE_CURRENT_SOURCE_DIR}/run ${CMAKE_CURRENT_SOURCE_DIR} release.pl ) # Needs specific provider #Linux_EthernetPort_EnumInstances.pl #Linux_EthernetPort_GetClass.pl #Linux_EthernetPort_GetInstance.pl #Linux_NextHopIPRoute_CreateInstance.pl #Linux_NextHopIPRoute_DeleteInstance.pl #ADD_TEST(bindings_perl_computersystem_assoc ${CMAKE_CURRENT_SOURCE_DIR}/run ${CMAKE_CURRENT_SOURCE_DIR} Linux_ComputerSystem_assoc.pl ) # needs WinRM system # ADD_TEST(bindings_perl_win32_operatingsystem ${CMAKE_CURRENT_SOURCE_DIR}/run ${CMAKE_CURRENT_SOURCE_DIR} win32_operatingsystem.pl ) # ADD_TEST(bindings_perl_win32_process ${CMAKE_CURRENT_SOURCE_DIR}/run ${CMAKE_CURRENT_SOURCE_DIR} win32_process.pl ) # ADD_TEST(bindings_perl_win32_services ${CMAKE_CURRENT_SOURCE_DIR}/run ${CMAKE_CURRENT_SOURCE_DIR} win32_services.pl ) openwsman-2.4.3/bindings/java/CMakeLists.txt000664 001750 001750 00000004224 12256012305 021255 0ustar00kentbkentb000000 000000 # # CMakeLists.txt for openwsman/bindings/java # # # This creates several files # 1. libjwsman.so # 2. *.java # MESSAGE(STATUS "Java compiler: ${JAVA_COMPILE}") MESSAGE(STATUS "Java runtime: ${JAVA_RUNTIME}") MESSAGE(STATUS "Java archiver: ${JAVA_ARCHIVE}") SET( SWIG_OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/openwsman_wrap.c" ) ADD_CUSTOM_COMMAND ( OUTPUT ${SWIG_OUTPUT} COMMAND ${CMAKE_COMMAND} -E echo_append "Creating wrapper code for Java ..." COMMAND ${SWIG_EXECUTABLE} -java -package org.openwsman -features autodoc -I${CMAKE_BINARY_DIR}/bindings -I${CMAKE_SOURCE_DIR}/bindings -I${CMAKE_SOURCE_DIR}/include -o ${SWIG_OUTPUT} ${SWIG_INPUT} COMMAND ${CMAKE_COMMAND} -E echo "Done." WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/../*.i DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/*.h ) SET( jar_NAME "openwsman-${PACKAGE_ARCHITECTURE}-${VERSION}.jar" ) MESSAGE(STATUS "Java archive name: ${jar_NAME}") IF(EXPLICIT_TARGET) SET( java_TARGET "-target") ENDIF(EXPLICIT_TARGET) IF(EXPLICIT_SOURCE) SET( java_SOURCE "-source") ENDIF(EXPLICIT_SOURCE) ADD_CUSTOM_COMMAND ( OUTPUT ${jar_NAME} POST_BUILD COMMAND ${CMAKE_COMMAND} -E echo_append "Compiling Java files ..." COMMAND ${JAVA_COMPILE} ${java_SOURCE} ${EXPLICIT_SOURCE} ${java_TARGET} ${EXPLICIT_TARGET} -d . *.java COMMAND ${CMAKE_COMMAND} -E echo_append "Creating JAR ..." COMMAND ${JAVA_ARCHIVE} cvf ${jar_NAME} *.so org/* DEPENDS ${SWIG_OUTPUT} ) ADD_CUSTOM_TARGET ( jwsman_all ALL COMMAND ${CMAKE_COMMAND} -E echo_append "Building Java bindings ..." DEPENDS ${jar_NAME} ) SET( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall" ) SET(jwsman_SRCS ${SWIG_OUTPUT} ${CMAKE_CURRENT_SOURCE_DIR}/../openwsman.c ) ADD_LIBRARY( jwsman SHARED ${jwsman_SRCS} ) INCLUDE_DIRECTORIES( ${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_SOURCE_DIR} ) INCLUDE_DIRECTORIES( ${CMAKE_SOURCE_DIR}/include ${CMAKE_SOURCE_DIR}/bindings ) INCLUDE_DIRECTORIES( ${JNI_INCLUDE_DIRS} ) TARGET_LINK_LIBRARIES( jwsman wsman ) TARGET_LINK_LIBRARIES( jwsman wsman_client ) INSTALL(FILES ${CMAKE_CURRENT_BINARY_DIR}/${jar_NAME} DESTINATION /usr/share/java) enable_testing() add_subdirectory(tests) openwsman-2.4.3/bindings/java/tests/run000755 001750 001750 00000000311 12256012305 020400 0ustar00kentbkentb000000 000000 #!/bin/bash # # run script for Java tests # # Usage: run # (cd $1; f=`dirname $0`; LD_LIBRARY_PATH=$f/../../../build/src/lib java -Djava.library.path=`pwd` -cp ../$2:$1 $3) openwsman-2.4.3/bindings/ruby/openwsman/openwsman.rb000664 001750 001750 00000006031 12256012305 023116 0ustar00kentbkentb000000 000000 # This is openwsman/openwsman # do NOT require this file, but do a simple # require 'openwsman' # instead # require 'openwsman/version' # this loads the binary .so file require '_openwsman' # this extends Openwsman::XmlNode with method_missing require 'openwsman/xmlnode' # this extends Openwsman::XmlDoc with method_missing require 'openwsman/xmldoc' # = About openwsman # Openwsman (http://www.openwsman.org) is a project intended to provide an open-source # implementation of the Web Services Management specification # (WS-Management) and to expose system management information on the # Linux operating system using the WS-Management protocol. WS-Management # is based on a suite of web services specifications and usage # requirements that exposes a set of operations focused on and covers # all system management aspects. # # = Using the bindings # The bindings provide access to the client-side API of openwsman. # You start by creating a Client instance and set up ClientOptions # to control the communication. # # The Client instance now provides the WS-Management operations, like # enumerate, get, invoke, etc. # # All client operations return a XmlDoc representing the SOAP response # from the system. # # You can then use XmlDoc methods to extract SOAP elements from the # response and dig down through its XmlNode and XmlAttr objects. module Openwsman class Transport # called when authentication credentials missing or wrong def Transport.auth_request_callback client, auth_type # override in client code # return Array of [ username, password ] # return nil to abort authentication end end # # return endpoint-reference (EPR) prefix for given classname and namespace # # * +classname+ - classname (using the _ format) # * +namespace+ - optional namespace, required for Windows WMI which embeds the namespace in the EPR # # ==== Examples # prefix = Openwsman.epr_prefix_for "CIM_Managed_Element" # => "http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2" # prefix = Openwsman.epr_prefix_for "Win32_Foo", "root/cimv2" # => "http://schemas.microsoft.com/wbem/wsman/1/wmi/root/cimv2" # def self.epr_prefix_for classname, namespace = nil prefix = Openwsman::uri_prefix classname prefix += "/#{namespace}" if namespace && !namespace.empty? prefix end # create full endpoint reference URI for namespace and classname # # * +classname+ - classname (using the _ format) # * +namespace+ - optional namespace, required for Windows WMI which embeds the namespace in the EPR # # ==== Examples # Openwsman.epr_uri_for "root/cimv2", "Win32_Foo" # => "http://schemas.microsoft.com/wbem/wsman/1/wmi/root/cimv2/Win32_Foo" def self.epr_uri_for namespace, classname raise "Namespace must not be nil" unless namespace raise "Classname must not be nil" unless classname epr = epr_prefix_for(classname,namespace) + "/#{classname}" end class EndPointReference def method_missing name, *args # :nodoc: selector(name) end end end openwsman-2.4.3/bindings/wsman-transport.i000664 001750 001750 00000033424 12256012305 021131 0ustar00kentbkentb000000 000000 /* * wsman-transport.i * client transport declarations for openwsman swig bindings * */ %rename(Transport) _WsManTransport; %nodefault _WsManTransport; typedef struct _WsManTransport {} WsManTransport; /* * Document-class: Transport * * Transport reflects details of the http(s) transport layer between * client and server. * */ /* rename those as _STR below */ %ignore _WS_NO_AUTH; %ignore _WS_BASIC_AUTH; %ignore _WS_DIGEST_AUTH; %ignore _WS_PASS_AUTH; %ignore _WS_NTLM_AUTH; %ignore _WS_GSSNEGOTIATE_AUTH; %include "u/libu.h" %include "wsman-client-transport.h" %extend _WsManTransport { /* No authentication */ %constant int NO_AUTH = WS_NO_AUTH; /* HTTP basic auth */ %constant int BASIC_AUTH = WS_BASIC_AUTH; /* HTTP digest auth */ %constant int DIGEST_AUTH = WS_DIGEST_AUTH; /* Windows Passport auth */ %constant int PASS_AUTH = WS_PASS_AUTH; /* Windows NT Lan manager auth */ %constant int NTLM_AUTH = WS_NTLM_AUTH; /* GSSAPI auth */ %constant int GSSNEGOTIATE_AUTH = WS_GSSNEGOTIATE_AUTH; /* No authentication */ %constant char *NO_AUTH_STR = _WS_NO_AUTH; /* HTTP basic auth */ %constant char *BASIC_AUTH_STR = _WS_BASIC_AUTH; /* HTTP digest auth */ %constant char *DIGEST_AUTH_STR = _WS_DIGEST_AUTH; /* Windows Passport auth */ %constant char *PASS_AUTH_STR = _WS_PASS_AUTH; /* Windows NT Lan manager auth */ %constant char *NTLM_AUTH_STR = _WS_NTLM_AUTH; /* GSSAPI auth */ %constant char *GSSNEGOTIATE_AUTH_STR = _WS_GSSNEGOTIATE_AUTH; #if defined(SWIGRUBY) %rename("auth_method?") is_auth_method(int method); %typemap(out) int is_auth_method "$result = ($1 != 0) ? Qtrue : Qfalse;"; #endif /* * Check if the passed method id is valid for authentication * call-seq: * transport.auth_method?(Integer) -> Boolean */ int is_auth_method(int method) { return wsman_is_auth_method((WsManClient *)$self, method); } /* * Close the transport. No further communication possible. */ void close() { wsman_transport_close_transport((WsManClient *)$self); } #if defined(SWIGRUBY) %rename("agent=") set_agent(const char *agent); #endif /* * Set the HTTP agent identifier (User-agent:) string * * This is how the client will show up in the servers http log. * Defaults to "Openwsman" * call-seq: * transport.agent = "Client identifier" */ void set_agent(const char *agent) { wsman_transport_set_agent((WsManClient *)$self, agent); } %newobject agent; /* * Get the HTTP agent identifier string * call-seq: * transport.agent -> String */ char *agent() { return wsman_transport_get_agent ((WsManClient *)$self); } #if defined(SWIGRUBY) %rename("username") get_username(); #endif %newobject get_username; /* * Server credentials * Get the username part of the http transport credentials * call-seq: * transport.username -> String */ char *get_username() { return wsman_transport_get_userName((WsManClient *)$self); } #if defined(SWIGRUBY) %rename("username=") set_username(char *user_name); #endif /* * Server credentials * Set the username part of the http transport credentials * call-seq: * transport.username = "Username" */ void set_username(char *user_name) { wsman_transport_set_userName((WsManClient *)$self, user_name); } #if defined(SWIGRUBY) %rename("password") get_password(); #endif %newobject get_password; /* * Server credentials * Get the password part of the http transport credentials * call-seq: * transport.password -> String */ char *get_password() { return wsman_transport_get_password((WsManClient *)$self); } #if defined(SWIGRUBY) %rename("password=") set_password(char *password); #endif /* * Server credentials * Set the password part of the http transport credentials * call-seq: * transport.password = "Password" */ void set_password(char *password) { wsman_transport_set_password((WsManClient *)$self, password); } #if defined(SWIGRUBY) %rename("proxy_username") get_proxy_username(); #endif %newobject get_proxy_username; /* * Windows clients: HTTP proxy credentials * * Get the username part of the http proxy credentials * call-seq: * transport.proxy_username -> String */ char *get_proxy_username() { return wsman_transport_get_proxy_username((WsManClient *)$self ); } #if defined(SWIGRUBY) %rename("proxy_username=") set_proxy_username(char *proxy_username); #endif /* * Windows clients: HTTP proxy credentials * * Set the username part of the http proxy credentials * call-seq: * transport.proxy_username = "proxy_username" */ void set_proxy_username(char *proxy_username) { wsman_transport_set_proxy_username((WsManClient *)$self, proxy_username ); } #if defined(SWIGRUBY) %rename("proxy_password") get_proxy_password(); #endif %newobject get_proxy_password; /* * Windows clients: HTTP proxy credentials * * Get the password part of the http proxy credentials * call-seq: * transport.proxy_password -> String */ char *get_proxy_password() { return wsman_transport_get_proxy_password((WsManClient *)$self ); } #if defined(SWIGRUBY) %rename("proxy_password=") set_proxy_password(char *proxy_password); #endif /* * Windows clients: HTTP proxy credentials * * Set the password part of the http proxy credentials * call-seq: * transport.proxy_password = "proxy_password" */ void set_proxy_password(char *proxy_password) { wsman_transport_set_proxy_password((WsManClient *)$self, proxy_password ); } #if defined(SWIGRUBY) %rename("auth_method=") set_auth_method( const char *am); #endif /* * Set the authentication method * Value must be one of: * +Openwsman::NO_AUTH_STR+ * +Openwsman::BASIC_AUTH_STR+ * +Openwsman::DIGEST_AUTH_STR+ * +Openwsman::PASS_AUTH_STR+ * +Openwsman::NTLM_AUTH_STR+ * +Openwsman::GSSNEGOTIATE_AUTH_STR+ */ void set_auth_method(const char *am) { wsman_transport_set_auth_method((WsManClient *)$self, am); } %newobject auth_method; /* * Set the authentication method * call-seq: * transport.auth_method -> String */ char *auth_method() { return wsman_transport_get_auth_method ((WsManClient *)$self); } /* * Set the authentication method string corresponding to the given * auth method id * * Value must be one of: * +Openwsman::NO_AUTH+ * +Openwsman::BASIC_AUTH+ * +Openwsman::DIGEST_AUTH+ * +Openwsman::PASS_AUTH+ * +Openwsman::NTLM_AUTH+ * +Openwsman::GSSNEGOTIATE_AUTH+ * * call-seq: * transport.auth_name(Integer) -> String */ static const char *auth_name(int auth) { return wsmc_transport_get_auth_name(auth); } /* * Get the authentication method integer id */ int auth_value() { return wsmc_transport_get_auth_value((WsManClient *)$self); } /* * Get string corresponding to given error code * call-seq: * transport.error_string(Integer) -> String */ static char *error_string(int err) { return wsman_transport_get_last_error_string(err); } #if defined(SWIGRUBY) %rename("timeout=") set_timeout(unsigned long timeout); #endif /* * Set the transport timeout in seconds * * ==== Note * This is the http layer timeout. Not to be confused with the * WS-Management operation timeout set via Openwsman::ClientOptions.timeout */ void set_timeout(unsigned long timeout) { wsman_transport_set_timeout((WsManClient *)$self, timeout); } /* * Get the transport timeout in seconds * call-seq: * transport.timeout -> Integer */ unsigned long timeout() { return wsman_transport_get_timeout((WsManClient *)$self); } #if defined(SWIGRUBY) %rename("verify_peer=") set_verify_peer( VALUE rvalue ); /* * verify the peer in SSL communication ? * * If passed +false+, +nil+, or 0: disable peer verification * else: enable peer verification */ void set_verify_peer( VALUE rvalue ) { unsigned int value; if ((rvalue == Qfalse) || (rvalue == Qnil)) { value = 0; } else if ((TYPE(rvalue) == T_FIXNUM) && (FIX2INT(rvalue) == 0)) { value = 0; } else { value = 1; } #else /* * verify the peer in SSL communication ? * no: == 0 * yes: != 0 */ void set_verify_peer( unsigned int value ) { #endif wsman_transport_set_verify_peer((WsManClient *)$self, value); } #if defined(SWIGRUBY) %rename("verify_peer?") verify_peer(); %typemap(out) unsigned int verify_peer "$result = ($1 != 0) ? Qtrue : Qfalse;"; #endif /* * Peer to be verified ? * call-seq: * transport.verify_peer? -> Boolean */ unsigned int verify_peer() { return wsman_transport_get_verify_peer((WsManClient *)$self); } #if defined(SWIGRUBY) %rename("verify_host=") set_verify_host(VALUE rvalue); /* * verify the host in SSL communication ? * * If passed +false+, +nil+, or 0: disable peer verification * else: enable peer verification */ void set_verify_host( VALUE rvalue ) { unsigned int value; if ((rvalue == Qfalse) || (rvalue == Qnil)) { value = 0; } else if ((TYPE(rvalue) == T_FIXNUM) && (FIX2INT(rvalue) == 0)) { value = 0; } else { value = 1; } #else /* * verify the host in SSL communication ? * no: == 0 * yes: != 0 */ void set_verify_host(unsigned int value) { #endif wsman_transport_set_verify_host((WsManClient *)$self, value); } #if defined(SWIGRUBY) %rename("verify_host?") verify_host(); %typemap(out) unsigned int verify_host "$result = ($1 != 0) ? Qtrue : Qfalse;"; #endif /* * Host to be verified ? * call-seq: * transport.verify_host? -> Boolean */ unsigned int verify_host() { return wsman_transport_get_verify_host((WsManClient *)$self); } #if defined(SWIGRUBY) %rename("proxy=") set_proxy(const char *proxy); #endif /* * Set http proxy URL * * Pass nil to disable proxy communication * ==== Example * transport.proxy = "http://your.proxy.com:80" */ void set_proxy(const char *proxy) { wsman_transport_set_proxy((WsManClient *)$self, proxy); } %newobject proxy; /* * Get http proxy URL */ char *proxy() { return wsman_transport_get_proxy((WsManClient *)$self); } #if defined(SWIGRUBY) %rename("proxyauth=") set_proxyauth(const char *pauth); #endif /* * Linux clients: HTTP proxy credentials * * Set the proxy username and password * ==== Example * transport.proxyauth = "username:password" */ void set_proxyauth(const char *pauth) { wsman_transport_set_proxyauth((WsManClient *)$self, pauth); } %newobject proxyauth; /* * Linux clients: HTTP proxy credentials * * Get the proxy username and password as "username:password" * call-seq: * transport.proxyauth -> String */ char *proxyauth(){ return wsman_transport_get_proxyauth((WsManClient *)$self); } #if defined(SWIGRUBY) %rename("cainfo=") set_cainfo(const char *cainfo); #endif /* * Set the certification authority (CAINFO) */ void set_cainfo(const char *cainfo) { wsman_transport_set_cainfo((WsManClient *)$self, cainfo); } %newobject cainfo; /* * Get the certification authority (CAINFO) * call-seq: * transport.cainfo -> String */ char *cainfo() { return wsman_transport_get_cainfo((WsManClient *)$self); } #if defined(SWIGRUBY) %rename("certhumbprint=") set_certhumbprint(const char *arg); #endif /* * Set the certification thumbprint */ void set_certhumbprint(const char *arg) { wsman_transport_set_certhumbprint((WsManClient *)$self, arg); } %newobject certhumbprint; /* * Set the certification thumbprint * call-seq: * transport.certhumbprint -> String */ char *certhumbprint() { return wsman_transport_get_certhumbprint((WsManClient *)$self); } #if defined(SWIGRUBY) %rename("capath=") set_capath(const char *capath); #endif /* * Set the path to the certification authority (CAINFO) store */ void set_capath(const char *capath) { wsman_transport_set_capath((WsManClient *)$self, capath); } %newobject capath; /* * Get the path to the certification authority (CAINFO) store */ char *capath() { return wsman_transport_get_capath((WsManClient *)$self); } #if defined(SWIGRUBY) %rename("caoid=") set_caoid(const char *oid); #endif /* * Windows client * * Set the CA OID * * ==== Reference * http://support.microsoft.com/kb/287547 */ void set_caoid(const char *oid) { wsman_transport_set_caoid((WsManClient *)$self, oid); } %newobject caoid; /* * Windows client * * Get the CA OID */ char *caoid() { return wsman_transport_get_caoid((WsManClient *)$self); } #ifdef _WIN32 #if defined(SWIGRUBY) %rename("calocal=") set_calocal(BOOL local); #endif /* * Windows client * * Use local CA ? */ void set_calocal(BOOL local) { wsman_transport_set_calocal((WsManClient *)$self, local); } /* * Windows client * * Use local CA ? * call-seq: * transport.calocal -> Boolean */ BOOL calocal() { return wsman_transport_get_calocal((WsManClient *)$self); } #endif #if defined(SWIGRUBY) %rename("cert=") set_cert(const char *cert); #endif /* * Set the certificate */ void set_cert(const char *cert) { wsman_transport_set_cert((WsManClient *)$self, cert); } %newobject cert; /* * Get the certificate */ char *cert() { return wsman_transport_get_cert((WsManClient *)$self); } #if defined(SWIGRUBY) %rename("key=") set_key(const char *key); #endif /* * Set the key */ void set_key(const char *key) { wsman_transport_set_key((WsManClient *)$self, key); } %newobject key; /* * Get the key */ char *key() { return wsman_transport_get_key((WsManClient *)$self); } } openwsman-2.4.3/bindings/perl/tests/Linux_NextHopIPRoute_CreateInstance.pl000664 001750 001750 00000005121 12256012305 027216 0ustar00kentbkentb000000 000000 #!/usr/bin/perl -w # # perl example to create a new Linux_NextHopIPRoute instance. # written by warptrosse@gmail.com # use strict; use warnings; use lib '../../../build/bindings/perl'; use lib '..'; use openwsman; # debug (to stderr) # openwsman::set_debug(1); # Create client instance. # (host, port, path, scheme, username, password) my $client = new openwsman::Client::('localhost', 5985, '/wsman', 'http', 'wsman', 'secret') or die print "[ERROR] Could not create client handler.\n"; # Alternate way. # my $client = new openwsman::Client::('http://wsman:secret@localhost:8889/wsman') # or die print "[ERROR] Could not create client handler.\n"; # Set up client options. my $options = new openwsman::ClientOptions::() or die print "[ERROR] Could not create client options handler.\n"; # Force basic auth. $client->transport()->set_auth_method($openwsman::BASIC_AUTH_STR); my $uri = 'http://sblim.sf.net/wbem/wscim/1/cim-schema/2/Linux_NextHopIPRoute'; # Uri. my @dataInfo = ( ['AddressType' , "1"], ['AdminDistance' , "1"], ['Caption' , "NextHop IPv4 route."], ['Description' , "NextHop IPv4 route."], ['DestinationAddress' , "192.168.0.0"], ['DestinationMask' , "24"], ['ElementName' , "IPv4-192.168.0.0/24"], ['Generation' , "1"], ['InstanceID' , "localhost|192.168.0.0|24|254|2|0|"], ['IsStatic' , "1"], ['OtherDerivation' , ""], ['PrefixLength' , ""], ['RouteDerivation' , "3"], ['RouteMetric' , "1"], ['TypeOfRoute' , "2"] ); # Selectors list. my $result; # Used to store obtained data. # Get class name. my $className; if(($uri =~ /.\/(\w+)$/)) { $className = $1; } else { print "[ERROR] Malformed uri.\n"; return 1; } # Establish data. # (key, value) my $data = new openwsman::XmlDoc::($className); my $root = $data->root(); $root->set_ns($uri); for(my $i=0 ; $iadd($uri, $dataInfo[$i][0], $dataInfo[$i][1]); } # Dump the XML request to stdout. # $options->set_dump_request(); # Create instance. # (options, uri, data, data length, encoding) $result = $client->create($options, $uri, $data->string(), length($data->string()),"utf-8"); unless($result && $result->is_fault eq 0) { print "[ERROR] Could not create instance.\n"; } else { # Print output. print "---------------------------------------------------\n"; print "Result: \n\n", $result->string(); print "---------------------------------------------------\n"; } openwsman-2.4.3/src/lib/test/test_string.c000664 001750 001750 00000002724 12256012305 021027 0ustar00kentbkentb000000 000000 #ifdef HAVE_CONFIG_H #include #endif #include //int facility = LOG_DAEMON; struct { char *uri_string, *result; } abs_tests[] = { { "http://aa.xx.com/test?a=b&c=d", "foo:" }, { NULL, NULL } }; int main(int argc, char *argv[]) { int i; const char *end, *question; char *u_string; // parse url // u_uri_t *uri = u_malloc(sizeof(u_uri_t)); for (i = 0; abs_tests[i].uri_string != NULL ; i++) { (void) console("%s", abs_tests[i].uri_string ); u_uri_parse(abs_tests[i].uri_string, &uri); (void) console("%s", uri->host); (void) console("%s", uri->path); u_string = u_strdup( abs_tests[i].uri_string ); end = strchr (u_string, '#'); if (!end) end = u_string + strlen(u_string); question = memchr (u_string, '?', end - u_string); char *query = NULL; if (question) { (void) console("%s", question); (void) console("%s", end); if (question[1]) { query = u_strndup (question + 1, end - (question + 1)); } } (void) console("%s", query); hash_t *h = u_parse_query(query); hnode_t *hn; hscan_t hs; hash_scan_begin(&hs, h); while ((hn = hash_scan_next(&hs))) printf("%s\t%s\n", (char*) hnode_getkey(hn), (char*) hnode_get(hn)); } return 0; } openwsman-2.4.3/cmake/modules/FindRuby.cmake000664 001750 001750 00000007725 12256012305 021264 0ustar00kentbkentb000000 000000 # - Find Ruby # This module finds if Ruby is installed and determines where the include files # and libraries are. It also determines what the name of the library is. This # code sets the following variables: # # RUBY_INCLUDE_PATH = path to where ruby.h can be found # RUBY_EXECUTABLE = full path to the ruby binary # Copyright (c) 2002 Kitware, Inc., Insight Consortium. All rights reserved. # See Copyright.txt or http://www.cmake.org/HTML/Copyright.html for details. if(RUBY_LIBRARY AND RUBY_INCLUDE_PATH) # Already in cache, be silent set(RUBY_FIND_QUIETLY TRUE) endif (RUBY_LIBRARY AND RUBY_INCLUDE_PATH) # RUBY_ARCHDIR=`$RUBY -r rbconfig -e 'printf("%s",RbConfig::CONFIG@<:@"archdir"@:>@)'` # RUBY_SITEARCHDIR=`$RUBY -r rbconfig -e 'printf("%s",RbConfig::CONFIG@<:@"sitearchdir"@:>@)'` # RUBY_SITEDIR=`$RUBY -r rbconfig -e 'printf("%s",RbConfig::CONFIG@<:@"sitelibdir"@:>@)'` # RUBY_LIBDIR=`$RUBY -r rbconfig -e 'printf("%s",RbConfig::CONFIG@<:@"libdir"@:>@)'` # RUBY_LIBRUBYARG=`$RUBY -r rbconfig -e 'printf("%s",RbConfig::CONFIG@<:@"LIBRUBYARG_SHARED"@:>@)'` FIND_PROGRAM(RUBY_EXECUTABLE NAMES ruby ruby19 ruby1.8 ruby18 ) EXECUTE_PROCESS(COMMAND ${RUBY_EXECUTABLE} -r rbconfig -e "print RbConfig::CONFIG['MAJOR']" OUTPUT_VARIABLE RUBY_VERSION_MAJOR) EXECUTE_PROCESS(COMMAND ${RUBY_EXECUTABLE} -r rbconfig -e "print RbConfig::CONFIG['MINOR']" OUTPUT_VARIABLE RUBY_VERSION_MINOR) EXECUTE_PROCESS(COMMAND ${RUBY_EXECUTABLE} -r rbconfig -e "print RbConfig::CONFIG['TEENY']" OUTPUT_VARIABLE RUBY_VERSION_PATCH) EXECUTE_PROCESS(COMMAND ${RUBY_EXECUTABLE} -r rbconfig -e "print RbConfig::CONFIG['archdir']" OUTPUT_VARIABLE RUBY_ARCH_DIR) EXECUTE_PROCESS(COMMAND ${RUBY_EXECUTABLE} -r rbconfig -e "print RbConfig::CONFIG['rubyhdrdir']" OUTPUT_VARIABLE RUBY_HDR_DIR ERROR_QUIET) EXECUTE_PROCESS(COMMAND ${RUBY_EXECUTABLE} -r rbconfig -e "print RbConfig::CONFIG['arch']" OUTPUT_VARIABLE RUBY_ARCH) EXECUTE_PROCESS(COMMAND ${RUBY_EXECUTABLE} -r rbconfig -e "print RbConfig::CONFIG['libdir']" OUTPUT_VARIABLE RUBY_POSSIBLE_LIB_PATH) EXECUTE_PROCESS(COMMAND ${RUBY_EXECUTABLE} -r rbconfig -e "print RbConfig::CONFIG['rubylibdir']" OUTPUT_VARIABLE RUBY_RUBY_LIB_PATH) # site_ruby EXECUTE_PROCESS(COMMAND ${RUBY_EXECUTABLE} -r rbconfig -e "print RbConfig::CONFIG['sitearchdir']" OUTPUT_VARIABLE RUBY_SITEARCH_DIR) EXECUTE_PROCESS(COMMAND ${RUBY_EXECUTABLE} -r rbconfig -e "print RbConfig::CONFIG['sitelibdir']" OUTPUT_VARIABLE RUBY_SITELIB_DIR) EXECUTE_PROCESS(COMMAND ${RUBY_EXECUTABLE} -r rbconfig -e "print RbConfig::CONFIG['vendorarchdir']" OUTPUT_VARIABLE RUBY_VENDORARCH_DIR ERROR_QUIET) IF(RUBY_VENDORARCH_DIR) IF(${RUBY_VENDORARCH_DIR} STREQUAL "nil") ELSE(${RUBY_VENDORARCH_DIR} STREQUAL "nil") EXECUTE_PROCESS(COMMAND ${RUBY_EXECUTABLE} -r rbconfig -e "print RbConfig::CONFIG['vendorlibdir']" OUTPUT_VARIABLE RUBY_VENDORLIB_DIR) ENDIF(${RUBY_VENDORARCH_DIR} STREQUAL "nil") ENDIF(RUBY_VENDORARCH_DIR) IF(NOT RUBY_VENDORLIB_DIR) # fall back to site*dir EXECUTE_PROCESS(COMMAND ${RUBY_EXECUTABLE} -r rbconfig -e "print RbConfig::CONFIG['sitearchdir']" OUTPUT_VARIABLE RUBY_VENDORARCH_DIR) EXECUTE_PROCESS(COMMAND ${RUBY_EXECUTABLE} -r rbconfig -e "print RbConfig::CONFIG['sitelibdir']" OUTPUT_VARIABLE RUBY_VENDORLIB_DIR) ENDIF(NOT RUBY_VENDORLIB_DIR) # this is not needed if you use "print" inside the ruby statements # remove the new lines from the output by replacing them with empty strings #STRING(REPLACE "\n" "" RUBY_ARCH_DIR "${RUBY_ARCH_DIR}") #STRING(REPLACE "\n" "" RUBY_POSSIBLE_LIB_PATH "${RUBY_POSSIBLE_LIB_PATH}") #STRING(REPLACE "\n" "" RUBY_RUBY_LIB_PATH "${RUBY_RUBY_LIB_PATH}") FIND_PATH(RUBY_INCLUDE_PATH NAMES ruby.h PATHS ${RUBY_HDR_DIR} ${RUBY_ARCH_DIR} /usr/lib/ruby/1.8/i586-linux-gnu/ ) FIND_LIBRARY(RUBY_LIBRARY NAMES ruby ruby1.9 ruby1.8 PATHS ${RUBY_POSSIBLE_LIB_PATH} ${RUBY_RUBY_LIB_PATH} ) MARK_AS_ADVANCED( RUBY_EXECUTABLE RUBY_LIBRARY RUBY_INCLUDE_PATH ) openwsman-2.4.3/bindings/ruby/tests/rbwsman.rb000664 001750 001750 00000000157 12256012305 021716 0ustar00kentbkentb000000 000000 module Openwsman File.join(File.dirname(__FILE__),'_loadpath') require 'openwsman' include Openwsman end openwsman-2.4.3/doc/plugin-framwork.txt000664 001750 001750 00000051604 12256012305 020435 0ustar00kentbkentb000000 000000 Plugin Framework Design ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Plugin Framework is designed as a bridge to connect WS-MAN with Plugins, it manages these plugins, including load and unload. All plugins are in a special directory. Plugin Framework just call wsman_plugins_load during its initialization. When WS-MAN receive the request from client, it analyze this request and deliver this request to the appropriate plugin, and get the response from this plugin. Then it envelops this response by WS-Management Specification, and send this package to client. 0. Structure of Plugin Framework ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -------------- -------------- | plugin 0 | | plugin 1 | ... -------------- -------------- | | ---------------------------------------------- | -------------------------- | Plugin Framework | -------------------------- -------------------------- | WS-MAN | -------------------------- 1. Importand Data Structure ~~~~~~~~~~~~~~~~~~~~~~~~~~~ struct __WsDispatchInterfaceInfo { unsigned long flags; // reserved char *notes; // plugin information -- note char *vendor; // plugin information -- vendor char *displayName; // plugin information -- titile char *compliance; // compliant protocol char *actionUriBase; // base part of the action URI string char *wsmanSystemUri; // WS-MAN system URI, it may be NULL char *wsmanResourceUri; // WS-MAN resource URI, it can not be // NULL void *extraData; // reserved WsDispatchEndPointInfo *endPoints; // pointer to table of resource. }; typedef struct __WsDispatchInterfaceInfo WsDispatchInterfaceInfo; This structure describes the plugin and its resource. The endPoints table is an array of struct __WsDispatchEndPointInfo ending with a all-zero entry. ================================================================================ struct __WsSelector { char *name; // selector name, it identifies with // mof class keybind. char *value; // selector value char *type; // selector type, char *description; // decription of }; typedef struct __WsSelector WsSelector; This structure describes the selectors about endpoint. ================================================================================ #define WS_DISP_TYPE_RAW_DOC 0 #define WS_DISP_TYPE_GET 1 #define WS_DISP_TYPE_PUT 2 #define WS_DISP_TYPE_CREATE 3 #define WS_DISP_TYPE_DELETE 4 #define WS_DISP_TYPE_ENUMERATE 5 #define WS_DISP_TYPE_PULL 6 #define WS_DISP_TYPE_RELEASE 7 #define WS_DISP_TYPE_UPDATE 8 #define WS_DISP_TYPE_GETSTATUS 9 #define WS_DISP_TYPE_SOAP_RPC 10 #define WS_DISP_TYPE_COUNT 11 struct __WsDispatchEndPointInfo { unsigned long flags; // it is one of the above macro char* rqstName; // request name, usually it is // NULL // except WS_DISP_TYPE_SOAP_RPC char* respName; // response name, usually it is // NULL except WS_DISP_TYPE_SOAP_RPC char* inAction; // an unique input action name char* outAction; // an unique output action name struct __XmlSerializerInfo* serializationInfo; // pointer to a table, used to // serialize this endpoint WsProcType serviceEndPoint; // hook fuction for this endpoint void* data; // pointer to the base resource // URI, used as a namespace struct __WsSelector* selectors; // pointer to a seclector table, // It may be NULL. }; typedef struct __WsDispatchEndPointInfo WsDispatchEndPointInfo; This structure describes all information about endpoint, An endpoint which represents a distinct type of management operation or value. The serializationInfo table is an array of struct __XmlSerializerInfo, only include one element, it include some detail about this endpoint The selectors table is an array of struct __WsSelector ending with a all-zero entry. =============================================================================== struct __XmlSerializerInfo { char* name; // property of resource unsigned short flagsMinCount; // count can be 1 for single // elementd; > 1 for fixed size // array; 0 for dynamic array. unsigned short funcMaxCount; XmlSerializationProc proc; // hook fuction for this property, // used to serialize this property. // it can be one of do_serialize_xxx XML_TYPE_PTR extData; // if type of this property is a // simple date, it is NULL, or // it is a pointer to a // __XmlSerializerInfo structure. }; typedef struct __XmlSerializerInfo XmlSerializerInfo; This structure deccribes all Serialization type information for resource ================================================================================ 2. useful MACRO ~~~~~~~~~~~~~~~ #define SER_UINT8(n, x, y)\ {(n), (x), (y), do_serialize_uint8, NULL} #define SER_UINT16(n, x, y)\ {(n), (x), (y), do_serialize_uint16, NULL} #define SER_UINT32(n, x, y)\ {(n), (x), (y), do_serialize_uint32, NULL} #define SER_BOOL(n, x, y)\ {(n), (x), (y), do_serialize_bool, NULL} #define SER_UINT8_PTR (n, x, y)\ {(n), SER_PTR | (x), (y), do_serialize_uint8, NULL} #define SER_UINT16_PTR (n, x, y)\ {(n), SER_PTR | (x), (y), do_serialize_uint16, NULL} #define SER_UINT32_PTR(n, x, y)\ {(n), SER_PTR | (x), (y), do_serialize_uint32, NULL} #define SER_BOOL_PTR(n, x, y)\ {(n), SER_PTR | (x), (y), do_serialize_bool, NULL} #define SER_STR(n, x, y)\ {(n), SER_PTR | (x), (y), do_serialize_string, NULL} #define SER_STRUCT(n, x, y, t)\ {(n), (x), (y), do_serialize_struct, t##_TypeItems} #define SER_DYN_ARRAY_PTR(t)\ {NULL, SER_PTR, 1, do_serialize_syn_size_array, t##_TypeInfo} #define SER_DYN_ARRAY(t)\ {NULL, 1, 1, do_serialize_dyn_size_array, t##_TypeInfo} #define SER_IN_UINT8 (n)\ {(n), 1, 1 | SER_IN, do_serialize_uint8, NULL} #define SER_IN_UINT16(n)\ {(n), 1, 1 | SER_IN, do_serialize_uint16, NULL} #define SER_IN_UINT32(n)\ {(n), 1, 1 | SER_IN, do_serialize_uint32, NULL} #define SER_IN_BOOL(n)\ {(n), 1, 1 | SER_IN, do_serialize_bool, NULL} #define SER_IN_UINT8_PTR (n)\ {(n), SER_PTR | 1, 1 | SER_IN, do_serialize_uint8, NULL} #define SER_IN_UINT16_PTR(n)\ {(n), SER_PTR | 1, 1 | SER_IN, do_serialize_uint16, NULL} #define SER_IN_UINT32_PTR(n)\ {(n), SER_PTR | 1, 1 | SER_IN, do_serialize_uint32, NULL} #define SER_IN_BOOL_PTR(n)\ {(n), SER_PTR | 1, 1 | SER_IN, do_serialize_bool, NULL} #define SER_IN_STR(n)\ {(n), SER_PTR | 1, 1 | SER_IN, do_serialize_string, NULL} #define SER_IN_STRUCT_PTR(n, t)\ {(n), SER_PTR | 1, 1 | SER_IN, do_serialize_Struct, t##_TypeItems} #define SER_OUT_UINT8 (n)\ {(n), 1, 1 | SER_OUT, do_serialize_uint8, NULL} #define SER_OUT_UINT16 (n)\ {(n), 1, 1 | SER_OUT, do_serialize_uint16, NULL} #define SER_OUT_UINT32(n)\ {(n), 1, 1 | SER_OUT, do_serialize_uint32, NULL} #define SER_OUT_BOOL(n)\ {(n), 1, 1 | SER_OUT, do_serialize_bool, NULL} #define SER_OUT_UINT8_PTR(n)\ {(n), SER_PTR | 1, 1 | SER_OUT, do_serialize_uint8, NULL} #define SER_OUT_UINT16_PTR(n)\ {(n), SER_PTR | 1, 1 | SER_OUT, do_serialize_uint16, NULL} #define SER_OUT_UINT32_PTR(n)\ {(n), SER_PTR | 1, 1 | SER_OUT, do_serialize_uint32, NULL} #define SER_OUT_BOOL_PTR(n)\ {(n), SER_PTR | 1, 1 | SER_OUT, do_serialize_bool, NULL} #define SER_OUT_STR(n)\ {(n), SER_PTR | 1, 1 | SER_OUT, do_serialize_string, NULL} #define SER_OUT_STRUCT_PTR(n, t)\ {(n), SER_PTR | 1, 1 | SER_OUT, do_serialize_struct, t##_TypeItems} #define SER_INOUT_UINT8 (n)\ {(n), 1, 1 | SER_INOUT, do_serialize_uint8, NULL} #define SER_INOUT_UINT16 (n)\ {(n), 1, 1 | SER_INOUT, do_serialize_uint16, NULL} #define SER_INOUT_UINT32(n)\ {(n), 1, 1 | SER_INOUT, do_serialize_uint32, NULL} #define SER_INOUT_BOOL(n)\ {(n), 1, 1 | SER_INOUT, do_serialize_bool, NULL} #define SER_INOUT_UINT8_PTR (n)\ {(n), SER_INOUT_PTR | 1, 1 | SER_INOUT, do_serialize_uint8, NULL} #define SER_INOUT_UINT16_PTR (n)\ {(n), SER_INOUT_PTR | 1, 1 | SER_INOUT, do_serialize_uint16, NULL} #define SER_INOUT_UINT32_PTR(n)\ {(n), SER_INOUT_PTR | 1, 1 | SER_INOUT, do_serialize_uint32, NULL} #define SER_INOUT_BOOL_PTR(n)\ {(n), SER_INOUT_PTR | 1, 1 | SER_INOUT, do_serialize_bool, NULL} #define SER_INOUT_STR(n)\ {(n), SER_INOUT_PTR | 1, 1 | SER_INOUT, do_serialize_string, NULL} #define SER_INOUT_STRUCT_PTR(n, t)\ {(n), SER_PTR | 1, 1 | SER_INOUT, do_serialize_struct, t##_TypeItems} #define SER_RET_VAL_UINT8 (n)\ {(n), 1, 1 | SER_RET_VAL, do_serialize_uint8, NULL} #define SER_RET_VAL_UINT16 (n)\ {(n), 1, 1 | SER_RET_VAL, do_serialize_uint16, NULL} #define SER_RET_VAL_UINT32(n)\ {(n), 1, 1 | SER_RET_VAL, do_serialize_uint32, NULL} #define SER_RET_VAL_BOOL(n)\ {(n), 1, 1 | SER_RET_VAL, do_serialize_bool, NULL} #define SER_RET_VAL_UINT8_PTR (n)\ {(n), SER_RET_VAL_PTR | 1, 1 | SER_RET_VAL, do_serialize_uint8, NULL} #define SER_RET_VAL_UINT16_PTR (n)\ {(n), SER_RET_VAL_PTR | 1, 1 | SER_RET_VAL, do_serialize_uint16, NULL} #define SER_RET_VAL_UINT32_PTR(n)\ {(n), SER_RET_VAL_PTR | 1, 1 | SER_RET_VAL, do_serialize_uint32, NULL} #define SER_RET_VAL_BOOL_PTR(n)\ {(n), SER_RET_VAL_PTR | 1, 1 | SER_RET_VAL, do_serialize_bool, NULL} #define SER_RET_VAL_STR(n)\ {(n), SER_RET_VAL_PTR | 1, 1 | SER_RET_VAL, do_serialize_string, NULL} #define SER_RET_VAL_STRUCT_PTR(n, t)\ {(n), SER_PTR | 1, 1 | SER_RET_VAL, do_serialize_struct, t##_TypeItems} #define SER_TYPE_STRUCT(n, t)\ struct __XmlSerializerInfo t##_TypeInfo[] = {\ {(n), 1, 1, do_serialize_struct, t##_TypeItems} } #define SER_START_ITEMS(n, t)\ struct __XmlSerializerInfo t##_TypeItems[] = { #define SER_END_ITEMS(n, t)\ {NULL, 0, 0, NULL, NULL} };\ SER_TYPE_STRUCT(n, t) These macros are used to create an array of items with name StateDescription_TypeInfo for example: SER_START_ITEMS("This", WsManThis) SER_STR("Vendor", 1, 1), SER_STR("Version", 1, 1), SER_END_ITEMS("This", WsManThis); After the preprocessing stage, the result is struct __XmlSerializerInfo WsManThis_TypeItems[] = { {("Vendor"), 0x8000 | (1), (1), do_serialize_string, 0}, {("Version"), 0x8000 | (1), (1), do_serialize_string, 0}, {0, 0, 0, 0, 0} }; struct __XmlSerializerInfo WsManThis_TypeInfo[] = { {(this), 1, 1, do_serialize_struct, WsManThis_TypeItems} }; ================================================================================ #define ADD_SELECTOR(n,t,d)\ { n, NULL, t, d} #define SELECTOR_LAST { NULL, NULL, NULL, NULL } #define START_TRANSFER_GET_SELECTORS(t) WsSelector t##_Get_Selectors[] = { #define FINISH_TRANSFER_GET_SELECTORS(t) SELECTOR_LAST } These macros are used to create array of items with name WsSelector. for example: START_TRANSFER_GET_SELECTORS(WsManThis) ADD_SELECTOR("CreationClassName", "string", "Creation Class Name"), FINISH_TRANSFER_GET_SELECTORS(IpmiSel); After the preprocessing stage, the result is struct WsSelector WsManThis_Get_Selectors[] = { { "CreationClassName", NULL, "string", "Creation Class Name" }, { 0, 0, 0, 0} }; ================================================================================ #define END_POINT_TRANSFER_GET(t, ns)\ { WS_DISP_TYPE_GET, NULL, NULL, TRANSFER_ACTION_GET, NULL,\ t##_TypeInfo, (WsProcType)t##_Get_EP, ns, t##_Get_Selectors} #define END_POINT_TRANSFER_GET_RAW(t, ns)\ { WS_DISP_TYPE_GET_RAW, NULL, NULL, TRANSFER_ACTION_GET, NULL,\ t##_TypeInfo, (WsProcType)t##_Get_EP, ns, t##_Get_Selectors} #define END_POINT_TRANSFER_PUT(t, ns)\ { WS_DISP_TYPE_PUT, NULL, NULL, TRANSFER_ACTION_PUT, NULL,\ t##_TypeInfo, (WsProcType)t##_Put_EP, ns, NULL} #define END_POINT_TRANSFER_ENUMERATE(t, ns)\ { WS_DISP_TYPE_ENUMERATE, NULL, NULL, ENUM_ACTION_ENUMERATE, NULL,\ t##_TypeInfo, (WsProcType)t##_Enumerate_EP, ns, NULL} #define END_POINT_TRANSFER_RELEASE(t, ns)\ { WS_DISP_TYPE_RELEASE, NULL, NULL, ENUM_ACTION_RELEASE, NULL,\ t##_TypeInfo, (WsProcType)t##_Release_EP, ns, NULL} #define END_POINT_TRANSFER_PULL(t, ns)\ { WS_DISP_TYPE_PULL, NULL, NULL, ENUM_ACTION_PULL, NULL,\ t##_TypeInfo, (WsProcType)t##_Pull_EP, ns, NULL} #define END_POINT_TRANSFER_PULL_RAW(t, ns)\ { WS_DISP_TYPE_PULL_RAW, NULL, NULL, ENUM_ACTION_PULL, NULL,\ t##_TypeInfo, (WsProcType)t##_Pull_EP, ns, NULL} #define END_POINT_PRIVATE_EP(t, a, m, ns) \ { WS_DISP_TYPE_PRIVATE, NULL, NULL, a, NULL, \ t##_TypeInfo, (WsProcType)t##_##m##_EP, ns, NULL } #define END_POINT_LAST { 0, NULL, NULL, NULL, NULL, NULL, NULL, NULL } #define SER_START_END_POINTS(t) WsDispatchEndPointInfo t##_EndPoints[] = { #define SER_FINISH_END_POINTS(t) END_POINT_LAST } These macros are used to create an array that describes all endpoints in this class for example: SER_START_END_POINTS(WsManThis) END_POINT_TRANSFER_GET(WsManThis, XML_NS_WS_MAN"/this"), SER_FINISH_END_POINTS(WsManThis); After the preprocessing stage, the result is: WsDispatchEndPointInfo WsManThis_EndPoints[] = { { 1, 0, 0, "http://schemas.xmlsoap.org/ws/2004/09/transfer/Get", WsManThis_TypeInfo, (WsProcType)WsManThis_Get_EP, "http://schemas.xmlsoap.org/ws/2005/06/management/this", WsMan_Get_Selectors}, { 0, 0, 0, 0, 0, 0, 0, 0 }}; ================================================================================ 3. write a plugin ~~~~~~~~~~~~~~~~~ requisite interfaces: int init(GModule *self, void **data); parameters: self a pointer to this module data reference to a user data structure. used to initial this plugin. return value: On error, 0 is returned, On success, a no_zerro value is returned. After loading a plugin, The Plugin Framework use this interface to initialize this plugin. ================================================================================ void get_endpoints(GModule *self, void **data); parameters: self a pointer to this module data reference to a WsDispatchEndPointInfo structure. This is the only way that the plugin framework collects all endpoints information about this plugin, so in this interface body, the plugin should initialize the WsDispatchEndPointInfo structre pointed by data. for example: void get_endpoints(GModule *self, void **data) { WsDispatchInterfaceInfo *itf = (WsDispatchInterfaceInfo *)*data; itf->flags = 0; itf->actionUriBase = XML_NS_WS_MAN; itf->wsmanSystemUri = NULL; itf->wsmanResourceUri = WS_MAN_THIS_RESOURCE_URI; itf->extraData = NULL; itf->endPoints = WsManThis_EndPoints; } ================================================================================ optional interface: void cleanup( GModule *self, void *data ); parameters: self a pointer to this module data reference to a user data structure. When the Plugin Framework free a plugin, it call this interface. ================================================================================ endpoint action interface: xxx* xxx_Get_EP(WsContextH cntx); parameter: cntx: It is a context about this require. The plugin can get some useful information from cntx, such as selector. return value: The xxx structure is declared in this plugin, it is invisible to the framework, but its fields must be identical with the items of an array with name StateDescription_TypeInfo The Plugin Framework call this api to get all properties of this resource. ================================================================================ int xxx_Put_EP(WsContextH cntx, void *data, void **outData) parameter: cntx: It is a context about this require. The plugin can get some useful information from cntx, such as selector. data: BTD outDdata: reference to buffer, used to store response information from plugin. return value: On success, return 0, on error, return non-zero value. The Plugin Framework call this api to model an update of an entire item. ================================================================================ int xxx_Enumerate_EP(WsContextH cntx, WsEnumerateInfo* enumInfo); parameter: cntx: It is a context about this require. The plugin can get some useful information from cntx, such as selector. enumInfo: output parameter. return value: On success, return 0, on error, reuturn non-zero value. The Plugin Framework call this api to begin an enumeration or query. ================================================================================ int xxx_Release_EP(WsContextH cntx, WsEnumerateInfo* enumInfo); parameter: cntx: It is a context about this require. The plugin can get some useful information from cntx, such as selector. enumInfo: the index field specifies an instance. return value: On success, return 0, on error, reuturn non-zero value. The Plugin Framework call this api to release an active enumerator ================================================================================ int xxx_Pull_EP(WsContextH cntx, WsEnumerateInfo* enumInfo); parameter: cntx: It is a context about this require. The plugin can get some useful information from cntx, such as selector. enumInfo: specify the enumeration information return value: On success, return 0, on error, reuturn non-zero value. The Plugin Framework call this api to retrieve the next batch of result from enumeration ================================================================================ int xxx_xxx_EP(SoapOpH soaph, void *data); parameter: soaph: pointer to a SOAP_OP_ENTRY structure, The plugin can get the context info from this pointer. data: pointer to this endpoint structure. We add a private endpoint to this plugin by 'The 'END_POINT_PRIVATE_EP' macro, WS_DISP_TYPE_PRIVATE flag is assigned to this endpoint. A function whose prototype is like as 'int xxx_xxx_EP(SoapOpH soaph, void *data)' is needed. The Plugin Framework will call this api to realize plugin's private action. for example: #define CATCH_RESP "CatchResponse" #define PLUGIN_INFO "This plugin is designed for IPMI_SEL class" int IpmiSel_Catch_EP(SoapOpH op, void* appData) { wsman_debug (WSMAN_DEBUG_LEVEL_DEBUG, "Catch Endpoint Called"); // get the context from op SoapH soap = soap_get_op_soap(op); WsContextH cntx = ws_create_ep_context(soap, soap_get_op_doc(op, 1)); // get endpoint information WsDispatchEndPointInfo* info = (WsDispatchEndPointInfo*)appData; XmlSerializerInfo* typeInfo = info->serializationInfo; void* data; WsXmlDocH doc = NULL; // add some code for private endpoint // create response doc wsman_debug (WSMAN_DEBUG_LEVEL_ERROR, "Creating Response doc"); doc = ws_create_response_envelope(cntx, soap_get_op_doc(op, 1), NULL); if ( doc ) { WsXmlNodeH body = ws_xml_get_soap_body(doc); WsXmlNodeH node = ws_xml_add_child(body, XML_NS_DOEM_TEST, CATCH_RESP, PLUGIN_INFO); } if ( doc ) { wsman_debug (WSMAN_DEBUG_LEVEL_ERROR, "Setting operation document"); soap_set_op_doc(op, doc, 0); soap_submit_op(op, soap_get_op_channel_id(op), NULL); ws_xml_destroy_doc(doc); } ws_serializer_free_all(cntx); return 0; } openwsman-2.4.3/RPMNAME000664 001750 001750 00000000012 12256012305 015010 0ustar00kentbkentb000000 000000 openwsman openwsman-2.4.3/tests/client/test_subscribe.c000664 001750 001750 00000021107 12256012305 021602 0ustar00kentbkentb000000 000000 /******************************************************************************* * 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 Liang Hou */ #include "wsman_config.h" #include #include #include #include #include #include #include "u/libu.h" #include "wsman-client-api.h" #include "wsman-client-transport.h" //int facility = LOG_DAEMON; int errors = 0; char *host = "langley.home.planux.com"; typedef struct { const char *server; int port; const char *path; const char *scheme; const char *username; const char *password; } ServerData; typedef struct { /* Explanation of what you should see */ const char *explanation; /* Resource UR to test against */ const char *resource_uri; /* Selectors in the form of a URI query key=value&key2=value2 */ char *selectors; int deliverymode; char *deliveryNotifyTo; char *deliveryEndTo; char *dialect; char *filter; int expiration; int heartbeat; int sendbookmark; char *referenceXML; const char* xpath_expression; char* expected_value; /* What the final status code should be. */ unsigned int final_status; unsigned int auth_data; } TestData; ServerData sd[] = { {"localhost", 5985, "/wsman", "http", "wsman", "secret"} }; TestData tests[] = { { "Subscribe to the server (push mode)", "http://schema.openwsman.org/2006/openwsman/test", NULL, 0, "http://localhost:80/eventsink", NULL, "http://schemas.microsoft.com/wbem/wsman/1/WQL", "select * from CIM_ProcessIndication", 0, 2, 0, NULL, "/s:Envelope/s:Body/wse:SubscribeResponse/wse:SubscriptionManager/wsa:ReferenceParameters/wse:Identifier", "uuid:", 200, 0 }, { "Subscribe to the server (pushwithack mode)", "http://schema.openwsman.org/2006/openwsman/test", NULL, 1, "http://localhost:80/eventsink", NULL, "http://schemas.microsoft.com/wbem/wsman/1/WQL", "select * from CIM_ProcessIndication", 3600, 0, 0, NULL, "/s:Envelope/s:Body/wse:SubscribeResponse/wse:SubscriptionManager/wsa:ReferenceParameters/wse:Identifier", "uuid:", 200, 0 }, { "Subscribe to the server (events mode)", "http://schema.openwsman.org/2006/openwsman/test", NULL, 2, "http://localhost:80/eventsink", NULL, "http://schemas.microsoft.com/wbem/wsman/1/WQL", "select * from CIM_ProcessIndication", 3600, 0, 0, NULL, "/s:Envelope/s:Body/wse:SubscribeResponse/wse:SubscriptionManager/wsa:ReferenceParameters/wse:Identifier", "uuid:", 200, 0 }, { "Subscribe to the server (pull mode)", "http://schema.openwsman.org/2006/openwsman/test", NULL, 3, "http://localhost:80/eventsink", NULL, "http://schemas.microsoft.com/wbem/wsman/1/WQL", "select * from CIM_ProcessIndication", 3600, 0, 0, NULL, "/s:Envelope/s:Body/wse:SubscribeResponse/wsen:EnumerationContext", "uuid:", 200, 0 }, { "Subscribe to the server (with invalid NotifyTo URL)", "http://schema.openwsman.org/2006/openwsman/test", NULL, 0, "localhost:80/eventsink", NULL, "http://schemas.microsoft.com/wbem/wsman/1/WQL", "select * from CIM_ProcessIndication", 3600, 0, 0, NULL, "/s:Envelope/s:Body/s:Fault/s:Code/s:Subcode/s:Value", "wsmb:DevliveryToUnusable", 500, 0 }, { "Subscribe to the server (with unsupported Dialect)", "http://schema.openwsman.org/2006/openwsman/test", NULL, 0, "http://localhost:80/eventsink", NULL, "http://schemas.microsoft.com/wbem/wsman/1/WQL2", "select * from CIM_ProcessIndication", 3600, 0, 0, NULL, "/s:Envelope/s:Body/s:Fault/s:Code/s:Subcode/s:Value", "wse:FilteringNotSupported", 400, 0 } }; int ntests = sizeof (tests) / sizeof (tests[0]); #if 0 static void wsman_output(WsXmlDocH doc) { ws_xml_dump_node_tree(stdout, ws_xml_get_doc_root(doc)); return; } #endif int main(int argc, char** argv) { int i; WsManClient *cl; WsXmlDocH doc; client_opt_t *options = NULL; filter_t *filter = NULL; if (getenv("OPENWSMAN_TEST_HOST")) { host = getenv("OPENWSMAN_TEST_HOST"); } for (i = 0; i < ntests; i++) { if (tests[i].selectors) { tests[i].selectors = u_strdup_printf(tests[i].selectors, host, host, host); } if (tests[i].expected_value) { tests[i].expected_value = u_strdup_printf(tests[i].expected_value, host, host, host); } printf ("Test %3d: %s ", i + 1, tests[i].explanation); cl = wsmc_create( sd[0].server, sd[0].port, sd[0].path, sd[0].scheme, sd[0].username, sd[0].password); wsmc_transport_init(cl, NULL); options = wsmc_options_init(); if (tests[i].selectors != NULL) wsmc_add_selectors_from_str (options, tests[i].selectors); if (tests[i].deliveryNotifyTo) options->delivery_uri = u_strdup(tests[i].deliveryNotifyTo); options->delivery_mode = tests[i].deliverymode; if(tests[i].sendbookmark) wsmc_set_action_option(options, FLAG_EVENT_SENDBOOKMARK); if(tests[i].heartbeat) options->heartbeat_interval = tests[i].heartbeat; if(tests[i].expiration) options->expires = tests[i].expiration; if(tests[i].referenceXML) options->reference = u_strdup(tests[i].referenceXML); if(tests[i].filter) filter = filter_create_simple(tests[i].dialect, tests[i].filter); doc = wsmc_action_subscribe(cl, tests[i].resource_uri, options, filter); if(!doc) { printf("\t\t\033[22;32msend request error!\033[m\n"); goto CONTINUE; } if (tests[i].final_status != wsmc_get_response_code(cl)) { printf("Status = %ld \t\t\033[22;31mFAILED\033[m\n", wsmc_get_response_code(cl)); goto CONTINUE; } if ((char *)tests[i].expected_value != NULL) { char *xp = ws_xml_get_xpath_value(doc, (char *)tests[i].xpath_expression); if (xp) { if (strncmp(xp,(char *)tests[i].expected_value, strlen((char *)tests[i].expected_value)) == 0) printf("\t\t\033[22;32mPASSED\033[m\n"); else printf("%s = %s\t\033[22;31mFAILED\033[m\n",(char *)tests[i].xpath_expression, xp); u_free(xp); } else { ws_xml_dump_node_tree(stdout, ws_xml_get_doc_root(doc)); printf(" No %s\t\033[22;31mFAILED\033[m\n", (char *)tests[i].xpath_expression); } } else { printf("\t\t\033[22;32mPASSED\033[m\n"); } ws_xml_destroy_doc(doc); CONTINUE: u_free(tests[i].selectors); u_free(tests[i].expected_value); wsmc_options_destroy(options); wsmc_release(cl); } return 0; } openwsman-2.4.3/src/plugins/redirect/redirect-README000664 001750 001750 00000003667 12256012305 022541 0ustar00kentbkentb000000 000000 While configuring the details for redirection, the following formats are to be used: i) in openwsman.conf file (the main configuration file) you can have a section like the following: [redirect] #server field is mandatory server='a.b.c.d' #resource field is mandatory resource='http://schemas.example.com/wbem/wscim/1/cim-schema/2' #the remaining fields below are optional. If not provides, these fields will be imported from main wsman command or defaults # username and password will be imported from the main wsman request username='user1' password='password' #default for url_path is '/wsman' url_path='/wsman' #default for authentication_method is basic authentication_method='basic' #default for cim_namespace is root/cimv2 cim_namespace='root/cimv2' #Default value of cacert is NULL. While talking to a remote WSMAN server over SSL, this has to be assigned some value. If not assigned some value, the redirection will fail. cacert='/etc/dummy.cert' #default of 5985 is used. port=5985 #Default vaule is 0 noverifypeer=0 #default value is 0 noverifyhost=0 #default value is NULL sslkey=NULL #default value is NULL cl_cert=NULL ii)In order to hide the sensitive username and password details better, you can include a new file to the openwsman.conf as follows [redirect] include='/etc/openwsman/redirect.conf' You can make the new conf file, only root read-only and hide the sensitive info better. The new redirect.conf file will capture the details in the following format: server='a.b.c.d' resource='http://schemas.example.com/wbem/wscim/1/cim-schema/2' username='user1' password='password' url_path='/wsman' authentication_method='basic' cim_namespace='root/cimv2' cacert='/etc/dummy.cert' port=5985 noverifypeer=0 noverifyhost=0 sslkey=NULL cl_cert=NULL All the above options are simila to the corresponding options provided to wsman program (in wsmancli package). Please refer to documentation in wsmancli for more details on each option. openwsman-2.4.3/src/authenticators/CMakeLists.txt000664 001750 001750 00000000257 12256012305 022365 0ustar00kentbkentb000000 000000 # # CMakeLists.txt for openwsman/src/authenticators # include_directories(${CMAKE_BINARY_DIR}) add_subdirectory(file) IF( HAVE_PAM ) add_subdirectory(pam) ENDIF( HAVE_PAM ) openwsman-2.4.3/package/openwsman.service.in000664 001750 001750 00000000250 12256012305 021363 0ustar00kentbkentb000000 000000 [Unit] Description=Openwsman WS-Management Service After=syslog.target [Service] Type=forking ExecStart=@prefix@/sbin/openwsmand [Install] WantedBy=multi-user.target openwsman-2.4.3/src/lib/u/LICENSE000664 001750 001750 00000003017 12256012305 016604 0ustar00kentbkentb000000 000000 LibU - Copyright (c) 2005, 2006 by KoanLogic srl 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 the KoanLogic srl 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 THE COPYRIGHT OWNER OR 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. openwsman-2.4.3/src/plugins/wsman/000775 001750 001750 00000000000 12256012305 017372 5ustar00kentbkentb000000 000000 openwsman-2.4.3/include/u/buf.h000664 001750 001750 00000001347 12256012305 016616 0ustar00kentbkentb000000 000000 #ifndef _U_LIBU_BUF_H_ #define _U_LIBU_BUF_H_ #include #ifdef HAVE_UNISTD_H #include #endif struct u_buf_s; typedef struct u_buf_s u_buf_t; int u_buf_append(u_buf_t *buf, void *data, size_t size); int u_buf_clear(u_buf_t *buf); int u_buf_detach(u_buf_t *buf); int u_buf_set(u_buf_t *buf, void *data, size_t size); int u_buf_load(u_buf_t *buf, char *fqn); int u_buf_free(u_buf_t *buf); int u_buf_create(u_buf_t **pbuf); int u_buf_reserve(u_buf_t *buf, size_t size); void* u_buf_ptr(u_buf_t *buf); size_t u_buf_len(u_buf_t *buf); void u_buf_set_len(u_buf_t *buf, size_t len); size_t u_buf_size(u_buf_t *buf); int u_buf_construct(u_buf_t *buf, void *ptr, size_t size, size_t len); char *u_buf_steal(u_buf_t *ubuf); #endif openwsman-2.4.3/doc/LICENSE.shttpd000664 001750 001750 00000002171 12256012305 017055 0ustar00kentbkentb000000 000000 /* * Copyright (c) 2004-2005 Sergey Lyubka * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), * to deal in the Software without restriction, including without limitation * the rights to use, copy, modify, merge, publish, distribute, sublicense, * and/or sell copies of the Software, and to permit persons to whom the * Software is furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included * in all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER * DEALINGS IN THE SOFTWARE. */ openwsman-2.4.3/NEWS000664 001750 001750 00000000000 12256012305 014462 0ustar00kentbkentb000000 000000 openwsman-2.4.3/src/lib/u/md5.c000664 001750 001750 00000030714 12256012305 016434 0ustar00kentbkentb000000 000000 /* Copyright (C) 1999, 2000, 2002 Aladdin Enterprises. All rights reserved. This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages arising from the use of this software. Permission is granted to anyone to use this software for any purpose, including commercial applications, and to alter it and redistribute it freely, subject to the following restrictions: 1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required. 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. 3. This notice may not be removed or altered from any source distribution. L. Peter Deutsch ghost@aladdin.com */ /* $Id: md5.c,v 1.6 2002/04/13 19:20:28 lpd Exp $ */ /* Independent implementation of MD5 (RFC 1321). This code implements the MD5 Algorithm defined in RFC 1321, whose text is available at http://www.ietf.org/rfc/rfc1321.txt The code is derived from the text of the RFC, including the test suite (section A.5) but excluding the rest of Appendix A. It does not include any code or documentation that is identified in the RFC as being copyrighted. The original and principal author of md5.c is L. Peter Deutsch . Other authors are noted in the change history that follows (in reverse chronological order): 2002-04-13 lpd Clarified derivation from RFC 1321; now handles byte order either statically or dynamically; added missing #include in library. 2002-03-11 lpd Corrected argument list for main(), and added int return type, in test program and T value program. 2002-02-21 lpd Added missing #include in test program. 2000-07-03 lpd Patched to eliminate warnings about "constant is unsigned in ANSI C, signed in traditional"; made test program self-checking. 1999-11-04 lpd Edited comments slightly for automatic TOC extraction. 1999-10-18 lpd Fixed typo in header comment (ansi2knr rather than md5). 1999-05-03 lpd Original version. */ #include "u/md5.h" #include #undef BYTE_ORDER /* 1 = big-endian, -1 = little-endian, 0 = unknown */ #ifdef ARCH_IS_BIG_ENDIAN # define BYTE_ORDER (ARCH_IS_BIG_ENDIAN ? 1 : -1) #else # define BYTE_ORDER 0 #endif #define T_MASK ((md5_word_t)~0) #define T1 /* 0xd76aa478 */ (T_MASK ^ 0x28955b87) #define T2 /* 0xe8c7b756 */ (T_MASK ^ 0x173848a9) #define T3 0x242070db #define T4 /* 0xc1bdceee */ (T_MASK ^ 0x3e423111) #define T5 /* 0xf57c0faf */ (T_MASK ^ 0x0a83f050) #define T6 0x4787c62a #define T7 /* 0xa8304613 */ (T_MASK ^ 0x57cfb9ec) #define T8 /* 0xfd469501 */ (T_MASK ^ 0x02b96afe) #define T9 0x698098d8 #define T10 /* 0x8b44f7af */ (T_MASK ^ 0x74bb0850) #define T11 /* 0xffff5bb1 */ (T_MASK ^ 0x0000a44e) #define T12 /* 0x895cd7be */ (T_MASK ^ 0x76a32841) #define T13 0x6b901122 #define T14 /* 0xfd987193 */ (T_MASK ^ 0x02678e6c) #define T15 /* 0xa679438e */ (T_MASK ^ 0x5986bc71) #define T16 0x49b40821 #define T17 /* 0xf61e2562 */ (T_MASK ^ 0x09e1da9d) #define T18 /* 0xc040b340 */ (T_MASK ^ 0x3fbf4cbf) #define T19 0x265e5a51 #define T20 /* 0xe9b6c7aa */ (T_MASK ^ 0x16493855) #define T21 /* 0xd62f105d */ (T_MASK ^ 0x29d0efa2) #define T22 0x02441453 #define T23 /* 0xd8a1e681 */ (T_MASK ^ 0x275e197e) #define T24 /* 0xe7d3fbc8 */ (T_MASK ^ 0x182c0437) #define T25 0x21e1cde6 #define T26 /* 0xc33707d6 */ (T_MASK ^ 0x3cc8f829) #define T27 /* 0xf4d50d87 */ (T_MASK ^ 0x0b2af278) #define T28 0x455a14ed #define T29 /* 0xa9e3e905 */ (T_MASK ^ 0x561c16fa) #define T30 /* 0xfcefa3f8 */ (T_MASK ^ 0x03105c07) #define T31 0x676f02d9 #define T32 /* 0x8d2a4c8a */ (T_MASK ^ 0x72d5b375) #define T33 /* 0xfffa3942 */ (T_MASK ^ 0x0005c6bd) #define T34 /* 0x8771f681 */ (T_MASK ^ 0x788e097e) #define T35 0x6d9d6122 #define T36 /* 0xfde5380c */ (T_MASK ^ 0x021ac7f3) #define T37 /* 0xa4beea44 */ (T_MASK ^ 0x5b4115bb) #define T38 0x4bdecfa9 #define T39 /* 0xf6bb4b60 */ (T_MASK ^ 0x0944b49f) #define T40 /* 0xbebfbc70 */ (T_MASK ^ 0x4140438f) #define T41 0x289b7ec6 #define T42 /* 0xeaa127fa */ (T_MASK ^ 0x155ed805) #define T43 /* 0xd4ef3085 */ (T_MASK ^ 0x2b10cf7a) #define T44 0x04881d05 #define T45 /* 0xd9d4d039 */ (T_MASK ^ 0x262b2fc6) #define T46 /* 0xe6db99e5 */ (T_MASK ^ 0x1924661a) #define T47 0x1fa27cf8 #define T48 /* 0xc4ac5665 */ (T_MASK ^ 0x3b53a99a) #define T49 /* 0xf4292244 */ (T_MASK ^ 0x0bd6ddbb) #define T50 0x432aff97 #define T51 /* 0xab9423a7 */ (T_MASK ^ 0x546bdc58) #define T52 /* 0xfc93a039 */ (T_MASK ^ 0x036c5fc6) #define T53 0x655b59c3 #define T54 /* 0x8f0ccc92 */ (T_MASK ^ 0x70f3336d) #define T55 /* 0xffeff47d */ (T_MASK ^ 0x00100b82) #define T56 /* 0x85845dd1 */ (T_MASK ^ 0x7a7ba22e) #define T57 0x6fa87e4f #define T58 /* 0xfe2ce6e0 */ (T_MASK ^ 0x01d3191f) #define T59 /* 0xa3014314 */ (T_MASK ^ 0x5cfebceb) #define T60 0x4e0811a1 #define T61 /* 0xf7537e82 */ (T_MASK ^ 0x08ac817d) #define T62 /* 0xbd3af235 */ (T_MASK ^ 0x42c50dca) #define T63 0x2ad7d2bb #define T64 /* 0xeb86d391 */ (T_MASK ^ 0x14792c6e) static void md5_process(md5_state_t *pms, const md5_byte_t *data /*[64]*/) { md5_word_t a = pms->abcd[0], b = pms->abcd[1], c = pms->abcd[2], d = pms->abcd[3]; md5_word_t t; #if BYTE_ORDER > 0 /* Define storage only for big-endian CPUs. */ md5_word_t X[16]; #else /* Define storage for little-endian or both types of CPUs. */ md5_word_t xbuf[16]; const md5_word_t *X; #endif { #if BYTE_ORDER == 0 /* * Determine dynamically whether this is a big-endian or * little-endian machine, since we can use a more efficient * algorithm on the latter. */ static const int w = 1; if (*((const md5_byte_t *)&w)) /* dynamic little-endian */ #endif #if BYTE_ORDER <= 0 /* little-endian */ { /* * On little-endian machines, we can process properly aligned * data without copying it. */ if (!((data - (const md5_byte_t *)0) & 3)) { /* data are properly aligned */ X = (const md5_word_t *)data; } else { /* not aligned */ memcpy(xbuf, data, 64); X = xbuf; } } #endif #if BYTE_ORDER == 0 else /* dynamic big-endian */ #endif #if BYTE_ORDER >= 0 /* big-endian */ { /* * On big-endian machines, we must arrange the bytes in the * right order. */ const md5_byte_t *xp = data; int i; # if BYTE_ORDER == 0 X = xbuf; /* (dynamic only) */ # else # define xbuf X /* (static only) */ # endif for (i = 0; i < 16; ++i, xp += 4) xbuf[i] = xp[0] + (xp[1] << 8) + (xp[2] << 16) + (xp[3] << 24); } #endif } #define ROTATE_LEFT(x, n) (((x) << (n)) | ((x) >> (32 - (n)))) /* Round 1. */ /* Let [abcd k s i] denote the operation a = b + ((a + F(b,c,d) + X[k] + T[i]) <<< s). */ #define F(x, y, z) (((x) & (y)) | (~(x) & (z))) #define SET(a, b, c, d, k, s, Ti)\ t = a + F(b,c,d) + X[k] + Ti;\ a = ROTATE_LEFT(t, s) + b /* Do the following 16 operations. */ SET(a, b, c, d, 0, 7, T1); SET(d, a, b, c, 1, 12, T2); SET(c, d, a, b, 2, 17, T3); SET(b, c, d, a, 3, 22, T4); SET(a, b, c, d, 4, 7, T5); SET(d, a, b, c, 5, 12, T6); SET(c, d, a, b, 6, 17, T7); SET(b, c, d, a, 7, 22, T8); SET(a, b, c, d, 8, 7, T9); SET(d, a, b, c, 9, 12, T10); SET(c, d, a, b, 10, 17, T11); SET(b, c, d, a, 11, 22, T12); SET(a, b, c, d, 12, 7, T13); SET(d, a, b, c, 13, 12, T14); SET(c, d, a, b, 14, 17, T15); SET(b, c, d, a, 15, 22, T16); #undef SET /* Round 2. */ /* Let [abcd k s i] denote the operation a = b + ((a + G(b,c,d) + X[k] + T[i]) <<< s). */ #define G(x, y, z) (((x) & (z)) | ((y) & ~(z))) #define SET(a, b, c, d, k, s, Ti)\ t = a + G(b,c,d) + X[k] + Ti;\ a = ROTATE_LEFT(t, s) + b /* Do the following 16 operations. */ SET(a, b, c, d, 1, 5, T17); SET(d, a, b, c, 6, 9, T18); SET(c, d, a, b, 11, 14, T19); SET(b, c, d, a, 0, 20, T20); SET(a, b, c, d, 5, 5, T21); SET(d, a, b, c, 10, 9, T22); SET(c, d, a, b, 15, 14, T23); SET(b, c, d, a, 4, 20, T24); SET(a, b, c, d, 9, 5, T25); SET(d, a, b, c, 14, 9, T26); SET(c, d, a, b, 3, 14, T27); SET(b, c, d, a, 8, 20, T28); SET(a, b, c, d, 13, 5, T29); SET(d, a, b, c, 2, 9, T30); SET(c, d, a, b, 7, 14, T31); SET(b, c, d, a, 12, 20, T32); #undef SET /* Round 3. */ /* Let [abcd k s t] denote the operation a = b + ((a + H(b,c,d) + X[k] + T[i]) <<< s). */ #define H(x, y, z) ((x) ^ (y) ^ (z)) #define SET(a, b, c, d, k, s, Ti)\ t = a + H(b,c,d) + X[k] + Ti;\ a = ROTATE_LEFT(t, s) + b /* Do the following 16 operations. */ SET(a, b, c, d, 5, 4, T33); SET(d, a, b, c, 8, 11, T34); SET(c, d, a, b, 11, 16, T35); SET(b, c, d, a, 14, 23, T36); SET(a, b, c, d, 1, 4, T37); SET(d, a, b, c, 4, 11, T38); SET(c, d, a, b, 7, 16, T39); SET(b, c, d, a, 10, 23, T40); SET(a, b, c, d, 13, 4, T41); SET(d, a, b, c, 0, 11, T42); SET(c, d, a, b, 3, 16, T43); SET(b, c, d, a, 6, 23, T44); SET(a, b, c, d, 9, 4, T45); SET(d, a, b, c, 12, 11, T46); SET(c, d, a, b, 15, 16, T47); SET(b, c, d, a, 2, 23, T48); #undef SET /* Round 4. */ /* Let [abcd k s t] denote the operation a = b + ((a + I(b,c,d) + X[k] + T[i]) <<< s). */ #define I(x, y, z) ((y) ^ ((x) | ~(z))) #define SET(a, b, c, d, k, s, Ti)\ t = a + I(b,c,d) + X[k] + Ti;\ a = ROTATE_LEFT(t, s) + b /* Do the following 16 operations. */ SET(a, b, c, d, 0, 6, T49); SET(d, a, b, c, 7, 10, T50); SET(c, d, a, b, 14, 15, T51); SET(b, c, d, a, 5, 21, T52); SET(a, b, c, d, 12, 6, T53); SET(d, a, b, c, 3, 10, T54); SET(c, d, a, b, 10, 15, T55); SET(b, c, d, a, 1, 21, T56); SET(a, b, c, d, 8, 6, T57); SET(d, a, b, c, 15, 10, T58); SET(c, d, a, b, 6, 15, T59); SET(b, c, d, a, 13, 21, T60); SET(a, b, c, d, 4, 6, T61); SET(d, a, b, c, 11, 10, T62); SET(c, d, a, b, 2, 15, T63); SET(b, c, d, a, 9, 21, T64); #undef SET /* Then perform the following additions. (That is increment each of the four registers by the value it had before this block was started.) */ pms->abcd[0] += a; pms->abcd[1] += b; pms->abcd[2] += c; pms->abcd[3] += d; } void md5_init(md5_state_t *pms) { pms->count[0] = pms->count[1] = 0; pms->abcd[0] = 0x67452301; pms->abcd[1] = /*0xefcdab89*/ T_MASK ^ 0x10325476; pms->abcd[2] = /*0x98badcfe*/ T_MASK ^ 0x67452301; pms->abcd[3] = 0x10325476; } void md5_append(md5_state_t *pms, const md5_byte_t *data, int nbytes) { const md5_byte_t *p = data; int left = nbytes; int offset = (pms->count[0] >> 3) & 63; md5_word_t nbits = (md5_word_t)(nbytes << 3); if (nbytes <= 0) return; /* Update the message length. */ pms->count[1] += nbytes >> 29; pms->count[0] += nbits; if (pms->count[0] < nbits) pms->count[1]++; /* Process an initial partial block. */ if (offset) { int copy = (offset + nbytes > 64 ? 64 - offset : nbytes); memcpy(pms->buf + offset, p, copy); if (offset + copy < 64) return; p += copy; left -= copy; md5_process(pms, pms->buf); } /* Process full blocks. */ for (; left >= 64; p += 64, left -= 64) md5_process(pms, p); /* Process a final partial block. */ if (left) memcpy(pms->buf, p, left); } void md5_finish(md5_state_t *pms, md5_byte_t digest[16]) { static const md5_byte_t pad[64] = { 0x80, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; md5_byte_t data[8]; int i; /* Save the length before padding. */ for (i = 0; i < 8; ++i) data[i] = (md5_byte_t)(pms->count[i >> 2] >> ((i & 3) << 3)); /* Pad to 56 bytes mod 64. */ md5_append(pms, pad, ((55 - (pms->count[0] >> 3)) & 63) + 1); /* Append the length. */ md5_append(pms, data, 8); for (i = 0; i < 16; ++i) digest[i] = (md5_byte_t)(pms->abcd[i >> 2] >> ((i & 3) << 3)); } char *md52char(md5_byte_t digest[16]) { char ctbl[16]={'0','1','2','3','4','5','6','7','8','9','a','b','c','d','e','f'}; static char str[33]; int i; for(i=0;i<16;i++){ str[2*i]=ctbl[(digest[i]>>4)&0xf]; str[2*i+1]=ctbl[digest[i]&0xf]; } str[32]='\0'; return str; } openwsman-2.4.3/bindings/ruby/Gemfile000664 001750 001750 00000000031 12256012305 020040 0ustar00kentbkentb000000 000000 source :rubygems gemspec openwsman-2.4.3/src/plugins/swig/python/tests/CMakeLists.txt000664 001750 001750 00000000230 12256012305 024434 0ustar00kentbkentb000000 000000 # # CMakeLists.txt for plugins/swig/python/tests # ENABLE_TESTING() ADD_TEST(plugin_python_loading python ${CMAKE_CURRENT_SOURCE_DIR}/loading.py) openwsman-2.4.3/tests/serialization/ser1.c000664 001750 001750 00000014330 12256012305 021033 0ustar00kentbkentb000000 000000 #include #include #include #include #include #include #include "CUnit/Basic.h" #include "u/libu.h" #include "wsman-soap.h" #include "wsman-xml.h" #include "wsman-soap.h" #include "wsman-xml-serializer.h" #include "wsman-xml-serialize.h" #include "wsman-epr.h" #include "wsman-debug.h" #define CLASSNAME "Sample" /* The suite initialization function. * Opens the temporary file used by the tests. * Returns zero on success, non-zero otherwise. */ static int init_ser1(void) { return 0; } /* The suite cleanup function. * Closes the temporary file used by the tests. * Returns zero on success, non-zero otherwise. */ static int clean_ser1(void) { return 0; } static void test_basic_types(void) { #define EX1_NS "http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_ComputerSystem" XML_TYPE_UINT16 myshorts[] = { 5, 11, 14, 19, 27, 36 }; SER_TYPEINFO_UINT16; struct __Sample_Servie { XML_TYPE_BOOL AcceptPause; XML_TYPE_BOOL AcceptStop; XML_TYPE_STR Caption; XML_TYPE_UINT32 CheckPoint; XML_TYPE_STR CreationClassName; XML_TYPE_STR Description; XML_TYPE_BOOL DesktopInteract; XML_TYPE_STR DisplayName; XML_TYPE_STR ErrorControl; XML_TYPE_UINT32 ExitCode; XML_TYPE_STR InstallDate; XML_TYPE_STR Name; XML_TYPE_STR PathName; XML_TYPE_UINT32 ProcessId; XML_TYPE_UINT32 ServiceSpecificExitCode; XML_TYPE_STR ServiceType; XML_TYPE_BOOL Started; XML_TYPE_STR StartMode; XML_TYPE_STR StartName; XML_TYPE_STR State; XML_TYPE_STR Status; XML_TYPE_STR SystemCreationClassName; XML_TYPE_STR SystemName; XML_TYPE_UINT32 TagId; XML_TYPE_UINT32 WaitHint; XML_TYPE_UINT64 Uint64; XML_TYPE_DYN_ARRAY shorts; }; typedef struct __Sample_Servie Sample_Servie; Sample_Servie servie = { 0, 1, "Caption", 30, "CreationClassName", "Description", 1, "DisplayName", "ErrorControl", 50, "InstallDate", "Name", "PathName", 60, 70, "ServiceType", 0, "StartMode", "StartName", "State", "Status", "SystemCreationClassName", "SystemName", 90, 100, 1000000, {6, myshorts } }; SER_START_ITEMS(Sample_Servie) SER_BOOL("AcceptPause", 1), SER_BOOL("AcceptStop", 1), SER_STR("Caption", 1), SER_UINT32("CheckPoint", 1), SER_STR("CreationClassName", 1), SER_STR("Description", 1), SER_BOOL("DesktopInteract", 1), SER_NS_STR(EX1_NS, "DisplayName", 1), SER_STR("ErrorControl", 1), SER_UINT32("ExitCode", 1), SER_STR("InstallDate", 1), SER_STR("Name", 1), SER_STR("PathName", 1), SER_UINT32("ProcessId", 1), SER_UINT32("ServiceSpecificExitCode", 1), SER_STR("ServiceType", 1), SER_BOOL("Started", 1), SER_STR("StartMode", 1), SER_STR("StartName", 1), SER_STR("State", 1), SER_STR("Status", 1), SER_STR("SystemCreationClassName", 1), SER_STR("SystemName", 1), SER_UINT32("TagId", 1), SER_UINT32("WaitHint", 1), SER_UINT64("Uint64", 1), SER_DYN_ARRAY("shorts", 0, 1000, uint16), SER_END_ITEMS(Sample_Servie); WsContextH cntx; WsXmlDocH doc; WsXmlNodeH node; int retval; cntx = ws_create_runtime(NULL); CU_ASSERT_PTR_NOT_NULL(cntx); doc = ws_xml_create_doc(cntx->soap, NULL, "example"); node = ws_xml_get_doc_root(doc); retval = ws_serialize(cntx, node, &servie, Sample_Servie_TypeInfo, CLASSNAME, NULL, NULL, 0); //ws_xml_dump_node_tree(stdout, node); node = ws_xml_get_doc_root(doc); Sample_Servie *cs = (Sample_Servie *) ws_deserialize(cntx, node, Sample_Servie_TypeInfo, CLASSNAME, NULL, NULL, 0, 0); CU_ASSERT_PTR_NOT_NULL(cs); retval = memcmp(cs, &servie, sizeof(&servie)); if (!retval) { CU_ASSERT_EQUAL( servie.AcceptPause, cs->AcceptPause ); CU_ASSERT_EQUAL( servie.AcceptStop, cs->AcceptStop ); CU_TEST( !strcmp(servie.Caption, cs->Caption) ); } else { CU_FAIL("memcpy failed"); } } static void test_static_struct(void) { typedef struct { XML_TYPE_BOOL a; XML_TYPE_STR string; XML_TYPE_BOOL b; } Embed; typedef struct { XML_TYPE_UINT32 A; Embed EMBED[2]; XML_TYPE_STR STRING; } Sample; Sample sample = { 10, {{1, "string 1", 0}, {0, "string 2", 1},}, "STRING", }; SER_START_ITEMS(Embed) SER_BOOL("a", 1), SER_STR("string", 1), SER_BOOL("b", 1), SER_END_ITEMS(Embed); SER_START_ITEMS(Sample) SER_UINT32("A", 1), SER_STRUCT("EMBED", 2, Embed), SER_STR("STRING", 1), SER_END_ITEMS(Sample); WsContextH cntx; WsXmlDocH doc; WsXmlNodeH node; int retval; cntx = ws_create_runtime(NULL); CU_ASSERT_PTR_NOT_NULL(cntx); doc = ws_xml_create_doc(cntx->soap, NULL, "example"); CU_ASSERT_PTR_NOT_NULL(doc); node = ws_xml_get_doc_root(doc); CU_ASSERT_PTR_NOT_NULL(node); retval = ws_serialize(cntx, node, &sample, Sample_TypeInfo, CLASSNAME, NULL, NULL, 0); //ws_xml_dump_node_tree(stdout, node); node = ws_xml_get_doc_root(doc); Sample *sample_out = (Sample *) ws_deserialize(cntx, node, Sample_TypeInfo, CLASSNAME, NULL, NULL, 0, 0); CU_ASSERT_PTR_NOT_NULL(sample_out); CU_ASSERT_TRUE(sample_out->A == 10 ); CU_ASSERT_TRUE(sample_out->EMBED[0].a); CU_ASSERT_FALSE(sample_out->EMBED[1].a); } /* The main() function for setting up and running the tests. * Returns a CUE_SUCCESS on successful running, another * CUnit error code on failure. */ int main() { CU_pSuite pSuite = NULL; /* initialize the CUnit test registry */ if (CUE_SUCCESS != CU_initialize_registry()) return CU_get_error(); /* add a suite to the registry */ pSuite = CU_add_suite("Suite_1", init_ser1, clean_ser1); if (NULL == pSuite) { CU_cleanup_registry(); return CU_get_error(); } /* add the tests to the suite */ /* NOTE - ORDER IS IMPORTANT - MUST TEST fread() AFTER fprintf() */ if ( (NULL == CU_add_test(pSuite, "test of static struct array", test_static_struct)) || (NULL == CU_add_test(pSuite, "test of basic_types", test_basic_types)) ) { CU_cleanup_registry(); return CU_get_error(); } /* Run all tests using the CUnit Basic interface */ CU_basic_set_mode(CU_BRM_VERBOSE); CU_basic_run_tests(); CU_cleanup_registry(); return CU_get_error(); } openwsman-2.4.3/tests/xml/000775 001750 001750 00000000000 12256012305 015737 5ustar00kentbkentb000000 000000 openwsman-2.4.3/src/plugins/wsman/test2/Makefile.am000664 001750 001750 00000000563 12256012305 022473 0ustar00kentbkentb000000 000000 plugindir = @PACKAGE_PLUGIN_DIR@ libwsman_test2_la_SOURCES = \ wsman_test2.c \ wsman_test2_stubs.c \ wsman_test2.h INCLUDES = -I$(top_srcdir)/src/lib \ -I$(top_srcdir)/src/libu LIBS = \ $(XML_LIBS) plugin_LTLIBRARIES= libwsman_test2.la libwsman_test2_la_LIBADD = \ $(XML_LIBS) \ -lpthread libwsman_test2_la_LDFLAGS= -version-info 1:0 openwsman-2.4.3/tests/epr/Makefile.am000664 001750 001750 00000000543 12256012305 017763 0ustar00kentbkentb000000 000000 INCLUDES = \ $(XML_CFLAGS) \ -I$(top_srcdir) \ -I$(top_srcdir)/include LIBS = \ $(XML_LIBS) \ $(top_builddir)/src/lib/libwsman.la \ $(top_builddir)/src/lib/libwsman_client.la\ -lcunit test_epr_SOURCES = test_epr.c test_WsmanEPR_SOURCES = test_WsmanEPR.cpp noinst_PROGRAMS = \ test_epr\ test_WsmanEPR openwsman-2.4.3/src/server/shttpd/compat_unix.h000664 001750 001750 00000001653 12256012305 022104 0ustar00kentbkentb000000 000000 /* * Copyright (c) 2004-2007 Sergey Lyubka * All rights reserved * * "THE BEER-WARE LICENSE" (Revision 42): * Sergey Lyubka wrote this file. As long as you retain this notice you * can do whatever you want with this stuff. If we meet some day, and you think * this stuff is worth it, you can buy me a beer in return. */ #include #include #include #include #include #include #include #include #include #include #include #ifndef SSL_LIB #define SSL_LIB "libssl.so" #endif #define DIRSEP '/' #define IS_DIRSEP_CHAR(c) ((c) == '/') #define O_BINARY 0 #define closesocket(a) close(a) #define ERRNO errno #define NO_GUI #define InitializeCriticalSection(x) /* FIXME UNIX version is not MT safe */ #define EnterCriticalSection(x) #define LeaveCriticalSection(x) openwsman-2.4.3/src/server/shttpd/compat_unix.c000664 001750 001750 00000004405 12256012305 022075 0ustar00kentbkentb000000 000000 /* * Copyright (c) 2004-2005 Sergey Lyubka * All rights reserved * * "THE BEER-WARE LICENSE" (Revision 42): * Sergey Lyubka wrote this file. As long as you retain this notice you * can do whatever you want with this stuff. If we meet some day, and you think * this stuff is worth it, you can buy me a beer in return. */ #include "shttpd_defs.h" void set_close_on_exec(int fd) { (void) fcntl(fd, F_SETFD, FD_CLOEXEC); } int my_stat(const char *path, struct stat *stp) { return (stat(path, stp)); } int my_open(const char *path, int flags, int mode) { return (open(path, flags, mode)); } int my_remove(const char *path) { return (remove(path)); } int my_rename(const char *path1, const char *path2) { return (rename(path1, path2)); } int my_mkdir(const char *path, int mode) { return (mkdir(path, mode)); } char * my_getcwd(char *buffer, int maxlen) { return (getcwd(buffer, maxlen)); } int set_non_blocking_mode(int fd) { int ret = -1; int flags; if ((flags = fcntl(fd, F_GETFL, 0)) == -1) { DBG(("nonblock: fcntl(F_GETFL): %d", ERRNO)); } else if (fcntl(fd, F_SETFL, flags | O_NONBLOCK) != 0) { DBG(("nonblock: fcntl(F_SETFL): %d", ERRNO)); } else { ret = 0; /* Success */ } return (ret); } #ifndef NO_CGI int spawn_process(struct conn *c, const char *prog, char *envblk, char *envp[], int sock, const char *dir) { int ret; pid_t pid; envblk = NULL; /* unused */ if ((pid = vfork()) == -1) { ret = -1; elog(E_LOG, c, "redirect: fork: %s", strerror(errno)); } else if (pid == 0) { /* Child */ (void) chdir(dir); (void) dup2(sock, 0); (void) dup2(sock, 1); (void) closesocket(sock); /* If error file is specified, send errors there */ if (c->ctx->error_log) (void) dup2(fileno(c->ctx->error_log), 2); /* Execute CGI program */ if (c->ctx->cgi_interpreter == NULL) { (void) execle(prog, prog, NULL, envp); elog(E_FATAL, c, "redirect: exec(%s)", prog); } else { (void) execle(c->ctx->cgi_interpreter, c->ctx->cgi_interpreter, prog, NULL, envp); elog(E_FATAL, c, "redirect: exec(%s %s)", c->ctx->cgi_interpreter, prog); } /* UNREACHED */ ret = -1; exit(EXIT_FAILURE); } else { /* Parent */ ret = 0; (void) closesocket(sock); } return (ret); } #endif /* !NO_CGI */ openwsman-2.4.3/package/000775 001750 001750 00000000000 12256012305 015370 5ustar00kentbkentb000000 000000 openwsman-2.4.3/etc/init/.cvsignore000664 001750 001750 00000000037 12256012305 017513 0ustar00kentbkentb000000 000000 Makefile.in Makefile wsmand.sh openwsman-2.4.3/src/plugins/swig/ruby/tests/CMakeLists.txt000664 001750 001750 00000000235 12256012305 024101 0ustar00kentbkentb000000 000000 # # CMakeLists.txt for openwsman/src/plugins/swig/ruby/test # ENABLE_TESTING() ADD_TEST(plugin_ruby_loading ruby -C ${CMAKE_CURRENT_SOURCE_DIR} loading.rb ) openwsman-2.4.3/include/u/list.h000664 001750 001750 00000015241 12256012305 017013 0ustar00kentbkentb000000 000000 /* * List Abstract Data Type * Copyright (C) 1997 Kaz Kylheku * * Free Software License: * * All rights are reserved by the author, with the following exceptions: * Permission is granted to freely reproduce and distribute this software, * possibly in exchange for a fee, provided that this copyright notice appears * intact. Permission is also granted to adapt this software to produce * derivative works, as long as the modified versions carry this copyright * notice and additional notices stating that the work has been modified. * This source code may be translated into executable form and incorporated * into proprietary software; there is no requirement for such software to * contain a copyright notice related to this source. * * $Id: list.h,v 1.19 1999/11/14 20:46:19 kaz Exp $ * $Name: kazlib_1_20 $ */ #ifndef LIST_H #define LIST_H #include #ifdef KAZLIB_SIDEEFFECT_DEBUG #include "sfx.h" #define LIST_SFX_CHECK(E) SFX_CHECK(E) #else #define LIST_SFX_CHECK(E) (E) #endif /* * Blurb for inclusion into C++ translation units */ #ifdef __cplusplus extern "C" { #endif typedef unsigned long listcount_t; #define LISTCOUNT_T_MAX ULONG_MAX typedef struct lnode_t { #if defined(LIST_IMPLEMENTATION) || !defined(KAZLIB_OPAQUE_DEBUG) struct lnode_t *list_next; struct lnode_t *list_prev; void *list_data; #else int list_dummy; #endif } lnode_t; typedef struct lnodepool_t { #if defined(LIST_IMPLEMENTATION) || !defined(KAZLIB_OPAQUE_DEBUG) struct lnode_t *list_pool; struct lnode_t *list_free; listcount_t list_size; #else int list_dummy; #endif } lnodepool_t; typedef struct list_t { #if defined(LIST_IMPLEMENTATION) || !defined(KAZLIB_OPAQUE_DEBUG) lnode_t list_nilnode; listcount_t list_nodecount; listcount_t list_maxcount; #else int list_dummy; #endif } list_t; lnode_t *ow_lnode_create(void *); lnode_t *ow_lnode_init(lnode_t *, void *); void ow_lnode_destroy(lnode_t *); void ow_lnode_put(lnode_t *, void *); void *ow_lnode_get(lnode_t *); int ow_lnode_is_in_a_list(lnode_t *); #if defined(LIST_IMPLEMENTATION) || !defined(KAZLIB_OPAQUE_DEBUG) #define lnode_put(N, D) ((N)->list_data = (D)) #define lnode_get(N) ((N)->list_data) #else #define lnode_put ow_lnode_put #define lnode_get ow_lnode_get #endif lnodepool_t *ow_lnode_pool_init(lnodepool_t *, lnode_t *, listcount_t); lnodepool_t *ow_lnode_pool_create(listcount_t); void ow_lnode_pool_destroy(lnodepool_t *); lnode_t *ow_lnode_borrow(lnodepool_t *, void *); void ow_lnode_return(lnodepool_t *, lnode_t *); int ow_lnode_pool_isempty(lnodepool_t *); int ow_lnode_pool_isfrom(lnodepool_t *, lnode_t *); list_t *ow_list_create(listcount_t); /* list_t *ow_list_init(list_t *list, listcount_t maxcount); */ void ow_list_destroy(list_t *); void ow_list_destroy_nodes(list_t *); void ow_list_return_nodes(list_t *, lnodepool_t *); listcount_t ow_list_count(list_t *); int ow_list_isempty(list_t *); int ow_list_isfull(list_t *); int ow_list_contains(list_t *, lnode_t *); void ow_list_append(list_t *, lnode_t *); void ow_list_prepend(list_t *, lnode_t *); void ow_list_ins_before(list_t *, lnode_t *, lnode_t *); void ow_list_ins_after(list_t *, lnode_t *, lnode_t *); lnode_t *ow_list_first(list_t *); lnode_t *ow_list_last(list_t *); lnode_t *ow_list_next(list_t *, lnode_t *); lnode_t *ow_list_prev(list_t *, lnode_t *); lnode_t *ow_list_del_first(list_t *); lnode_t *ow_list_del_last(list_t *); lnode_t *ow_list_delete(list_t *, lnode_t *); lnode_t *ow_list_delete2(list_t *, lnode_t *); void ow_list_process(list_t *, void *, void (*)(list_t *, lnode_t *, void *)); int ow_list_verify(list_t *); #define lnode_create ow_lnode_create #define lnode_init ow_lnode_init #define lnode_destroy ow_lnode_destroy #define lnode_is_in_a_list ow_lnode_is_in_a_list #define lnode_pool_init ow_lnode_pool_init #define lnode_pool_create ow_lnode_pool_create #define lnode_pool_destroy ow_lnode_pool_destroy #define lnode_borrow ow_lnode_borrow #define lnode_return ow_lnode_return #define lnode_pool_isfrom ow_lnode_pool_isfrom #define list_create ow_list_create #define list_init ow_list_init #define list_destroy ow_list_destroy #define list_destroy_nodes ow_list_destroy_nodes #define list_return_nodes ow_list_return_nodes #define list_contains ow_list_contains #define list_ins_before ow_list_ins_before #define list_ins_after ow_list_ins_after #define list_delete ow_list_delete #define list_delete2 ow_list_delete2 #define list_process ow_list_process #define list_verify ow_list_verify #if defined(LIST_IMPLEMENTATION) || !defined(KAZLIB_OPAQUE_DEBUG) #define lnode_pool_isempty(P) ((P)->list_free == 0) #define list_count(L) ((L)->list_nodecount) #define list_isempty(L) ((L)->list_nodecount == 0) #define list_isfull(L) (LIST_SFX_CHECK(L)->list_nodecount == (L)->list_maxcount) #define list_next(L, N) (LIST_SFX_CHECK(N)->list_next == &(L)->list_nilnode ? NULL : (N)->list_next) #define list_prev(L, N) (LIST_SFX_CHECK(N)->list_prev == &(L)->list_nilnode ? NULL : (N)->list_prev) #define list_first(L) list_next(LIST_SFX_CHECK(L), &(L)->list_nilnode) #define list_last(L) list_prev(LIST_SFX_CHECK(L), &(L)->list_nilnode) #else #define lnode_pool_isempty ow_lnode_pool_isempty #define list_count ow_list_count #define list_isempty ow_list_isempty #define list_isfull ow_list_isfull #define list_first ow_list_first #define list_last ow_list_last #define list_next ow_list_next #define list_prev ow_list_prev #endif #if defined(LIST_IMPLEMENTATION) || !defined(KAZLIB_OPAQUE_DEBUG) #define list_append(L, N) list_ins_before(LIST_SFX_CHECK(L), N, &(L)->list_nilnode) #define list_prepend(L, N) list_ins_after(LIST_SFX_CHECK(L), N, &(L)->list_nilnode) #define list_del_first(L) list_delete(LIST_SFX_CHECK(L), list_first(L)) #define list_del_last(L) list_delete(LIST_SFX_CHECK(L), list_last(L)) #else #define list_append ow_list_append #define list_prepend ow_list_prepend #define list_del_first ow_list_del_first #define list_del_last ow_list_del_last #endif /* destination list on the left, source on the right */ void ow_list_extract(list_t *, list_t *, lnode_t *, lnode_t *); void ow_list_transfer(list_t *, list_t *, lnode_t *first); void ow_list_merge(list_t *, list_t *, int (const void *, const void *)); void ow_list_sort(list_t *, int (const void *, const void *)); lnode_t *ow_list_find(list_t *, const void *, int (const void *, const void *)); int ow_list_is_sorted(list_t *, int (const void *, const void *)); #define list_extract ow_list_extract #define list_transfer ow_list_transfer #define list_merge ow_list_merge #define list_sort ow_list_sort #define list_find ow_list_find #define list_is_sorted ow_list_is_sorted #ifdef __cplusplus } #endif #endif openwsman-2.4.3/src/server/shttpd/compat_win32.h000664 001750 001750 00000004527 12256012305 022066 0ustar00kentbkentb000000 000000 /* * Copyright (c) 2004-2007 Sergey Lyubka * All rights reserved * * "THE BEER-WARE LICENSE" (Revision 42): * Sergey Lyubka wrote this file. As long as you retain this notice you * can do whatever you want with this stuff. If we meet some day, and you think * this stuff is worth it, you can buy me a beer in return. */ /* Tip from Justin Maximilian, suppress errors from winsock2.h */ #define _WINSOCKAPI_ #include #include #include #include #include #include #ifndef _WIN32_WCE #ifdef _MSC_VER /* pragmas not valid on MinGW */ #pragma comment(lib,"ws2_32") #pragma comment(lib,"user32") #pragma comment(lib,"comctl32") #pragma comment(lib,"comdlg32") #pragma comment(lib,"shell32") #ifdef NO_GUI #pragma comment(linker,"/subsystem:console") #else #pragma comment(linker,"/subsystem:windows") #endif /* NO_GUI */ #endif /* _MSC_VER */ #include #include #include #else /* _WIN32_WCE */ /* Windows CE-specific definitions */ #define NO_CGI /* WinCE has no pipes */ #define NO_GUI /* temporarily until it is fixed */ #pragma comment(lib,"ws2") /* WinCE has both Unicode and ANSI versions of GetProcAddress */ #undef GetProcAddress #define GetProcAddress GetProcAddressA #include "compat_wince.h" #endif /* _WIN32_WCE */ #define ERRNO GetLastError() #define NO_SOCKLEN_T #define SSL_LIB L"libssl32.dll" #define DIRSEP '\\' #define IS_DIRSEP_CHAR(c) ((c) == '/' || (c) == '\\') #define O_NONBLOCK 0 #define EWOULDBLOCK WSAEWOULDBLOCK #define snprintf _snprintf #define vsnprintf _vsnprintf #define mkdir(x,y) _mkdir(x) #define popen(x,y) _popen(x, y) #define pclose(x) _pclose(x) #define dlopen(x,y) LoadLibraryW(x) #define dlsym(x,y) (void *) GetProcAddress(x,y) #define _POSIX_ #ifdef __LCC__ #include #endif /* __LCC__ */ #ifdef _MSC_VER /* MinGW already has these */ typedef unsigned int uint32_t; typedef unsigned short uint16_t; typedef __int64 uint64_t; #define S_ISDIR(x) ((x) & _S_IFDIR) #endif /* _MSC_VER */ /* * POSIX dirent interface */ struct dirent { char d_name[FILENAME_MAX]; }; typedef struct DIR { HANDLE handle; WIN32_FIND_DATAW info; struct dirent result; char *name; } DIR; extern DIR *opendir(const char *name); extern int closedir(DIR *dir); extern struct dirent *readdir(DIR *dir); openwsman-2.4.3/src/lib/u/log.c000664 001750 001750 00000005617 12256012305 016534 0ustar00kentbkentb000000 000000 /* * Copyright (c) 2005, 2006 by KoanLogic s.r.l. - All rights reserved. */ static const char rcsid[] = "$Id: log.c,v 1.9 2006/03/11 14:41:16 tat Exp $"; #ifdef HAVE_CONFIG_H #include #endif #include #include #include #include #include #include #ifdef HAVE_UNISTD_H #include #endif #include #include #include #include #include /* applications that use libu will define their own "int facility" variable */ extern int facility; /* log hook. if not-zero use this function to write log messages */ static u_log_hook_t hook = NULL; static void *hook_arg = NULL; int facility = LOG_DAEMON; #ifdef WIN32 #define err_type DWORD #define save_errno(var) var = GetLastError(); #define restore_errno(var) SetLastError(var); #else #define err_type int #define save_errno(var) var = errno; #define restore_errno(var) errno = var; #endif static __INLINE__ const char* u_log_label(int lev) { switch(lev) { case LOG_CRIT: return "crt"; case LOG_ERR: return "err"; case LOG_WARNING: return "wrn"; case LOG_NOTICE: return "not"; case LOG_INFO: return "inf"; case LOG_DEBUG: return "dbg"; default: syslog(LOG_WARNING, "[wrn][%d:::] unknown log level: %d", getpid(), lev); return "unk"; } } static int u_log(int fac, int level, const char *fmt, ...) { va_list ap; char buf[U_MAX_LOG_LENGTH]; va_start(ap, fmt); if(hook) { if(vsnprintf(buf, U_MAX_LOG_LENGTH, fmt, ap) > U_MAX_LOG_LENGTH) { va_end(ap); return ~0; /* buffer too small */ } buf[U_MAX_LOG_LENGTH - 1] = 0; hook(hook_arg, level, buf); } else vsyslog(fac | level, fmt, ap); va_end(ap); return 0; } int u_log_set_hook(u_log_hook_t func, void *arg, u_log_hook_t *old, void **parg) { if(old) *old = hook; if(parg) *parg = hook_arg; hook = func; hook_arg = arg; return 0; } int u_log_write_ex(int fac, int lev, int ctx, const char* file, int line, const char *func, const char* fmt, ...) { va_list ap; char msg[U_MAX_LOG_LENGTH]; int rc; err_type savederr; save_errno(savederr); /* build the message to send to the log system */ va_start(ap, fmt); rc = vsnprintf(msg, U_MAX_LOG_LENGTH, fmt, ap); va_end(ap); if(rc > U_MAX_LOG_LENGTH) goto err; /* message too long */ /* ok, send the msg to the logger */ if(ctx) u_log(fac, lev, "[%s][%d:%s:%d:%s] %s", u_log_label(lev), getpid(), file, line, func, msg); else u_log(fac, lev, "[%s][%d:::] %s", u_log_label(lev), getpid(), msg); restore_errno(savederr); return 0; err: restore_errno(savederr); return ~0; } openwsman-2.4.3/bindings/perl/tests/CIM_EnumClasses.pl000664 001750 001750 00000003216 12256012305 023147 0ustar00kentbkentb000000 000000 #!/usr/bin/perl -w # # perl example to enumerate CIMOM classes names. # written by warptrosse@gmail.com # use strict; use warnings; use lib '../../../build/bindings/perl'; use lib '..'; use openwsman; # debug (to stderr) # openwsman::set_debug(1); # Create client instance. # (host, port, path, scheme, username, password) my $client = new openwsman::Client::('localhost', 5985, '/wsman', 'http', 'wsman', 'secret') or die print "[ERROR] Could not create client handler.\n"; # Alternate way. # my $client = new openwsman::Client::('http://wsman:secret@localhost:8889/wsman') # or die print "[ERROR] Could not create client handler.\n"; # Set up client options. my $options = new openwsman::ClientOptions::() or die print "[ERROR] Could not create client options handler.\n"; # Force basic auth. $client->transport()->set_auth_method($openwsman::BASIC_AUTH_STR); my $uri = $openwsman::XML_NS_CIM_INTRINSIC; # Uri. my $method = $openwsman::CIM_ACTION_ENUMERATE_CLASS_NAMES; # GetClass Method. my $result; # Used to store obtained data. # Get classes. # (options, resource uri) $result = $client->invoke($options, $uri, $method); unless($result && $result->is_fault eq 0) { die print "[ERROR] Could not get classes.\n"; } my $classesInfo = $result->body()->child(); # Get items. my @classes; # Classes list. for((my $cnt = 0) ; ($cnt<$classesInfo->size()) ; ($cnt++)) { push @classes, $classesInfo->get($cnt)->text(); } print "---------------------------------------------------\n"; print "Classes names:\n\n"; foreach(@classes) { print $_, "\n"; } print "---------------------------------------------------\n"; openwsman-2.4.3/src/server/shttpd/compat_win32.c000664 001750 001750 00000053316 12256012305 022061 0ustar00kentbkentb000000 000000 /* * Copyright (c) 2004-2005 Sergey Lyubka * All rights reserved * * "THE BEER-WARE LICENSE" (Revision 42): * Sergey Lyubka wrote this file. As long as you retain this notice you * can do whatever you want with this stuff. If we meet some day, and you think * this stuff is worth it, you can buy me a beer in return. */ #include "shttpd_defs.h" static const char *config_file = CONFIG; #if !defined(NO_GUI) static HICON hIcon; /* SHTTPD icon handle */ HWND hLog; /* Log window */ /* * Dialog box control IDs */ #define ID_GROUP 100 #define ID_SAVE 101 #define ID_STATUS 102 #define ID_STATIC 103 #define ID_SETTINGS 104 #define ID_QUIT 105 #define ID_TRAYICON 106 #define ID_TIMER 107 #define ID_ICON 108 #define ID_ADVANCED 109 #define ID_SHOWLOG 110 #define ID_LOG 111 #define ID_USER 200 #define ID_DELTA 1000 static void run_server(void *param) { struct shttpd_ctx *ctx = param; open_listening_ports(ctx); while (WaitForSingleObject(ctx->ev[0], 0) != WAIT_OBJECT_0) shttpd_poll(ctx, 1000); SetEvent(ctx->ev[1]); shttpd_fini(ctx); } /* * Save the configuration back into config file */ static void save_config(HWND hDlg, FILE *fp) { const struct opt *opt; char text[FILENAME_MAX]; int id; if (fp == NULL) elog(E_FATAL, NULL, "save_config: cannot open %s", config_file); for (opt = options; opt->name != NULL; opt++) { id = ID_USER + (opt - options); /* Control ID */ /* Do not save if the text is the same as default */ if (opt->flags & OPT_BOOL) (void) fprintf(fp, "%s\t%d\n", opt->name, IsDlgButtonChecked(hDlg, id)); else if (GetDlgItemText(hDlg, id, text, sizeof(text)) != 0 && (opt->def == NULL || strcmp(text, opt->def) != 0)) (void) fprintf(fp, "%s\t%s\n", opt->name, text); } (void) fclose(fp); } static void set_control_values(HWND hDlg, const struct shttpd_ctx *ctx) { const struct opt *opt; const union variant *v; char buf[FILENAME_MAX]; int id; for (opt = options; opt->name != NULL; opt++) { id = ID_USER + (opt - options); v = (union variant *) ((char *) ctx + opt->ofs); if (opt->flags & OPT_BOOL) { CheckDlgButton(hDlg, id, v->v_int ? BST_CHECKED : BST_UNCHECKED); } else if (opt->flags & OPT_INT) { snprintf(buf, sizeof(buf), "%d", v->v_int); SetDlgItemText(hDlg, id, buf); } else { SetDlgItemText(hDlg, id, v->v_str); } } } static BOOL CALLBACK DlgProc(HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam) { static struct shttpd_ctx *ctx, **pctx; HANDLE ev; const struct opt *opt; DWORD tid; int id, up; char text[256]; switch (msg) { case WM_CLOSE: KillTimer(hDlg, ID_TIMER); DestroyWindow(hDlg); break; case WM_COMMAND: switch (LOWORD(wParam)) { case ID_SAVE: EnableWindow(GetDlgItem(hDlg, ID_SAVE), FALSE); save_config(hDlg, fopen(config_file, "w+")); ev = ctx->ev[1]; SetEvent(ctx->ev[0]); WaitForSingleObject(ev, INFINITE); *pctx = ctx = init_from_argc_argv(config_file, 0, NULL); open_listening_ports(ctx); _beginthread(run_server, 0, ctx); EnableWindow(GetDlgItem(hDlg, ID_SAVE), TRUE); break; } id = ID_USER + ID_DELTA; for (opt = options; opt->name != NULL; opt++, id++) if (LOWORD(wParam) == id) { OPENFILENAME of; BROWSEINFO bi; char path[FILENAME_MAX] = ""; memset(&of, 0, sizeof(of)); of.lStructSize = sizeof(of); of.hwndOwner = (HWND) hDlg; of.lpstrFile = path; of.nMaxFile = sizeof(path); of.lpstrInitialDir = ctx->document_root; of.Flags = OFN_CREATEPROMPT | OFN_NOCHANGEDIR; memset(&bi, 0, sizeof(bi)); bi.hwndOwner = (HWND) hDlg; bi.lpszTitle = "Choose WWW root directory:"; bi.ulFlags = BIF_RETURNONLYFSDIRS; if (opt->flags & OPT_DIR) SHGetPathFromIDList( SHBrowseForFolder(&bi), path); else GetOpenFileName(&of); if (path[0] != '\0') SetWindowText(GetDlgItem(hDlg, id - ID_DELTA), path); } break; case WM_INITDIALOG: pctx = (struct shttpd_ctx **) lParam; ctx = *pctx; SendMessage(hDlg,WM_SETICON,(WPARAM)ICON_SMALL,(LPARAM)hIcon); SendMessage(hDlg,WM_SETICON,(WPARAM)ICON_BIG,(LPARAM)hIcon); SetWindowText(hDlg, "SHTTPD settings"); SetFocus(GetDlgItem(hDlg, ID_SAVE)); set_control_values(hDlg, ctx); break; default: break; } return FALSE; } static void * align(void *ptr, DWORD alig) { ULONG ul = (ULONG) ptr; ul += alig; ul &= ~alig; return ((void *) ul); } static void add_control(unsigned char **mem, DLGTEMPLATE *dia, WORD type, DWORD id, DWORD style, WORD x, WORD y, WORD cx, WORD cy, const char *caption) { DLGITEMTEMPLATE *tp; LPWORD p; dia->cdit++; *mem = align(*mem, 3); tp = (DLGITEMTEMPLATE *) *mem; tp->id = (WORD)id; tp->style = style; tp->dwExtendedStyle = 0; tp->x = x; tp->y = y; tp->cx = cx; tp->cy = cy; p = align(*mem + sizeof(*tp), 1); *p++ = 0xffff; *p++ = type; while (*caption != '\0') *p++ = (WCHAR) *caption++; *p++ = 0; p = align(p, 1); *p++ = 0; *mem = (unsigned char *) p; } static void show_settings_dialog(struct shttpd_ctx **ctxp) { #define HEIGHT 15 #define WIDTH 400 #define LABEL_WIDTH 70 unsigned char mem[4096], *p; DWORD style; DLGTEMPLATE *dia = (DLGTEMPLATE *) mem; WORD cl, x, y, width, nelems = 0; const struct opt *opt; static int guard; static struct { DLGTEMPLATE template; /* 18 bytes */ WORD menu, class; wchar_t caption[1]; WORD fontsiz; wchar_t fontface[7]; } dialog_header = {{WS_CAPTION | WS_POPUP | WS_SYSMENU | WS_VISIBLE | DS_SETFONT | WS_DLGFRAME, WS_EX_TOOLWINDOW, 0, 200, 200, WIDTH, 0}, 0, 0, L"", 8, L"Tahoma"}; if (guard == 0) guard++; else return; (void) memset(mem, 0, sizeof(mem)); (void) memcpy(mem, &dialog_header, sizeof(dialog_header)); p = mem + sizeof(dialog_header); for (opt = options; opt->name != NULL; opt++) { style = WS_CHILD | WS_VISIBLE | WS_TABSTOP; x = 10 + (WIDTH / 2) * (nelems % 2); y = (nelems/2 + 1) * HEIGHT + 5; width = WIDTH / 2 - 20 - LABEL_WIDTH; if (opt->flags & OPT_INT) { style |= ES_NUMBER; cl = 0x81; style |= WS_BORDER | ES_AUTOHSCROLL; } else if (opt->flags & OPT_BOOL) { cl = 0x80; style |= BS_AUTOCHECKBOX; } else if (opt->flags & (OPT_DIR | OPT_FILE)) { style |= WS_BORDER | ES_AUTOHSCROLL; width -= 20; cl = 0x81; add_control(&p, dia, 0x80, ID_USER + ID_DELTA + (opt - options), WS_VISIBLE | WS_CHILD | BS_PUSHBUTTON, (WORD) (x + width + LABEL_WIDTH + 5), y, 15, 12, "..."); } else { cl = 0x81; style |= WS_BORDER | ES_AUTOHSCROLL; } add_control(&p, dia, 0x82, ID_STATIC, WS_VISIBLE | WS_CHILD, x, y, LABEL_WIDTH, HEIGHT, opt->desc); add_control(&p, dia, cl, ID_USER + (opt - options), style, (WORD) (x + LABEL_WIDTH), y, width, 12, ""); nelems++; } y = (WORD) (((nelems + 1)/2 + 1) * HEIGHT + 5); add_control(&p, dia, 0x80, ID_GROUP, WS_CHILD | WS_VISIBLE | BS_GROUPBOX, 5, 5, WIDTH - 10, y, "Settings"); y += 10; add_control(&p, dia, 0x80, ID_SAVE, WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON | WS_TABSTOP, WIDTH - 70, y, 65, 12, "Save Settings"); #if 0 add_control(&p, dia, 0x80, ID_ADVANCED, WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON | WS_TABSTOP, WIDTH - 190, y, 110, 12, "Show Advanced Settings >>"); #endif add_control(&p, dia, 0x82, ID_STATIC, WS_CHILD | WS_VISIBLE | WS_DISABLED, 5, y, 180, 12,"SHTTPD v." VERSION " (http://shttpd.sourceforge.net)"); dia->cy = ((nelems + 1)/2 + 1) * HEIGHT + 30; DialogBoxIndirectParam(NULL, dia, NULL, DlgProc, (LPARAM) ctxp); guard--; } static BOOL CALLBACK LogProc(HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam) { static struct shttpd_ctx *ctx; static HWND hStatus; HWND hEdit; RECT rect, rect2, rect3, rect4; int len, up, widths[] = {120, 220, 330, 460, -1}; char text[256], buf[1024 * 64]; switch (msg) { case WM_CLOSE: KillTimer(hDlg, ID_TIMER); DestroyWindow(hDlg); break; case WM_APP: hEdit = GetDlgItem(hDlg, ID_LOG); len = GetWindowText(hEdit, buf, sizeof(buf)); if (len > sizeof(buf) * 4 / 5) len = sizeof(buf) * 4 / 5; snprintf(buf + len, sizeof(buf) - len, "%s\r\n", (char *) lParam); SetWindowText(hEdit, buf); SendMessage(hEdit, WM_VSCROLL, SB_BOTTOM, 0); break; case WM_TIMER: /* Print statistics on a status bar */ up = current_time - ctx->start_time; (void) snprintf(text, sizeof(text), " Up: %3d h %2d min %2d sec", up / 3600, up / 60 % 60, up % 60); SendMessage(hStatus, SB_SETTEXT, 0, (LPARAM) text); (void) snprintf(text, sizeof(text), " Requests: %u", ctx->nrequests); SendMessage(hStatus, SB_SETTEXT, 1, (LPARAM) text); (void) snprintf(text, sizeof(text), " Sent: %4.2f Mb", (double) ctx->out / 1048576); SendMessage(hStatus, SB_SETTEXT, 2, (LPARAM) text); (void) snprintf(text, sizeof(text), " Received: %4.2f Mb", (double) ctx->in / 1048576); SendMessage(hStatus, SB_SETTEXT, 3, (LPARAM) text); break; case WM_INITDIALOG: ctx = (struct shttpd_ctx *) lParam; SendMessage(hDlg,WM_SETICON,(WPARAM)ICON_SMALL,(LPARAM)hIcon); SendMessage(hDlg,WM_SETICON,(WPARAM)ICON_BIG,(LPARAM)hIcon); hStatus = CreateStatusWindow(WS_CHILD | WS_VISIBLE, "", hDlg, ID_STATUS); SendMessage(hStatus, SB_SETPARTS, 5, (LPARAM) widths); SendMessage(hStatus, SB_SETTEXT, 4, (LPARAM) " Running"); SetWindowText(hDlg, "SHTTPD web server log"); SetTimer(hDlg, ID_TIMER, 1000, NULL); GetWindowRect(GetDesktopWindow(), &rect3); GetWindowRect(hDlg, &rect4); GetClientRect(hDlg, &rect); GetClientRect(hStatus, &rect2); SetWindowPos(GetDlgItem(hDlg, ID_LOG), 0, 0, 0, rect.right, rect.bottom - rect2.bottom, 0); SetWindowPos(hDlg, HWND_TOPMOST, rect3.right - (rect4.right - rect4.left), rect3.bottom - (rect4.bottom - rect4.top) - 30, 0, 0, SWP_NOSIZE); SetFocus(hStatus); SendMessage(hDlg, WM_TIMER, 0, 0); hLog = hDlg; break; default: break; } return (FALSE); } static void show_log_window(struct shttpd_ctx *ctx) { unsigned char mem[4096], *p; DWORD style; DLGTEMPLATE *dia = (DLGTEMPLATE *) mem; WORD cl, x, y, width, nelems = 0; static struct { DLGTEMPLATE template; /* 18 bytes */ WORD menu, class; wchar_t caption[1]; WORD fontsiz; wchar_t fontface[7]; } dialog_header = {{WS_CAPTION | WS_POPUP | WS_VISIBLE | WS_SYSMENU | DS_SETFONT | WS_DLGFRAME, WS_EX_TOOLWINDOW, 0, 200, 200, 400, 100}, 0, 0, L"", 8, L"Tahoma"}; if (hLog != NULL) return; (void) memset(mem, 0, sizeof(mem)); (void) memcpy(mem, &dialog_header, sizeof(dialog_header)); p = mem + sizeof(dialog_header); add_control(&p, dia, 0x81, ID_LOG, WS_CHILD | WS_VISIBLE | WS_BORDER | WS_VSCROLL | ES_MULTILINE | ES_AUTOVSCROLL | ES_READONLY, 5, 5, WIDTH - 10, 60, ""); DialogBoxIndirectParam(NULL, dia, NULL, LogProc, (LPARAM) ctx); hLog = NULL; } static LRESULT CALLBACK WindowProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) { static NOTIFYICONDATA ni; static struct shttpd_ctx *ctx; DWORD tid; /* Thread ID */ HMENU hMenu; POINT pt; switch (msg) { case WM_CREATE: ctx = ((CREATESTRUCT *) lParam)->lpCreateParams; memset(&ni, 0, sizeof(ni)); ni.cbSize = sizeof(ni); ni.uID = ID_TRAYICON; ni.uFlags = NIF_ICON | NIF_MESSAGE | NIF_TIP; ni.hIcon = hIcon; ni.hWnd = hWnd; snprintf(ni.szTip, sizeof(ni.szTip), "SHTTPD web server"); ni.uCallbackMessage = WM_USER; Shell_NotifyIcon(NIM_ADD, &ni); ctx->ev[0] = CreateEvent(0, TRUE, FALSE, 0); ctx->ev[1] = CreateEvent(0, TRUE, FALSE, 0); _beginthread(run_server, 0, ctx); break; case WM_CLOSE: Shell_NotifyIcon(NIM_DELETE, &ni); PostQuitMessage(0); break; case WM_COMMAND: switch (LOWORD(wParam)) { case ID_SETTINGS: show_settings_dialog(&ctx); break; case ID_QUIT: SendMessage(hWnd, WM_CLOSE, wParam, lParam); PostQuitMessage(0); break; case ID_SHOWLOG: show_log_window(ctx); break; } break; case WM_USER: switch (lParam) { case WM_RBUTTONUP: case WM_LBUTTONUP: case WM_LBUTTONDBLCLK: hMenu = CreatePopupMenu(); AppendMenu(hMenu, 0, ID_SETTINGS, "Settings"); AppendMenu(hMenu, 0, ID_SHOWLOG, "Show Log"); AppendMenu(hMenu, 0, ID_QUIT, "Exit SHTTPD"); GetCursorPos(&pt); TrackPopupMenu(hMenu, 0, pt.x, pt.y, 0, hWnd, NULL); DestroyMenu(hMenu); break; } break; } return (DefWindowProc(hWnd, msg, wParam, lParam)); } int WINAPI WinMain(HINSTANCE h, HINSTANCE prev, char *cmdline, int show) { struct shttpd_ctx *ctx; WNDCLASS cls; HWND hWnd; MSG msg; ctx = init_from_argc_argv(config_file, 0, NULL); (void) memset(&cls, 0, sizeof(cls)); hIcon = LoadIcon(GetModuleHandle(NULL), MAKEINTRESOURCE(ID_ICON)); if (hIcon == NULL) hIcon = LoadIcon(NULL, IDI_APPLICATION); cls.lpfnWndProc = (WNDPROC) WindowProc; cls.hIcon = hIcon; cls.lpszClassName = "shttpd v." VERSION; if (!RegisterClass(&cls)) elog(E_FATAL, NULL, "RegisterClass: %d", ERRNO); else if ((hWnd = CreateWindow(cls.lpszClassName, "",WS_OVERLAPPEDWINDOW, 0, 0, 0, 0, NULL, NULL, NULL, ctx)) == NULL) elog(E_FATAL, NULL, "CreateWindow: %d", ERRNO); while (GetMessage(&msg, (HWND) NULL, 0, 0)) { TranslateMessage(&msg); DispatchMessage(&msg); } return (0); } #endif /* NO_GUI */ static void fix_directory_separators(char *path) { for (; *path != '\0'; path++) { if (*path == '/') *path = '\\'; if (*path == '\\') while (path[1] == '\\' || path[1] == '/') (void) memmove(path + 1, path + 2, strlen(path + 2) + 1); } } int my_open(const char *path, int flags, int mode) { char buf[FILENAME_MAX]; wchar_t wbuf[FILENAME_MAX]; my_strlcpy(buf, path, sizeof(buf)); fix_directory_separators(buf); MultiByteToWideChar(CP_UTF8, 0, buf, -1, wbuf, sizeof(wbuf)); return (_wopen(wbuf, flags)); } int my_stat(const char *path, struct stat *stp) { char buf[FILENAME_MAX], *p; wchar_t wbuf[FILENAME_MAX]; my_strlcpy(buf, path, sizeof(buf)); fix_directory_separators(buf); p = buf + strlen(buf) - 1; while (p > buf && *p == '\\' && p[-1] != ':') *p-- = '\0'; MultiByteToWideChar(CP_UTF8, 0, buf, -1, wbuf, sizeof(wbuf)); return (_wstat(wbuf, (struct _stat *) stp)); } int my_remove(const char *path) { char buf[FILENAME_MAX]; wchar_t wbuf[FILENAME_MAX]; my_strlcpy(buf, path, sizeof(buf)); fix_directory_separators(buf); MultiByteToWideChar(CP_UTF8, 0, buf, -1, wbuf, sizeof(wbuf)); return (_wremove(wbuf)); } int my_rename(const char *path1, const char *path2) { char buf1[FILENAME_MAX]; char buf2[FILENAME_MAX]; wchar_t wbuf1[FILENAME_MAX]; wchar_t wbuf2[FILENAME_MAX]; my_strlcpy(buf1, path1, sizeof(buf1)); my_strlcpy(buf2, path2, sizeof(buf2)); fix_directory_separators(buf1); fix_directory_separators(buf2); MultiByteToWideChar(CP_UTF8, 0, buf1, -1, wbuf1, sizeof(wbuf1)); MultiByteToWideChar(CP_UTF8, 0, buf2, -1, wbuf2, sizeof(wbuf2)); return (_wrename(wbuf1, wbuf2)); } int my_mkdir(const char *path, int mode) { char buf[FILENAME_MAX]; wchar_t wbuf[FILENAME_MAX]; my_strlcpy(buf, path, sizeof(buf)); fix_directory_separators(buf); MultiByteToWideChar(CP_UTF8, 0, buf, -1, wbuf, sizeof(wbuf)); return (_wmkdir(wbuf)); } static char * wide_to_utf8(const wchar_t *str) { char *buf = NULL; if (str) { int nchar = WideCharToMultiByte(CP_UTF8, 0, str, -1, NULL, 0, NULL, NULL); if (nchar > 0) { buf = malloc(nchar); if (!buf) errno = ENOMEM; else if (!WideCharToMultiByte(CP_UTF8, 0, str, -1, buf, nchar, NULL, NULL)) { free(buf); buf = NULL; errno = EINVAL; } } else errno = EINVAL; } else errno = EINVAL; return buf; } char * my_getcwd(char *buffer, int maxlen) { char *result = NULL; wchar_t *wbuffer, *wresult; if (buffer) { /* User-supplied buffer */ wbuffer = malloc(maxlen * sizeof(wchar_t)); if (wbuffer == NULL) return NULL; } else /* Dynamically allocated buffer */ wbuffer = NULL; wresult = _wgetcwd(wbuffer, maxlen); if (wresult) { int err = errno; if (buffer) { /* User-supplied buffer */ int n = WideCharToMultiByte(CP_UTF8, 0, wresult, -1, buffer, maxlen, NULL, NULL); if (n == 0) err = ERANGE; free(wbuffer); result = buffer; } else { /* Buffer allocated by _wgetcwd() */ result = wide_to_utf8(wresult); err = errno; free(wresult); } errno = err; } return result; } DIR * opendir(const char *name) { DIR *dir = NULL; char path[FILENAME_MAX]; wchar_t wpath[FILENAME_MAX]; if (name == NULL || name[0] == '\0') { errno = EINVAL; } else if ((dir = malloc(sizeof(*dir))) == NULL) { errno = ENOMEM; } else { snprintf(path, sizeof(path), "%s/*", name); fix_directory_separators(path); MultiByteToWideChar(CP_UTF8, 0, path, -1, wpath, sizeof(wpath)); dir->handle = FindFirstFileW(wpath, &dir->info); if (dir->handle != INVALID_HANDLE_VALUE) { dir->result.d_name[0] = '\0'; } else { free(dir); dir = NULL; } } return (dir); } int closedir(DIR *dir) { int result = -1; if (dir != NULL) { if (dir->handle != INVALID_HANDLE_VALUE) result = FindClose(dir->handle) ? 0 : -1; free(dir); } if (result == -1) errno = EBADF; return (result); } struct dirent * readdir(DIR *dir) { struct dirent *result = 0; if (dir && dir->handle != INVALID_HANDLE_VALUE) { if(!dir->result.d_name || FindNextFileW(dir->handle, &dir->info)) { result = &dir->result; WideCharToMultiByte(CP_UTF8, 0, dir->info.cFileName, -1, result->d_name, sizeof(result->d_name), NULL, NULL); } } else { errno = EBADF; } return (result); } int set_non_blocking_mode(int fd) { unsigned long on = 1; return (ioctlsocket(fd, FIONBIO, &on)); } void set_close_on_exec(int fd) { fd = 0; /* Do nothing. There is no FD_CLOEXEC on Windows */ } #if !defined(NO_CGI) struct threadparam { SOCKET s; HANDLE hPipe; big_int_t content_len; }; /* * Thread function that reads POST data from the socket pair * and writes it to the CGI process. */ static void//DWORD WINAPI stdoutput(void *arg) { struct threadparam *tp = arg; int n, sent, stop = 0; big_int_t total = 0; DWORD k; char buf[BUFSIZ]; size_t max_recv; max_recv = min(sizeof(buf), tp->content_len - total); while (!stop && max_recv > 0 && (n = recv(tp->s, buf, max_recv, 0)) > 0) { for (sent = 0; !stop && sent < n; sent += k) if (!WriteFile(tp->hPipe, buf + sent, n - sent, &k, 0)) stop++; total += n; max_recv = min(sizeof(buf), tp->content_len - total); } CloseHandle(tp->hPipe); /* Suppose we have POSTed everything */ free(tp); } /* * Thread function that reads CGI output and pushes it to the socket pair. */ static void stdinput(void *arg) { struct threadparam *tp = arg; static int ntotal; int k, stop = 0; DWORD n, sent; char buf[BUFSIZ]; while (!stop && ReadFile(tp->hPipe, buf, sizeof(buf), &n, NULL)) { ntotal += n; for (sent = 0; !stop && sent < n; sent += k) if ((k = send(tp->s, buf + sent, n - sent, 0)) <= 0) stop++; } CloseHandle(tp->hPipe); /* * Windows is a piece of crap. When this thread closes its end * of the socket pair, the other end (get_cgi() function) may loose * some data. I presume, this happens if get_cgi() is not fast enough, * and the data written by this end does not "push-ed" to the other * end socket buffer. So after closesocket() the remaining data is * gone. If I put shutdown() before closesocket(), that seems to * fix the problem, but I am not sure this is the right fix. * XXX (submitted by James Marshall) we do not do shutdown() on UNIX. * If fork() is called from user callback, shutdown() messes up things. */ shutdown(tp->s, 2); closesocket(tp->s); free(tp); _endthread(); } static void spawn_stdio_thread(int sock, HANDLE hPipe, void (*func)(void *), big_int_t content_len) { struct threadparam *tp; DWORD tid; tp = malloc(sizeof(*tp)); assert(tp != NULL); tp->s = sock; tp->hPipe = hPipe; tp->content_len = content_len; _beginthread(func, 0, tp); } int spawn_process(struct conn *c, const char *prog, char *envblk, char *envp[], int sock, const char *dir) { HANDLE a[2], b[2], h[2], me; DWORD flags; char *p, cmdline[FILENAME_MAX], line[FILENAME_MAX]; FILE *fp; STARTUPINFOA si; PROCESS_INFORMATION pi; me = GetCurrentProcess(); flags = DUPLICATE_CLOSE_SOURCE | DUPLICATE_SAME_ACCESS; /* FIXME add error checking code here */ CreatePipe(&a[0], &a[1], NULL, 0); CreatePipe(&b[0], &b[1], NULL, 0); DuplicateHandle(me, a[0], me, &h[0], 0, TRUE, flags); DuplicateHandle(me, b[1], me, &h[1], 0, TRUE, flags); (void) memset(&si, 0, sizeof(si)); (void) memset(&pi, 0, sizeof(pi)); /* XXX redirect CGI errors to the error log file */ si.cb = sizeof(si); si.dwFlags = STARTF_USESTDHANDLES | STARTF_USESHOWWINDOW; si.wShowWindow = SW_HIDE; si.hStdOutput = si.hStdError = h[1]; si.hStdInput = h[0]; /* If CGI file is a script, try to read the interpreter line */ if (c->ctx->cgi_interpreter == NULL) { if ((fp = fopen(prog, "r")) != NULL) { (void) fgets(line, sizeof(line), fp); if (memcmp(line, "#!", 2) != 0) line[2] = '\0'; /* Trim whitespaces from interpreter name */ for (p = &line[strlen(line) - 1]; p > line && isspace(*p); p--) *p = '\0'; (void) fclose(fp); } (void) snprintf(cmdline, sizeof(cmdline), "%s%s%s", line + 2, line[2] == '\0' ? "" : " ", prog); } else { (void) snprintf(cmdline, sizeof(cmdline), "%s %s", c->ctx->cgi_interpreter, prog); } (void) snprintf(line, sizeof(line), "%s", dir); fix_directory_separators(line); fix_directory_separators(cmdline); /* * Spawn reader & writer threads before we create CGI process. * Otherwise CGI process may die too quickly, loosing the data */ spawn_stdio_thread(sock, b[0], stdinput, 0); spawn_stdio_thread(sock, a[1], stdoutput, c->rem.content_len); if (CreateProcessA(NULL, cmdline, NULL, NULL, TRUE, CREATE_NEW_PROCESS_GROUP, envblk, line, &si, &pi) == 0) { elog(E_LOG, c,"redirect: CreateProcess(%s): %d",cmdline,ERRNO); return (-1); } else { CloseHandle(h[0]); CloseHandle(h[1]); CloseHandle(pi.hThread); CloseHandle(pi.hProcess); } return (0); } #endif /* !NO_CGI */ openwsman-2.4.3/src/plugins/cim/README000664 001750 001750 00000000334 12256012305 017675 0ustar00kentbkentb000000 000000 This is a collection of information bits and reminders for the cim plugin - if any additions are made to the CIM plugin files, it should be kept in mind that the WsmanStatus.fault_msg needs to be explicitly free'd. openwsman-2.4.3/src/plugins/CMakeLists.txt000664 001750 001750 00000000422 12256012305 021003 0ustar00kentbkentb000000 000000 # # CMakeLists.txt for openwsmann/src/plugins enable_testing() add_subdirectory(identify) add_subdirectory(wsman) add_subdirectory(redirect) if(BUILD_LIBCIM) add_subdirectory(cim) endif(BUILD_LIBCIM) if(BUILD_SWIG_PLUGIN) add_subdirectory(swig) endif(BUILD_SWIG_PLUGIN) openwsman-2.4.3/src/plugins/swig/plugin.i000664 001750 001750 00000013507 12256012305 020674 0ustar00kentbkentb000000 000000 %{ /* * swig based openwsman server plugin * * Written by Klaus Kaempf * */ /***************************************************************************** * Copyright (C) 2008 Novell Inc. All rights reserved. * Copyright (C) 2008 SUSE Linux Products GmbH. 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 Novell Inc. nor of SUSE Linux Products GmbH 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 Novell Inc. OR SUSE Linux Products GmbH 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. *****************************************************************************/ %} %module openwsman #if defined(SWIGJAVA) %module jwsman #endif #if defined(SWIGPYTHON) %module pywsman #endif #if defined(SWIGCSHARP) %module cswsman #endif %feature("autodoc","1"); %include "typemaps.i" %include exception.i #define __type %{ /* * type definitions to keep the C code generic */ #if defined(SWIGPYTHON) #define Target_Null_p(x) (x == Py_None) #define Target_INCREF(x) Py_INCREF(x) #define Target_DECREF(x) Py_DECREF(x) #define Target_True Py_True #define Target_False Py_False #define Target_Null NULL #define Target_Void Py_None typedef PyObject * Target_Type; #define Target_Bool(x) PyBool_FromLong(x) #define Target_WChar(x) PyInt_FromLong(x) #define Target_Int(x) PyInt_FromLong(x) #define Target_String(x) PyString_FromString(x) #define Target_Real(x) Py_None #define Target_Array() PyList_New(0) #define Target_SizedArray(len) PyList_New(len) #define Target_Append(x,y) PyList_Append(x,y) #define Target_DateTime(x) Py_None #include #define TARGET_THREAD_BEGIN_BLOCK SWIG_PYTHON_THREAD_BEGIN_BLOCK #define TARGET_THREAD_END_BLOCK SWIG_PYTHON_THREAD_END_BLOCK #define TARGET_THREAD_BEGIN_ALLOW SWIG_PYTHON_THREAD_BEGIN_ALLOW #define TARGET_THREAD_END_ALLOW SWIG_PYTHON_THREAD_END_ALLOW #endif #if defined(SWIGRUBY) #define Target_Null_p(x) NIL_P(x) #define Target_INCREF(x) #define Target_DECREF(x) #define Target_True Qtrue #define Target_False Qfalse #define Target_Null Qnil #define Target_Void Qnil typedef VALUE Target_Type; #define Target_Bool(x) ((x)?Qtrue:Qfalse) #define Target_WChar(x) INT2FIX(x) #define Target_Int(x) INT2FIX(x) #define Target_String(x) rb_str_new2(x) #define Target_Real(x) rb_float_new(x) #define Target_Array() rb_ary_new() #define Target_SizedArray(len) rb_ary_new2(len) #define Target_Append(x,y) rb_ary_push(x,y) #define Target_DateTime(x) Qnil #define TARGET_THREAD_BEGIN_BLOCK do {} while(0) #define TARGET_THREAD_END_BLOCK do {} while(0) #define TARGET_THREAD_BEGIN_ALLOW do {} while(0) #define TARGET_THREAD_END_ALLOW do {} while(0) #include #if HAVE_RUBY_IO_H #include /* Ruby 1.9 style */ #else #include #endif #endif #if defined(SWIGPERL) #define TARGET_THREAD_BEGIN_BLOCK do {} while(0) #define TARGET_THREAD_END_BLOCK do {} while(0) #define TARGET_THREAD_BEGIN_ALLOW do {} while(0) #define TARGET_THREAD_END_ALLOW do {} while(0) SWIGINTERNINLINE SV *SWIG_From_long SWIG_PERL_DECL_ARGS_1(long value); SWIGINTERNINLINE SV *SWIG_FromCharPtr(const char *cptr); SWIGINTERNINLINE SV *SWIG_From_double SWIG_PERL_DECL_ARGS_1(double value); #define Target_Null_p(x) (x == NULL) #define Target_INCREF(x) #define Target_DECREF(x) #define Target_True (&PL_sv_yes) #define Target_False (&PL_sv_no) #define Target_Null NULL #define Target_Void NULL typedef SV * Target_Type; #define Target_Bool(x) (x)?Target_True:Target_False #define Target_WChar(x) NULL #define Target_Int(x) SWIG_From_long(x) #define Target_String(x) SWIG_FromCharPtr(x) #define Target_Real(x) SWIG_From_double(x) #define Target_Array() (SV *)newAV() #define Target_SizedArray(len) (SV *)newAV() #define Target_Append(x,y) av_push(((AV *)(x)), y) #define Target_DateTime(x) NULL #include #include #endif #include #include #include #include #include #include #include #include #include #if defined(SWIGRUBY) #include #endif #if defined(SWIGPYTHON) #include #endif #if defined(SWIGJAVA) #include #endif /* fool swig into aliasing WsManClient and WsManTransport */ struct _WsManTransport { }; typedef struct _WsManTransport WsManTransport; #include "../src/swig-plugin.c" %} /* get type declarations from openwsman client bindings */ %include "wsman-xml.i" %include "wsman-soap.i" %include "wsman-names.i" %include "wsman-filter.i" %include "wsman-client.i" %include "wsman-transport.i" openwsman-2.4.3/src/lib/wsman-debug.c000664 001750 001750 00000004745 12256012305 017721 0ustar00kentbkentb000000 000000 /******************************************************************************* * 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 Vadim Revyakin */ #ifdef HAVE_CONFIG_H #include #endif #include #include #include "wsman-debug.h" static int debug_level = DEBUG_LEVEL_ALWAYS; void wsman_debug_set_level(debug_level_e level) { debug_level = level; } debug_level_e wsman_debug_get_level(void) { return debug_level; } int wsman_debug_level_debugged(debug_level_e level) { return (level <= debug_level); } void wsman_debug_message_handler(const char *str, debug_level_e level, void *user_data) { if (wsman_debug_level_debugged(level)) { struct tm *tm; time_t now; char timestr[128]; time(&now); tm = localtime(&now); strftime(timestr, 128, "%b %e %T", tm); fprintf(stderr, "%s %s\n", timestr, str); } } openwsman-2.4.3/src/plugins/wsman/test2/wsman_test2_stubs.c000664 001750 001750 00000006657 12256012305 024303 0ustar00kentbkentb000000 000000 /******************************************************************************* * 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 Eugene Yarmosh */ #include "config.h" #include "stdlib.h" #include "stdio.h" #include "string.h" #include "ctype.h" #include #include "ws_utilities.h" #include "ws_errors.h" #include "ws_xml_api.h" #include "soap_api.h" #include "xml_serializer.h" #include "ws_dispatcher.h" #include "wsman_test2.h" #include "wsman-debug.h" WsManTest2 g_WsManTest21 = { "Simple Test" }; WsManTest2 g_WsManTest22 = { "Simple Test 1" }; WsManTest2 g_WsManTest23 = { "Simple Test 2" }; WsManTest2* g_WsManTest2Arr[2] = { &g_WsManTest22, &g_WsManTest23 }; // ******************* WS-MAN this ******************************* WsManTest2* WsManTest2_Get_EP(WsContextH cntx) { wsman_debug (WSMAN_DEBUG_LEVEL_DEBUG, "Get Endpoint Called"); return &g_WsManTest21; } int WsManTest2_Put_EP(WsContextH cntx, void *in, WsManTest2 **out) { WsManTest2 *x = (WsManTest2 *)malloc(sizeof(WsManTest2)); x = (WsManTest2 *)in; wsman_debug (WSMAN_DEBUG_LEVEL_DEBUG, "Put Endpoint Called: %s", x->Test); g_WsManTest21 = *x; *out = x; return 0; } int WsManTest2_Enumerate_EP(WsContextH cntx, WsEnumerateInfo* enumInfo) { wsman_debug (WSMAN_DEBUG_LEVEL_DEBUG, "Enumerate Endpoint Called"); return 0; } int WsManTest2_Release_EP(WsContextH cntx, WsEnumerateInfo* enumInfo) { wsman_debug (WSMAN_DEBUG_LEVEL_DEBUG, "Release Endpoint Called"); return 0; } int WsManTest2_Pull_EP(WsContextH cntx, WsEnumerateInfo* enumInfo) { wsman_debug (WSMAN_DEBUG_LEVEL_DEBUG, "Pull Endpoint Called"); if ( enumInfo->index >= 0 && enumInfo->index < 2 ) { enumInfo->pullResultPtr = g_WsManTest2Arr[enumInfo->index]; } else { enumInfo->pullResultPtr = NULL; } return 0; } openwsman-2.4.3/bindings/ruby/tests/xmlnode.rb000664 001750 001750 00000003033 12256012305 021707 0ustar00kentbkentb000000 000000 # test XmlNode class require 'test/unit' require File.join(File.dirname(__FILE__),'_loadpath') require 'openwsman' class XmlNodeTest < Test::Unit::TestCase # Nodes are not constructed, but added to other nodes def test_node_constructor doc = Openwsman::XmlDoc.new "node" assert doc root = doc.root root.add( Openwsman::XML_NS_SOAP_1_2, "one" ) assert root[0].name = "one" root.add( Openwsman::XML_NS_SOAP_1_2, "two", "2" ) child = root.add( Openwsman::XML_NS_SOAP_1_2, "three", "drei" ) assert child.ns == Openwsman::XML_NS_SOAP_1_2 assert child.name == "three" assert child.text == "drei" assert root.size == 3 child.text = "troi" assert child.text == "troi" assert root[2] == child i = 0 root.each { |c| i += 1 } assert i == root.size end def test_node_accessor doc = Openwsman::create_soap_envelope assert doc header = doc.element("Header") assert header assert header.name == "Header" assert header.to_s body = doc.element("Body") assert body assert body.name == "Body" assert body.to_s envelope = doc.envelope assert envelope assert envelope.name == "Envelope" assert envelope.ns == Openwsman::XML_NS_SOAP_1_2 end def test_node_add doc = Openwsman::XmlDoc.new "node" root = doc.root node = root.add("ns", "name", "value") root << node root << node root << node assert root.size == 4 assert root[1] != node # its a dup assert root[0].name == root[1].name puts doc.to_xml end end openwsman-2.4.3/src/plugins/cim/CMakeLists.txt000664 001750 001750 00000001135 12256012305 021555 0ustar00kentbkentb000000 000000 # # CMakeLists.txt for openwsman/src/plugins/cim # INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/include ${CMAKE_SOURCE_DIR}/include/cim ${SFCC_INCLUDES} ${CMAKE_SOURCE_DIR} ${CMAKE_BINARY_DIR} ) SET(cim_plugin_SOURCES sfcc-interface.c sfcc-interface.h cim_data.c cim_data_stubs.c cim_data.h ) ADD_LIBRARY( wsman_cim_plugin SHARED ${cim_plugin_SOURCES} ) TARGET_LINK_LIBRARIES( wsman_cim_plugin wsman ) TARGET_LINK_LIBRARIES( wsman_cim_plugin ${SFCC_LIBRARIES} ) SET_TARGET_PROPERTIES(wsman_cim_plugin PROPERTIES VERSION 1.0.0 SOVERSION 1) INSTALL(TARGETS wsman_cim_plugin DESTINATION ${PACKAGE_PLUGIN_DIR}) openwsman-2.4.3/include/Makefile.am000664 001750 001750 00000001411 12256012305 017451 0ustar00kentbkentb000000 000000 AM_CFLAGS = @CFLAGS@ -DPACKAGE_PLUGIN_DIR="\"${PACKAGE_PLUGIN_DIR}\"" SUBDIRS = u cim wsmanincludedir = $(includedir)/openwsman wsmaninclude_HEADERS = \ wsman-types.h \ wsman-names.h \ wsman-debug.h \ wsman-client.h \ wsman-client-api.h \ wsman-xml-api.h \ wsman-client-transport.h \ wsman-xml-serializer.h \ wsman-xml-serialize.h \ wsman-server-api.h \ wsman-faults.h \ wsman-soap-message.h \ wsman-api.h \ wsman-declarations.h \ wsman-soap.h \ wsman-epr.h \ wsman-filter.h \ wsman-soap-envelope.h \ wsman-subscription-repository.h \ wsman-event-pool.h \ wsman-cimindication-processor.h EXTRA_DIST = wsman-xml.h \ wsman-xml-binding.h \ wsman-dispatcher.h \ wsman-xml-serialize.h \ wsman-server.h \ wsman-plugins.h openwsman-2.4.3/src/plugins/wsman/test/Makefile.am000664 001750 001750 00000000515 12256012305 022406 0ustar00kentbkentb000000 000000 plugindir = @PACKAGE_PLUGIN_DIR@ libwsman_test_la_SOURCES = \ wsman_test.c \ wsman_test_stubs.c \ wsman_test.h INCLUDES = -I$(top_srcdir)/include LIBS = \ $(XML_LIBS) plugin_LTLIBRARIES= libwsman_test.la libwsman_test_la_LIBADD = \ $(XML_LIBS) \ -lpthread libwsman_test_la_LDFLAGS= -version-info 1:0 openwsman-2.4.3/src/server/shttpd/md5.h000664 001750 001750 00000001312 12256012305 020233 0ustar00kentbkentb000000 000000 /* * Copyright (c) 2004-2005 Sergey Lyubka * All rights reserved * * "THE BEER-WARE LICENSE" (Revision 42): * Sergey Lyubka wrote this file. As long as you retain this notice you * can do whatever you want with this stuff. If we meet some day, and you think * this stuff is worth it, you can buy me a beer in return. */ #ifndef MD5_HEADER_INCLUDED #define MD5_HEADER_INCLUDED typedef struct MD5Context { uint32_t buf[4]; uint32_t bits[2]; unsigned char in[64]; } MD5_CTX; extern void MD5Init(MD5_CTX *ctx); extern void MD5Update(MD5_CTX *ctx, unsigned char const *buf, unsigned len); extern void MD5Final(unsigned char digest[16], MD5_CTX *ctx); #endif /*MD5_HEADER_INCLUDED */ openwsman-2.4.3/tests/filter/000775 001750 001750 00000000000 12256012305 016424 5ustar00kentbkentb000000 000000 openwsman-2.4.3/src/server/shttpd/md5.c000664 001750 001750 00000017003 12256012305 020232 0ustar00kentbkentb000000 000000 /* * This code implements the MD5 message-digest algorithm. * The algorithm is due to Ron Rivest. This code was * written by Colin Plumb in 1993, no copyright is claimed. * This code is in the public domain; do with it what you wish. * * Equivalent code is available from RSA Data Security, Inc. * This code has been tested against that, and is equivalent, * except that you don't need to include two pages of legalese * with every copy. * * To compute the message digest of a chunk of bytes, declare an * MD5Context structure, pass it to MD5Init, call MD5Update as * needed on buffers full of bytes, and then call MD5Final, which * will fill a supplied 16-byte array with the digest. */ #include "shttpd_defs.h" #ifndef HAVE_MD5 #if __BYTE_ORDER == 1234 #define byteReverse(buf, len) /* Nothing */ #else /* * Note: this code is harmless on little-endian machines. */ static void byteReverse(unsigned char *buf, unsigned longs) { uint32_t t; do { t = (uint32_t) ((unsigned) buf[3] << 8 | buf[2]) << 16 | ((unsigned) buf[1] << 8 | buf[0]); *(uint32_t *) buf = t; buf += 4; } while (--longs); } #endif /* __BYTE_ORDER */ /* The four core functions - F1 is optimized somewhat */ /* #define F1(x, y, z) (x & y | ~x & z) */ #define F1(x, y, z) (z ^ (x & (y ^ z))) #define F2(x, y, z) F1(z, x, y) #define F3(x, y, z) (x ^ y ^ z) #define F4(x, y, z) (y ^ (x | ~z)) /* This is the central step in the MD5 algorithm. */ #define MD5STEP(f, w, x, y, z, data, s) \ ( w += f(x, y, z) + data, w = w<>(32-s), w += x ) /* * Start MD5 accumulation. Set bit count to 0 and buffer to mysterious * initialization constants. */ void MD5Init(MD5_CTX *ctx) { ctx->buf[0] = 0x67452301; ctx->buf[1] = 0xefcdab89; ctx->buf[2] = 0x98badcfe; ctx->buf[3] = 0x10325476; ctx->bits[0] = 0; ctx->bits[1] = 0; } /* * The core of the MD5 algorithm, this alters an existing MD5 hash to * reflect the addition of 16 longwords of new data. MD5Update blocks * the data and converts bytes into longwords for this routine. */ static void MD5Transform(uint32_t buf[4], uint32_t const in[16]) { register uint32_t a, b, c, d; a = buf[0]; b = buf[1]; c = buf[2]; d = buf[3]; MD5STEP(F1, a, b, c, d, in[0] + 0xd76aa478, 7); MD5STEP(F1, d, a, b, c, in[1] + 0xe8c7b756, 12); MD5STEP(F1, c, d, a, b, in[2] + 0x242070db, 17); MD5STEP(F1, b, c, d, a, in[3] + 0xc1bdceee, 22); MD5STEP(F1, a, b, c, d, in[4] + 0xf57c0faf, 7); MD5STEP(F1, d, a, b, c, in[5] + 0x4787c62a, 12); MD5STEP(F1, c, d, a, b, in[6] + 0xa8304613, 17); MD5STEP(F1, b, c, d, a, in[7] + 0xfd469501, 22); MD5STEP(F1, a, b, c, d, in[8] + 0x698098d8, 7); MD5STEP(F1, d, a, b, c, in[9] + 0x8b44f7af, 12); MD5STEP(F1, c, d, a, b, in[10] + 0xffff5bb1, 17); MD5STEP(F1, b, c, d, a, in[11] + 0x895cd7be, 22); MD5STEP(F1, a, b, c, d, in[12] + 0x6b901122, 7); MD5STEP(F1, d, a, b, c, in[13] + 0xfd987193, 12); MD5STEP(F1, c, d, a, b, in[14] + 0xa679438e, 17); MD5STEP(F1, b, c, d, a, in[15] + 0x49b40821, 22); MD5STEP(F2, a, b, c, d, in[1] + 0xf61e2562, 5); MD5STEP(F2, d, a, b, c, in[6] + 0xc040b340, 9); MD5STEP(F2, c, d, a, b, in[11] + 0x265e5a51, 14); MD5STEP(F2, b, c, d, a, in[0] + 0xe9b6c7aa, 20); MD5STEP(F2, a, b, c, d, in[5] + 0xd62f105d, 5); MD5STEP(F2, d, a, b, c, in[10] + 0x02441453, 9); MD5STEP(F2, c, d, a, b, in[15] + 0xd8a1e681, 14); MD5STEP(F2, b, c, d, a, in[4] + 0xe7d3fbc8, 20); MD5STEP(F2, a, b, c, d, in[9] + 0x21e1cde6, 5); MD5STEP(F2, d, a, b, c, in[14] + 0xc33707d6, 9); MD5STEP(F2, c, d, a, b, in[3] + 0xf4d50d87, 14); MD5STEP(F2, b, c, d, a, in[8] + 0x455a14ed, 20); MD5STEP(F2, a, b, c, d, in[13] + 0xa9e3e905, 5); MD5STEP(F2, d, a, b, c, in[2] + 0xfcefa3f8, 9); MD5STEP(F2, c, d, a, b, in[7] + 0x676f02d9, 14); MD5STEP(F2, b, c, d, a, in[12] + 0x8d2a4c8a, 20); MD5STEP(F3, a, b, c, d, in[5] + 0xfffa3942, 4); MD5STEP(F3, d, a, b, c, in[8] + 0x8771f681, 11); MD5STEP(F3, c, d, a, b, in[11] + 0x6d9d6122, 16); MD5STEP(F3, b, c, d, a, in[14] + 0xfde5380c, 23); MD5STEP(F3, a, b, c, d, in[1] + 0xa4beea44, 4); MD5STEP(F3, d, a, b, c, in[4] + 0x4bdecfa9, 11); MD5STEP(F3, c, d, a, b, in[7] + 0xf6bb4b60, 16); MD5STEP(F3, b, c, d, a, in[10] + 0xbebfbc70, 23); MD5STEP(F3, a, b, c, d, in[13] + 0x289b7ec6, 4); MD5STEP(F3, d, a, b, c, in[0] + 0xeaa127fa, 11); MD5STEP(F3, c, d, a, b, in[3] + 0xd4ef3085, 16); MD5STEP(F3, b, c, d, a, in[6] + 0x04881d05, 23); MD5STEP(F3, a, b, c, d, in[9] + 0xd9d4d039, 4); MD5STEP(F3, d, a, b, c, in[12] + 0xe6db99e5, 11); MD5STEP(F3, c, d, a, b, in[15] + 0x1fa27cf8, 16); MD5STEP(F3, b, c, d, a, in[2] + 0xc4ac5665, 23); MD5STEP(F4, a, b, c, d, in[0] + 0xf4292244, 6); MD5STEP(F4, d, a, b, c, in[7] + 0x432aff97, 10); MD5STEP(F4, c, d, a, b, in[14] + 0xab9423a7, 15); MD5STEP(F4, b, c, d, a, in[5] + 0xfc93a039, 21); MD5STEP(F4, a, b, c, d, in[12] + 0x655b59c3, 6); MD5STEP(F4, d, a, b, c, in[3] + 0x8f0ccc92, 10); MD5STEP(F4, c, d, a, b, in[10] + 0xffeff47d, 15); MD5STEP(F4, b, c, d, a, in[1] + 0x85845dd1, 21); MD5STEP(F4, a, b, c, d, in[8] + 0x6fa87e4f, 6); MD5STEP(F4, d, a, b, c, in[15] + 0xfe2ce6e0, 10); MD5STEP(F4, c, d, a, b, in[6] + 0xa3014314, 15); MD5STEP(F4, b, c, d, a, in[13] + 0x4e0811a1, 21); MD5STEP(F4, a, b, c, d, in[4] + 0xf7537e82, 6); MD5STEP(F4, d, a, b, c, in[11] + 0xbd3af235, 10); MD5STEP(F4, c, d, a, b, in[2] + 0x2ad7d2bb, 15); MD5STEP(F4, b, c, d, a, in[9] + 0xeb86d391, 21); buf[0] += a; buf[1] += b; buf[2] += c; buf[3] += d; } /* * Update context to reflect the concatenation of another buffer full * of bytes. */ void MD5Update(MD5_CTX *ctx, unsigned char const *buf, unsigned len) { uint32_t t; /* Update bitcount */ t = ctx->bits[0]; if ((ctx->bits[0] = t + ((uint32_t) len << 3)) < t) ctx->bits[1]++; /* Carry from low to high */ ctx->bits[1] += len >> 29; t = (t >> 3) & 0x3f; /* Bytes already in shsInfo->data */ /* Handle any leading odd-sized chunks */ if (t) { unsigned char *p = (unsigned char *) ctx->in + t; t = 64 - t; if (len < t) { memcpy(p, buf, len); return; } memcpy(p, buf, t); byteReverse(ctx->in, 16); MD5Transform(ctx->buf, (uint32_t *) ctx->in); buf += t; len -= t; } /* Process data in 64-byte chunks */ while (len >= 64) { memcpy(ctx->in, buf, 64); byteReverse(ctx->in, 16); MD5Transform(ctx->buf, (uint32_t *) ctx->in); buf += 64; len -= 64; } /* Handle any remaining bytes of data. */ memcpy(ctx->in, buf, len); } /* * Final wrapup - pad to 64-byte boundary with the bit pattern * 1 0* (64-bit count of bits processed, MSB-first) */ void MD5Final(unsigned char digest[16], MD5_CTX *ctx) { unsigned count; unsigned char *p; /* Compute number of bytes mod 64 */ count = (ctx->bits[0] >> 3) & 0x3F; /* Set the first char of padding to 0x80. This is safe since there is always at least one byte free */ p = ctx->in + count; *p++ = 0x80; /* Bytes of padding needed to make 64 bytes */ count = 64 - 1 - count; /* Pad out to 56 mod 64 */ if (count < 8) { /* Two lots of padding: Pad the first block to 64 bytes */ memset(p, 0, count); byteReverse(ctx->in, 16); MD5Transform(ctx->buf, (uint32_t *) ctx->in); /* Now fill the next block with 56 bytes */ memset(ctx->in, 0, 56); } else { /* Pad block to 56 bytes */ memset(p, 0, count - 8); } byteReverse(ctx->in, 14); /* Append length in bits and transform */ ((uint32_t *) ctx->in)[14] = ctx->bits[0]; ((uint32_t *) ctx->in)[15] = ctx->bits[1]; MD5Transform(ctx->buf, (uint32_t *) ctx->in); byteReverse((unsigned char *) ctx->buf, 4); memcpy(digest, ctx->buf, 16); memset((char *) ctx, 0, sizeof(ctx)); /* In case it's sensitive */ } #endif /* !HAVE_MD5 */ openwsman-2.4.3/bindings/perl/tests/000775 001750 001750 00000000000 12256012305 017676 5ustar00kentbkentb000000 000000 openwsman-2.4.3/src/server/shttpd/000775 001750 001750 00000000000 12256012305 017400 5ustar00kentbkentb000000 000000 openwsman-2.4.3/bindings/ruby/tests/loading.rb000664 001750 001750 00000000330 12256012305 021653 0ustar00kentbkentb000000 000000 # test loading of extension require 'test/unit' class LoadTest < Test::Unit::TestCase def test_loading require File.join(File.dirname(__FILE__),'_loadpath') require 'openwsman' assert true end end openwsman-2.4.3/src/server/Makefile.am000664 001750 001750 00000002506 12256012305 020131 0ustar00kentbkentb000000 000000 INCLUDES = \ -I$(top_srcdir) \ -I$(top_srcdir)/include \ -I$(top_srcdir)/src/server/shttpd \ $(OPENSSL_CFLAGS) \ -DEMBEDDED -DNO_CGI -DNO_SSI \ -DPACKAGE_PLUGIN_DIR="\"${PACKAGE_PLUGIN_DIR}\"" \ -DPACKAGE_AUTH_DIR="\"${PACKAGE_AUTH_DIR}\"" \ -DPACKAGE_SUBSCRIPTION_DIR="\"${PACKAGE_SUBSCRIPTION_DIR}\"" LIBS = \ $(OPENSSL_LIBS) \ $(top_builddir)/src/lib/libwsman.la \ $(top_builddir)/src/lib/libwsman_server.la if ENABLE_EVENTING_SUPPORT LIBS += $(top_builddir)/src/lib/libwsman_client.la endif if USE_OPENSSL INCLUDES += -DHAVE_OPENSSL $(OPENSSL_CFLAGS) LIBS += -lssl endif sbin_PROGRAMS = openwsmand openwsmand_SOURCES = \ shttpd/string.c \ shttpd/shttpd.c \ shttpd/auth.c \ shttpd/md5.c \ shttpd/adapter.c \ shttpd/cgi.c \ shttpd/mime_type.c shttpd/config.c shttpd/io_socket.c \ shttpd/io_ssl.c shttpd/io_emb.c shttpd/compat_unix.c shttpd/io_dir.c shttpd/io_file.c \ shttpd/shttpd_defs.h shttpd/llist.h shttpd/shttpd.h shttpd/std_includes.h shttpd/io.h shttpd/md5.h shttpd/ssl.h \ shttpd/compat_unix.h shttpd/compat_win32.h shttpd/compat_rtems.h shttpd/adapter.h\ wsmand-listener.h \ wsmand-daemon.c \ wsmand-daemon.h \ wsmand-listener.c \ gss.c \ wsmand.c install-data-local: $(mkinstalldirs) $(DESTDIR)$(PACKAGE_SUBSCRIPTION_DIR) openwsman-2.4.3/cmake/modules/FindPythonLinkLibs.cmake000664 001750 001750 00000001737 12256012305 023251 0ustar00kentbkentb000000 000000 # # FindPythonLinkLibs.cmake # # Find Python libraries to link against # # See http://www.itk.org/Bug/view.php?id=2257 for a complete thread on # the problem # # python -c 'import distutils.sysconfig as s; c = s.get_config_var; print c("LOCALMODLIBS"), c("LIBS")' EXECUTE_PROCESS(COMMAND ${PYTHON_EXECUTABLE} -c "from sys import stdout; import distutils.sysconfig as s; c = s.get_config_var; stdout.write(c(\"LOCALMODLIBS\")); stdout.write(c(\"LIBS\"))" OUTPUT_VARIABLE PYTHON_LINK_LIBS) EXECUTE_PROCESS(COMMAND ${PYTHON_EXECUTABLE} -c "import sys; sys.stdout.write(str(sys.version_info[0]));" OUTPUT_VARIABLE PYTHON_MAJOR_VERSION) EXECUTE_PROCESS(COMMAND ${PYTHON_EXECUTABLE} -c "import sys; sys.stdout.write(str(sys.version_info[1]));" OUTPUT_VARIABLE PYTHON_MINOR_VERSION) #SET(PYTHON_SHARED_LIBRARY "-lpython${PYTHON_MAJOR_VERSION}.${PYTHON_MINOR_VERSION}") #SET(PYTHON_LINK_LIBS "${PYTHON_SHARED_LIBRARY} ${PYTHON_LINK_LIBS}") #MESSAGE(STATUS "Python link libs: ${PYTHON_LINK_LIBS}") openwsman-2.4.3/src/plugins/swig/ruby/tests/loading.rb000664 001750 001750 00000000145 12256012305 023303 0ustar00kentbkentb000000 000000 # load openwsmanplugin.rb $:.unshift "../../../../../build/bindings/ruby" require 'openwsmanplugin' openwsman-2.4.3/bindings/java/Makefile.am000664 001750 001750 00000001657 12256012305 020560 0ustar00kentbkentb000000 000000 # # Makefile.am for openwsman/bindings/java # SUBDIRS = tests javadir = @libdir@/java INCLUDES = -I$(top_srcdir) \ -I$(top_srcdir)/include \ -I$(top_srcdir)/bindings \ $(OPENSSL_CFLAGS) \ -DSYSCONFDIR=\""$(sysconfdir)/openwsman"\" LIBS = $(OPENSSL_LIBS) \ $(top_builddir)/src/lib/libwsman.la \ $(top_builddir)/src/lib/libwsman_client.la \ $(top_builddir)/src/lib/libwsman_curl_client_transport.la GENERATED = openwsman_wrap.c SWIG_INPUT = ../openwsman.i libjwsman_la_SOURCES = openwsman_wrap.c \ ../openwsman.c $(SWIG_INPUT) libjwsman_la_LIBADD = $(LIBS) -lpthread $(CURL_LIBS) libjwsman_la_LDFLAGS = -module -avoid-version $(NO_UNDEFINED) java_LTLIBRARIES = libjwsman.la $(GENERATED): $(SWIG_INPUT) $(SWIG) -java -package org.openwsman -I$(top_srcdir)/include -o $@ $< dist-hook: rm -f $(distdir)/openwsman_wrap.c CLEANFILES= $(GENERATED) *.java *.class EXTRA_DIST = helpers.hopenwsman-2.4.3/src/lib/u/memory.c000664 001750 001750 00000001511 12256012305 017250 0ustar00kentbkentb000000 000000 /* * Copyright (c) 2005, 2006 by KoanLogic s.r.l. - All rights reserved. */ static const char rcsid[] = "$Id: memory.c,v 1.2 2006/01/09 12:38:38 tat Exp $"; #include #include /** * \defgroup alloc Memory * \{ */ /** \brief Wrapper for malloc(3) */ void *u_malloc (size_t sz) { return malloc(sz); } /** \brief Wrapper for calloc(3) */ void *u_calloc (size_t cnt, size_t sz) { return calloc(cnt, sz); } /** \brief Alloc a contiguous region of \p sz bytes and zero-fill it */ void *u_zalloc (size_t sz) { return calloc(1, sz); } /** \brief Wrapper for realloc(3) */ void *u_realloc (void *ptr, size_t sz) { return realloc(ptr, sz); } /** \brief Wrapper for free(3), sanity checks the supplied pointer */ void u_free (void *ptr) { if (ptr) free(ptr); } /** * \} */ openwsman-2.4.3/tests/client/test_invoke.c000664 001750 001750 00000016162 12256012305 021121 0ustar00kentbkentb000000 000000 /******************************************************************************* * 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 */ #include "wsman_config.h" #include #include #include #include #include #include #include "u/libu.h" #include "wsman-xml-api.h" #include "wsman-soap.h" #include "wsman-xml.h" #include "wsman-xml-serializer.h" #include "wsman-client.h" #include "wsman-client-transport.h" #include "wsman-debug.h" //int facility = LOG_DAEMON; int errors = 0; char *host = "langley.home.planux.com"; typedef struct { const char *server; int port; const char *path; const char *scheme; const char *username; const char *password; } ServerData; typedef struct { /* Explanation of what you should see */ const char *explanation; /* Resource UR to test against */ const char *resource_uri; /* Selectors in the form of a URI query key=value&key2=value2 */ char *selectors; const char *properties; const char *method; const char* xpath_expression; const char* expected_value; /* What the final status code should be. */ unsigned int final_status; } TestData; ServerData sd[] = { {"localhost", 5985, "/wsman", "http", "wsman", "secret"} }; TestData tests[] = { { "Custom method without any selectors. ", "http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/OMC_SystemTimeService", NULL, NULL, "ManageSystemTime", "/s:Envelope/s:Body/s:Fault/s:Code/s:Subcode/s:Value", "wsman:InvalidSelectors", 500 }, { "Custom method without any parameters. ", "http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/OMC_SystemTimeService", "SystemCreationClassName=OMC_UnitaryComputerSystem&SystemName=%s&CreationClassName=OMC_SystemTimeService&Name=timeservice", NULL, "ManageSystemTime", "/s:Envelope/s:Body/s:Fault/s:Code/s:Subcode/s:Value", "wsman:InvalidParameter", 500 }, { "Custom method without any parameters/method. ", "http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/OMC_SystemTimeService", "SystemCreationClassName=OMC_UnitaryComputerSystem&SystemName=%s&CreationClassName=OMC_SystemTimeService&Name=timeservice", NULL, NULL, "/s:Envelope/s:Body/s:Fault/s:Code/s:Subcode/s:Value", "wsa:DestinationUnreachable", 500 }, { "Custom method with wrong parameters. ", "http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/OMC_SystemTimeService", "SystemCreationClassName=OMC_UnitaryComputerSystem&SystemName=%s&CreationClassName=OMC_SystemTimeService&Name=timeservice", "GetRequestx=TRUE", "ManageSystemTime", "/s:Envelope/s:Body/s:Fault/s:Code/s:Subcode/s:Value", "wsman:InvalidParameter", 500 }, { "Custom method with correct parameters. ", "http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/OMC_SystemTimeService", "SystemCreationClassName=OMC_UnitaryComputerSystem&SystemName=%s&CreationClassName=OMC_SystemTimeService&Name=timeservice", "GetRequest=TRUE", "ManageSystemTime", "/s:Envelope/s:Body/n1:ManageSystemTime_OUTPUT/ReturnValue", "0", 200 } }; int ntests = sizeof (tests) / sizeof (tests[0]); static void wsman_output(WsXmlDocH doc) { ws_xml_dump_node_tree(stdout, ws_xml_get_doc_root(doc)); return; } int main(int argc, char** argv) { int i; WsManClient *cl; WsXmlDocH doc; client_opt_t *options = NULL; if (getenv("OPENWSMAN_TEST_HOST")) { host = getenv("OPENWSMAN_TEST_HOST"); } for (i = 0; i < ntests; i++) { printf ("Test %3d: %s ", i + 1, tests[i].explanation); tests[i].selectors = u_strdup_printf(tests[i].selectors, host, host, host); cl = wsmc_create(sd[0].server, sd[0].port, sd[0].path, sd[0].scheme, sd[0].username, sd[0].password); wsmc_transport_init(cl, NULL); options = wsmc_options_init(); if (tests[i].selectors != NULL) wsmc_add_selectors_from_str(options, tests[i].selectors); if (tests[i].properties != NULL) wsmc_add_prop_from_str(options, tests[i].properties); doc = wsmc_action_invoke(cl, (char *)tests[i].resource_uri, options, (char *)tests[i].method, NULL); if (!doc) { printf("\t\t\033[22;31mUNRESOLVED\033[m\n"); goto CONTINUE; } if (tests[i].final_status != wsmc_get_response_code(cl)) { printf("Status = %ld \t\t\t\033[22;31mFAILED\033[m\n", wsmc_get_response_code(cl)); goto CONTINUE; } if (0) wsman_output(doc); if ((char *)tests[i].expected_value != NULL) { char *xp = ws_xml_get_xpath_value(doc, (char *)tests[i].xpath_expression); if (xp) { if (strcmp(xp, (char *)tests[i].expected_value ) == 0) printf("\t\t\t\t\033[22;32mPASSED\033[m\n"); else printf("%s\t\033[22;31mFAILED\033[m\n", (char *)tests[i].expected_value); u_free(xp); } else { printf("No xpath value \t\t\033[22;31mFAILED\033[m\n"); } } ws_xml_destroy_doc(doc); CONTINUE: u_free(tests[i].selectors); wsmc_options_destroy(options); wsmc_release(cl); } return 0; } openwsman-2.4.3/bindings/java/tests/000775 001750 001750 00000000000 12256012305 017655 5ustar00kentbkentb000000 000000 openwsman-2.4.3/bindings/ruby/tests/xmlfind.rb000664 001750 001750 00000002422 12256012305 021703 0ustar00kentbkentb000000 000000 # test find/next operations on XmlNode class require 'test/unit' require File.join(File.dirname(__FILE__),'_loadpath') require 'openwsman' class XmlFindTest < Test::Unit::TestCase def setup @doc = Openwsman::create_doc_from_file("EnumKey.xml") end def teardown end def test_doc assert @doc end def test_find snames = @doc.sNames assert snames end def test_next node = @doc.sNames assert node next_node = node.next assert next_node end def test_count node = @doc.sNames assert node # # iterate over sNames # count = 0 while node do node = node.next count += 1 end assert_equal 26, count # # iterate over all children count = 0 @doc.EnumKey_OUTPUT.each do count += 1 end # one more, because ReturnValue is the last child assert_equal 27, count assert_equal count, @doc.EnumKey_OUTPUT.size # # now limit to sNames # count = 0 @doc.EnumKey_OUTPUT.each("sNames") do count += 1 end assert_equal 26, count assert_equal count, @doc.EnumKey_OUTPUT.size("sNames") # # now limit to ReturnValue # count = 0 @doc.EnumKey_OUTPUT.each("ReturnValue") do count += 1 end assert_equal 1, count end end openwsman-2.4.3/include/wsman-xml-api.h000664 001750 001750 00000020300 12256012305 020256 0ustar00kentbkentb000000 000000 /******************************************************************************* * 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 Eugene Yarmosh */ #ifndef WS_XML_API_H_ #define WS_XML_API_H_ #ifdef __cplusplus extern "C" { #endif /* __cplusplus */ #include #include "wsman-types.h" /** * @defgroup XML XML * @brief XML API * * @{ */ // context #define WS_CONTEXT_TYPE_MASK 0x0f #define WS_CONTEXT_FREE_DATA 0x80 #define WS_CONTEXT_TYPE_STRING 0x01 #define WS_CONTEXT_TYPE_ULONG 0x02 #define WS_CONTEXT_TYPE_XMLDOC 0x03 #define WS_CONTEXT_TYPE_XMLNODE 0x04 #define WS_CONTEXT_TYPE_BLOB 0x05 #define WS_CONTEXT_TYPE_FAULT 0x06 #define XML_LAST_CHILD (-1) #define XML_ELEMENT_NEXT (-2) #define XML_ELEMENT_PREV (-3) #define XML_ELEMENT_PARENT (-4) #define XML_NS_URI 1 #define XML_NS_PREFIX 2 #define XML_LOCAL_NAME 3 #define XML_TEXT_VALUE 4 #define XML_COUNT_NODE 10 #define XML_COUNT_NS 11 #define XML_COUNT_ATTR 12 #define PROCESSED_MSG_ID_MAX_SIZE 200 #define WSMAN_MINIMAL_ENVELOPE_SIZE_REQUEST 8192 void ws_xml_free_memory(void *ptr); typedef int (*WsXmlEnumCallback) (WsXmlNodeH, void *); typedef int (*WsXmlNsEnumCallback) (WsXmlNodeH, WsXmlNsH, void *); // Dumping void ws_xml_dump_node_tree(FILE * f, WsXmlNodeH node); /* indented, using doc encoding */ void ws_xml_dump_memory_node_tree(WsXmlNodeH node, char **buf, int *ptrSize); /* indented, using given encoding (default: utf-8) */ void ws_xml_dump_memory_node_tree_enc(WsXmlNodeH node, char **buf, int *ptrSize, const char *encoding); void ws_xml_dump_doc(FILE * f, WsXmlDocH doc); /* non-indented, using given encoding */ void ws_xml_dump_memory_enc(WsXmlDocH doc, char **buf, int *ptrSize, const char *encoding); // WSXmlDoc handling WsXmlNodeH ws_xml_get_doc_root(WsXmlDocH doc); void ws_xml_destroy_doc(WsXmlDocH doc); char *ws_xml_get_xpath_value(WsXmlDocH doc, char *expression); WsXmlDocH ws_xml_create_soap_envelope(void); WsXmlNodeH ws_xml_get_soap_envelope(WsXmlDocH doc); WsXmlNodeH ws_xml_get_soap_header(WsXmlDocH doc); WsXmlNodeH ws_xml_get_soap_body(WsXmlDocH doc); WsXmlNodeH ws_xml_get_soap_element(WsXmlDocH doc, const char *name); // WsXmlNode handling WsXmlDocH ws_xml_get_node_doc(WsXmlNodeH node); void ws_xml_duplicate_tree(WsXmlNodeH dstNode, WsXmlNodeH srcNode); int ws_xml_duplicate_children(WsXmlNodeH dstNode, WsXmlNodeH srcNode); WsXmlNodeH ws_xml_get_node_parent(WsXmlNodeH node); int ws_xml_get_child_count(WsXmlNodeH parent); int ws_xml_get_child_count_by_qname(WsXmlNodeH parent, const char *nsUri, const char *name); WsXmlNodeH ws_xml_get_child(WsXmlNodeH parent, int index, const char *nsUri, const char *localName); int ws_xml_enum_children(WsXmlNodeH parent, WsXmlEnumCallback callback, void *data, int bRecursive); WsXmlNodeH ws_xml_add_child(WsXmlNodeH node, const char *ns, const char *localName, const char *val); WsXmlNodeH ws_xml_add_prev_sibling(WsXmlNodeH node, const char *ns, const char *localName, const char *val); WsXmlNodeH ws_xml_add_child_sort(WsXmlNodeH node, const char *ns, const char *localName, const char *val, int xmlescape); WsXmlNodeH ws_xml_add_empty_child_format(WsXmlNodeH node, const char *nsUri, const char *format, ...); WsXmlNsH ws_xml_ns_add(WsXmlNodeH node, const char *uri, const char *prefix); void ws_xml_set_ns(WsXmlNodeH r, const char* ns, const char* prefix ); WsXmlNodeH ws_xml_add_child_format(WsXmlNodeH node, const char *nsUri, const char *localName, const char *format, ...); WsXmlNodeH ws_xml_add_qname_child(WsXmlNodeH parent, const char *nameNs, const char *name, const char *valueNs, const char *value); int ws_xml_enum_tree(WsXmlNodeH top, WsXmlEnumCallback callback, void *data, int bRecursive); WsXmlNodeH ws_xml_find_in_tree(WsXmlNodeH head, const char *nsUri, const char *localName, int bRecursive); int ws_xml_is_node_qname(WsXmlNodeH node, const char *nsUri, const char *name); char *ws_xml_get_node_local_name(WsXmlNodeH node); char *ws_xml_get_node_name_ns(WsXmlNodeH node); int ws_xml_set_node_name(WsXmlNodeH node, const char *nsUri, const char *name); int ws_xml_set_node_qname_val(WsXmlNodeH node, const char *valNsUri, const char *valName); int ws_xml_get_ns_count(WsXmlNodeH node, int bWalkUpTree); void ws_xml_ns_enum(WsXmlNodeH node, WsXmlNsEnumCallback callback, void *data, int bWalkUpTree); WsXmlNsH ws_xml_find_ns(WsXmlNodeH node, const char *nsUri, const char *prefix, int bWalkUpTree); WsXmlNsH ws_xml_get_ns(WsXmlNodeH node, int index); WsXmlNsH ws_xml_define_ns(WsXmlNodeH node, const char *nsUri, const char *nsPrefix, int bDefault); char *ws_xml_get_ns_prefix(WsXmlNsH ns); char *ws_xml_get_ns_uri(WsXmlNsH ns); unsigned long ws_xml_get_node_ulong(WsXmlNodeH node); int ws_xml_set_node_ulong(WsXmlNodeH node, unsigned long uVal); int ws_xml_set_node_long(WsXmlNodeH node, long Val); int ws_xml_set_node_real(WsXmlNodeH node, double Val); char *ws_xml_get_node_text(WsXmlNodeH node); int ws_xml_set_node_text(WsXmlNodeH node, const char *text); void ws_xml_duplicate_attr(WsXmlNodeH dstNode, WsXmlNodeH srcNode); int ws_xml_get_node_attr_count(WsXmlNodeH node); WsXmlAttrH ws_xml_get_node_attr(WsXmlNodeH node, int index); WsXmlAttrH ws_xml_find_node_attr(WsXmlNodeH node, const char *attrNs, const char *attrName); WsXmlAttrH ws_xml_add_node_attr(WsXmlNodeH node, const char *nsUri, const char *name, const char *value); WsXmlAttrH ws_xml_add_qname_attr(WsXmlNodeH node, const char *nameNs, const char *name, const char *valueNs, const char *value); unsigned long ws_xml_find_attr_ulong(WsXmlNodeH node, const char *ns, const char *attrName); int ws_xml_find_attr_bool(WsXmlNodeH node, const char *ns, const char *attrName); void ws_xml_remove_node_attr(WsXmlAttrH attr); char *ws_xml_get_attr_name(WsXmlAttrH attr); char *ws_xml_get_attr_ns(WsXmlAttrH attr); char *ws_xml_get_attr_ns_prefix(WsXmlAttrH attr); char *ws_xml_get_attr_value(WsXmlAttrH attr); char *ws_xml_find_attr_value(WsXmlNodeH node, const char *ns, const char *attrName); void ws_xml_make_default_prefix(WsXmlNodeH node, const char *uri, char *buf, int bufsize); void ws_xml_copy_node(WsXmlNodeH src, WsXmlNodeH dst); WsXmlDocH ws_xml_clone_and_create_doc(WsXmlDocH doc, const char *rootNsUri, const char *rootName ); /** @} */ #ifdef __cplusplus } #endif /* __cplusplus */ #endif /*WS_XML_API_H_ */ openwsman-2.4.3/bindings/wsman-xml.i000664 001750 001750 00000042315 12256012305 017674 0ustar00kentbkentb000000 000000 /* * wsman-xml.i * xml structure accessors for openwsman swig bindings * */ /* * Document-class: XmlNs * Xml namespace */ %rename(XmlNs) __WsXmlNs; %nodefault __WsXmlNs; /* part of WsXmlAttr */ struct __WsXmlNs {}; /* without empty struct, the %rename isn't executed. */ typedef struct __WsXmlNs* WsXmlNsH; /* * XmlDoc * * Implementation advice * DONT do a %newobject on functions returning WsXmlDoc. Swig will * free the WsXmlDocH immediately after wrapping ! */ %rename(XmlDoc) _WsXmlDoc; %nodefault _WsXmlDoc; struct _WsXmlDoc {}; typedef struct _WsXmlDoc* WsXmlDocH; /* * Document-class: XmlDoc * * XmlDoc holds an XML document and thus represents the root of an XML * tree. XmlDoc is optimized for SOAP type documents, giving accessors * to the SOAP envelope, header and body. * * Instances of the other XML related classes like XmlAttr and XmlNode * can only be created with an associated XmlDoc instance. * * Main properties of the XML document are * * name of the root element * * encoding (defaults to _UTF-8_) * */ %extend _WsXmlDoc { /* * Create XmlDoc with node name * optionally pass namespace as 2nd arg (defaults to NULL) */ _WsXmlDoc(const char *name, const char *ns = NULL) { return ws_xml_create_doc(ns, name); } /* destructor */ ~_WsXmlDoc() { ws_xml_destroy_doc( $self ); } %typemap(newfree) char * "free($1);"; #if defined(SWIGRUBY) %alias string "to_xml"; #endif #if defined(SWIGPYTHON) %rename("__str__") string(); #endif #if defined(SWIGJAVA) %rename("toString") string(); #endif %newobject string; /* * generic (indented) string representation of the XmlDoc UTF-8 encoded. * see encode for setting the encoding. * * alias: to_xml * * call-seq: * doc.string -> String * doc.to_xml -> String */ char *string() { int size; char *buf; /* force utf-8 encoding since e.g. winrm sends utf-16 */ ws_xml_dump_memory_node_tree_enc( ws_xml_get_doc_root($self), &buf, &size, "UTF-8" ); return buf; } #if defined(SWIGRUBY) %alias encode "to_s"; #endif %newobject encode; /* * encode document as string with specific encoding * (non-indented representation) * * encoding defaults to 'utf-8' * * alias: to_s * * call-seq: * doc.encode -> String * doc.encode("UTF-16") -> String * doc.to_s -> string * */ char *encode(const char *encoding = "utf-8") { int size; char *buf; ws_xml_dump_memory_enc( $self, &buf, &size, encoding ); return buf; } /* * dump document to file * * call-seq: * doc.dump(IO) -> nil */ void dump_file(FILE *fp) { ws_xml_dump_doc( fp, $self ); } /* * get root node of doc * call-seq: * doc.root -> XmlNode * */ WsXmlNodeH root() { return ws_xml_get_doc_root( $self ); } /* * get soap envelope node * call-seq: * doc.envelope -> XmlNode * */ WsXmlNodeH envelope() { return ws_xml_get_soap_envelope( $self ); } /* * get soap header node * call-seq: * doc.header -> XmlNode * */ WsXmlNodeH header() { return ws_xml_get_soap_header( $self ); } /* * get soap body node * call-seq: * doc.body -> XmlNode * */ WsXmlNodeH body() { return ws_xml_get_soap_body( $self ); } /* * get soap element node by name * returns nil if no element with the name can be found * * call-seq: * doc.element(String) -> XmlNode * */ WsXmlNodeH element(const char *name) { return ws_xml_get_soap_element( $self, name ); } %newobject context; /* * get enumeration context as string * return nil if context not present or empty * * call-seq: * doc.context -> String * */ const char *context() { char *c = wsmc_get_enum_context( $self ); if (c) { if (*c) return c; u_free(c); } return NULL; } /* * Generate fault document based on given status * * This creates a new XmlDoc instance representing a fault * * call-seq: * doc.generate_fault(Openwsman::Status) -> XmlDoc * */ WsXmlDocH generate_fault(WsmanStatus *s) { return wsman_generate_fault( $self, s->fault_code, s->fault_detail_code, s->fault_msg); } #if defined(SWIGRUBY) %rename("fault?") is_fault(); %typemap(out) int is_fault "$result = ($1 != 0) ? Qtrue : Qfalse;"; #endif #if defined(SWIGJAVA) %rename("isFault") is_fault(); %typemap(jstype) int is_fault "boolean" %typemap(javaout) int is_fault { return ( $jnicall != 0 ) ? true : false; } #endif /* * Check if document represents a fault * * call-seq: * doc.fault?(XmlDoc) -> Boolean * */ int is_fault() { return wsmc_check_for_fault( $self ); } %newobject fault; /* * retrieve fault data * * call-seq: * doc.fault(XmlDoc) -> Openwsman::Fault * doc.fault(XmlDoc) -> nil # if XmlDoc is not a fault */ WsManFault *fault() { WsManFault *f = NULL; if (wsmc_check_for_fault($self)) { f = (WsManFault *)calloc(1, sizeof(WsManFault)); wsmc_get_fault_data($self, f); } return f; } /* * Generate response envelope document, optionally relating to a * specific action. * * This creates a new XmlDoc instance representing a response. * * call-seq: * doc.create_response_envelope(String action) -> XmlDoc * */ WsXmlDocH create_response_envelope(const char *action = NULL) { return wsman_create_response_envelope($self, action); } #if defined(SWIGRUBY) %rename("end_of_sequence?") is_end_of_sequence(); %typemap(out) int is_end_of_sequence "$result = ($1 != 0) ? Qtrue : Qfalse;"; #endif /* * Check if document represents an end of sequence (last enumeration item) * * call-seq: * doc.is_end_of_sequence() -> Boolean */ int is_end_of_sequence() { return NULL != ws_xml_find_in_tree( ws_xml_get_soap_body( $self ), XML_NS_ENUMERATION, WSENUM_END_OF_SEQUENCE, 1 ); } } /* * Document-class: XmlNode * * XmlNode is a node inside the XML document tree. * * A node has * * a name * * a namespace (optional) * * attributes * * text (optional) * * a parent * * a document (root) * * children (empty for tail nodes) * */ %rename(XmlNode) __WsXmlNode; %nodefault __WsXmlNode; struct __WsXmlNode {}; /* without empty struct, the %rename isn't executed. */ typedef struct __WsXmlNode* WsXmlNodeH; %extend __WsXmlNode { ~__WsXmlNode() { ws_xml_unlink_node($self); } #if defined(SWIGRUBY) %alias text "to_s"; %alias string "to_xml"; #endif #if defined(SWIGPYTHON) %rename("__str__") text(); #endif #if defined(SWIGJAVA) %rename("toString") text(); %rename("toXML") string(); #endif %newobject string; /* * dump node as XML string * * alias: to_xml * * call-seq: * node.string(XmlNode) -> String */ char *string() { int size; char *buf; ws_xml_dump_memory_node_tree( $self, &buf, &size ); return buf; } /* * dump node to file * * call-seq: * node.dump_file(IO) -> nil */ void dump_file(FILE *fp) { ws_xml_dump_node_tree( fp, $self ); } #if defined(SWIGRUBY) %alias equal "=="; %typemap(out) int equal "$result = ($1 != 0) ? Qtrue : Qfalse;"; #endif #if defined(SWIGPERL) int __eq__( WsXmlNodeH n ) #else int equal( WsXmlNodeH n ) #endif /* * Test for identity (same object) * * call-seq: * XmlNode == XmlNode -> Boolean */ { return $self == n; } /* * get text (without xml tags) of node * * alias: to_s * * call-seq: * node.text(XmlNode) -> String */ char *text() { return ws_xml_get_node_text( $self ); } #if defined(SWIGRUBY) %rename( "text=" ) set_text( const char *text ); #endif /* * Set text of node * * call-seq: * node.text = String */ void set_text( const char *text ) { ws_xml_set_node_text( $self, text ); } /* * get XmlDoc to which node belongs * * call-seq: * node.doc -> XmlDoc */ WsXmlDocH doc() { return ws_xml_get_node_doc( $self ); } /* * get parent for node * * call-seq: * node.parent -> XmlNode */ WsXmlNodeH parent() { return ws_xml_get_node_parent( $self ); } #if defined(SWIGRUBY) %alias child "first"; #endif /* * get first child of node * * call-seq: * node.child -> XmlNode */ WsXmlNodeH child() { return xml_parser_get_first_child($self); } /* * get name for node * * call-seq: * node.name -> String */ char *name() { return ws_xml_get_node_local_name( $self ); } #if defined(SWIGRUBY) %rename("name=") set_name( const char *name); #endif /* * set name of node * * call-seq: * node.name = String */ void set_name( const char *name ) { ws_xml_set_node_name( $self, ws_xml_get_node_name_ns( $self ), name ); } /* * get namespace for node * * call-seq: * node.ns -> String */ char *ns() { return ws_xml_get_node_name_ns( $self ); } #if defined(SWIGRUBY) %rename("ns=") set_ns( const char *nsuri ); #endif /* * set namespace of node * * call-seq: * node.ns = String */ void set_ns( const char *ns ) { ws_xml_set_ns( $self, ns, ws_xml_get_node_name_ns_prefix($self) ); } /* * get prefix of nodes namespace * * call-seq: * node.prefix -> String */ const char *prefix() { return ws_xml_get_node_name_ns_prefix($self); } #if defined(SWIGRUBY) %rename("lang=") set_lang(const char *lang); #endif /* * set language * * call-seq: * node.lang = String */ void set_lang(const char *lang) { ws_xml_set_node_lang($self, lang); } /* * find node within tree * a NULL passed as 'ns' (namespace) is treated as wildcard * * call-seq: * node.find("namespace", "name") -> String # recursive * node.find("namespace", "name", 0) -> String # non-recursive */ WsXmlNodeH find( const char *ns, const char *name, int recursive = 1) { return ws_xml_find_in_tree( $self, ns, name, recursive ); } /* * iterate over siblings * * finds next sibling with same namespace and name * * See also XmlNode#each * * XmlNode#each iterates over children, XmlNode#next over siblings * * Example: * * ... * ... * ... * ... * ... * ... * * * node = root.Foo # points to node * * bar = node.Bar * while bar do * bar = bar.next * end * * will give you four iterations (all nodes) * * child = node.Bar * while child do * child = child.next(1) * end * * will give you six iterations (all children of ) * The latter example is equal to * * node.each do |child| * ... * end * */ WsXmlNodeH next(int all = 0) { WsXmlNodeH next_node = xml_parser_get_next_child($self); if (next_node && !all) { const char *ns_uri = ws_xml_get_node_name_ns($self); const char *name = ws_xml_get_node_local_name($self); if (ws_xml_is_node_qname(next_node, ns_uri, name) == 0) { next_node = NULL; } } return next_node; } /* * count node children * if name given, count children with this name * if name + ns given, count children with this namespace and name */ int size(const char *name = NULL, const char *ns = NULL) { return ws_xml_get_child_count_by_qname($self, ns, name); } /* * add child (namespace, name, text) to node */ WsXmlNodeH add( const char *ns, const char *name, const char *text = NULL ) { return ws_xml_add_child( $self, ns, name, text ); } /* * add child (namespace, name, text) before(!) node */ WsXmlNodeH add_before( const char *ns, const char *name, const char *text = NULL ) { return ws_xml_add_prev_sibling( $self, ns, name, text ); } #if defined(SWIGRUBY) %alias add "<<"; #endif /* * add node as child */ WsXmlNodeH add(WsXmlNodeH node) { ws_xml_duplicate_tree( $self, node ); return $self; } #if defined(SWIGRUBY) /* * iterate over children * * See also XmlNode#next * * XmlNode#each iterates over children, XmlNode#next over siblings * * can be limited to children with specific name (and specific namespace) * * for array-like constructs, e.g * * .. * .. * .. * .. * .. * .. * * doc.Parent.each do |child| * ... iterates over all 6 children ... * end * * use XmlNode#next as in * node = doc.OtherChild * while node do * ... do something with node ... * node = node.next * end * * call-seq: * node.each { |XmlNode| ... } * node.each("name") { |XmlNode| ... } * node.each("name", "namespace") { |XmlNode| ... } */ void each(const char *name = NULL, const char *ns = NULL) { int i = 0; WsXmlNodeH node = $self; int count = ws_xml_get_child_count_by_qname( node, ns, name ); while ( i < count ) { rb_yield( SWIG_NewPointerObj((void*) ws_xml_get_child(node, i, ns, name), SWIGTYPE_p___WsXmlNode, 0)); ++i; } } #endif #if defined(SWIGPYTHON) /* * iterate over children * */ %pythoncode %{ def __iter__(self): r = range(0,self.size()) while r: yield self.get(r.pop(0)) %} #endif #if defined(SWIGRUBY) %alias get "[]"; #endif /* * get child by index * * call-seq: * node.get(42) -> XmlNode * node.get(42, "name") -> XmlNode * node.get(42, "name", "namespace") -> XmlNode */ WsXmlNodeH get(int i, const char *name = NULL, const char *ns = NULL) { if (i < 0 || i >= ws_xml_get_child_count_by_qname($self,ns,name)) return NULL; return ws_xml_get_child($self, i, ns, name); } /* * get first child by name (and namespace) * * call-seq: * node.get("name") -> XmlNode * node.get("name", "namespace") -> XmlNode */ WsXmlNodeH get(const char *name, const char *ns = NULL) { return ws_xml_get_child($self, 0, ns, name); } #if defined(SWIGRUBY) /* * get node attribute by index or name * * call-seq: * node.attr(1) -> XmlAttr * node.attr("name") -> XmlAttr * node.attr("name", "namespace") -> XmlAttr */ WsXmlAttrH attr(VALUE index = Qnil, VALUE namespace = Qnil) { if (NIL_P(index)) { /* nil */ return ws_xml_get_node_attr( $self, 0 ); } else if (FIXNUM_P(index)) { /* numeric */ return ws_xml_get_node_attr( $self, FIX2INT(index) ); } else { /* convert to string */ const char *ns = NULL; const char *name = as_string(index); if (!NIL_P(namespace)) { ns = as_string(namespace); } return ws_xml_find_node_attr( $self, ns, name ); } } #else /* get node attribute */ WsXmlAttrH attr(int index = 0) { return ws_xml_get_node_attr( $self, index ); } #endif /* * count node attribute * * call-seq: * node.attr_count -> Integer */ int attr_count() { return ws_xml_get_node_attr_count( $self ); } /* * find node attribute by name * * call-seq: * node.attr_find("namespace", "name") -> XmlAttr */ WsXmlAttrH attr_find( const char *ns, const char *name ) { return ws_xml_find_node_attr( $self, ns, name ); } /* * add attribute to node * * call-seq: * node.attr_add("namespace", "name", "value") -> XmlAttr */ WsXmlAttrH attr_add( const char *ns, const char *name, const char *value ) { return ws_xml_add_node_attr( $self, ns, name, value ); } /* * get end point reference * * call-seq: * node.epr("namespace", "epr_node_name", Integer embedded) -> EndPointReference */ epr_t *epr( const char *ns, const char *epr_node_name, int embedded) { return epr_deserialize($self, ns, epr_node_name, embedded); } #if defined(SWIGRUBY) /* * enumerate attributes * * call-seq: * node.each_attr { |XmlAttr| ... } */ void each_attr() { int i = 0; while ( i < ws_xml_get_node_attr_count( $self ) ) { rb_yield( SWIG_NewPointerObj((void*) ws_xml_get_node_attr($self, i), SWIGTYPE_p___WsXmlAttr, 0)); ++i; } } #endif } /* * Document-class: XmlAttr * An XmlAttr is a key/value pair representing an attribute of a node. * * An attribute has * * a name (the key) * * a namespace (optional) * * a value * * There is no standalone constructor available for XmlAttr, use * XmlNode.add_attr() to create a new attribute. * */ %rename(XmlAttr) __WsXmlAttr; %nodefault __WsXmlAttr; /* part of WsXmlNode */ struct __WsXmlAttr {}; /* without empty struct, the %rename isn't executed. */ typedef struct __WsXmlAttr* WsXmlAttrH; %extend __WsXmlAttr { #if defined(SWIGRUBY) %alias value "to_s"; #endif /* * get name for attr * * call-seq: * attr.name -> String */ char *name() { return ws_xml_get_attr_name( $self ); } /* * get namespace for attr * * call-seq: * attr.ns -> String */ char *ns() { return ws_xml_get_attr_ns( $self ); } /* * get value for attr * * call-seq: * attr.value -> String */ char *value() { return ws_xml_get_attr_value( $self ); } /* * remove note attribute * * call-seq: * attr.remove -> nil */ void remove() { ws_xml_remove_node_attr( $self ); } } openwsman-2.4.3/src/lib/wsman-filter.c000664 001750 001750 00000033730 12256012305 020114 0ustar00kentbkentb000000 000000 /******************************************************************************* * 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 Liang Hou, Intel Corp. */ #include "u/libu.h" #include "wsman-xml.h" #include "wsman-names.h" #include "wsman-filter.h" filter_t * filter_initialize(void) { filter_t *filter = u_zalloc(sizeof(filter_t)); return filter; } static int filter_set(filter_t *filter, const char *dialect, const char *query, epr_t *epr, hash_t *selectors, const int assocType, const char *assocClass, const char *resultClass, const char *role, const char *resultRole, char **resultProp, const int propNum) { int i = 0; if(dialect == NULL) { filter->dialect = u_strdup(WSM_XPATH_FILTER_DIALECT); } else { filter->dialect = u_strdup(dialect); } if (query) { filter->query = u_strdup(query); } else if(epr != 0) { filter->epr = epr_copy(epr); filter->assocType = assocType; if(assocClass) filter->assocClass = u_strdup(assocClass); if(resultClass) filter->resultClass = u_strdup(resultClass); if(role) filter->role = u_strdup(role); if(resultRole) filter->resultRole = u_strdup(resultRole); if(resultProp && propNum) { filter->resultProp = u_malloc(propNum*sizeof(char *)); filter->PropNum = propNum; while(i < propNum) { filter->resultProp[i] = u_strdup(resultProp[i]); i++; } } } else if(selectors) { hnode_t *hn; hscan_t hs; Selector *p; selector_entry *entry; filter->selectorset.count = hash_count(selectors); filter->selectorset.selectors = u_malloc(sizeof(Selector)* filter->selectorset.count); p = filter->selectorset.selectors; hash_scan_begin(&hs, selectors); while ((hn = hash_scan_next(&hs))) { p->name = u_strdup((char *)hnode_getkey(hn)); entry = (selector_entry *)hnode_get(hn); if(entry->type == 1) { p->type = 1; p->value = (char *)epr_copy(entry->entry.eprp); debug("key=%s value=%p(nested epr)", (char *) hnode_getkey(hn), p->value); } else { p->type = 0; p->value = u_strdup(entry->entry.text); debug("key=%s value=%s", (char *) hnode_getkey(hn), p->value); } p++; } } else goto cleanup; return 0; cleanup: return 1; } filter_t *filter_create(const char *dialect, const char *query, epr_t *epr, hash_t *selectors, const int assocType, const char *assocClass, const char *resultClass, const char *role, const char *resultRole, char **resultProp, const int propNum) { int ret = 0; filter_t *filter = filter_initialize(); if (filter == NULL) return NULL; ret = filter_set(filter, dialect, query, epr, selectors, assocType, assocClass, resultClass, role, resultRole, resultProp, propNum); if (ret == 1 ) { filter_destroy(filter); return NULL; } else { return filter; } } int filter_set_simple(filter_t *filter, const char *dialect, const char *query) { return filter_set(filter, dialect, query, NULL, NULL, 0, NULL, NULL, NULL, NULL, NULL, 0); } filter_t * filter_create_simple(const char *dialect, const char *query) { return filter_create(dialect, query, NULL, NULL, 0, NULL, NULL, NULL, NULL, NULL, 0); } int filter_set_assoc(filter_t *filter, epr_t *epr, const int assocType, const char *assocClass, const char *resultClass, const char *role, const char *resultRole, char **resultProp, const int propNum) { return filter_set(filter, WSM_ASSOCIATION_FILTER_DIALECT, NULL, epr, NULL, assocType, assocClass, resultClass, role, resultRole, resultProp, propNum); } filter_t * filter_create_assoc(epr_t *epr, const int assocType, const char *assocClass, const char *resultClass, const char *role, const char *resultRole, char **resultProp, const int propNum) { return filter_create(WSM_ASSOCIATION_FILTER_DIALECT, NULL, epr, NULL, assocType, assocClass, resultClass, role, resultRole, resultProp, propNum); } filter_t * filter_create_selector(hash_t *selectors) { return filter_create(WSM_SELECTOR_FILTER_DIALECT, NULL, NULL, selectors, 0, NULL, NULL, NULL, NULL, NULL, 0); } int filter_add_selector(filter_t *filter, const char* key, const char *value) { int i; Selector *entry; if(filter == NULL || key == NULL || value == NULL) return 0; entry = filter->selectorset.selectors; for(i = 0; i < filter->selectorset.count; i++) { if(strcmp(key, entry[i].name) == 0) return -1; } entry = u_realloc(entry, (filter->selectorset.count+1) * sizeof(Selector)); if(entry == NULL) return -1; entry[filter->selectorset.count].type = 0; entry[filter->selectorset.count].name = u_strdup(key); entry[filter->selectorset.count].value = u_strdup(value); filter->selectorset.selectors = entry; filter->selectorset.count++; return 0; } filter_t * filter_copy(filter_t *filter) { filter_t *filter_cpy = NULL; Selector *p1; Selector *p2; int i = 0; if(filter == NULL) return NULL; filter_cpy = u_zalloc(sizeof(filter_t)); if(filter_cpy == NULL) return NULL; if(filter->dialect) filter_cpy->dialect = u_strdup(filter->dialect); filter_cpy->assocType = filter->assocType; if(filter->epr) filter_cpy->epr = epr_copy(filter->epr); if(filter->query) filter_cpy->query = u_strdup(filter->query); filter_cpy->selectorset.count = filter->selectorset.count; filter_cpy->selectorset.selectors = u_malloc(sizeof(Selector) * filter->selectorset.count); p1 = filter->selectorset.selectors; p2 = filter_cpy->selectorset.selectors; for(i = 0; i < filter_cpy->selectorset.count; i++) { p2->name = u_strdup(p1->name); p2->type = p1->type; if(p1->type == 0) p2->value = u_strdup(p1->value); else p2->value = (char *)epr_copy((epr_t*)p1->value); p1++; p2++; } if(filter->assocClass) filter_cpy->assocClass = u_strdup(filter->assocClass); if(filter->resultClass) filter_cpy->resultClass = u_strdup(filter->resultClass); if(filter->resultRole) filter_cpy->resultRole = u_strdup(filter->resultRole); if(filter->resultProp) { int i = 0; filter_cpy->resultProp = u_malloc(filter->PropNum*sizeof(char *)); filter_cpy->PropNum = filter->PropNum; while(i < filter->PropNum) { filter_cpy->resultProp[i] = u_strdup(filter->resultProp[i]); i++; } } return filter_cpy; } void filter_destroy(filter_t *filter) { Selector *p; int i; if(filter == NULL) return; if(filter->assocClass) u_free(filter->assocClass); if(filter->dialect) u_free(filter->dialect); if(filter->query) u_free(filter->query); if(filter->epr) epr_destroy(filter->epr); p = filter->selectorset.selectors; for(i = 0; i< filter->selectorset.count; i++) { u_free(p->name); if(p->type == 0) u_free(p->value); else epr_destroy((epr_t*)p->value); p++; } u_free(filter->selectorset.selectors); if(filter->resultClass) u_free(filter->resultClass); if(filter->resultProp) { int i = 0; while(i < filter->PropNum) { u_free(filter->resultProp[i]); i++; } u_free(filter->resultProp); } if(filter->resultRole) u_free(filter->resultRole); if(filter->role) u_free(filter->role); u_free(filter); } int filter_serialize(WsXmlNodeH node, filter_t *filter, const char *ns) { int r = 0; WsXmlNodeH filter_node = NULL; WsXmlNodeH instance_node = NULL; if(filter->query) { filter_node = ws_xml_add_child(node, ns, WSM_FILTER, filter->query); } else if(filter->epr) { filter_node = ws_xml_add_child(node, ns, WSM_FILTER, NULL); if(filter->assocType == 0) instance_node = ws_xml_add_child(filter_node, XML_NS_CIM_BINDING, WSMB_ASSOCIATED_INSTANCES, NULL); else instance_node = ws_xml_add_child(filter_node, XML_NS_CIM_BINDING, WSMB_ASSOCIATION_INSTANCES, NULL); r = epr_serialize(instance_node, XML_NS_CIM_BINDING, WSMB_OBJECT, filter->epr, 1); if(r) return r; if(filter->assocClass) ws_xml_add_child(instance_node, XML_NS_CIM_BINDING, WSMB_ASSOCIATION_CLASS_NAME, filter->assocClass); if(filter->role) ws_xml_add_child(instance_node, XML_NS_CIM_BINDING, WSMB_ROLE, filter->role); if(filter->resultClass) ws_xml_add_child(instance_node, XML_NS_CIM_BINDING, WSMB_RESULT_CLASS_NAME, filter->resultClass); if(filter->resultRole) ws_xml_add_child(instance_node, XML_NS_CIM_BINDING, WSMB_RESULT_ROLE, filter->resultRole); if(filter->resultProp) { int i = 0; while(i < filter->PropNum) { ws_xml_add_child(instance_node, XML_NS_CIM_BINDING, WSMB_INCLUDE_RESULT_PROPERTY, filter->resultProp[i]); i++; } } } else if(filter->selectorset.count) { int i = 0; filter_node = ws_xml_add_child(node, ns, WSM_FILTER, NULL); node = ws_xml_add_child(filter_node, XML_NS_WS_MAN, WSM_SELECTOR_SET, NULL); while (i < filter->selectorset.count) { if(filter->selectorset.selectors[i].type == 0) { instance_node = ws_xml_add_child(node, XML_NS_WS_MAN, WSM_SELECTOR, filter->selectorset.selectors[i].value); ws_xml_add_node_attr(instance_node, NULL, WSM_NAME, filter->selectorset.selectors[i].name); } else { epr_serialize(node, NULL, NULL, (epr_t *)filter->selectorset.selectors[i].value, 1); } i++; } } else { return -1; } if(filter->dialect) ws_xml_add_node_attr(filter_node, NULL, WSM_DIALECT, filter->dialect); return r; } filter_t * filter_deserialize(WsXmlNodeH node, const char *ns) { char *dialect = NULL; int properNum = 0; int i = 0; WsXmlAttrH attr = NULL; filter_t *filter = NULL; WsXmlNodeH instance_node = NULL; WsXmlNodeH entry_node = NULL; /* look for wse:Filter */ WsXmlNodeH filter_node = ws_xml_get_child(node, 0, ns, WSM_FILTER); if(filter_node == NULL) return NULL; filter = u_zalloc(sizeof(filter_t)); dialect = ws_xml_find_attr_value(filter_node, NULL, WSM_DIALECT); if(dialect) filter->dialect = u_strdup(dialect); else{ attr = ws_xml_get_node_attr(filter_node, 0); if(attr) { filter->dialect = u_strdup(ws_xml_get_attr_value(attr)); } else filter->dialect = u_strdup(WSM_XPATH_FILTER_DIALECT); } if(strcmp(filter->dialect , WSM_ASSOCIATION_FILTER_DIALECT) == 0) { instance_node = ws_xml_get_child(filter_node, 0, XML_NS_CIM_BINDING, WSMB_ASSOCIATED_INSTANCES); if(instance_node) { filter->assocType = 0; } else { instance_node = ws_xml_get_child(filter_node, 0, XML_NS_CIM_BINDING, WSMB_ASSOCIATION_INSTANCES); if(instance_node) { filter->assocType = 1; } else goto CLEANUP; } filter->epr = epr_deserialize(instance_node, XML_NS_CIM_BINDING, WSMB_OBJECT, 1); entry_node = ws_xml_get_child(instance_node, 0, XML_NS_CIM_BINDING, WSMB_ASSOCIATION_CLASS_NAME); if(entry_node) filter->assocClass = u_strdup(ws_xml_get_node_text(entry_node)); entry_node = ws_xml_get_child(instance_node, 0, XML_NS_CIM_BINDING, WSMB_ROLE); if(entry_node) filter->role = u_strdup(ws_xml_get_node_text(entry_node)); entry_node = ws_xml_get_child(instance_node, 0, XML_NS_CIM_BINDING, WSMB_RESULT_CLASS_NAME); if(entry_node) filter->resultClass = u_strdup(ws_xml_get_node_text(entry_node)); entry_node = ws_xml_get_child(instance_node, 0, XML_NS_CIM_BINDING, WSMB_RESULT_ROLE); if(entry_node) filter->resultRole = u_strdup(ws_xml_get_node_text(entry_node)); properNum = ws_xml_get_child_count(instance_node) - 4; filter->resultProp = u_zalloc(properNum * sizeof(char*)); while(i < properNum) { filter_node = ws_xml_get_child(instance_node, i, XML_NS_CIM_BINDING, WSMB_INCLUDE_RESULT_PROPERTY); if(filter_node == NULL) break; filter->resultProp[i] = u_strdup(ws_xml_get_node_text(filter_node)); i++; } filter->PropNum = i; } else if(strcmp(filter->dialect, WSM_SELECTOR_FILTER_DIALECT) == 0) { filter_node = ws_xml_get_child(filter_node, 0, XML_NS_WS_MAN, WSM_SELECTOR_SET); if(filter_node == NULL) goto CLEANUP; filter->selectorset.count = ws_xml_get_child_count(filter_node); filter->selectorset.selectors = u_malloc(sizeof(Selector) * filter->selectorset.count ); while(i < filter->selectorset.count) { entry_node = ws_xml_get_child(filter_node, i, XML_NS_WS_MAN, WSM_SELECTOR); if(entry_node == NULL) break; attr = ws_xml_find_node_attr(entry_node, NULL, WSM_NAME); if(attr) { filter->selectorset.selectors[i].name = u_strdup(ws_xml_get_attr_value(attr)); } instance_node = ws_xml_get_child(entry_node, 0, XML_NS_ADDRESSING, WSA_EPR); if(instance_node) { filter->selectorset.selectors[i].type = 1; filter->selectorset.selectors[i].value = (char *)epr_deserialize(instance_node, NULL, NULL, 1); } else { filter->selectorset.selectors[i].type = 0; filter->selectorset.selectors[i].value = u_strdup(ws_xml_get_node_text(entry_node)); } i++; } } else filter->query = u_strdup(ws_xml_get_node_text(filter_node)); return filter; CLEANUP: filter_destroy(filter); return NULL; } openwsman-2.4.3/src/server/shttpd/log.c000664 001750 001750 00000005025 12256012305 020327 0ustar00kentbkentb000000 000000 /* * Copyright (c) 2004-2005 Sergey Lyubka * All rights reserved * * "THE BEER-WARE LICENSE" (Revision 42): * Sergey Lyubka wrote this file. As long as you retain this notice you * can do whatever you want with this stuff. If we meet some day, and you think * this stuff is worth it, you can buy me a beer in return. */ #include "shttpd_defs.h" /* * Log function */ void elog(int flags, struct conn *c, const char *fmt, ...) { char date[64], buf[URI_MAX]; int len; FILE *fp = c == NULL ? NULL : c->ctx->error_log; va_list ap; /* Print to stderr */ if (c == NULL || c->ctx->inetd_mode == 0) { va_start(ap, fmt); (void) vfprintf(stderr, fmt, ap); (void) fputc('\n', stderr); va_end(ap); } strftime(date, sizeof(date), "%a %b %d %H:%M:%S %Y", localtime(¤t_time)); len = snprintf(buf, sizeof(buf), "[%s] [error] [client %s] \"%s\" ", date, c ? inet_ntoa(c->sa.u.sin.sin_addr) : "-", c && c->request ? c->request : "-"); va_start(ap, fmt); (void) vsnprintf(buf + len, sizeof(buf) - len, fmt, ap); va_end(ap); buf[sizeof(buf) - 1] = '\0'; if (fp != NULL && (flags & (E_FATAL | E_LOG))) { (void) fprintf(fp, "%s\n", buf); (void) fflush(fp); } #if defined(_WIN32) && !defined(NO_GUI) { extern HWND hLog; if (hLog != NULL) SendMessage(hLog, WM_APP, 0, (LPARAM) buf); } #endif /* _WIN32 */ if (flags & E_FATAL) exit(EXIT_FAILURE); } #if 0 void log_access(FILE *fp, const struct conn *c) { static const struct vec dash = {"-", 1}; const struct vec *user = &c->ch.user.v_vec; const struct vec *referer = &c->ch.referer.v_vec; const struct vec *user_agent = &c->ch.useragent.v_vec; char date[64], buf[URI_MAX], *q1 = "\"", *q2 = "\""; if (user->len == 0) user = ‐ if (referer->len == 0) { referer = ‐ q1 = ""; } if (user_agent->len == 0) { user_agent = ‐ q2 = ""; } (void) strftime(date, sizeof(date), "%d/%b/%Y:%H:%M:%S", localtime(¤t_time)); (void) snprintf(buf, sizeof(buf), "%s - %.*s [%s %+05d] \"%s\" %d %lu %s%.*s%s %s%.*s%s", inet_ntoa(c->sa.u.sin.sin_addr), user->len, user->ptr, date, tz_offset, c->request ? c->request : "-", c->status, (unsigned long) c->loc.io.total, q1, referer->len, referer->ptr, q1, q2, user_agent->len, user_agent->ptr, q2); if (fp != NULL) { (void) fprintf(fp, "%s\n", buf); (void) fflush(fp); } #if defined(_WIN32) && !defined(NO_GUI) { extern HWND hLog; if (hLog != NULL) SendMessage(hLog, WM_APP, 0, (LPARAM) buf); } #endif /* _WIN32 */ } #endif openwsman-2.4.3/README.md000664 001750 001750 00000020377 12256012305 015265 0ustar00kentbkentb000000 000000 # How to compile and run openwsman from GIT ? After checking out the project from git, create a build directory with mkdir build cd into it cd build cmake .. make See `package/openwsman.spec.in` for running cmake in 'release' mode Most likely you will need to install some of the packages, depending on the distribution you are running. Pre-build (RPM) packages for many distributions are available at [[the openSUSE build service|https://build.opensuse.org/project/show?project=Openwsman]] ## Packages and other software needed: * libxml2 * sblim-sfcc (from the sblim project) * swig and python for python binding support * other development packages like cmake, gcc, etc. After all packages are installed, compile everything and install. The server can run as a daemon, which would require root access; But it can be run in the foreground with debugging messages printed to stdout as well. This the help output when you run: /usr/sbin/openwsmand --help Usage: openwsmand [OPTION...] WS-Management Server Help Options: -?, --help Show help options Application Options: -n, --no-plugins Do not load any plugins -d, --debug Start daemon in foreground and turn on debugging -s, --syslog=0-6 Set the verbosity of syslog output. -c, --config-file= Alternate configuration file Starting from version 0.1.1 a configuration file is needed. you can find an example in the `./etc` directory. The configuration file has the following syntax: [server] port = 5985 #ssl_port = 5986 ssl_cert_file = /etc/openwsman/servercert.pem ssl_key_file = /etc/openwsman/serverkey.pem #digest_password_file = /etc/openwsman/digest_auth.passwd basic_password_file = /etc/openwsman/simple_auth.passwd enum_idle_timeout = 5000 min_threads = 1 max_threads = 1 #use_digest is OBSOLETED, see below. # # Authentication backend for BASIC authentication. Default is to read a configuration file defined with 'basic_password_file' # #basic_authenticator = libwsman_pam_auth.so #basic_authenticator_arg = openwsman [client] port = 5988 agent = openwsman 2.2.4 [cim] default_cim_namespace = root/cimv2 # The following are in part fake namespaces for some publicly available CIM implementations. vendor_namespaces = OpenWBEM=http://schema.openwbem.org/wbem/wscim/1/cim-schema/2,Linux=http://sblim.sf.net/wbem/wscim/1/cim-schema/2,OMC=http://schema.omc-project.org/wbem/wscim/1/cim-schema/2,Reef=http://reef.sblim.sf.net/wbem/wscim/1/cim-schema/2,CWS=http://cws.sblim.sf.net/wbem/wscim/1/cim-schema/2 To run in SSL mode you need to enable the SSL port and create certificates and adapt the configuration with the correct path to the files. To start the server in the foreground, run: /usr/sbin/openwsmand -d You can also specify the configuration file to be used on the command line using the -c option. On the client side, which has the following options /usr/bin/wsman --help-all Usage: wsman [Option...] Help Options -?, --help --help-all Show help options --help-enumeration Enumeration Options --help-tests Test Cases --help-cim CIM Options --help-flags Request Flags --help-event Subscription Options Enumeration -m, --max-elements= Max Elements Per Pull/Optimized Enumeration -o, --optimize Optimize enumeration results -E, --estimate-count Return estimation of total items -M, --enum-mode=epr|objepr Enumeration Mode -U, --enum-context= Enumeration Context (For use with Pull and Release) Tests -f, --from-file= Send request from file -R, --print-request print request on stdout -Q, --request Only output reqest. Not send it. -S, --step Do not perform multiple operations (do not pull data when enumerating) CIM -N, --namespace= CIM Namespace (default is root/cimv2) -B, --binding-enum-mode=none|include|exclude CIM binding Enumeration Mode -T, --cim-extensions Show CIM Extensions -W, --references CIM References -w, --associators CIM Associators Flags -x, --filter= Filter -D, --dialect= Filter Dialect -t, --operation-timeout=