version 1.41, 2017/01/06 13:26:09 |
version 1.42, 2017/02/14 18:13:05 |
|
|
{ |
{ |
struct args *args = self->args; |
struct args *args = self->args; |
struct client *c = item->client; |
struct client *c = item->client; |
struct session *s; |
|
struct paste_buffer *pb; |
struct paste_buffer *pb; |
const char *path, *bufname, *bufdata, *start, *end, *cwd; |
const char *path, *bufname, *bufdata, *start, *end; |
const char *flags; |
const char *flags; |
char *msg, *file, resolved[PATH_MAX]; |
char *msg, *file; |
size_t size, used, msglen, bufsize; |
size_t size, used, msglen, bufsize; |
FILE *f; |
FILE *f; |
|
|
|
|
goto do_print; |
goto do_print; |
} |
} |
|
|
if (c != NULL && c->session == NULL && c->cwd != NULL) |
|
cwd = c->cwd; |
|
else if (c != NULL && (s = c->session) != NULL && s->cwd != NULL) |
|
cwd = s->cwd; |
|
else |
|
cwd = "."; |
|
|
|
flags = "wb"; |
flags = "wb"; |
if (args_has(self->args, 'a')) |
if (args_has(self->args, 'a')) |
flags = "ab"; |
flags = "ab"; |
|
|
if (*path == '/') |
file = server_client_get_path(c, path); |
file = xstrdup(path); |
f = fopen(file, flags); |
else |
|
xasprintf(&file, "%s/%s", cwd, path); |
|
if (realpath(file, resolved) == NULL && |
|
strlcpy(resolved, file, sizeof resolved) >= sizeof resolved) { |
|
cmdq_error(item, "%s: %s", file, strerror(ENAMETOOLONG)); |
|
return (CMD_RETURN_ERROR); |
|
} |
|
f = fopen(resolved, flags); |
|
free(file); |
|
if (f == NULL) { |
if (f == NULL) { |
cmdq_error(item, "%s: %s", resolved, strerror(errno)); |
cmdq_error(item, "%s: %s", file, strerror(errno)); |
|
free(file); |
return (CMD_RETURN_ERROR); |
return (CMD_RETURN_ERROR); |
} |
} |
|
|
if (fwrite(bufdata, 1, bufsize, f) != bufsize) { |
if (fwrite(bufdata, 1, bufsize, f) != bufsize) { |
cmdq_error(item, "%s: write error", resolved); |
cmdq_error(item, "%s: write error", file); |
fclose(f); |
fclose(f); |
return (CMD_RETURN_ERROR); |
return (CMD_RETURN_ERROR); |
} |
} |
|
|
fclose(f); |
fclose(f); |
|
free(file); |
|
|
return (CMD_RETURN_NORMAL); |
return (CMD_RETURN_NORMAL); |
|
|