Skip to content

Commit a884a53

Browse files
committed
add limited w32 implementation of setitimer w/o microsecond functionality
1 parent add0b12 commit a884a53

File tree

5 files changed

+36
-56
lines changed

5 files changed

+36
-56
lines changed

contrib/win32/win32compat/inc/sys/time.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,13 @@ struct timeval
1111
long tv_usec;
1212
};
1313

14+
struct itimerval {
15+
struct timeval it_interval; /* Timer interval */
16+
struct timeval it_value; /* Current value */
17+
};
18+
19+
#define ITIMER_REAL 0
20+
1421
int usleep(unsigned int);
1522
int gettimeofday(struct timeval *, void *);
1623
int nanosleep(const struct timespec *, struct timespec *);

contrib/win32/win32compat/inc/unistd.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,9 @@ int w32_dup2(int oldfd, int newfd);
4949
unsigned int w32_alarm(unsigned int seconds);
5050
#define alarm w32_alarm
5151

52+
int w32_setitimer(int which, const struct itimerval* new_value, struct itimerval* old_value);
53+
#define setitimer w32_setitimer
54+
5255
long w32_lseek(int fd, unsigned __int64 offset, int origin);
5356
#define lseek w32_lseek
5457

contrib/win32/win32compat/signal_internal.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ struct _timer_info {
3232
ULONGLONG ticks_at_start; /* 0 if timer is not live */
3333
__int64 run_time_sec; /* time in seconds, timer is set to go off from ticks_at_start */
3434
};
35+
3536
int sw_init_timer();
3637

3738
#define MAXIMUM_WAIT_OBJECTS_ENHANCED 1024

contrib/win32/win32compat/signal_sigalrm.c

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
*/
3030

3131
#include "signal_internal.h"
32+
#include "inc\sys\time.h"
3233
#include "inc\signal.h"
3334
#include "debug.h"
3435

@@ -64,8 +65,8 @@ w32_alarm(unsigned int sec)
6465
due.QuadPart *= sec;
6566
/* this call resets the timer if it is already active */
6667
if (!SetWaitableTimer(timer_info.timer, &due, 0, sigalrm_APC, NULL, FALSE)) {
67-
debug3("alram() - ERROR SetWaitableTimer() %d", GetLastError());
68-
return 0;;
68+
debug3("alarm() - ERROR SetWaitableTimer() %d", GetLastError());
69+
return 0;
6970
}
7071

7172
/* if timer was already ative, return when it was due */
@@ -80,6 +81,23 @@ w32_alarm(unsigned int sec)
8081
return ret;
8182
}
8283

84+
int w32_setitimer(int which, const struct itimerval *new_value, struct itimerval *old_value)
85+
{
86+
if (which != ITIMER_REAL) {
87+
errno = EINVAL;
88+
return -1;
89+
}
90+
if (old_value != NULL) {
91+
errno = EINVAL;
92+
return -1;
93+
}
94+
if (new_value->it_value.tv_sec == 0 && new_value->it_value.tv_usec == 0) {
95+
w32_alarm(0);
96+
return 0;
97+
}
98+
return w32_alarm(new_value->it_value.tv_sec);
99+
}
100+
83101
int
84102
sw_init_timer()
85103
{

sshd-session.c

Lines changed: 5 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -232,55 +232,6 @@ mm_is_monitor(void)
232232
}
233233

234234
#ifdef WINDOWS
235-
/* copied from sshd.c */
236-
static struct sshbuf*
237-
pack_hostkeys(void)
238-
{
239-
struct sshbuf* keybuf = NULL, * hostkeys = NULL;
240-
int r;
241-
u_int i;
242-
243-
if ((keybuf = sshbuf_new()) == NULL ||
244-
(hostkeys = sshbuf_new()) == NULL)
245-
fatal_f("sshbuf_new failed");
246-
247-
/* pack hostkeys into a string. Empty key slots get empty strings */
248-
for (i = 0; i < options.num_host_key_files; i++) {
249-
/* private key */
250-
sshbuf_reset(keybuf);
251-
if (sensitive_data.host_keys[i] != NULL &&
252-
(r = sshkey_private_serialize(sensitive_data.host_keys[i],
253-
keybuf)) != 0)
254-
fatal_fr(r, "serialize hostkey private");
255-
if ((r = sshbuf_put_stringb(hostkeys, keybuf)) != 0)
256-
fatal_fr(r, "compose hostkey private");
257-
/* public key */
258-
if (sensitive_data.host_pubkeys[i] != NULL) {
259-
if ((r = sshkey_puts(sensitive_data.host_pubkeys[i],
260-
hostkeys)) != 0)
261-
fatal_fr(r, "compose hostkey public");
262-
}
263-
else {
264-
if ((r = sshbuf_put_string(hostkeys, NULL, 0)) != 0)
265-
fatal_fr(r, "compose hostkey empty public");
266-
}
267-
/* cert */
268-
if (sensitive_data.host_certificates[i] != NULL) {
269-
if ((r = sshkey_puts(
270-
sensitive_data.host_certificates[i],
271-
hostkeys)) != 0)
272-
fatal_fr(r, "compose host cert");
273-
}
274-
else {
275-
if ((r = sshbuf_put_string(hostkeys, NULL, 0)) != 0)
276-
fatal_fr(r, "compose host cert empty");
277-
}
278-
}
279-
280-
sshbuf_free(keybuf);
281-
return hostkeys;
282-
}
283-
284235
static void
285236
send_config_state(int fd, struct sshbuf* conf)
286237
{
@@ -726,11 +677,12 @@ privsep_preauth(struct ssh *ssh)
726677
fcntl(pmonitor->m_log_sendfd, F_SETFD, FD_CLOEXEC);
727678

728679
/* Arrange for logging to be sent to the monitor */
729-
set_log_handler(mm_log_handler, pmonitor);
680+
//TODO: implement /*child*/ part of below using sshd-auth
681+
//set_log_handler(mm_log_handler, pmonitor);
730682

731-
privsep_preauth_child();
732-
setproctitle("%s", "[net]");
733-
return 0;
683+
//privsep_preauth_child();
684+
//setproctitle("%s", "[net]");
685+
//return 0;
734686
}
735687
else { /* parent */
736688
posix_spawn_file_actions_t actions;
@@ -1352,7 +1304,6 @@ main(int ac, char **av)
13521304
sigset_t sigmask;
13531305
uint64_t timing_secret = 0;
13541306
struct itimerval itv;
1355-
13561307
sigemptyset(&sigmask);
13571308
sigprocmask(SIG_SETMASK, &sigmask, NULL);
13581309

0 commit comments

Comments
 (0)