misc.c (181110) | misc.c (181111) |
---|---|
1/* $OpenBSD: misc.c,v 1.64 2006/08/03 03:34:42 deraadt Exp $ */ | 1/* $OpenBSD: misc.c,v 1.69 2008/06/13 01:38:23 dtucker Exp $ */ |
2/* 3 * Copyright (c) 2000 Markus Friedl. All rights reserved. 4 * Copyright (c) 2005,2006 Damien Miller. All rights reserved. 5 * 6 * Redistribution and use in source and binary forms, with or without 7 * modification, are permitted provided that the following conditions 8 * are met: 9 * 1. Redistributions of source code must retain the above copyright --- 27 unchanged lines hidden (view full) --- 37#include <string.h> 38#include <unistd.h> 39 40#include <netinet/in.h> 41#include <netinet/tcp.h> 42 43#include <errno.h> 44#include <fcntl.h> | 2/* 3 * Copyright (c) 2000 Markus Friedl. All rights reserved. 4 * Copyright (c) 2005,2006 Damien Miller. All rights reserved. 5 * 6 * Redistribution and use in source and binary forms, with or without 7 * modification, are permitted provided that the following conditions 8 * are met: 9 * 1. Redistributions of source code must retain the above copyright --- 27 unchanged lines hidden (view full) --- 37#include <string.h> 38#include <unistd.h> 39 40#include <netinet/in.h> 41#include <netinet/tcp.h> 42 43#include <errno.h> 44#include <fcntl.h> |
45#include <netdb.h> |
|
45#ifdef HAVE_PATHS_H 46# include <paths.h> 47#include <pwd.h> 48#endif 49#ifdef SSH_TUN_OPENBSD 50#include <net/if.h> 51#endif 52 --- 62 unchanged lines hidden (view full) --- 115 if (fcntl(fd, F_SETFL, val) == -1) { 116 debug("fcntl(%d, F_SETFL, ~O_NONBLOCK): %s", 117 fd, strerror(errno)); 118 return (-1); 119 } 120 return (0); 121} 122 | 46#ifdef HAVE_PATHS_H 47# include <paths.h> 48#include <pwd.h> 49#endif 50#ifdef SSH_TUN_OPENBSD 51#include <net/if.h> 52#endif 53 --- 62 unchanged lines hidden (view full) --- 116 if (fcntl(fd, F_SETFL, val) == -1) { 117 debug("fcntl(%d, F_SETFL, ~O_NONBLOCK): %s", 118 fd, strerror(errno)); 119 return (-1); 120 } 121 return (0); 122} 123 |
124const char * 125ssh_gai_strerror(int gaierr) 126{ 127 if (gaierr == EAI_SYSTEM) 128 return strerror(errno); 129 return gai_strerror(gaierr); 130} 131 |
|
123/* disable nagle on socket */ 124void 125set_nodelay(int fd) 126{ 127 int opt; 128 socklen_t optlen; 129 130 optlen = sizeof opt; --- 389 unchanged lines hidden (view full) --- 520 slash = path - filename; 521 if (slash > sizeof(user) - 1) 522 fatal("tilde_expand_filename: ~username too long"); 523 memcpy(user, filename, slash); 524 user[slash] = '\0'; 525 if ((pw = getpwnam(user)) == NULL) 526 fatal("tilde_expand_filename: No such user %s", user); 527 } else if ((pw = getpwuid(uid)) == NULL) /* ~/path */ | 132/* disable nagle on socket */ 133void 134set_nodelay(int fd) 135{ 136 int opt; 137 socklen_t optlen; 138 139 optlen = sizeof opt; --- 389 unchanged lines hidden (view full) --- 529 slash = path - filename; 530 if (slash > sizeof(user) - 1) 531 fatal("tilde_expand_filename: ~username too long"); 532 memcpy(user, filename, slash); 533 user[slash] = '\0'; 534 if ((pw = getpwnam(user)) == NULL) 535 fatal("tilde_expand_filename: No such user %s", user); 536 } else if ((pw = getpwuid(uid)) == NULL) /* ~/path */ |
528 fatal("tilde_expand_filename: No such uid %d", uid); | 537 fatal("tilde_expand_filename: No such uid %ld", (long)uid); |
529 530 if (strlcpy(ret, pw->pw_dir, sizeof(ret)) >= sizeof(ret)) 531 fatal("tilde_expand_filename: Path too long"); 532 533 /* Make sure directory has a trailing '/' */ 534 len = strlen(pw->pw_dir); 535 if ((len == 0 || pw->pw_dir[len - 1] != '/') && 536 strlcat(ret, "/", sizeof(ret)) >= sizeof(ret)) --- 74 unchanged lines hidden (view full) --- 611 * Read an entire line from a public key file into a static buffer, discarding 612 * lines that exceed the buffer size. Returns 0 on success, -1 on failure. 613 */ 614int 615read_keyfile_line(FILE *f, const char *filename, char *buf, size_t bufsz, 616 u_long *lineno) 617{ 618 while (fgets(buf, bufsz, f) != NULL) { | 538 539 if (strlcpy(ret, pw->pw_dir, sizeof(ret)) >= sizeof(ret)) 540 fatal("tilde_expand_filename: Path too long"); 541 542 /* Make sure directory has a trailing '/' */ 543 len = strlen(pw->pw_dir); 544 if ((len == 0 || pw->pw_dir[len - 1] != '/') && 545 strlcat(ret, "/", sizeof(ret)) >= sizeof(ret)) --- 74 unchanged lines hidden (view full) --- 620 * Read an entire line from a public key file into a static buffer, discarding 621 * lines that exceed the buffer size. Returns 0 on success, -1 on failure. 622 */ 623int 624read_keyfile_line(FILE *f, const char *filename, char *buf, size_t bufsz, 625 u_long *lineno) 626{ 627 while (fgets(buf, bufsz, f) != NULL) { |
628 if (buf[0] == '\0') 629 continue; |
|
619 (*lineno)++; 620 if (buf[strlen(buf) - 1] == '\n' || feof(f)) { 621 return 0; 622 } else { 623 debug("%s: %s line %lu exceeds size limit", __func__, 624 filename, *lineno); 625 /* discard remainder of line */ 626 while (fgetc(f) != '\n' && !feof(f)) --- 189 unchanged lines hidden (view full) --- 816void 817put_u16(void *vp, u_int16_t v) 818{ 819 u_char *p = (u_char *)vp; 820 821 p[0] = (u_char)(v >> 8) & 0xff; 822 p[1] = (u_char)v & 0xff; 823} | 630 (*lineno)++; 631 if (buf[strlen(buf) - 1] == '\n' || feof(f)) { 632 return 0; 633 } else { 634 debug("%s: %s line %lu exceeds size limit", __func__, 635 filename, *lineno); 636 /* discard remainder of line */ 637 while (fgetc(f) != '\n' && !feof(f)) --- 189 unchanged lines hidden (view full) --- 827void 828put_u16(void *vp, u_int16_t v) 829{ 830 u_char *p = (u_char *)vp; 831 832 p[0] = (u_char)(v >> 8) & 0xff; 833 p[1] = (u_char)v & 0xff; 834} |
835 836void 837ms_subtract_diff(struct timeval *start, int *ms) 838{ 839 struct timeval diff, finish; 840 841 gettimeofday(&finish, NULL); 842 timersub(&finish, start, &diff); 843 *ms -= (diff.tv_sec * 1000) + (diff.tv_usec / 1000); 844} 845 846void 847ms_to_timeval(struct timeval *tv, int ms) 848{ 849 if (ms < 0) 850 ms = 0; 851 tv->tv_sec = ms / 1000; 852 tv->tv_usec = (ms % 1000) * 1000; 853} 854 |
|