diff --git a/Recipe b/Recipe index 10366fe0..eabdf3fa 100644 --- a/Recipe +++ b/Recipe @@ -270,7 +270,7 @@ MISC = misc marshal MISCNET = timing callback MISC version settings tree234 proxy CONF be_misc WINMISC = MISCNET winstore winnet winhandl cmdline windefs winmisc winproxy + wintime winhsock errsock winsecur winucs miscucs -UXMISC = MISCNET uxstore uxsel uxnet uxpeer uxmisc uxproxy time +UXMISC = MISCNET uxstore uxsel uxnet uxpeer uxmisc uxproxy errsock time # import.c and dependencies, for PuTTYgen-like utilities that have to # load foreign key files. diff --git a/errsock.c b/errsock.c index d4878a9a..7e5f97be 100644 --- a/errsock.c +++ b/errsock.c @@ -56,11 +56,23 @@ static const SocketVtable ErrorSocket_sockvt = { sk_error_peer_info, }; -Socket *new_error_socket(const char *errmsg, Plug *plug) +static Socket *new_error_socket_internal(char *errmsg, Plug *plug) { ErrorSocket *es = snew(ErrorSocket); es->sock.vt = &ErrorSocket_sockvt; es->plug = plug; - es->error = dupstr(errmsg); + es->error = errmsg; return &es->sock; } + +Socket *new_error_socket_fmt(Plug *plug, const char *fmt, ...) +{ + va_list ap; + char *msg; + + va_start(ap, fmt); + msg = dupvprintf(fmt, ap); + va_end(ap); + + return new_error_socket_internal(msg, plug); +} diff --git a/network.h b/network.h index 62361d11..f7152054 100644 --- a/network.h +++ b/network.h @@ -220,7 +220,7 @@ char *get_hostname(void); * Trivial socket implementation which just stores an error. Found in * errsock.c. */ -Socket *new_error_socket(const char *errmsg, Plug *plug); +Socket *new_error_socket_fmt(Plug *plug, const char *fmt, ...); /* * Trivial plug that does absolutely nothing. Found in nullplug.c. diff --git a/windows/winnpc.c b/windows/winnpc.c index b61ddada..63387230 100644 --- a/windows/winnpc.c +++ b/windows/winnpc.c @@ -23,7 +23,6 @@ Socket *new_named_pipe_client(const char *pipename, Plug *plug) HANDLE pipehandle; PSID usersid, pipeowner; PSECURITY_DESCRIPTOR psd; - char *err; Socket *ret; assert(strncmp(pipename, "\\\\.\\pipe\\", 9) == 0); @@ -38,11 +37,9 @@ Socket *new_named_pipe_client(const char *pipename, Plug *plug) break; if (GetLastError() != ERROR_PIPE_BUSY) { - err = dupprintf("Unable to open named pipe '%s': %s", - pipename, win_strerror(GetLastError())); - ret = new_error_socket(err, plug); - sfree(err); - return ret; + return new_error_socket_fmt( + plug, "Unable to open named pipe '%s': %s", + pipename, win_strerror(GetLastError())); } /* @@ -53,41 +50,33 @@ Socket *new_named_pipe_client(const char *pipename, Plug *plug) * take excessively long.) */ if (!WaitNamedPipe(pipename, NMPWAIT_USE_DEFAULT_WAIT)) { - err = dupprintf("Error waiting for named pipe '%s': %s", - pipename, win_strerror(GetLastError())); - ret = new_error_socket(err, plug); - sfree(err); - return ret; + return new_error_socket_fmt( + plug, "Error waiting for named pipe '%s': %s", + pipename, win_strerror(GetLastError())); } } if ((usersid = get_user_sid()) == NULL) { CloseHandle(pipehandle); - err = dupprintf("Unable to get user SID"); - ret = new_error_socket(err, plug); - sfree(err); - return ret; + return new_error_socket_fmt( + plug, "Unable to get user SID: %s", win_strerror(GetLastError())); } if (p_GetSecurityInfo(pipehandle, SE_KERNEL_OBJECT, OWNER_SECURITY_INFORMATION, &pipeowner, NULL, NULL, NULL, &psd) != ERROR_SUCCESS) { - err = dupprintf("Unable to get named pipe security information: %s", - win_strerror(GetLastError())); - ret = new_error_socket(err, plug); - sfree(err); CloseHandle(pipehandle); - return ret; + return new_error_socket_fmt( + plug, "Unable to get named pipe security information: %s", + win_strerror(GetLastError())); } if (!EqualSid(pipeowner, usersid)) { - err = dupprintf("Owner of named pipe '%s' is not us", pipename); - ret = new_error_socket(err, plug); - sfree(err); CloseHandle(pipehandle); LocalFree(psd); - return ret; + return new_error_socket_fmt( + plug, "Owner of named pipe '%s' is not us", pipename); } LocalFree(psd); diff --git a/windows/winproxy.c b/windows/winproxy.c index 2059d964..d0a8884b 100644 --- a/windows/winproxy.c +++ b/windows/winproxy.c @@ -50,30 +50,30 @@ Socket *platform_new_connection(SockAddr *addr, const char *hostname, sa.lpSecurityDescriptor = NULL; /* default */ sa.bInheritHandle = TRUE; if (!CreatePipe(&us_from_cmd, &cmd_to_us, &sa, 0)) { - Socket *ret = - new_error_socket("Unable to create pipes for proxy command", plug); sfree(cmd); - return ret; + return new_error_socket_fmt( + plug, "Unable to create pipes for proxy command: %s", + win_strerror(GetLastError())); } if (!CreatePipe(&cmd_from_us, &us_to_cmd, &sa, 0)) { - Socket *ret = - new_error_socket("Unable to create pipes for proxy command", plug); sfree(cmd); CloseHandle(us_from_cmd); CloseHandle(cmd_to_us); - return ret; + return new_error_socket_fmt( + plug, "Unable to create pipes for proxy command: %s", + win_strerror(GetLastError())); } if (!CreatePipe(&us_from_cmd_err, &cmd_err_to_us, &sa, 0)) { - Socket *ret = new_error_socket - ("Unable to create pipes for proxy command", plug); sfree(cmd); CloseHandle(us_from_cmd); CloseHandle(cmd_to_us); CloseHandle(us_to_cmd); CloseHandle(cmd_from_us); - return ret; + return new_error_socket_fmt( + plug, "Unable to create pipes for proxy command: %s", + win_strerror(GetLastError())); } SetHandleInformation(us_to_cmd, HANDLE_FLAG_INHERIT, 0);