Lines Matching +full:timeout +full:- +full:tap +full:- +full:ms
4 * Copyright (c) 2005-2020 Damien Miller. All rights reserved.
104 for (i--; i > 0; i--) { in rtrim()
131 /* set/unset filedescriptor to non-blocking */
138 if (val == -1) { in set_nonblock()
140 return (-1); in set_nonblock()
148 if (fcntl(fd, F_SETFL, val) == -1) { in set_nonblock()
151 return (-1); in set_nonblock()
162 if (val == -1) { in unset_nonblock()
164 return (-1); in unset_nonblock()
172 if (fcntl(fd, F_SETFL, val) == -1) { in unset_nonblock()
175 return (-1); in unset_nonblock()
196 if (getsockopt(fd, IPPROTO_TCP, TCP_NODELAY, &opt, &optlen) == -1) { in set_nodelay()
206 if (setsockopt(fd, IPPROTO_TCP, TCP_NODELAY, &opt, sizeof opt) == -1) in set_nodelay()
216 if (setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &on, sizeof(on)) == -1) { in set_reuseaddr()
218 return -1; in set_reuseaddr()
234 if (getsockopt(fd, SOL_SOCKET, SO_RTABLE, &rtable, &len) == -1) { in get_rdomain()
262 return -1; in set_rdomain()
265 &rtable, sizeof(rtable)) == -1) { in set_rdomain()
268 return -1; in set_rdomain()
273 return -1; in set_rdomain()
284 if (getsockname(fd, (struct sockaddr *)&to, &tolen) == -1) in get_sock_af()
285 return -1; in get_sock_af()
288 IN6_IS_ADDR_V4MAPPED(&((struct sockaddr_in6 *)&to)->sin6_addr)) in get_sock_af()
301 case -1: in set_sock_tos()
308 &tos, sizeof(tos)) == -1) { in set_sock_tos()
318 &tos, sizeof(tos)) == -1) { in set_sock_tos()
334 * Returns 0 if fd ready or -1 on timeout or error (see errno).
340 struct timespec timeout; in waitfd() local
344 if (timeoutp && *timeoutp == -1) in waitfd()
348 ptimeout_init(&timeout); in waitfd()
350 ptimeout_deadline_ms(&timeout, *timeoutp); in waitfd()
359 return -1; in waitfd()
362 r = ppoll(&pfd, 1, ptimeout_get_tsp(&timeout), in waitfd()
368 *timeoutp = ptimeout_get_ms(&timeout); in waitfd()
372 else if (r == -1 && errno != EAGAIN && errno != EINTR) in waitfd()
373 return -1; in waitfd()
377 /* timeout */ in waitfd()
379 return -1; in waitfd()
385 * Returns 0 if fd ready or -1 on timeout or error (see errno).
393 * Attempt a non-blocking connect(2) to the specified address, waiting up to
394 * *timeoutp milliseconds for the connection to complete. If the timeout is
397 * Returns 0 on success or -1 on failure.
406 /* No timeout: just do a blocking connect() */ in timeout_connect()
419 return -1; in timeout_connect()
423 if (waitfd(sockfd, timeoutp, POLLIN | POLLOUT, NULL) == -1) in timeout_connect()
424 return -1; in timeout_connect()
427 if (getsockopt(sockfd, SOL_SOCKET, SO_ERROR, &optval, &optlen) == -1) { in timeout_connect()
429 return -1; in timeout_connect()
433 return -1; in timeout_connect()
509 copy->pw_name = xstrdup(pw->pw_name); in pwcopy()
510 copy->pw_passwd = xstrdup(pw->pw_passwd == NULL ? "*" : pw->pw_passwd); in pwcopy()
512 copy->pw_gecos = xstrdup(pw->pw_gecos); in pwcopy()
514 copy->pw_uid = pw->pw_uid; in pwcopy()
515 copy->pw_gid = pw->pw_gid; in pwcopy()
517 copy->pw_expire = pw->pw_expire; in pwcopy()
520 copy->pw_change = pw->pw_change; in pwcopy()
523 copy->pw_class = xstrdup(pw->pw_class); in pwcopy()
525 copy->pw_dir = xstrdup(pw->pw_dir); in pwcopy()
526 copy->pw_shell = xstrdup(pw->pw_shell); in pwcopy()
533 * Return -1 if invalid.
546 return ntohs(se->s_port); in a2port()
547 return -1; in a2port()
614 * Return -1 if time string is invalid.
624 return -1; in convtime()
627 return -1; in convtime()
643 np--; /* back up */ in convtime()
670 if (total > INT_MAX - secs) in convtime()
681 return -1; in convtime()
732 if (asprintf(&hoststr, "[%s]:%d", host, (int)port) == -1) in put_host_port()
798 if (*host == '[' && host[strlen(host) - 1] == ']') { in cleanhostname()
799 host[strlen(host) - 1] = '\0'; in cleanhostname()
835 * Returns 0 on success, -1 on failure.
842 int ret = -1; in parse_user_host_path()
902 * If port was not specified then *portp will be -1.
903 * Returns 0 on success, -1 on failure.
910 int port = -1, ret = -1; in parse_user_host_port()
917 *portp = -1; in parse_user_host_port()
920 return -1; in parse_user_host_port()
959 * Converts a two-byte hex string to decimal.
960 * Returns the decimal value or -1 for invalid input.
970 result[i] = (unsigned char)(s[i] - '0'); in hexchar()
972 result[i] = (unsigned char)(s[i] - 'a') + 10; in hexchar()
974 result[i] = (unsigned char)(s[i] - 'A') + 10; in hexchar()
976 return -1; in hexchar()
982 * Decode an url-encoded string.
1003 (ch = hexchar(src + 1)) == -1) { in urldecode()
1022 * See https://tools.ietf.org/html/draft-ietf-secsh-scp-sftp-ssh-uri-04
1023 * Either user or path may be url-encoded (but not host or port).
1028 * If port was not specified then *portp will be -1.
1030 * Returns 0 on success, 1 if non-uri/wrong scheme, -1 on error/invalid uri.
1038 int port = -1, ret = -1; in parse_uri()
1051 *portp = -1; in parse_uri()
1057 /* Extract optional ssh-info (username + connection params) */ in parse_uri()
1135 if (r == -1) in addargs()
1138 nalloc = args->nalloc; in addargs()
1139 if (args->list == NULL) { in addargs()
1141 args->num = 0; in addargs()
1142 } else if (args->num > (256 * 1024)) in addargs()
1144 else if (args->num >= args->nalloc) in addargs()
1146 else if (args->num+2 >= nalloc) in addargs()
1149 args->list = xrecallocarray(args->list, args->nalloc, in addargs()
1151 args->nalloc = nalloc; in addargs()
1152 args->list[args->num++] = cp; in addargs()
1153 args->list[args->num] = NULL; in addargs()
1166 if (r == -1) in replacearg()
1168 if (args->list == NULL || args->num >= args->nalloc) in replacearg()
1171 if (which >= args->num) in replacearg()
1173 which, args->num); in replacearg()
1174 free(args->list[which]); in replacearg()
1175 args->list[which] = cp; in replacearg()
1185 if (args->list != NULL && args->num < args->nalloc) { in freeargs()
1186 for (i = 0; i < args->num; i++) in freeargs()
1187 free(args->list[i]); in freeargs()
1188 free(args->list); in freeargs()
1190 args->nalloc = args->num = 0; in freeargs()
1191 args->list = NULL; in freeargs()
1205 int ret = -1, r, slash; in tilde_expand()
1225 copy[path - copy] = '\0'; in tilde_expand()
1245 slash = (len = strlen(pw->pw_dir)) == 0 || pw->pw_dir[len - 1] != '/'; in tilde_expand()
1247 if ((r = xasprintf(&s, "%s%s%s", pw->pw_dir, in tilde_expand()
1332 len = varend - string; in vdollar_percent_expand()
1334 error_f("zero-length environment variable"); in vdollar_percent_expand()
1343 debug3_f("expand ${%s} -> '%s'", var, val); in vdollar_percent_expand()
1375 fatal_fr(r, "sshbuf_put %%-repl"); in vdollar_percent_expand()
1460 int fd = -1, sock; in tun_open()
1467 tunbase = "tap"; in tun_open()
1474 for (tun = 100; tun >= 0; tun--) { in tun_open()
1482 return -1; in tun_open()
1485 if (fd == -1) { in tun_open()
1487 return -1; in tun_open()
1494 if ((sock = socket(PF_UNIX, SOCK_STREAM, 0)) == -1) in tun_open()
1497 if (ioctl(sock, SIOCGIFFLAGS, &ifr) == -1) { in tun_open()
1505 if (ioctl(sock, SIOCSIFFLAGS, &ifr) == -1) { in tun_open()
1523 return -1; in tun_open()
1526 return (-1); in tun_open()
1535 if ((nullfd = dupfd = open(_PATH_DEVNULL, O_RDWR)) == -1) { in sanitise_stdfd()
1542 if (fcntl(dupfd, F_GETFL) == -1 && errno == EBADF) { in sanitise_stdfd()
1543 if (dup2(nullfd, dupfd) == -1) { in sanitise_stdfd()
1704 ms_subtract_diff(struct timeval *start, int *ms) in ms_subtract_diff() argument
1710 *ms -= (diff.tv_sec * 1000) + (diff.tv_usec / 1000); in ms_subtract_diff()
1714 ms_to_timespec(struct timespec *ts, int ms) in ms_to_timespec() argument
1716 if (ms < 0) in ms_to_timespec()
1717 ms = 0; in ms_to_timespec()
1718 ts->tv_sec = ms / 1000; in ms_to_timespec()
1719 ts->tv_nsec = (ms % 1000) * 1000 * 1000; in ms_to_timespec()
1749 ts->tv_sec = tv.tv_sec; in monotime_ts()
1750 ts->tv_nsec = (long)tv.tv_usec * 1000; in monotime_ts()
1759 tv->tv_sec = ts.tv_sec; in monotime_tv()
1760 tv->tv_usec = ts.tv_nsec / 1000; in monotime_tv()
1784 bw->buflen = buflen; in bandwidth_limit_init()
1785 bw->rate = kbps; in bandwidth_limit_init()
1786 bw->thresh = buflen; in bandwidth_limit_init()
1787 bw->lamt = 0; in bandwidth_limit_init()
1788 timerclear(&bw->bwstart); in bandwidth_limit_init()
1789 timerclear(&bw->bwend); in bandwidth_limit_init()
1792 /* Callback from read/write loop to insert bandwidth-limiting delays */
1799 bw->lamt += read_len; in bandwidth_limit()
1800 if (!timerisset(&bw->bwstart)) { in bandwidth_limit()
1801 monotime_tv(&bw->bwstart); in bandwidth_limit()
1804 if (bw->lamt < bw->thresh) in bandwidth_limit()
1807 monotime_tv(&bw->bwend); in bandwidth_limit()
1808 timersub(&bw->bwend, &bw->bwstart, &bw->bwend); in bandwidth_limit()
1809 if (!timerisset(&bw->bwend)) in bandwidth_limit()
1812 bw->lamt *= 8; in bandwidth_limit()
1813 waitlen = (double)1000000L * bw->lamt / bw->rate; in bandwidth_limit()
1815 bw->bwstart.tv_sec = waitlen / 1000000L; in bandwidth_limit()
1816 bw->bwstart.tv_usec = waitlen % 1000000L; in bandwidth_limit()
1818 if (timercmp(&bw->bwstart, &bw->bwend, >)) { in bandwidth_limit()
1819 timersub(&bw->bwstart, &bw->bwend, &bw->bwend); in bandwidth_limit()
1822 if (bw->bwend.tv_sec) { in bandwidth_limit()
1823 bw->thresh /= 2; in bandwidth_limit()
1824 if (bw->thresh < bw->buflen / 4) in bandwidth_limit()
1825 bw->thresh = bw->buflen / 4; in bandwidth_limit()
1826 } else if (bw->bwend.tv_usec < 10000) { in bandwidth_limit()
1827 bw->thresh *= 2; in bandwidth_limit()
1828 if (bw->thresh > bw->buflen * 8) in bandwidth_limit()
1829 bw->thresh = bw->buflen * 8; in bandwidth_limit()
1832 TIMEVAL_TO_TIMESPEC(&bw->bwend, &ts); in bandwidth_limit()
1833 while (nanosleep(&ts, &rm) == -1) { in bandwidth_limit()
1840 bw->lamt = 0; in bandwidth_limit()
1841 monotime_tv(&bw->bwstart); in bandwidth_limit()
1852 r = snprintf(s, len, "%s/ssh-XXXXXXXXXXXX", tmpdir); in mktemp_proto()
1856 r = snprintf(s, len, "/tmp/ssh-XXXXXXXXXXXX"); in mktemp_proto()
1891 { NULL, -1 }
1902 return -1; in parse_ipqos()
1910 return -1; in parse_ipqos()
1947 return -1; in unix_listener()
1951 if (sock == -1) { in unix_listener()
1955 return -1; in unix_listener()
1961 if (bind(sock, (struct sockaddr *)&sunaddr, sizeof(sunaddr)) == -1) { in unix_listener()
1966 return -1; in unix_listener()
1968 if (listen(sock, backlog) == -1) { in unix_listener()
1974 return -1; in unix_listener()
1986 if (setsockopt(s, IPPROTO_IPV6, IPV6_V6ONLY, &on, sizeof(on)) == -1) in sock_set_v6only()
1992 * Compares two strings that maybe be NULL. Returns non-zero if strings
2006 * Compare two forwards, returning non-zero if they are identical or
2012 if (strcmp_maybe_null(a->listen_host, b->listen_host) == 0) in forward_equals()
2014 if (a->listen_port != b->listen_port) in forward_equals()
2016 if (strcmp_maybe_null(a->listen_path, b->listen_path) == 0) in forward_equals()
2018 if (strcmp_maybe_null(a->connect_host, b->connect_host) == 0) in forward_equals()
2020 if (a->connect_port != b->connect_port) in forward_equals()
2022 if (strcmp_maybe_null(a->connect_path, b->connect_path) == 0) in forward_equals()
2028 /* returns port number, FWD_PERMIT_ANY_PORT or -1 on error */
2038 return -1; in permitopen_port()
2193 (*argcp)--; in argv_next()
2217 /* Returns 0 if pid exited cleanly, non-zero otherwise */
2223 while (waitpid(pid, &status, 0) == -1) { in exited_cleanly()
2226 return -1; in exited_cleanly()
2231 return -1; in exited_cleanly()
2235 return -1; in exited_cleanly()
2251 * Returns 0 on success and -1 on failure
2265 return -1; in safe_path()
2270 if (!S_ISREG(stp->st_mode)) { in safe_path()
2272 return -1; in safe_path()
2274 if ((!platform_sys_dir_uid(stp->st_uid) && stp->st_uid != uid) || in safe_path()
2275 (stp->st_mode & 022) != 0) { in safe_path()
2278 return -1; in safe_path()
2285 return -1; in safe_path()
2289 if (stat(buf, &st) == -1 || in safe_path()
2294 return -1; in safe_path()
2315 * Returns 0 on success and -1 on failure
2324 if (fstat(fd, &st) == -1) { in safe_path_fd()
2327 return -1; in safe_path_fd()
2329 return safe_path(file, &st, pw->pw_dir, pw->pw_uid, err, errlen); in safe_path_fd()
2377 if (i >= envsize - 1) { in child_set_env()
2424 if (c != '.' && c != '-' && !isalnum(c) && in valid_domain()
2432 if (name[l - 1] == '.') in valid_domain()
2433 name[l - 1] = '\0'; in valid_domain()
2486 if (l > 1 && strcasecmp(s + l - 1, "Z") == 0) { in parse_absolute_time()
2488 l--; in parse_absolute_time()
2489 } else if (l > 3 && strcasecmp(s + l - 3, "UTC") == 0) { in parse_absolute_time()
2491 l -= 3; in parse_absolute_time()
2495 * is white-space or other non-alphanumeric characters between in parse_absolute_time()
2500 fmt = "%Y-%m-%d"; in parse_absolute_time()
2501 snprintf(buf, sizeof(buf), "%.4s-%.2s-%.2s", s, s + 4, s + 6); in parse_absolute_time()
2504 fmt = "%Y-%m-%dT%H:%M"; in parse_absolute_time()
2505 snprintf(buf, sizeof(buf), "%.4s-%.2s-%.2sT%.2s:%.2s", in parse_absolute_time()
2509 fmt = "%Y-%m-%dT%H:%M:%S"; in parse_absolute_time()
2510 snprintf(buf, sizeof(buf), "%.4s-%.2s-%.2sT%.2s:%.2s:%.2s", in parse_absolute_time()
2539 strlcpy(buf, "UNKNOWN-TIME", len); in format_absolute_time()
2541 strftime(buf, len, "%Y-%m-%dT%H:%M:%S", &tm); in format_absolute_time()
2546 * Returns 0 on success or non-zero on failure.
2560 return -1; in parse_pattern_interval()
2565 return -1; in parse_pattern_interval()
2570 return -1; in parse_pattern_interval()
2598 /* authorized_key-style options parsing helpers */
2602 * 'no-opt'. Returns -1 if option not matched, 1 if option matches or 0
2614 if (allow_negate && strncasecmp(opts, "no-", 3) == 0) { in opt_flag()
2622 return -1; in opt_flag()
2721 if (sigaction(signum, &sa, &osa) == -1) { in ssh_signal()
2733 if ((devnull = open(_PATH_DEVNULL, O_RDWR)) == -1) { in stdfd_devnull()
2736 return -1; in stdfd_devnull()
2738 if ((do_stdin && dup2(devnull, STDIN_FILENO) == -1) || in stdfd_devnull()
2739 (do_stdout && dup2(devnull, STDOUT_FILENO) == -1) || in stdfd_devnull()
2740 (do_stderr && dup2(devnull, STDERR_FILENO) == -1)) { in stdfd_devnull()
2742 ret = -1; in stdfd_devnull()
2784 tag, command, pw->pw_name, flags); in subprocess()
2799 * and appears safe-ish to execute in subprocess()
2807 if (stat(av[0], &st) == -1) { in subprocess()
2818 if (pipe(p) == -1) { in subprocess()
2829 case -1: /* error */ in subprocess()
2840 child_set_env(&env, &nenv, "USER", pw->pw_name); in subprocess()
2841 child_set_env(&env, &nenv, "LOGNAME", pw->pw_name); in subprocess()
2842 child_set_env(&env, &nenv, "HOME", pw->pw_dir); in subprocess()
2850 if ((devnull = open(_PATH_DEVNULL, O_RDWR)) == -1) { in subprocess()
2855 if (dup2(devnull, STDIN_FILENO) == -1) { in subprocess()
2861 fd = -1; in subprocess()
2866 if (fd != -1 && dup2(fd, STDOUT_FILENO) == -1) { in subprocess()
2873 initgroups(pw->pw_name, pw->pw_gid) == -1) { in subprocess()
2875 pw->pw_name, (u_int)pw->pw_gid, strerror(errno)); in subprocess()
2878 if (setresgid(pw->pw_gid, pw->pw_gid, pw->pw_gid) == -1) { in subprocess()
2879 error("%s: setresgid %u: %s", tag, (u_int)pw->pw_gid, in subprocess()
2883 if (setresuid(pw->pw_uid, pw->pw_uid, pw->pw_uid) == -1) { in subprocess()
2884 error("%s: setresuid %u: %s", tag, (u_int)pw->pw_uid, in subprocess()
2890 dup2(STDIN_FILENO, STDERR_FILENO) == -1) { in subprocess()
2913 while (waitpid(pid, NULL, 0) == -1 && errno == EINTR) in subprocess()
2961 /* Initialise a poll/ppoll timeout with an indefinite deadline */
2969 pt->tv_sec = -1; in ptimeout_init()
2970 pt->tv_nsec = 0; in ptimeout_init()
2977 if (pt->tv_sec == -1 || pt->tv_sec >= sec) { in ptimeout_deadline_sec()
2978 pt->tv_sec = sec; in ptimeout_deadline_sec()
2979 pt->tv_nsec = 0; in ptimeout_deadline_sec()
2987 if (pt->tv_sec == -1 || timespeccmp(pt, p, >=)) in ptimeout_deadline_tsp()
2991 /* Specify a poll/ppoll deadline of at most 'ms' milliseconds */
2993 ptimeout_deadline_ms(struct timespec *pt, long ms) in ptimeout_deadline_ms() argument
2997 p.tv_sec = ms / 1000; in ptimeout_deadline_ms()
2998 p.tv_nsec = (ms % 1000) * 1000000; in ptimeout_deadline_ms()
3011 /* 'when' is now or in the past. Timeout ASAP */ in ptimeout_deadline_monotime_tsp()
3012 pt->tv_sec = 0; in ptimeout_deadline_monotime_tsp()
3013 pt->tv_nsec = 0; in ptimeout_deadline_monotime_tsp()
3031 /* Get a poll(2) timeout value in milliseconds */
3035 if (pt->tv_sec == -1) in ptimeout_get_ms()
3036 return -1; in ptimeout_get_ms()
3037 if (pt->tv_sec >= (INT_MAX - (pt->tv_nsec / 1000000)) / 1000) in ptimeout_get_ms()
3039 return (pt->tv_sec * 1000) + (pt->tv_nsec / 1000000); in ptimeout_get_ms()
3042 /* Get a ppoll(2) timeout value as a timespec pointer */
3046 return pt->tv_sec == -1 ? NULL : pt; in ptimeout_get_tsp()
3049 /* Returns non-zero if a timeout has been set (i.e. is not indefinite) */
3053 return pt->tv_sec != -1; in ptimeout_isset()
3065 int ret = -1, r; in lib_contains_symbol()
3070 if ((r = nlist(path, nl)) == -1) { in lib_contains_symbol()
3084 int fd, ret = -1; in lib_contains_symbol()
3092 return -1; in lib_contains_symbol()