annotate scpmisc.c @ 1426:89f8c5960527

test for linux/pkt-sched.h rather than SO_PRIORITY
author Matt Johnston <matt@ucc.asn.au>
date Fri, 23 Jun 2017 23:36:33 +0800
parents e7f11ed5fe28
children 9579377b5f8b
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1226
952624727411 Add note about OpenSSH origin
Matt Johnston <matt@ucc.asn.au>
parents: 725
diff changeset
1 /* Dropbear Note: This file is based on OpenSSH 4.3p2. Avoid unnecessary
952624727411 Add note about OpenSSH origin
Matt Johnston <matt@ucc.asn.au>
parents: 725
diff changeset
2 changes to simplify future updates */
952624727411 Add note about OpenSSH origin
Matt Johnston <matt@ucc.asn.au>
parents: 725
diff changeset
3
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
4 /*
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
5 * Copyright (c) 2000 Markus Friedl. All rights reserved.
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
6 *
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
7 * Redistribution and use in source and binary forms, with or without
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
8 * modification, are permitted provided that the following conditions
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
9 * are met:
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
10 * 1. Redistributions of source code must retain the above copyright
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
11 * notice, this list of conditions and the following disclaimer.
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
12 * 2. Redistributions in binary form must reproduce the above copyright
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
13 * notice, this list of conditions and the following disclaimer in the
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
14 * documentation and/or other materials provided with the distribution.
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
15 *
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
17 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
18 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
19 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
20 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
21 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
22 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
23 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
25 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
26 */
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
27
38
5c6f9d27ea1c get rid of the substitution... We want a fixed identifier
Matt Johnston <matt@ucc.asn.au>
parents: 4
diff changeset
28 /*RCSID("OpenBSD: misc.c,v 1.22 2003/09/18 08:49:45 markus Exp ");*/
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
29
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
30 /* For xmalloc, xfree etc:
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
31 * Author: Tatu Ylonen <[email protected]>
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
32 * Copyright (c) 1995 Tatu Ylonen <[email protected]>, Espoo, Finland
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
33 * All rights reserved
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
34 * Versions of malloc and friends that check their results, and never return
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
35 * failure (they call fatal if they encounter an error).
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
36 *
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
37 * As far as I am concerned, the code I have written for this software
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
38 * can be used freely for any purpose. Any derived versions of this
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
39 * software must be clearly marked as such, and if the derived work is
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
40 * incompatible with the protocol description in the RFC file, it must be
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
41 * called by a name other than "ssh" or "Secure Shell".
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
42 */
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
43
38
5c6f9d27ea1c get rid of the substitution... We want a fixed identifier
Matt Johnston <matt@ucc.asn.au>
parents: 4
diff changeset
44 /*RCSID("OpenBSD: xmalloc.c,v 1.16 2001/07/23 18:21:46 stevesk Exp ");*/
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
45
725
49f68a7b7a55 Define _GNU_SOURCE for vasprintf
Matt Johnston <matt@ucc.asn.au>
parents: 287
diff changeset
46 #define _GNU_SOURCE
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
47 #include "includes.h"
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
48 #include "scpmisc.h"
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
49
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
50 void *
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
51 xmalloc(size_t size)
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
52 {
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
53 void *ptr;
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
54
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
55 if (size == 0) {
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
56 fprintf(stderr, "xmalloc: zero size\n");
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
57 exit(EXIT_FAILURE);
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
58 }
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
59 ptr = malloc(size);
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
60 if (ptr == NULL) {
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
61 fprintf(stderr, "xmalloc: out of memory (allocating %lu bytes)\n", (u_long) size);
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
62 exit(EXIT_FAILURE);
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
63 }
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
64 return ptr;
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
65 }
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
66
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
67 void *
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
68 xrealloc(void *ptr, size_t new_size)
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
69 {
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
70 void *new_ptr;
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
71
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
72 if (new_size == 0) {
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
73 fprintf(stderr, "xrealloc: zero size\n");
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
74 exit(EXIT_FAILURE);
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
75 }
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
76 if (ptr == NULL)
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
77 new_ptr = malloc(new_size);
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
78 else
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
79 new_ptr = realloc(ptr, new_size);
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
80 if (new_ptr == NULL) {
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
81 fprintf(stderr, "xrealloc: out of memory (new_size %lu bytes)\n", (u_long) new_size);
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
82 exit(EXIT_FAILURE);
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
83 }
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
84 return new_ptr;
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
85 }
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
86
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
87 void
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
88 xfree(void *ptr)
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
89 {
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
90 if (ptr == NULL) {
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
91 fprintf(stderr, "xfree: NULL pointer given as argument\n");
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
92 exit(EXIT_FAILURE);
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
93 }
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
94 free(ptr);
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
95 }
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
96
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
97 char *
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
98 xstrdup(const char *str)
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
99 {
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
100 size_t len;
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
101 char *cp;
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
102
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
103 len = strlen(str) + 1;
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
104 cp = xmalloc(len);
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
105 strncpy(cp, str, len);
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
106 return cp;
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
107 }
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
108
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
109 char *
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
110 cleanhostname(char *host)
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
111 {
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
112 if (*host == '[' && host[strlen(host) - 1] == ']') {
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
113 host[strlen(host) - 1] = '\0';
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
114 return (host + 1);
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
115 } else
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
116 return host;
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
117 }
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
118
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
119 char *
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
120 colon(char *cp)
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
121 {
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
122 int flag = 0;
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
123
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
124 if (*cp == ':') /* Leading colon is part of file name. */
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
125 return (0);
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
126 if (*cp == '[')
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
127 flag = 1;
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
128
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
129 for (; *cp; ++cp) {
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
130 if (*cp == '@' && *(cp+1) == '[')
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
131 flag = 1;
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
132 if (*cp == ']' && *(cp+1) == ':' && flag)
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
133 return (cp+1);
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
134 if (*cp == ':' && !flag)
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
135 return (cp);
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
136 if (*cp == '/')
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
137 return (0);
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
138 }
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
139 return (0);
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
140 }
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
141
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
142 /* function to assist building execv() arguments */
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
143 void
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
144 addargs(arglist *args, char *fmt, ...)
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
145 {
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
146 va_list ap;
287
b72f98803e46 Update to scp from OpenSSH portable 4.3p2
Matt Johnston <matt@ucc.asn.au>
parents: 38
diff changeset
147 char *cp;
b72f98803e46 Update to scp from OpenSSH portable 4.3p2
Matt Johnston <matt@ucc.asn.au>
parents: 38
diff changeset
148 u_int nalloc;
b72f98803e46 Update to scp from OpenSSH portable 4.3p2
Matt Johnston <matt@ucc.asn.au>
parents: 38
diff changeset
149 int r;
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
150
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
151 va_start(ap, fmt);
287
b72f98803e46 Update to scp from OpenSSH portable 4.3p2
Matt Johnston <matt@ucc.asn.au>
parents: 38
diff changeset
152 r = vasprintf(&cp, fmt, ap);
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
153 va_end(ap);
287
b72f98803e46 Update to scp from OpenSSH portable 4.3p2
Matt Johnston <matt@ucc.asn.au>
parents: 38
diff changeset
154 if (r == -1)
b72f98803e46 Update to scp from OpenSSH portable 4.3p2
Matt Johnston <matt@ucc.asn.au>
parents: 38
diff changeset
155 fatal("addargs: argument too long");
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
156
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
157 nalloc = args->nalloc;
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
158 if (args->list == NULL) {
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
159 nalloc = 32;
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
160 args->num = 0;
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
161 } else if (args->num+2 >= nalloc)
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
162 nalloc *= 2;
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
163
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
164 args->list = xrealloc(args->list, nalloc * sizeof(char *));
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
165 args->nalloc = nalloc;
287
b72f98803e46 Update to scp from OpenSSH portable 4.3p2
Matt Johnston <matt@ucc.asn.au>
parents: 38
diff changeset
166 args->list[args->num++] = cp;
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
167 args->list[args->num] = NULL;
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
168 }
287
b72f98803e46 Update to scp from OpenSSH portable 4.3p2
Matt Johnston <matt@ucc.asn.au>
parents: 38
diff changeset
169
b72f98803e46 Update to scp from OpenSSH portable 4.3p2
Matt Johnston <matt@ucc.asn.au>
parents: 38
diff changeset
170 void
b72f98803e46 Update to scp from OpenSSH portable 4.3p2
Matt Johnston <matt@ucc.asn.au>
parents: 38
diff changeset
171 replacearg(arglist *args, u_int which, char *fmt, ...)
b72f98803e46 Update to scp from OpenSSH portable 4.3p2
Matt Johnston <matt@ucc.asn.au>
parents: 38
diff changeset
172 {
b72f98803e46 Update to scp from OpenSSH portable 4.3p2
Matt Johnston <matt@ucc.asn.au>
parents: 38
diff changeset
173 va_list ap;
b72f98803e46 Update to scp from OpenSSH portable 4.3p2
Matt Johnston <matt@ucc.asn.au>
parents: 38
diff changeset
174 char *cp;
b72f98803e46 Update to scp from OpenSSH portable 4.3p2
Matt Johnston <matt@ucc.asn.au>
parents: 38
diff changeset
175 int r;
b72f98803e46 Update to scp from OpenSSH portable 4.3p2
Matt Johnston <matt@ucc.asn.au>
parents: 38
diff changeset
176
b72f98803e46 Update to scp from OpenSSH portable 4.3p2
Matt Johnston <matt@ucc.asn.au>
parents: 38
diff changeset
177 va_start(ap, fmt);
b72f98803e46 Update to scp from OpenSSH portable 4.3p2
Matt Johnston <matt@ucc.asn.au>
parents: 38
diff changeset
178 r = vasprintf(&cp, fmt, ap);
b72f98803e46 Update to scp from OpenSSH portable 4.3p2
Matt Johnston <matt@ucc.asn.au>
parents: 38
diff changeset
179 va_end(ap);
b72f98803e46 Update to scp from OpenSSH portable 4.3p2
Matt Johnston <matt@ucc.asn.au>
parents: 38
diff changeset
180 if (r == -1)
b72f98803e46 Update to scp from OpenSSH portable 4.3p2
Matt Johnston <matt@ucc.asn.au>
parents: 38
diff changeset
181 fatal("replacearg: argument too long");
b72f98803e46 Update to scp from OpenSSH portable 4.3p2
Matt Johnston <matt@ucc.asn.au>
parents: 38
diff changeset
182
b72f98803e46 Update to scp from OpenSSH portable 4.3p2
Matt Johnston <matt@ucc.asn.au>
parents: 38
diff changeset
183 if (which >= args->num)
b72f98803e46 Update to scp from OpenSSH portable 4.3p2
Matt Johnston <matt@ucc.asn.au>
parents: 38
diff changeset
184 fatal("replacearg: tried to replace invalid arg %d >= %d",
b72f98803e46 Update to scp from OpenSSH portable 4.3p2
Matt Johnston <matt@ucc.asn.au>
parents: 38
diff changeset
185 which, args->num);
b72f98803e46 Update to scp from OpenSSH portable 4.3p2
Matt Johnston <matt@ucc.asn.au>
parents: 38
diff changeset
186 xfree(args->list[which]);
b72f98803e46 Update to scp from OpenSSH portable 4.3p2
Matt Johnston <matt@ucc.asn.au>
parents: 38
diff changeset
187 args->list[which] = cp;
b72f98803e46 Update to scp from OpenSSH portable 4.3p2
Matt Johnston <matt@ucc.asn.au>
parents: 38
diff changeset
188 }
b72f98803e46 Update to scp from OpenSSH portable 4.3p2
Matt Johnston <matt@ucc.asn.au>
parents: 38
diff changeset
189
b72f98803e46 Update to scp from OpenSSH portable 4.3p2
Matt Johnston <matt@ucc.asn.au>
parents: 38
diff changeset
190 void
b72f98803e46 Update to scp from OpenSSH portable 4.3p2
Matt Johnston <matt@ucc.asn.au>
parents: 38
diff changeset
191 freeargs(arglist *args)
b72f98803e46 Update to scp from OpenSSH portable 4.3p2
Matt Johnston <matt@ucc.asn.au>
parents: 38
diff changeset
192 {
b72f98803e46 Update to scp from OpenSSH portable 4.3p2
Matt Johnston <matt@ucc.asn.au>
parents: 38
diff changeset
193 u_int i;
b72f98803e46 Update to scp from OpenSSH portable 4.3p2
Matt Johnston <matt@ucc.asn.au>
parents: 38
diff changeset
194
b72f98803e46 Update to scp from OpenSSH portable 4.3p2
Matt Johnston <matt@ucc.asn.au>
parents: 38
diff changeset
195 if (args->list != NULL) {
b72f98803e46 Update to scp from OpenSSH portable 4.3p2
Matt Johnston <matt@ucc.asn.au>
parents: 38
diff changeset
196 for (i = 0; i < args->num; i++)
b72f98803e46 Update to scp from OpenSSH portable 4.3p2
Matt Johnston <matt@ucc.asn.au>
parents: 38
diff changeset
197 xfree(args->list[i]);
b72f98803e46 Update to scp from OpenSSH portable 4.3p2
Matt Johnston <matt@ucc.asn.au>
parents: 38
diff changeset
198 xfree(args->list);
b72f98803e46 Update to scp from OpenSSH portable 4.3p2
Matt Johnston <matt@ucc.asn.au>
parents: 38
diff changeset
199 args->nalloc = args->num = 0;
b72f98803e46 Update to scp from OpenSSH portable 4.3p2
Matt Johnston <matt@ucc.asn.au>
parents: 38
diff changeset
200 args->list = NULL;
b72f98803e46 Update to scp from OpenSSH portable 4.3p2
Matt Johnston <matt@ucc.asn.au>
parents: 38
diff changeset
201 }
b72f98803e46 Update to scp from OpenSSH portable 4.3p2
Matt Johnston <matt@ucc.asn.au>
parents: 38
diff changeset
202 }
b72f98803e46 Update to scp from OpenSSH portable 4.3p2
Matt Johnston <matt@ucc.asn.au>
parents: 38
diff changeset
203
b72f98803e46 Update to scp from OpenSSH portable 4.3p2
Matt Johnston <matt@ucc.asn.au>
parents: 38
diff changeset
204 /*
b72f98803e46 Update to scp from OpenSSH portable 4.3p2
Matt Johnston <matt@ucc.asn.au>
parents: 38
diff changeset
205 * NB. duplicate __progname in case it is an alias for argv[0]
b72f98803e46 Update to scp from OpenSSH portable 4.3p2
Matt Johnston <matt@ucc.asn.au>
parents: 38
diff changeset
206 * Otherwise it may get clobbered by setproctitle()
b72f98803e46 Update to scp from OpenSSH portable 4.3p2
Matt Johnston <matt@ucc.asn.au>
parents: 38
diff changeset
207 */
b72f98803e46 Update to scp from OpenSSH portable 4.3p2
Matt Johnston <matt@ucc.asn.au>
parents: 38
diff changeset
208 char *ssh_get_progname(char *argv0)
b72f98803e46 Update to scp from OpenSSH portable 4.3p2
Matt Johnston <matt@ucc.asn.au>
parents: 38
diff changeset
209 {
b72f98803e46 Update to scp from OpenSSH portable 4.3p2
Matt Johnston <matt@ucc.asn.au>
parents: 38
diff changeset
210 char *p;
b72f98803e46 Update to scp from OpenSSH portable 4.3p2
Matt Johnston <matt@ucc.asn.au>
parents: 38
diff changeset
211
b72f98803e46 Update to scp from OpenSSH portable 4.3p2
Matt Johnston <matt@ucc.asn.au>
parents: 38
diff changeset
212 if (argv0 == NULL)
b72f98803e46 Update to scp from OpenSSH portable 4.3p2
Matt Johnston <matt@ucc.asn.au>
parents: 38
diff changeset
213 return ("unknown"); /* XXX */
b72f98803e46 Update to scp from OpenSSH portable 4.3p2
Matt Johnston <matt@ucc.asn.au>
parents: 38
diff changeset
214 p = strrchr(argv0, '/');
b72f98803e46 Update to scp from OpenSSH portable 4.3p2
Matt Johnston <matt@ucc.asn.au>
parents: 38
diff changeset
215 if (p == NULL)
b72f98803e46 Update to scp from OpenSSH portable 4.3p2
Matt Johnston <matt@ucc.asn.au>
parents: 38
diff changeset
216 p = argv0;
b72f98803e46 Update to scp from OpenSSH portable 4.3p2
Matt Johnston <matt@ucc.asn.au>
parents: 38
diff changeset
217 else
b72f98803e46 Update to scp from OpenSSH portable 4.3p2
Matt Johnston <matt@ucc.asn.au>
parents: 38
diff changeset
218 p++;
b72f98803e46 Update to scp from OpenSSH portable 4.3p2
Matt Johnston <matt@ucc.asn.au>
parents: 38
diff changeset
219
b72f98803e46 Update to scp from OpenSSH portable 4.3p2
Matt Johnston <matt@ucc.asn.au>
parents: 38
diff changeset
220 return (xstrdup(p));
b72f98803e46 Update to scp from OpenSSH portable 4.3p2
Matt Johnston <matt@ucc.asn.au>
parents: 38
diff changeset
221 }
b72f98803e46 Update to scp from OpenSSH portable 4.3p2
Matt Johnston <matt@ucc.asn.au>
parents: 38
diff changeset
222
b72f98803e46 Update to scp from OpenSSH portable 4.3p2
Matt Johnston <matt@ucc.asn.au>
parents: 38
diff changeset
223 void fatal(char* fmt,...)
b72f98803e46 Update to scp from OpenSSH portable 4.3p2
Matt Johnston <matt@ucc.asn.au>
parents: 38
diff changeset
224 {
b72f98803e46 Update to scp from OpenSSH portable 4.3p2
Matt Johnston <matt@ucc.asn.au>
parents: 38
diff changeset
225 va_list args;
b72f98803e46 Update to scp from OpenSSH portable 4.3p2
Matt Johnston <matt@ucc.asn.au>
parents: 38
diff changeset
226 va_start(args, fmt);
b72f98803e46 Update to scp from OpenSSH portable 4.3p2
Matt Johnston <matt@ucc.asn.au>
parents: 38
diff changeset
227 vfprintf(stderr, fmt, args);
b72f98803e46 Update to scp from OpenSSH portable 4.3p2
Matt Johnston <matt@ucc.asn.au>
parents: 38
diff changeset
228 va_end(args);
1227
5dde22e8a189 scp: Have `fatal()' append a newline to the message
Michael Witten <mfwitten@gmail.com>
parents: 1226
diff changeset
229 fputc('\n', stderr);
287
b72f98803e46 Update to scp from OpenSSH portable 4.3p2
Matt Johnston <matt@ucc.asn.au>
parents: 38
diff changeset
230 exit(255);
b72f98803e46 Update to scp from OpenSSH portable 4.3p2
Matt Johnston <matt@ucc.asn.au>
parents: 38
diff changeset
231 }
b72f98803e46 Update to scp from OpenSSH portable 4.3p2
Matt Johnston <matt@ucc.asn.au>
parents: 38
diff changeset
232
b72f98803e46 Update to scp from OpenSSH portable 4.3p2
Matt Johnston <matt@ucc.asn.au>
parents: 38
diff changeset
233 void
b72f98803e46 Update to scp from OpenSSH portable 4.3p2
Matt Johnston <matt@ucc.asn.au>
parents: 38
diff changeset
234 sanitise_stdfd(void)
b72f98803e46 Update to scp from OpenSSH portable 4.3p2
Matt Johnston <matt@ucc.asn.au>
parents: 38
diff changeset
235 {
b72f98803e46 Update to scp from OpenSSH portable 4.3p2
Matt Johnston <matt@ucc.asn.au>
parents: 38
diff changeset
236 int nullfd, dupfd;
b72f98803e46 Update to scp from OpenSSH portable 4.3p2
Matt Johnston <matt@ucc.asn.au>
parents: 38
diff changeset
237
1387
e7f11ed5fe28 Use DROPBEAR_PATH_DEVNULL instead of undefined _PATH_DEVNULL
Ben Gardner <bgardner@wabtec.com>
parents: 1227
diff changeset
238 if ((nullfd = dupfd = open(DROPBEAR_PATH_DEVNULL, O_RDWR)) == -1) {
287
b72f98803e46 Update to scp from OpenSSH portable 4.3p2
Matt Johnston <matt@ucc.asn.au>
parents: 38
diff changeset
239 fprintf(stderr, "Couldn't open /dev/null: %s", strerror(errno));
b72f98803e46 Update to scp from OpenSSH portable 4.3p2
Matt Johnston <matt@ucc.asn.au>
parents: 38
diff changeset
240 exit(1);
b72f98803e46 Update to scp from OpenSSH portable 4.3p2
Matt Johnston <matt@ucc.asn.au>
parents: 38
diff changeset
241 }
b72f98803e46 Update to scp from OpenSSH portable 4.3p2
Matt Johnston <matt@ucc.asn.au>
parents: 38
diff changeset
242 while (++dupfd <= 2) {
b72f98803e46 Update to scp from OpenSSH portable 4.3p2
Matt Johnston <matt@ucc.asn.au>
parents: 38
diff changeset
243 /* Only clobber closed fds */
b72f98803e46 Update to scp from OpenSSH portable 4.3p2
Matt Johnston <matt@ucc.asn.au>
parents: 38
diff changeset
244 if (fcntl(dupfd, F_GETFL, 0) >= 0)
b72f98803e46 Update to scp from OpenSSH portable 4.3p2
Matt Johnston <matt@ucc.asn.au>
parents: 38
diff changeset
245 continue;
b72f98803e46 Update to scp from OpenSSH portable 4.3p2
Matt Johnston <matt@ucc.asn.au>
parents: 38
diff changeset
246 if (dup2(nullfd, dupfd) == -1) {
b72f98803e46 Update to scp from OpenSSH portable 4.3p2
Matt Johnston <matt@ucc.asn.au>
parents: 38
diff changeset
247 fprintf(stderr, "dup2: %s", strerror(errno));
b72f98803e46 Update to scp from OpenSSH portable 4.3p2
Matt Johnston <matt@ucc.asn.au>
parents: 38
diff changeset
248 exit(1);
b72f98803e46 Update to scp from OpenSSH portable 4.3p2
Matt Johnston <matt@ucc.asn.au>
parents: 38
diff changeset
249 }
b72f98803e46 Update to scp from OpenSSH portable 4.3p2
Matt Johnston <matt@ucc.asn.au>
parents: 38
diff changeset
250 }
b72f98803e46 Update to scp from OpenSSH portable 4.3p2
Matt Johnston <matt@ucc.asn.au>
parents: 38
diff changeset
251 if (nullfd > 2)
b72f98803e46 Update to scp from OpenSSH portable 4.3p2
Matt Johnston <matt@ucc.asn.au>
parents: 38
diff changeset
252 close(nullfd);
b72f98803e46 Update to scp from OpenSSH portable 4.3p2
Matt Johnston <matt@ucc.asn.au>
parents: 38
diff changeset
253 }