diff options
Diffstat (limited to 'sftp-common.c')
-rw-r--r-- | sftp-common.c | 31 |
1 files changed, 20 insertions, 11 deletions
diff --git a/sftp-common.c b/sftp-common.c index 7ebadcc53..a042875c6 100644 --- a/sftp-common.c +++ b/sftp-common.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: sftp-common.c,v 1.20 2006/08/03 03:34:42 deraadt Exp $ */ | 1 | /* $OpenBSD: sftp-common.c,v 1.23 2010/01/15 09:24:23 markus Exp $ */ |
2 | /* | 2 | /* |
3 | * Copyright (c) 2001 Markus Friedl. All rights reserved. | 3 | * Copyright (c) 2001 Markus Friedl. All rights reserved. |
4 | * Copyright (c) 2001 Damien Miller. All rights reserved. | 4 | * Copyright (c) 2001 Damien Miller. All rights reserved. |
@@ -36,6 +36,9 @@ | |||
36 | #include <string.h> | 36 | #include <string.h> |
37 | #include <time.h> | 37 | #include <time.h> |
38 | #include <stdarg.h> | 38 | #include <stdarg.h> |
39 | #ifdef HAVE_UTIL_H | ||
40 | #include <util.h> | ||
41 | #endif | ||
39 | 42 | ||
40 | #include "xmalloc.h" | 43 | #include "xmalloc.h" |
41 | #include "buffer.h" | 44 | #include "buffer.h" |
@@ -184,24 +187,23 @@ fx2txt(int status) | |||
184 | * drwxr-xr-x 5 markus markus 1024 Jan 13 18:39 .ssh | 187 | * drwxr-xr-x 5 markus markus 1024 Jan 13 18:39 .ssh |
185 | */ | 188 | */ |
186 | char * | 189 | char * |
187 | ls_file(const char *name, const struct stat *st, int remote) | 190 | ls_file(const char *name, const struct stat *st, int remote, int si_units) |
188 | { | 191 | { |
189 | int ulen, glen, sz = 0; | 192 | int ulen, glen, sz = 0; |
190 | struct passwd *pw; | ||
191 | struct group *gr; | ||
192 | struct tm *ltime = localtime(&st->st_mtime); | 193 | struct tm *ltime = localtime(&st->st_mtime); |
193 | char *user, *group; | 194 | char *user, *group; |
194 | char buf[1024], mode[11+1], tbuf[12+1], ubuf[11+1], gbuf[11+1]; | 195 | char buf[1024], mode[11+1], tbuf[12+1], ubuf[11+1], gbuf[11+1]; |
196 | char sbuf[FMT_SCALED_STRSIZE]; | ||
195 | 197 | ||
196 | strmode(st->st_mode, mode); | 198 | strmode(st->st_mode, mode); |
197 | if (!remote && (pw = getpwuid(st->st_uid)) != NULL) { | 199 | if (!remote) { |
198 | user = pw->pw_name; | 200 | user = user_from_uid(st->st_uid, 0); |
199 | } else { | 201 | } else { |
200 | snprintf(ubuf, sizeof ubuf, "%u", (u_int)st->st_uid); | 202 | snprintf(ubuf, sizeof ubuf, "%u", (u_int)st->st_uid); |
201 | user = ubuf; | 203 | user = ubuf; |
202 | } | 204 | } |
203 | if (!remote && (gr = getgrgid(st->st_gid)) != NULL) { | 205 | if (!remote) { |
204 | group = gr->gr_name; | 206 | group = group_from_gid(st->st_gid, 0); |
205 | } else { | 207 | } else { |
206 | snprintf(gbuf, sizeof gbuf, "%u", (u_int)st->st_gid); | 208 | snprintf(gbuf, sizeof gbuf, "%u", (u_int)st->st_gid); |
207 | group = gbuf; | 209 | group = gbuf; |
@@ -216,8 +218,15 @@ ls_file(const char *name, const struct stat *st, int remote) | |||
216 | tbuf[0] = '\0'; | 218 | tbuf[0] = '\0'; |
217 | ulen = MAX(strlen(user), 8); | 219 | ulen = MAX(strlen(user), 8); |
218 | glen = MAX(strlen(group), 8); | 220 | glen = MAX(strlen(group), 8); |
219 | snprintf(buf, sizeof buf, "%s %3u %-*s %-*s %8llu %s %s", mode, | 221 | if (si_units) { |
220 | (u_int)st->st_nlink, ulen, user, glen, group, | 222 | fmt_scaled((long long)st->st_size, sbuf); |
221 | (unsigned long long)st->st_size, tbuf, name); | 223 | snprintf(buf, sizeof buf, "%s %3u %-*s %-*s %8s %s %s", mode, |
224 | (u_int)st->st_nlink, ulen, user, glen, group, | ||
225 | sbuf, tbuf, name); | ||
226 | } else { | ||
227 | snprintf(buf, sizeof buf, "%s %3u %-*s %-*s %8llu %s %s", mode, | ||
228 | (u_int)st->st_nlink, ulen, user, glen, group, | ||
229 | (unsigned long long)st->st_size, tbuf, name); | ||
230 | } | ||
222 | return xstrdup(buf); | 231 | return xstrdup(buf); |
223 | } | 232 | } |