OpenCoverage

sftp-common.c

Absolute File Name:/home/opencoverage/opencoverage/guest-scripts/openssh/src/sftp-common.c
Switch to Source codePreprocessed file
LineSourceCount
1-
2-
3-
4-
5-
6-
7-
8-
9-
10-
11-
12-
13-
14-
15void-
16attrib_clear(Attrib *a)-
17{-
18 a->flags = 0;-
19 a->size = 0;-
20 a->uid = 0;-
21 a->gid = 0;-
22 a->perm = 0;-
23 a->atime = 0;-
24 a->mtime = 0;-
25}
never executed: end of block
0
26-
27-
28void-
29stat_to_attrib(const struct stat *st, Attrib *a)-
30{-
31 attrib_clear(a);-
32 a->flags = 0;-
33 a->flags |= 0x00000001;-
34 a->size = st->st_size;-
35 a->flags |= 0x00000002;-
36 a->uid = st->st_uid;-
37 a->gid = st->st_gid;-
38 a->flags |= 0x00000004;-
39 a->perm = st->st_mode;-
40 a->flags |= 0x00000008;-
41 a->atime = st->-
42 st_atim.tv_sec-
43 ;-
44 a->mtime = st->-
45 st_mtim.tv_sec-
46 ;-
47}
never executed: end of block
0
48-
49-
50void-
51attrib_to_stat(const Attrib *a, struct stat *st)-
52{-
53 memset(st, 0, sizeof(*st));-
54-
55 if (a->flags & 0x00000001
a->flags & 0x00000001Description
TRUEnever evaluated
FALSEnever evaluated
)
0
56 st->st_size = a->size;
never executed: st->st_size = a->size;
0
57 if (a->flags & 0x00000002
a->flags & 0x00000002Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
58 st->st_uid = a->uid;-
59 st->st_gid = a->gid;-
60 }
never executed: end of block
0
61 if (a->flags & 0x00000004
a->flags & 0x00000004Description
TRUEnever evaluated
FALSEnever evaluated
)
0
62 st->st_mode = a->perm;
never executed: st->st_mode = a->perm;
0
63 if (a->flags & 0x00000008
a->flags & 0x00000008Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
64 st->-
65 st_atim.tv_sec -
66 = a->atime;-
67 st->-
68 st_mtim.tv_sec -
69 = a->mtime;-
70 }
never executed: end of block
0
71}
never executed: end of block
0
72-
73-
74int-
75decode_attrib(struct sshbuf *b, Attrib *a)-
76{-
77 int r;-
78-
79 attrib_clear(a);-
80 if ((
(r = sshbuf_ge...->flags)) != 0Description
TRUEnever evaluated
FALSEnever evaluated
r = sshbuf_get_u32(b, &a->flags)) != 0
(r = sshbuf_ge...->flags)) != 0Description
TRUEnever evaluated
FALSEnever evaluated
)
0
81 return
never executed: return r;
r;
never executed: return r;
0
82 if (a->flags & 0x00000001
a->flags & 0x00000001Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
83 if ((
(r = sshbuf_ge...a->size)) != 0Description
TRUEnever evaluated
FALSEnever evaluated
r = sshbuf_get_u64(b, &a->size)) != 0
(r = sshbuf_ge...a->size)) != 0Description
TRUEnever evaluated
FALSEnever evaluated
)
0
84 return
never executed: return r;
r;
never executed: return r;
0
85 }
never executed: end of block
0
86 if (a->flags & 0x00000002
a->flags & 0x00000002Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
87 if ((
(r = sshbuf_ge...&a->uid)) != 0Description
TRUEnever evaluated
FALSEnever evaluated
r = sshbuf_get_u32(b, &a->uid)) != 0
(r = sshbuf_ge...&a->uid)) != 0Description
TRUEnever evaluated
FALSEnever evaluated
||
0
88 (
(r = sshbuf_ge...&a->gid)) != 0Description
TRUEnever evaluated
FALSEnever evaluated
r = sshbuf_get_u32(b, &a->gid)) != 0
(r = sshbuf_ge...&a->gid)) != 0Description
TRUEnever evaluated
FALSEnever evaluated
)
0
89 return
never executed: return r;
r;
never executed: return r;
0
90 }
never executed: end of block
0
91 if (a->flags & 0x00000004
a->flags & 0x00000004Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
92 if ((
(r = sshbuf_ge...a->perm)) != 0Description
TRUEnever evaluated
FALSEnever evaluated
r = sshbuf_get_u32(b, &a->perm)) != 0
(r = sshbuf_ge...a->perm)) != 0Description
TRUEnever evaluated
FALSEnever evaluated
)
0
93 return
never executed: return r;
r;
never executed: return r;
0
94 }
never executed: end of block
0
95 if (a->flags & 0x00000008
a->flags & 0x00000008Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
96 if ((
(r = sshbuf_ge...->atime)) != 0Description
TRUEnever evaluated
FALSEnever evaluated
r = sshbuf_get_u32(b, &a->atime)) != 0
(r = sshbuf_ge...->atime)) != 0Description
TRUEnever evaluated
FALSEnever evaluated
||
0
97 (
(r = sshbuf_ge...->mtime)) != 0Description
TRUEnever evaluated
FALSEnever evaluated
r = sshbuf_get_u32(b, &a->mtime)) != 0
(r = sshbuf_ge...->mtime)) != 0Description
TRUEnever evaluated
FALSEnever evaluated
)
0
98 return
never executed: return r;
r;
never executed: return r;
0
99 }
never executed: end of block
0
100-
101 if (a->flags & 0x80000000
a->flags & 0x80000000Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
102 char *type;-
103 u_char *data;-
104 size_t dlen;-
105 u_int i, count;-
106-
107 if ((
(r = sshbuf_ge... &count)) != 0Description
TRUEnever evaluated
FALSEnever evaluated
r = sshbuf_get_u32(b, &count)) != 0
(r = sshbuf_ge... &count)) != 0Description
TRUEnever evaluated
FALSEnever evaluated
)
0
108 fatal("%s: buffer error: %s", __func__, ssh_err(r));
never executed: fatal("%s: buffer error: %s", __func__, ssh_err(r));
0
109 for (i = 0; i < count
i < countDescription
TRUEnever evaluated
FALSEnever evaluated
; i++) {
0
110 if ((
(r = sshbuf_ge...d *)0) )) != 0Description
TRUEnever evaluated
FALSEnever evaluated
r = sshbuf_get_cstring(b, &type,
(r = sshbuf_ge...d *)0) )) != 0Description
TRUEnever evaluated
FALSEnever evaluated
0
111 ((void *)0)
(r = sshbuf_ge...d *)0) )) != 0Description
TRUEnever evaluated
FALSEnever evaluated
0
112 )) != 0
(r = sshbuf_ge...d *)0) )) != 0Description
TRUEnever evaluated
FALSEnever evaluated
||
0
113 (
(r = sshbuf_ge..., &dlen)) != 0Description
TRUEnever evaluated
FALSEnever evaluated
r = sshbuf_get_string(b, &data, &dlen)) != 0
(r = sshbuf_ge..., &dlen)) != 0Description
TRUEnever evaluated
FALSEnever evaluated
)
0
114 return
never executed: return r;
r;
never executed: return r;
0
115 debug3("Got file attribute \"%.100s\" len %zu",-
116 type, dlen);-
117 free(type);-
118 free(data);-
119 }
never executed: end of block
0
120 }
never executed: end of block
0
121 return
never executed: return 0;
0;
never executed: return 0;
0
122}-
123-
124-
125int-
126encode_attrib(struct sshbuf *b, const Attrib *a)-
127{-
128 int r;-
129-
130 if ((
(r = sshbuf_pu...->flags)) != 0Description
TRUEnever evaluated
FALSEnever evaluated
r = sshbuf_put_u32(b, a->flags)) != 0
(r = sshbuf_pu...->flags)) != 0Description
TRUEnever evaluated
FALSEnever evaluated
)
0
131 return
never executed: return r;
r;
never executed: return r;
0
132 if (a->flags & 0x00000001
a->flags & 0x00000001Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
133 if ((
(r = sshbuf_pu...a->size)) != 0Description
TRUEnever evaluated
FALSEnever evaluated
r = sshbuf_put_u64(b, a->size)) != 0
(r = sshbuf_pu...a->size)) != 0Description
TRUEnever evaluated
FALSEnever evaluated
)
0
134 return
never executed: return r;
r;
never executed: return r;
0
135 }
never executed: end of block
0
136 if (a->flags & 0x00000002
a->flags & 0x00000002Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
137 if ((
(r = sshbuf_pu... a->uid)) != 0Description
TRUEnever evaluated
FALSEnever evaluated
r = sshbuf_put_u32(b, a->uid)) != 0
(r = sshbuf_pu... a->uid)) != 0Description
TRUEnever evaluated
FALSEnever evaluated
||
0
138 (
(r = sshbuf_pu... a->gid)) != 0Description
TRUEnever evaluated
FALSEnever evaluated
r = sshbuf_put_u32(b, a->gid)) != 0
(r = sshbuf_pu... a->gid)) != 0Description
TRUEnever evaluated
FALSEnever evaluated
)
0
139 return
never executed: return r;
r;
never executed: return r;
0
140 }
never executed: end of block
0
141 if (a->flags & 0x00000004
a->flags & 0x00000004Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
142 if ((
(r = sshbuf_pu...a->perm)) != 0Description
TRUEnever evaluated
FALSEnever evaluated
r = sshbuf_put_u32(b, a->perm)) != 0
(r = sshbuf_pu...a->perm)) != 0Description
TRUEnever evaluated
FALSEnever evaluated
)
0
143 return
never executed: return r;
r;
never executed: return r;
0
144 }
never executed: end of block
0
145 if (a->flags & 0x00000008
a->flags & 0x00000008Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
146 if ((
(r = sshbuf_pu...->atime)) != 0Description
TRUEnever evaluated
FALSEnever evaluated
r = sshbuf_put_u32(b, a->atime)) != 0
(r = sshbuf_pu...->atime)) != 0Description
TRUEnever evaluated
FALSEnever evaluated
||
0
147 (
(r = sshbuf_pu...->mtime)) != 0Description
TRUEnever evaluated
FALSEnever evaluated
r = sshbuf_put_u32(b, a->mtime)) != 0
(r = sshbuf_pu...->mtime)) != 0Description
TRUEnever evaluated
FALSEnever evaluated
)
0
148 return
never executed: return r;
r;
never executed: return r;
0
149 }
never executed: end of block
0
150 return
never executed: return 0;
0;
never executed: return 0;
0
151}-
152-
153-
154const char *-
155fx2txt(int status)-
156{-
157 switch (status) {-
158 case
never executed: case 0:
0:
never executed: case 0:
0
159 return
never executed: return("No error");
("No error");
never executed: return("No error");
0
160 case
never executed: case 1:
1:
never executed: case 1:
0
161 return
never executed: return("End of file");
("End of file");
never executed: return("End of file");
0
162 case
never executed: case 2:
2:
never executed: case 2:
0
163 return
never executed: return("No such file or directory");
("No such file or directory");
never executed: return("No such file or directory");
0
164 case
never executed: case 3:
3:
never executed: case 3:
0
165 return
never executed: return("Permission denied");
("Permission denied");
never executed: return("Permission denied");
0
166 case
never executed: case 4:
4:
never executed: case 4:
0
167 return
never executed: return("Failure");
("Failure");
never executed: return("Failure");
0
168 case
never executed: case 5:
5:
never executed: case 5:
0
169 return
never executed: return("Bad message");
("Bad message");
never executed: return("Bad message");
0
170 case
never executed: case 6:
6:
never executed: case 6:
0
171 return
never executed: return("No connection");
("No connection");
never executed: return("No connection");
0
172 case
never executed: case 7:
7:
never executed: case 7:
0
173 return
never executed: return("Connection lost");
("Connection lost");
never executed: return("Connection lost");
0
174 case
never executed: case 8:
8:
never executed: case 8:
0
175 return
never executed: return("Operation unsupported");
("Operation unsupported");
never executed: return("Operation unsupported");
0
176 default
never executed: default:
:
never executed: default:
0
177 return
never executed: return("Unknown status");
("Unknown status");
never executed: return("Unknown status");
0
178 }-
179-
180}-
181-
182-
183-
184-
185char *-
186ls_file(const char *name, const struct stat *st, int remote, int si_units)-
187{-
188 int ulen, glen, sz = 0;-
189 struct tm *ltime = localtime(&st->-
190 st_mtim.tv_sec-
191 );-
192 const char *user, *group;-
193 char buf[1024], lc[8], mode[11+1], tbuf[12+1], ubuf[11+1], gbuf[11+1];-
194 char sbuf[7];-
195 time_t now;-
196-
197 strmode(st->st_mode, mode);-
198 if (remote
remoteDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
199 snprintf(ubuf, sizeof ubuf, "%u", (u_int)st->st_uid);-
200 user = ubuf;-
201 snprintf(gbuf, sizeof gbuf, "%u", (u_int)st->st_gid);-
202 group = gbuf;-
203 strlcpy(lc, "?", sizeof(lc));-
204 }
never executed: end of block
else {
0
205 user = user_from_uid(st->st_uid, 0);-
206 group = group_from_gid(st->st_gid, 0);-
207 snprintf(lc, sizeof(lc), "%u", (u_int)st->st_nlink);-
208 }
never executed: end of block
0
209 if (ltime !=
ltime != ((void *)0)Description
TRUEnever evaluated
FALSEnever evaluated
0
210 ((void *)0)
ltime != ((void *)0)Description
TRUEnever evaluated
FALSEnever evaluated
0
211 ) {-
212 now = time(-
213 ((void *)0)-
214 );-
215 if (now - (365*24*60*60)/2 < st->
now - (365*24*...st_mtim.tv_secDescription
TRUEnever evaluated
FALSEnever evaluated
0
216 st_mtim.tv_sec
now - (365*24*...st_mtim.tv_secDescription
TRUEnever evaluated
FALSEnever evaluated
0
217 &&-
218 now >= st->
now >= st-> st_mtim.tv_secDescription
TRUEnever evaluated
FALSEnever evaluated
0
219 st_mtim.tv_sec
now >= st-> st_mtim.tv_secDescription
TRUEnever evaluated
FALSEnever evaluated
0
220 )-
221 sz = strftime(tbuf, sizeof tbuf, "%b %e %H:%M", ltime);
never executed: sz = strftime(tbuf, sizeof tbuf, "%b %e %H:%M", ltime);
0
222 else-
223 sz = strftime(tbuf, sizeof tbuf, "%b %e %Y", ltime);
never executed: sz = strftime(tbuf, sizeof tbuf, "%b %e %Y", ltime);
0
224 }-
225 if (sz == 0
sz == 0Description
TRUEnever evaluated
FALSEnever evaluated
)
0
226 tbuf[0] = '\0';
never executed: tbuf[0] = '\0';
0
227 ulen = (((
((strlen(user)) > (8))Description
TRUEnever evaluated
FALSEnever evaluated
strlen(user)) > (8))
((strlen(user)) > (8))Description
TRUEnever evaluated
FALSEnever evaluated
? (strlen(user)) : (8));
0
228 glen = (((
((strlen(group)) > (8))Description
TRUEnever evaluated
FALSEnever evaluated
strlen(group)) > (8))
((strlen(group)) > (8))Description
TRUEnever evaluated
FALSEnever evaluated
? (strlen(group)) : (8));
0
229 if (si_units
si_unitsDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
230 fmt_scaled((long long)st->st_size, sbuf);-
231 snprintf(buf, sizeof buf, "%s %3s %-*s %-*s %8s %s %s",-
232 mode, lc, ulen, user, glen, group,-
233 sbuf, tbuf, name);-
234 }
never executed: end of block
else {
0
235 snprintf(buf, sizeof buf, "%s %3s %-*s %-*s %8llu %s %s",-
236 mode, lc, ulen, user, glen, group,-
237 (unsigned long long)st->st_size, tbuf, name);-
238 }
never executed: end of block
0
239 return
never executed: return xstrdup(buf);
xstrdup(buf);
never executed: return xstrdup(buf);
0
240}-
Switch to Source codePreprocessed file

Generated by Squish Coco 4.2.2