diff options
author | Damien Miller <djm@mindrot.org> | 2002-09-12 09:54:25 +1000 |
---|---|---|
committer | Damien Miller <djm@mindrot.org> | 2002-09-12 09:54:25 +1000 |
commit | e1a49817078a22056be87cde74467d52583e9ea1 (patch) | |
tree | 1ad843d67b9e1ebaf49a91be0004aed57485c3db /sftp-common.c | |
parent | 789e95dbe931bad60cb5f91d995470f433f4e02b (diff) |
- djm@cvs.openbsd.org 2002/09/11 22:41:50
[sftp.1 sftp-client.c sftp-client.h sftp-common.c sftp-common.h]
[sftp-glob.c sftp-glob.h sftp-int.c sftp-server.c]
support for short/long listings and globbing in "ls"; ok markus@
Diffstat (limited to 'sftp-common.c')
-rw-r--r-- | sftp-common.c | 64 |
1 files changed, 63 insertions, 1 deletions
diff --git a/sftp-common.c b/sftp-common.c index 6bed0ab8a..082345486 100644 --- a/sftp-common.c +++ b/sftp-common.c | |||
@@ -24,7 +24,7 @@ | |||
24 | */ | 24 | */ |
25 | 25 | ||
26 | #include "includes.h" | 26 | #include "includes.h" |
27 | RCSID("$OpenBSD: sftp-common.c,v 1.6 2002/06/23 09:30:14 deraadt Exp $"); | 27 | RCSID("$OpenBSD: sftp-common.c,v 1.7 2002/09/11 22:41:50 djm Exp $"); |
28 | 28 | ||
29 | #include "buffer.h" | 29 | #include "buffer.h" |
30 | #include "bufaux.h" | 30 | #include "bufaux.h" |
@@ -65,6 +65,26 @@ stat_to_attrib(struct stat *st, Attrib *a) | |||
65 | a->mtime = st->st_mtime; | 65 | a->mtime = st->st_mtime; |
66 | } | 66 | } |
67 | 67 | ||
68 | /* Convert from filexfer attribs to struct stat */ | ||
69 | void | ||
70 | attrib_to_stat(Attrib *a, struct stat *st) | ||
71 | { | ||
72 | memset(st, 0, sizeof(*st)); | ||
73 | |||
74 | if (a->flags & SSH2_FILEXFER_ATTR_SIZE) | ||
75 | st->st_size = a->size; | ||
76 | if (a->flags & SSH2_FILEXFER_ATTR_UIDGID) { | ||
77 | st->st_uid = a->uid; | ||
78 | st->st_gid = a->gid; | ||
79 | } | ||
80 | if (a->flags & SSH2_FILEXFER_ATTR_PERMISSIONS) | ||
81 | st->st_mode = a->perm; | ||
82 | if (a->flags & SSH2_FILEXFER_ATTR_ACMODTIME) { | ||
83 | st->st_atime = a->atime; | ||
84 | st->st_mtime = a->mtime; | ||
85 | } | ||
86 | } | ||
87 | |||
68 | /* Decode attributes in buffer */ | 88 | /* Decode attributes in buffer */ |
69 | Attrib * | 89 | Attrib * |
70 | decode_attrib(Buffer *b) | 90 | decode_attrib(Buffer *b) |
@@ -149,3 +169,45 @@ fx2txt(int status) | |||
149 | } | 169 | } |
150 | /* NOTREACHED */ | 170 | /* NOTREACHED */ |
151 | } | 171 | } |
172 | |||
173 | /* | ||
174 | * drwxr-xr-x 5 markus markus 1024 Jan 13 18:39 .ssh | ||
175 | */ | ||
176 | char * | ||
177 | ls_file(char *name, struct stat *st, int remote) | ||
178 | { | ||
179 | int ulen, glen, sz = 0; | ||
180 | struct passwd *pw; | ||
181 | struct group *gr; | ||
182 | struct tm *ltime = localtime(&st->st_mtime); | ||
183 | char *user, *group; | ||
184 | char buf[1024], mode[11+1], tbuf[12+1], ubuf[11+1], gbuf[11+1]; | ||
185 | |||
186 | strmode(st->st_mode, mode); | ||
187 | if (!remote && (pw = getpwuid(st->st_uid)) != NULL) { | ||
188 | user = pw->pw_name; | ||
189 | } else { | ||
190 | snprintf(ubuf, sizeof ubuf, "%u", (u_int)st->st_uid); | ||
191 | user = ubuf; | ||
192 | } | ||
193 | if (!remote && (gr = getgrgid(st->st_gid)) != NULL) { | ||
194 | group = gr->gr_name; | ||
195 | } else { | ||
196 | snprintf(gbuf, sizeof gbuf, "%u", (u_int)st->st_gid); | ||
197 | group = gbuf; | ||
198 | } | ||
199 | if (ltime != NULL) { | ||
200 | if (time(NULL) - st->st_mtime < (365*24*60*60)/2) | ||
201 | sz = strftime(tbuf, sizeof tbuf, "%b %e %H:%M", ltime); | ||
202 | else | ||
203 | sz = strftime(tbuf, sizeof tbuf, "%b %e %Y", ltime); | ||
204 | } | ||
205 | if (sz == 0) | ||
206 | tbuf[0] = '\0'; | ||
207 | ulen = MAX(strlen(user), 8); | ||
208 | glen = MAX(strlen(group), 8); | ||
209 | snprintf(buf, sizeof buf, "%s %3d %-*s %-*s %8llu %s %s", mode, | ||
210 | st->st_nlink, ulen, user, glen, group, | ||
211 | (u_int64_t)st->st_size, tbuf, name); | ||
212 | return xstrdup(buf); | ||
213 | } | ||