Mercurial > dropbear
annotate scpmisc.c @ 313:fabcee551349 ucc-axis-hack
fix up newlines for the serial bit
author | matt-ucc@ucc.asn.au |
---|---|
date | Sun, 26 Mar 2006 13:18:30 +0000 |
parents | b27fcd28f9dc |
children |
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 |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
43 #include "includes.h" |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
44 #include "scpmisc.h" |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
45 |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
46 void * |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
47 xmalloc(size_t size) |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
48 { |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
49 void *ptr; |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
50 |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
51 if (size == 0) { |
299
740e782679be
Various changes to compile+kind of run on UCC's axis board.
Matt Johnston <matt@ucc.asn.au>
parents:
38
diff
changeset
|
52 printf( "xmalloc: zero size\n"); |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
53 exit(EXIT_FAILURE); |
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 ptr = malloc(size); |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
56 if (ptr == NULL) { |
299
740e782679be
Various changes to compile+kind of run on UCC's axis board.
Matt Johnston <matt@ucc.asn.au>
parents:
38
diff
changeset
|
57 printf( "xmalloc: out of memory (allocating %lu bytes)\n", (u_long) size); |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
58 exit(EXIT_FAILURE); |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
59 } |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
60 return ptr; |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
61 } |
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 void * |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
64 xrealloc(void *ptr, size_t new_size) |
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 void *new_ptr; |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
67 |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
68 if (new_size == 0) { |
299
740e782679be
Various changes to compile+kind of run on UCC's axis board.
Matt Johnston <matt@ucc.asn.au>
parents:
38
diff
changeset
|
69 printf( "xrealloc: zero size\n"); |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
70 exit(EXIT_FAILURE); |
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 (ptr == NULL) |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
73 new_ptr = malloc(new_size); |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
74 else |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
75 new_ptr = realloc(ptr, new_size); |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
76 if (new_ptr == NULL) { |
299
740e782679be
Various changes to compile+kind of run on UCC's axis board.
Matt Johnston <matt@ucc.asn.au>
parents:
38
diff
changeset
|
77 printf( "xrealloc: out of memory (new_size %lu bytes)\n", (u_long) new_size); |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
78 exit(EXIT_FAILURE); |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
79 } |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
80 return new_ptr; |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
81 } |
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 void |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
84 xfree(void *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 if (ptr == NULL) { |
299
740e782679be
Various changes to compile+kind of run on UCC's axis board.
Matt Johnston <matt@ucc.asn.au>
parents:
38
diff
changeset
|
87 printf( "xfree: NULL pointer given as argument\n"); |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
88 exit(EXIT_FAILURE); |
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 free(ptr); |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
91 } |
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 char * |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
94 xstrdup(const char *str) |
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 size_t len; |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
97 char *cp; |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
98 |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
99 len = strlen(str) + 1; |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
100 cp = xmalloc(len); |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
101 strncpy(cp, str, len); |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
102 return cp; |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
103 } |
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 char * |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
106 cleanhostname(char *host) |
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 if (*host == '[' && host[strlen(host) - 1] == ']') { |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
109 host[strlen(host) - 1] = '\0'; |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
110 return (host + 1); |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
111 } else |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
112 return host; |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
113 } |
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 char * |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
116 colon(char *cp) |
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 int flag = 0; |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
119 |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
120 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
|
121 return (0); |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
122 if (*cp == '[') |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
123 flag = 1; |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
124 |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
125 for (; *cp; ++cp) { |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
126 if (*cp == '@' && *(cp+1) == '[') |
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 if (*cp == ']' && *(cp+1) == ':' && flag) |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
129 return (cp+1); |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
130 if (*cp == ':' && !flag) |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
131 return (cp); |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
132 if (*cp == '/') |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
133 return (0); |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
134 } |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
135 return (0); |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
136 } |
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 /* function to assist building execv() arguments */ |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
139 void |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
140 addargs(arglist *args, char *fmt, ...) |
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 va_list ap; |
287
b72f98803e46
Update to scp from OpenSSH portable 4.3p2
Matt Johnston <matt@ucc.asn.au>
parents:
38
diff
changeset
|
143 char *cp; |
b72f98803e46
Update to scp from OpenSSH portable 4.3p2
Matt Johnston <matt@ucc.asn.au>
parents:
38
diff
changeset
|
144 u_int nalloc; |
b72f98803e46
Update to scp from OpenSSH portable 4.3p2
Matt Johnston <matt@ucc.asn.au>
parents:
38
diff
changeset
|
145 int r; |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
146 |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
147 va_start(ap, fmt); |
287
b72f98803e46
Update to scp from OpenSSH portable 4.3p2
Matt Johnston <matt@ucc.asn.au>
parents:
38
diff
changeset
|
148 r = vasprintf(&cp, fmt, ap); |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
149 va_end(ap); |
287
b72f98803e46
Update to scp from OpenSSH portable 4.3p2
Matt Johnston <matt@ucc.asn.au>
parents:
38
diff
changeset
|
150 if (r == -1) |
b72f98803e46
Update to scp from OpenSSH portable 4.3p2
Matt Johnston <matt@ucc.asn.au>
parents:
38
diff
changeset
|
151 fatal("addargs: argument too long"); |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
152 |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
153 nalloc = args->nalloc; |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
154 if (args->list == NULL) { |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
155 nalloc = 32; |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
156 args->num = 0; |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
157 } else if (args->num+2 >= nalloc) |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
158 nalloc *= 2; |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
159 |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
160 args->list = xrealloc(args->list, nalloc * sizeof(char *)); |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
161 args->nalloc = nalloc; |
287
b72f98803e46
Update to scp from OpenSSH portable 4.3p2
Matt Johnston <matt@ucc.asn.au>
parents:
38
diff
changeset
|
162 args->list[args->num++] = cp; |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
163 args->list[args->num] = NULL; |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
164 } |
287
b72f98803e46
Update to scp from OpenSSH portable 4.3p2
Matt Johnston <matt@ucc.asn.au>
parents:
38
diff
changeset
|
165 |
b72f98803e46
Update to scp from OpenSSH portable 4.3p2
Matt Johnston <matt@ucc.asn.au>
parents:
38
diff
changeset
|
166 void |
b72f98803e46
Update to scp from OpenSSH portable 4.3p2
Matt Johnston <matt@ucc.asn.au>
parents:
38
diff
changeset
|
167 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
|
168 { |
b72f98803e46
Update to scp from OpenSSH portable 4.3p2
Matt Johnston <matt@ucc.asn.au>
parents:
38
diff
changeset
|
169 va_list ap; |
b72f98803e46
Update to scp from OpenSSH portable 4.3p2
Matt Johnston <matt@ucc.asn.au>
parents:
38
diff
changeset
|
170 char *cp; |
b72f98803e46
Update to scp from OpenSSH portable 4.3p2
Matt Johnston <matt@ucc.asn.au>
parents:
38
diff
changeset
|
171 int r; |
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_start(ap, fmt); |
b72f98803e46
Update to scp from OpenSSH portable 4.3p2
Matt Johnston <matt@ucc.asn.au>
parents:
38
diff
changeset
|
174 r = vasprintf(&cp, fmt, ap); |
b72f98803e46
Update to scp from OpenSSH portable 4.3p2
Matt Johnston <matt@ucc.asn.au>
parents:
38
diff
changeset
|
175 va_end(ap); |
b72f98803e46
Update to scp from OpenSSH portable 4.3p2
Matt Johnston <matt@ucc.asn.au>
parents:
38
diff
changeset
|
176 if (r == -1) |
b72f98803e46
Update to scp from OpenSSH portable 4.3p2
Matt Johnston <matt@ucc.asn.au>
parents:
38
diff
changeset
|
177 fatal("replacearg: argument too long"); |
b72f98803e46
Update to scp from OpenSSH portable 4.3p2
Matt Johnston <matt@ucc.asn.au>
parents:
38
diff
changeset
|
178 |
b72f98803e46
Update to scp from OpenSSH portable 4.3p2
Matt Johnston <matt@ucc.asn.au>
parents:
38
diff
changeset
|
179 if (which >= args->num) |
b72f98803e46
Update to scp from OpenSSH portable 4.3p2
Matt Johnston <matt@ucc.asn.au>
parents:
38
diff
changeset
|
180 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
|
181 which, args->num); |
b72f98803e46
Update to scp from OpenSSH portable 4.3p2
Matt Johnston <matt@ucc.asn.au>
parents:
38
diff
changeset
|
182 xfree(args->list[which]); |
b72f98803e46
Update to scp from OpenSSH portable 4.3p2
Matt Johnston <matt@ucc.asn.au>
parents:
38
diff
changeset
|
183 args->list[which] = cp; |
b72f98803e46
Update to scp from OpenSSH portable 4.3p2
Matt Johnston <matt@ucc.asn.au>
parents:
38
diff
changeset
|
184 } |
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 void |
b72f98803e46
Update to scp from OpenSSH portable 4.3p2
Matt Johnston <matt@ucc.asn.au>
parents:
38
diff
changeset
|
187 freeargs(arglist *args) |
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 u_int i; |
b72f98803e46
Update to scp from OpenSSH portable 4.3p2
Matt Johnston <matt@ucc.asn.au>
parents:
38
diff
changeset
|
190 |
b72f98803e46
Update to scp from OpenSSH portable 4.3p2
Matt Johnston <matt@ucc.asn.au>
parents:
38
diff
changeset
|
191 if (args->list != NULL) { |
b72f98803e46
Update to scp from OpenSSH portable 4.3p2
Matt Johnston <matt@ucc.asn.au>
parents:
38
diff
changeset
|
192 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
|
193 xfree(args->list[i]); |
b72f98803e46
Update to scp from OpenSSH portable 4.3p2
Matt Johnston <matt@ucc.asn.au>
parents:
38
diff
changeset
|
194 xfree(args->list); |
b72f98803e46
Update to scp from OpenSSH portable 4.3p2
Matt Johnston <matt@ucc.asn.au>
parents:
38
diff
changeset
|
195 args->nalloc = args->num = 0; |
b72f98803e46
Update to scp from OpenSSH portable 4.3p2
Matt Johnston <matt@ucc.asn.au>
parents:
38
diff
changeset
|
196 args->list = NULL; |
b72f98803e46
Update to scp from OpenSSH portable 4.3p2
Matt Johnston <matt@ucc.asn.au>
parents:
38
diff
changeset
|
197 } |
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 * 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
|
202 * 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
|
203 */ |
b72f98803e46
Update to scp from OpenSSH portable 4.3p2
Matt Johnston <matt@ucc.asn.au>
parents:
38
diff
changeset
|
204 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
|
205 { |
b72f98803e46
Update to scp from OpenSSH portable 4.3p2
Matt Johnston <matt@ucc.asn.au>
parents:
38
diff
changeset
|
206 char *p; |
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 if (argv0 == NULL) |
b72f98803e46
Update to scp from OpenSSH portable 4.3p2
Matt Johnston <matt@ucc.asn.au>
parents:
38
diff
changeset
|
209 return ("unknown"); /* XXX */ |
b72f98803e46
Update to scp from OpenSSH portable 4.3p2
Matt Johnston <matt@ucc.asn.au>
parents:
38
diff
changeset
|
210 p = strrchr(argv0, '/'); |
b72f98803e46
Update to scp from OpenSSH portable 4.3p2
Matt Johnston <matt@ucc.asn.au>
parents:
38
diff
changeset
|
211 if (p == NULL) |
b72f98803e46
Update to scp from OpenSSH portable 4.3p2
Matt Johnston <matt@ucc.asn.au>
parents:
38
diff
changeset
|
212 p = argv0; |
b72f98803e46
Update to scp from OpenSSH portable 4.3p2
Matt Johnston <matt@ucc.asn.au>
parents:
38
diff
changeset
|
213 else |
b72f98803e46
Update to scp from OpenSSH portable 4.3p2
Matt Johnston <matt@ucc.asn.au>
parents:
38
diff
changeset
|
214 p++; |
b72f98803e46
Update to scp from OpenSSH portable 4.3p2
Matt Johnston <matt@ucc.asn.au>
parents:
38
diff
changeset
|
215 |
b72f98803e46
Update to scp from OpenSSH portable 4.3p2
Matt Johnston <matt@ucc.asn.au>
parents:
38
diff
changeset
|
216 return (xstrdup(p)); |
b72f98803e46
Update to scp from OpenSSH portable 4.3p2
Matt Johnston <matt@ucc.asn.au>
parents:
38
diff
changeset
|
217 } |
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 void fatal(char* fmt,...) |
b72f98803e46
Update to scp from OpenSSH portable 4.3p2
Matt Johnston <matt@ucc.asn.au>
parents:
38
diff
changeset
|
220 { |
b72f98803e46
Update to scp from OpenSSH portable 4.3p2
Matt Johnston <matt@ucc.asn.au>
parents:
38
diff
changeset
|
221 va_list args; |
b72f98803e46
Update to scp from OpenSSH portable 4.3p2
Matt Johnston <matt@ucc.asn.au>
parents:
38
diff
changeset
|
222 va_start(args, fmt); |
303
b27fcd28f9dc
printf not fprintf for scp stuff
Matt Johnston <matt@ucc.asn.au>
parents:
302
diff
changeset
|
223 vprintf( fmt, args); |
287
b72f98803e46
Update to scp from OpenSSH portable 4.3p2
Matt Johnston <matt@ucc.asn.au>
parents:
38
diff
changeset
|
224 va_end(args); |
b72f98803e46
Update to scp from OpenSSH portable 4.3p2
Matt Johnston <matt@ucc.asn.au>
parents:
38
diff
changeset
|
225 exit(255); |
b72f98803e46
Update to scp from OpenSSH portable 4.3p2
Matt Johnston <matt@ucc.asn.au>
parents:
38
diff
changeset
|
226 } |
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 void |
b72f98803e46
Update to scp from OpenSSH portable 4.3p2
Matt Johnston <matt@ucc.asn.au>
parents:
38
diff
changeset
|
229 sanitise_stdfd(void) |
b72f98803e46
Update to scp from OpenSSH portable 4.3p2
Matt Johnston <matt@ucc.asn.au>
parents:
38
diff
changeset
|
230 { |
b72f98803e46
Update to scp from OpenSSH portable 4.3p2
Matt Johnston <matt@ucc.asn.au>
parents:
38
diff
changeset
|
231 int nullfd, dupfd; |
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 if ((nullfd = dupfd = open(_PATH_DEVNULL, O_RDWR)) == -1) { |
303
b27fcd28f9dc
printf not fprintf for scp stuff
Matt Johnston <matt@ucc.asn.au>
parents:
302
diff
changeset
|
234 printf( "Couldn't open /dev/null: %s", strerror(errno)); |
287
b72f98803e46
Update to scp from OpenSSH portable 4.3p2
Matt Johnston <matt@ucc.asn.au>
parents:
38
diff
changeset
|
235 exit(1); |
b72f98803e46
Update to scp from OpenSSH portable 4.3p2
Matt Johnston <matt@ucc.asn.au>
parents:
38
diff
changeset
|
236 } |
b72f98803e46
Update to scp from OpenSSH portable 4.3p2
Matt Johnston <matt@ucc.asn.au>
parents:
38
diff
changeset
|
237 while (++dupfd <= 2) { |
b72f98803e46
Update to scp from OpenSSH portable 4.3p2
Matt Johnston <matt@ucc.asn.au>
parents:
38
diff
changeset
|
238 /* Only clobber closed fds */ |
b72f98803e46
Update to scp from OpenSSH portable 4.3p2
Matt Johnston <matt@ucc.asn.au>
parents:
38
diff
changeset
|
239 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
|
240 continue; |
b72f98803e46
Update to scp from OpenSSH portable 4.3p2
Matt Johnston <matt@ucc.asn.au>
parents:
38
diff
changeset
|
241 if (dup2(nullfd, dupfd) == -1) { |
303
b27fcd28f9dc
printf not fprintf for scp stuff
Matt Johnston <matt@ucc.asn.au>
parents:
302
diff
changeset
|
242 printf( "dup2: %s", strerror(errno)); |
287
b72f98803e46
Update to scp from OpenSSH portable 4.3p2
Matt Johnston <matt@ucc.asn.au>
parents:
38
diff
changeset
|
243 exit(1); |
b72f98803e46
Update to scp from OpenSSH portable 4.3p2
Matt Johnston <matt@ucc.asn.au>
parents:
38
diff
changeset
|
244 } |
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 if (nullfd > 2) |
b72f98803e46
Update to scp from OpenSSH portable 4.3p2
Matt Johnston <matt@ucc.asn.au>
parents:
38
diff
changeset
|
247 close(nullfd); |
b72f98803e46
Update to scp from OpenSSH portable 4.3p2
Matt Johnston <matt@ucc.asn.au>
parents:
38
diff
changeset
|
248 } |