Mercurial > dropbear
annotate scpmisc.c @ 766:d1575fdc29a6 ecc
start on ecdsa keys
author | Matt Johnston <matt@ucc.asn.au> |
---|---|
date | Tue, 09 Apr 2013 00:36:04 +0800 |
parents | 49f68a7b7a55 |
children | 952624727411 |
rev | line source |
---|---|
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
1 /* |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
2 * Copyright (c) 2000 Markus Friedl. All rights reserved. |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
3 * |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
4 * 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
|
5 * modification, are permitted provided that the following conditions |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
6 * are met: |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
7 * 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
|
8 * 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
|
9 * 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
|
10 * 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
|
11 * 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
|
12 * |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
13 * 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
|
14 * 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
|
15 * 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
|
16 * 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
|
17 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
18 * 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
|
19 * 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
|
20 * 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
|
21 * (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
|
22 * 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
|
23 */ |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
24 |
38
5c6f9d27ea1c
get rid of the substitution... We want a fixed identifier
Matt Johnston <matt@ucc.asn.au>
parents:
4
diff
changeset
|
25 /*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
|
26 |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
27 /* For xmalloc, xfree etc: |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
28 * Author: Tatu Ylonen <[email protected]> |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
29 * 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
|
30 * All rights reserved |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
31 * 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
|
32 * 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
|
33 * |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
34 * 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
|
35 * 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
|
36 * 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
|
37 * 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
|
38 * 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
|
39 */ |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
40 |
38
5c6f9d27ea1c
get rid of the substitution... We want a fixed identifier
Matt Johnston <matt@ucc.asn.au>
parents:
4
diff
changeset
|
41 /*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
|
42 |
725
49f68a7b7a55
Define _GNU_SOURCE for vasprintf
Matt Johnston <matt@ucc.asn.au>
parents:
287
diff
changeset
|
43 #define _GNU_SOURCE |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
44 #include "includes.h" |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
45 #include "scpmisc.h" |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
46 |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
47 void * |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
48 xmalloc(size_t size) |
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 *ptr; |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
51 |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
52 if (size == 0) { |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
53 fprintf(stderr, "xmalloc: zero size\n"); |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
54 exit(EXIT_FAILURE); |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
55 } |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
56 ptr = malloc(size); |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
57 if (ptr == NULL) { |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
58 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
|
59 exit(EXIT_FAILURE); |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
60 } |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
61 return ptr; |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
62 } |
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 void * |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
65 xrealloc(void *ptr, size_t new_size) |
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 *new_ptr; |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
68 |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
69 if (new_size == 0) { |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
70 fprintf(stderr, "xrealloc: zero size\n"); |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
71 exit(EXIT_FAILURE); |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
72 } |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
73 if (ptr == NULL) |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
74 new_ptr = malloc(new_size); |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
75 else |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
76 new_ptr = realloc(ptr, new_size); |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
77 if (new_ptr == NULL) { |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
78 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
|
79 exit(EXIT_FAILURE); |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
80 } |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
81 return new_ptr; |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
82 } |
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 void |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
85 xfree(void *ptr) |
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 if (ptr == NULL) { |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
88 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
|
89 exit(EXIT_FAILURE); |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
90 } |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
91 free(ptr); |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
92 } |
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 char * |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
95 xstrdup(const char *str) |
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 size_t len; |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
98 char *cp; |
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 len = strlen(str) + 1; |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
101 cp = xmalloc(len); |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
102 strncpy(cp, str, len); |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
103 return cp; |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
104 } |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
105 |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
106 char * |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
107 cleanhostname(char *host) |
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 if (*host == '[' && host[strlen(host) - 1] == ']') { |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
110 host[strlen(host) - 1] = '\0'; |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
111 return (host + 1); |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
112 } else |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
113 return host; |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
114 } |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
115 |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
116 char * |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
117 colon(char *cp) |
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 int flag = 0; |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
120 |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
121 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
|
122 return (0); |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
123 if (*cp == '[') |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
124 flag = 1; |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
125 |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
126 for (; *cp; ++cp) { |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
127 if (*cp == '@' && *(cp+1) == '[') |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
128 flag = 1; |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
129 if (*cp == ']' && *(cp+1) == ':' && flag) |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
130 return (cp+1); |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
131 if (*cp == ':' && !flag) |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
132 return (cp); |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
133 if (*cp == '/') |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
134 return (0); |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
135 } |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
136 return (0); |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
137 } |
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 /* function to assist building execv() arguments */ |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
140 void |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
141 addargs(arglist *args, char *fmt, ...) |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
142 { |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
143 va_list ap; |
287
b72f98803e46
Update to scp from OpenSSH portable 4.3p2
Matt Johnston <matt@ucc.asn.au>
parents:
38
diff
changeset
|
144 char *cp; |
b72f98803e46
Update to scp from OpenSSH portable 4.3p2
Matt Johnston <matt@ucc.asn.au>
parents:
38
diff
changeset
|
145 u_int nalloc; |
b72f98803e46
Update to scp from OpenSSH portable 4.3p2
Matt Johnston <matt@ucc.asn.au>
parents:
38
diff
changeset
|
146 int r; |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
147 |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
148 va_start(ap, fmt); |
287
b72f98803e46
Update to scp from OpenSSH portable 4.3p2
Matt Johnston <matt@ucc.asn.au>
parents:
38
diff
changeset
|
149 r = vasprintf(&cp, fmt, ap); |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
150 va_end(ap); |
287
b72f98803e46
Update to scp from OpenSSH portable 4.3p2
Matt Johnston <matt@ucc.asn.au>
parents:
38
diff
changeset
|
151 if (r == -1) |
b72f98803e46
Update to scp from OpenSSH portable 4.3p2
Matt Johnston <matt@ucc.asn.au>
parents:
38
diff
changeset
|
152 fatal("addargs: argument too long"); |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
153 |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
154 nalloc = args->nalloc; |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
155 if (args->list == NULL) { |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
156 nalloc = 32; |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
157 args->num = 0; |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
158 } else if (args->num+2 >= nalloc) |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
159 nalloc *= 2; |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
160 |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
161 args->list = xrealloc(args->list, nalloc * sizeof(char *)); |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
162 args->nalloc = nalloc; |
287
b72f98803e46
Update to scp from OpenSSH portable 4.3p2
Matt Johnston <matt@ucc.asn.au>
parents:
38
diff
changeset
|
163 args->list[args->num++] = cp; |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
164 args->list[args->num] = NULL; |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
165 } |
287
b72f98803e46
Update to scp from OpenSSH portable 4.3p2
Matt Johnston <matt@ucc.asn.au>
parents:
38
diff
changeset
|
166 |
b72f98803e46
Update to scp from OpenSSH portable 4.3p2
Matt Johnston <matt@ucc.asn.au>
parents:
38
diff
changeset
|
167 void |
b72f98803e46
Update to scp from OpenSSH portable 4.3p2
Matt Johnston <matt@ucc.asn.au>
parents:
38
diff
changeset
|
168 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
|
169 { |
b72f98803e46
Update to scp from OpenSSH portable 4.3p2
Matt Johnston <matt@ucc.asn.au>
parents:
38
diff
changeset
|
170 va_list ap; |
b72f98803e46
Update to scp from OpenSSH portable 4.3p2
Matt Johnston <matt@ucc.asn.au>
parents:
38
diff
changeset
|
171 char *cp; |
b72f98803e46
Update to scp from OpenSSH portable 4.3p2
Matt Johnston <matt@ucc.asn.au>
parents:
38
diff
changeset
|
172 int r; |
b72f98803e46
Update to scp from OpenSSH portable 4.3p2
Matt Johnston <matt@ucc.asn.au>
parents:
38
diff
changeset
|
173 |
b72f98803e46
Update to scp from OpenSSH portable 4.3p2
Matt Johnston <matt@ucc.asn.au>
parents:
38
diff
changeset
|
174 va_start(ap, fmt); |
b72f98803e46
Update to scp from OpenSSH portable 4.3p2
Matt Johnston <matt@ucc.asn.au>
parents:
38
diff
changeset
|
175 r = vasprintf(&cp, fmt, ap); |
b72f98803e46
Update to scp from OpenSSH portable 4.3p2
Matt Johnston <matt@ucc.asn.au>
parents:
38
diff
changeset
|
176 va_end(ap); |
b72f98803e46
Update to scp from OpenSSH portable 4.3p2
Matt Johnston <matt@ucc.asn.au>
parents:
38
diff
changeset
|
177 if (r == -1) |
b72f98803e46
Update to scp from OpenSSH portable 4.3p2
Matt Johnston <matt@ucc.asn.au>
parents:
38
diff
changeset
|
178 fatal("replacearg: argument too long"); |
b72f98803e46
Update to scp from OpenSSH portable 4.3p2
Matt Johnston <matt@ucc.asn.au>
parents:
38
diff
changeset
|
179 |
b72f98803e46
Update to scp from OpenSSH portable 4.3p2
Matt Johnston <matt@ucc.asn.au>
parents:
38
diff
changeset
|
180 if (which >= args->num) |
b72f98803e46
Update to scp from OpenSSH portable 4.3p2
Matt Johnston <matt@ucc.asn.au>
parents:
38
diff
changeset
|
181 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
|
182 which, args->num); |
b72f98803e46
Update to scp from OpenSSH portable 4.3p2
Matt Johnston <matt@ucc.asn.au>
parents:
38
diff
changeset
|
183 xfree(args->list[which]); |
b72f98803e46
Update to scp from OpenSSH portable 4.3p2
Matt Johnston <matt@ucc.asn.au>
parents:
38
diff
changeset
|
184 args->list[which] = cp; |
b72f98803e46
Update to scp from OpenSSH portable 4.3p2
Matt Johnston <matt@ucc.asn.au>
parents:
38
diff
changeset
|
185 } |
b72f98803e46
Update to scp from OpenSSH portable 4.3p2
Matt Johnston <matt@ucc.asn.au>
parents:
38
diff
changeset
|
186 |
b72f98803e46
Update to scp from OpenSSH portable 4.3p2
Matt Johnston <matt@ucc.asn.au>
parents:
38
diff
changeset
|
187 void |
b72f98803e46
Update to scp from OpenSSH portable 4.3p2
Matt Johnston <matt@ucc.asn.au>
parents:
38
diff
changeset
|
188 freeargs(arglist *args) |
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 u_int i; |
b72f98803e46
Update to scp from OpenSSH portable 4.3p2
Matt Johnston <matt@ucc.asn.au>
parents:
38
diff
changeset
|
191 |
b72f98803e46
Update to scp from OpenSSH portable 4.3p2
Matt Johnston <matt@ucc.asn.au>
parents:
38
diff
changeset
|
192 if (args->list != NULL) { |
b72f98803e46
Update to scp from OpenSSH portable 4.3p2
Matt Johnston <matt@ucc.asn.au>
parents:
38
diff
changeset
|
193 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
|
194 xfree(args->list[i]); |
b72f98803e46
Update to scp from OpenSSH portable 4.3p2
Matt Johnston <matt@ucc.asn.au>
parents:
38
diff
changeset
|
195 xfree(args->list); |
b72f98803e46
Update to scp from OpenSSH portable 4.3p2
Matt Johnston <matt@ucc.asn.au>
parents:
38
diff
changeset
|
196 args->nalloc = args->num = 0; |
b72f98803e46
Update to scp from OpenSSH portable 4.3p2
Matt Johnston <matt@ucc.asn.au>
parents:
38
diff
changeset
|
197 args->list = NULL; |
b72f98803e46
Update to scp from OpenSSH portable 4.3p2
Matt Johnston <matt@ucc.asn.au>
parents:
38
diff
changeset
|
198 } |
b72f98803e46
Update to scp from OpenSSH portable 4.3p2
Matt Johnston <matt@ucc.asn.au>
parents:
38
diff
changeset
|
199 } |
b72f98803e46
Update to scp from OpenSSH portable 4.3p2
Matt Johnston <matt@ucc.asn.au>
parents:
38
diff
changeset
|
200 |
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 * 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
|
203 * 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
|
204 */ |
b72f98803e46
Update to scp from OpenSSH portable 4.3p2
Matt Johnston <matt@ucc.asn.au>
parents:
38
diff
changeset
|
205 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
|
206 { |
b72f98803e46
Update to scp from OpenSSH portable 4.3p2
Matt Johnston <matt@ucc.asn.au>
parents:
38
diff
changeset
|
207 char *p; |
b72f98803e46
Update to scp from OpenSSH portable 4.3p2
Matt Johnston <matt@ucc.asn.au>
parents:
38
diff
changeset
|
208 |
b72f98803e46
Update to scp from OpenSSH portable 4.3p2
Matt Johnston <matt@ucc.asn.au>
parents:
38
diff
changeset
|
209 if (argv0 == NULL) |
b72f98803e46
Update to scp from OpenSSH portable 4.3p2
Matt Johnston <matt@ucc.asn.au>
parents:
38
diff
changeset
|
210 return ("unknown"); /* XXX */ |
b72f98803e46
Update to scp from OpenSSH portable 4.3p2
Matt Johnston <matt@ucc.asn.au>
parents:
38
diff
changeset
|
211 p = strrchr(argv0, '/'); |
b72f98803e46
Update to scp from OpenSSH portable 4.3p2
Matt Johnston <matt@ucc.asn.au>
parents:
38
diff
changeset
|
212 if (p == NULL) |
b72f98803e46
Update to scp from OpenSSH portable 4.3p2
Matt Johnston <matt@ucc.asn.au>
parents:
38
diff
changeset
|
213 p = argv0; |
b72f98803e46
Update to scp from OpenSSH portable 4.3p2
Matt Johnston <matt@ucc.asn.au>
parents:
38
diff
changeset
|
214 else |
b72f98803e46
Update to scp from OpenSSH portable 4.3p2
Matt Johnston <matt@ucc.asn.au>
parents:
38
diff
changeset
|
215 p++; |
b72f98803e46
Update to scp from OpenSSH portable 4.3p2
Matt Johnston <matt@ucc.asn.au>
parents:
38
diff
changeset
|
216 |
b72f98803e46
Update to scp from OpenSSH portable 4.3p2
Matt Johnston <matt@ucc.asn.au>
parents:
38
diff
changeset
|
217 return (xstrdup(p)); |
b72f98803e46
Update to scp from OpenSSH portable 4.3p2
Matt Johnston <matt@ucc.asn.au>
parents:
38
diff
changeset
|
218 } |
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 void fatal(char* fmt,...) |
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 va_list args; |
b72f98803e46
Update to scp from OpenSSH portable 4.3p2
Matt Johnston <matt@ucc.asn.au>
parents:
38
diff
changeset
|
223 va_start(args, fmt); |
b72f98803e46
Update to scp from OpenSSH portable 4.3p2
Matt Johnston <matt@ucc.asn.au>
parents:
38
diff
changeset
|
224 vfprintf(stderr, fmt, args); |
b72f98803e46
Update to scp from OpenSSH portable 4.3p2
Matt Johnston <matt@ucc.asn.au>
parents:
38
diff
changeset
|
225 va_end(args); |
b72f98803e46
Update to scp from OpenSSH portable 4.3p2
Matt Johnston <matt@ucc.asn.au>
parents:
38
diff
changeset
|
226 exit(255); |
b72f98803e46
Update to scp from OpenSSH portable 4.3p2
Matt Johnston <matt@ucc.asn.au>
parents:
38
diff
changeset
|
227 } |
b72f98803e46
Update to scp from OpenSSH portable 4.3p2
Matt Johnston <matt@ucc.asn.au>
parents:
38
diff
changeset
|
228 |
b72f98803e46
Update to scp from OpenSSH portable 4.3p2
Matt Johnston <matt@ucc.asn.au>
parents:
38
diff
changeset
|
229 void |
b72f98803e46
Update to scp from OpenSSH portable 4.3p2
Matt Johnston <matt@ucc.asn.au>
parents:
38
diff
changeset
|
230 sanitise_stdfd(void) |
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 int nullfd, dupfd; |
b72f98803e46
Update to scp from OpenSSH portable 4.3p2
Matt Johnston <matt@ucc.asn.au>
parents:
38
diff
changeset
|
233 |
b72f98803e46
Update to scp from OpenSSH portable 4.3p2
Matt Johnston <matt@ucc.asn.au>
parents:
38
diff
changeset
|
234 if ((nullfd = dupfd = open(_PATH_DEVNULL, O_RDWR)) == -1) { |
b72f98803e46
Update to scp from OpenSSH portable 4.3p2
Matt Johnston <matt@ucc.asn.au>
parents:
38
diff
changeset
|
235 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
|
236 exit(1); |
b72f98803e46
Update to scp from OpenSSH portable 4.3p2
Matt Johnston <matt@ucc.asn.au>
parents:
38
diff
changeset
|
237 } |
b72f98803e46
Update to scp from OpenSSH portable 4.3p2
Matt Johnston <matt@ucc.asn.au>
parents:
38
diff
changeset
|
238 while (++dupfd <= 2) { |
b72f98803e46
Update to scp from OpenSSH portable 4.3p2
Matt Johnston <matt@ucc.asn.au>
parents:
38
diff
changeset
|
239 /* Only clobber closed fds */ |
b72f98803e46
Update to scp from OpenSSH portable 4.3p2
Matt Johnston <matt@ucc.asn.au>
parents:
38
diff
changeset
|
240 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
|
241 continue; |
b72f98803e46
Update to scp from OpenSSH portable 4.3p2
Matt Johnston <matt@ucc.asn.au>
parents:
38
diff
changeset
|
242 if (dup2(nullfd, dupfd) == -1) { |
b72f98803e46
Update to scp from OpenSSH portable 4.3p2
Matt Johnston <matt@ucc.asn.au>
parents:
38
diff
changeset
|
243 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
|
244 exit(1); |
b72f98803e46
Update to scp from OpenSSH portable 4.3p2
Matt Johnston <matt@ucc.asn.au>
parents:
38
diff
changeset
|
245 } |
b72f98803e46
Update to scp from OpenSSH portable 4.3p2
Matt Johnston <matt@ucc.asn.au>
parents:
38
diff
changeset
|
246 } |
b72f98803e46
Update to scp from OpenSSH portable 4.3p2
Matt Johnston <matt@ucc.asn.au>
parents:
38
diff
changeset
|
247 if (nullfd > 2) |
b72f98803e46
Update to scp from OpenSSH portable 4.3p2
Matt Johnston <matt@ucc.asn.au>
parents:
38
diff
changeset
|
248 close(nullfd); |
b72f98803e46
Update to scp from OpenSSH portable 4.3p2
Matt Johnston <matt@ucc.asn.au>
parents:
38
diff
changeset
|
249 } |