summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRyo Nakamura <upa@haeena.net>2024-02-20 16:14:26 +0900
committerRyo Nakamura <upa@haeena.net>2024-02-20 16:14:26 +0900
commitfc0ced1828f6da5e6664223c660b47f295e459e2 (patch)
tree2176c77a6b43c8cdb0bd403ae48e2cf89135edec
parent0695c1e2e4b417763942c6311033b29922b9c778 (diff)
checkpoint includes username
-rw-r--r--src/checkpoint.c22
-rw-r--r--src/checkpoint.h4
-rw-r--r--src/mscp.c4
3 files changed, 20 insertions, 10 deletions
diff --git a/src/checkpoint.c b/src/checkpoint.c
index ee75c78..8450cbc 100644
--- a/src/checkpoint.c
+++ b/src/checkpoint.c
@@ -126,16 +126,17 @@ static int checkpoint_write_chunk(int fd, struct chunk *c)
return 0;
}
-int checkpoint_save(const char *pathname, int dir, char *remote, pool *path_pool,
- pool *chunk_pool)
+int checkpoint_save(const char *pathname, int dir, const char *user, const char *remote,
+ pool *path_pool, pool *chunk_pool)
{
struct checkpoint_file_hdr hdr;
struct checkpoint_obj_meta meta;
struct iovec iov[3];
struct chunk *c;
struct path *p;
+ char buf[1024];
unsigned int i, nr_paths, nr_chunks;
- int fd;
+ int fd, ret;
fd = open(pathname, O_WRONLY | O_CREAT | O_TRUNC,
S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH);
@@ -149,17 +150,26 @@ int checkpoint_save(const char *pathname, int dir, char *remote, pool *path_pool
hdr.version = MSCP_CHECKPOINT_VERSION;
/* write meta */
+ if (user)
+ ret = snprintf(buf, sizeof(buf), "%s@%s", user, remote);
+ else
+ ret = snprintf(buf, sizeof(buf), "%s", remote);
+ if (ret >= sizeof(buf)) {
+ priv_set_errv("too long username and/or remote");
+ return -1;
+ }
+
memset(&meta, 0, sizeof(meta));
meta.hdr.type = OBJ_TYPE_META;
- meta.hdr.len = htons(sizeof(meta) + strlen(remote) + 1);
+ meta.hdr.len = htons(sizeof(meta) + strlen(buf) + 1);
meta.direction = dir;
iov[0].iov_base = &hdr;
iov[0].iov_len = sizeof(hdr);
iov[1].iov_base = &meta;
iov[1].iov_len = sizeof(meta);
- iov[2].iov_base = remote;
- iov[2].iov_len = strlen(remote) + 1;
+ iov[2].iov_base = buf;
+ iov[2].iov_len = strlen(buf) + 1;
if (writev(fd, iov, 3) < 0) {
priv_set_errv("writev: %s", strerrno());
diff --git a/src/checkpoint.h b/src/checkpoint.h
index d0d0948..c20dad1 100644
--- a/src/checkpoint.h
+++ b/src/checkpoint.h
@@ -4,8 +4,8 @@
#include <pool.h>
/* checkpoint_save() stores states to a checkponint file (pathname) */
-int checkpoint_save(const char *pathname, int dir, char *remote_host, pool *path_pool,
- pool *chunk_pool);
+int checkpoint_save(const char *pathname, int dir, const char *user, const char *remote,
+ pool *path_pool, pool *chunk_pool);
/* checkpoint_load_meta() reads a checkpoint file (pathname) and returns
* remote host string to *remote and transfer direction to *dir.
diff --git a/src/mscp.c b/src/mscp.c
index 0937c97..34dd8db 100644
--- a/src/mscp.c
+++ b/src/mscp.c
@@ -522,8 +522,8 @@ int mscp_checkpoint_load(struct mscp *m, const char *pathname)
int mscp_checkpoint_save(struct mscp *m, const char *pathname)
{
- return checkpoint_save(pathname, m->direction, m->remote, m->path_pool,
- m->chunk_pool);
+ return checkpoint_save(pathname, m->direction, m->ssh_opts->login_name,
+ m->remote, m->path_pool, m->chunk_pool);
}
static void *mscp_copy_thread(void *arg);