Deleted Added
full compact
sftp-common.c (181110) sftp-common.c (204917)
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/*
3 * Copyright (c) 2001 Markus Friedl. All rights reserved.
4 * Copyright (c) 2001 Damien Miller. All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 * 1. Redistributions of source code must retain the above copyright

--- 21 unchanged lines hidden (view full) ---

31#include <sys/param.h>
32
33#include <grp.h>
34#include <pwd.h>
35#include <stdio.h>
36#include <string.h>
37#include <time.h>
38#include <stdarg.h>
2/*
3 * Copyright (c) 2001 Markus Friedl. All rights reserved.
4 * Copyright (c) 2001 Damien Miller. All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 * 1. Redistributions of source code must retain the above copyright

--- 21 unchanged lines hidden (view full) ---

31#include <sys/param.h>
32
33#include <grp.h>
34#include <pwd.h>
35#include <stdio.h>
36#include <string.h>
37#include <time.h>
38#include <stdarg.h>
39#ifdef HAVE_UTIL_H
40#include <util.h>
41#endif
39
40#include "xmalloc.h"
41#include "buffer.h"
42#include "log.h"
43
44#include "sftp.h"
45#include "sftp-common.h"
46

--- 132 unchanged lines hidden (view full) ---

179 }
180 /* NOTREACHED */
181}
182
183/*
184 * drwxr-xr-x 5 markus markus 1024 Jan 13 18:39 .ssh
185 */
186char *
42
43#include "xmalloc.h"
44#include "buffer.h"
45#include "log.h"
46
47#include "sftp.h"
48#include "sftp-common.h"
49

--- 132 unchanged lines hidden (view full) ---

182 }
183 /* NOTREACHED */
184}
185
186/*
187 * drwxr-xr-x 5 markus markus 1024 Jan 13 18:39 .ssh
188 */
189char *
187ls_file(const char *name, const struct stat *st, int remote)
190ls_file(const char *name, const struct stat *st, int remote, int si_units)
188{
189 int ulen, glen, sz = 0;
191{
192 int ulen, glen, sz = 0;
190 struct passwd *pw;
191 struct group *gr;
192 struct tm *ltime = localtime(&st->st_mtime);
193 char *user, *group;
194 char buf[1024], mode[11+1], tbuf[12+1], ubuf[11+1], gbuf[11+1];
193 struct tm *ltime = localtime(&st->st_mtime);
194 char *user, *group;
195 char buf[1024], mode[11+1], tbuf[12+1], ubuf[11+1], gbuf[11+1];
196 char sbuf[FMT_SCALED_STRSIZE];
195
196 strmode(st->st_mode, mode);
197
198 strmode(st->st_mode, mode);
197 if (!remote && (pw = getpwuid(st->st_uid)) != NULL) {
198 user = pw->pw_name;
199 if (!remote) {
200 user = user_from_uid(st->st_uid, 0);
199 } else {
200 snprintf(ubuf, sizeof ubuf, "%u", (u_int)st->st_uid);
201 user = ubuf;
202 }
201 } else {
202 snprintf(ubuf, sizeof ubuf, "%u", (u_int)st->st_uid);
203 user = ubuf;
204 }
203 if (!remote && (gr = getgrgid(st->st_gid)) != NULL) {
204 group = gr->gr_name;
205 if (!remote) {
206 group = group_from_gid(st->st_gid, 0);
205 } else {
206 snprintf(gbuf, sizeof gbuf, "%u", (u_int)st->st_gid);
207 group = gbuf;
208 }
209 if (ltime != NULL) {
210 if (time(NULL) - st->st_mtime < (365*24*60*60)/2)
211 sz = strftime(tbuf, sizeof tbuf, "%b %e %H:%M", ltime);
212 else
213 sz = strftime(tbuf, sizeof tbuf, "%b %e %Y", ltime);
214 }
215 if (sz == 0)
216 tbuf[0] = '\0';
217 ulen = MAX(strlen(user), 8);
218 glen = MAX(strlen(group), 8);
207 } else {
208 snprintf(gbuf, sizeof gbuf, "%u", (u_int)st->st_gid);
209 group = gbuf;
210 }
211 if (ltime != NULL) {
212 if (time(NULL) - st->st_mtime < (365*24*60*60)/2)
213 sz = strftime(tbuf, sizeof tbuf, "%b %e %H:%M", ltime);
214 else
215 sz = strftime(tbuf, sizeof tbuf, "%b %e %Y", ltime);
216 }
217 if (sz == 0)
218 tbuf[0] = '\0';
219 ulen = MAX(strlen(user), 8);
220 glen = MAX(strlen(group), 8);
219 snprintf(buf, sizeof buf, "%s %3u %-*s %-*s %8llu %s %s", mode,
220 (u_int)st->st_nlink, ulen, user, glen, group,
221 (unsigned long long)st->st_size, tbuf, name);
221 if (si_units) {
222 fmt_scaled((long long)st->st_size, sbuf);
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);
223}
231 return xstrdup(buf);
232}