mirror of
https://github.com/upa/mscp.git
synced 2026-02-15 17:54:43 +08:00
add validate for path object and update manpage
This commit is contained in:
@@ -139,7 +139,7 @@ determined as an attack. The default value is 0.
|
|||||||
|
|
||||||
.TP
|
.TP
|
||||||
.B \-W \fICHECKPOINT\fR
|
.B \-W \fICHECKPOINT\fR
|
||||||
Specifies a checkpoint file path to save the state of a failed
|
Specifies a checkpoint file to save the state of a failed
|
||||||
transfer. When transferring fails due to, for example, connection
|
transfer. When transferring fails due to, for example, connection
|
||||||
disruption or user interrupt,
|
disruption or user interrupt,
|
||||||
.B mscp
|
.B mscp
|
||||||
@@ -153,7 +153,7 @@ option with
|
|||||||
|
|
||||||
.TP
|
.TP
|
||||||
.B \-R \fICHECKPOINT\fR
|
.B \-R \fICHECKPOINT\fR
|
||||||
Specifies a checkpoint file path to resume a transfer. When this
|
Specifies a checkpoint file to resume a transfer. When this
|
||||||
option with a checkpoint file is passed,
|
option with a checkpoint file is passed,
|
||||||
.B mscp
|
.B mscp
|
||||||
loads a remote host, copy direction, and files and their chunks to be
|
loads a remote host, copy direction, and files and their chunks to be
|
||||||
@@ -163,14 +163,12 @@ can resume a past failed transfer from the checkpoint. Resumeing with
|
|||||||
a checkpoint does not require
|
a checkpoint does not require
|
||||||
.I source ... target
|
.I source ... target
|
||||||
arguments. Other options for establishing SSH connections, for
|
arguments. Other options for establishing SSH connections, for
|
||||||
example, username, port number, config file, should be specified as
|
example, login_name, port number, config file, should be specified as
|
||||||
with the failed run. In addition, checkpoint files contain files as
|
with the failed run. In addition, checkpoint files contain files as
|
||||||
relative paths. Thus, you must run
|
relative paths. Thus, you must run
|
||||||
.B mscp
|
.B mscp
|
||||||
in the same working directory as the failed run.
|
in the same working directory as the failed run. You can see contents
|
||||||
|
of a checkpoint file with
|
||||||
|
|
||||||
You can see contents of a checkpoint file with
|
|
||||||
.B mscp
|
.B mscp
|
||||||
.I \-vvv \-D \-R CHECKOPOINT
|
.I \-vvv \-D \-R CHECKOPOINT
|
||||||
command.
|
command.
|
||||||
|
|||||||
33
doc/mscp.rst
33
doc/mscp.rst
@@ -2,7 +2,7 @@
|
|||||||
MSCP
|
MSCP
|
||||||
====
|
====
|
||||||
|
|
||||||
:Date: v0.1.4-19-g5f628b6
|
:Date: v0.1.4-20-g19c73af
|
||||||
|
|
||||||
NAME
|
NAME
|
||||||
====
|
====
|
||||||
@@ -71,27 +71,24 @@ OPTIONS
|
|||||||
determined as an attack. The default value is 0.
|
determined as an attack. The default value is 0.
|
||||||
|
|
||||||
**-W CHECKPOINT**
|
**-W CHECKPOINT**
|
||||||
Specifies a checkpoint file path to save the state of a failed
|
Specifies a checkpoint file to save the state of a failed transfer.
|
||||||
transfer. When transferring fails due to, for example, connection
|
When transferring fails due to, for example, connection disruption or
|
||||||
disruption or user interrupt, **mscp** writes the information about
|
user interrupt, **mscp** writes the information about remaining files
|
||||||
remaining files and chunks to the specified checkpoint file. **-W**
|
and chunks to the specified checkpoint file. **-W** option with
|
||||||
option with **-D** (dry-run mode) only writes a checkpoint file and
|
**-D** (dry-run mode) only writes a checkpoint file and exits.
|
||||||
exits.
|
|
||||||
|
|
||||||
**-R CHECKPOINT**
|
**-R CHECKPOINT**
|
||||||
Specifies a checkpoint file path to resume a transfer. When this
|
Specifies a checkpoint file to resume a transfer. When this option
|
||||||
option with a checkpoint file is passed, **mscp** loads a remote
|
with a checkpoint file is passed, **mscp** loads a remote host, copy
|
||||||
host, copy direction, and files and their chunks to be transferred
|
direction, and files and their chunks to be transferred from the
|
||||||
from the checkpoint file. Namely, **mscp** can resume a past failed
|
checkpoint file. Namely, **mscp** can resume a past failed transfer
|
||||||
transfer from the checkpoint. Resumeing with a checkpoint does not
|
from the checkpoint. Resumeing with a checkpoint does not require
|
||||||
require *source ... target* arguments. Other options for establishing
|
*source ... target* arguments. Other options for establishing SSH
|
||||||
SSH connections, for example, username, port number, config file,
|
connections, for example, login_name, port number, config file,
|
||||||
should be specified as with the failed run. In addition, checkpoint
|
should be specified as with the failed run. In addition, checkpoint
|
||||||
files contain files as relative paths. Thus, you must run **mscp** in
|
files contain files as relative paths. Thus, you must run **mscp** in
|
||||||
the same working directory as the failed run.
|
the same working directory as the failed run. You can see contents of
|
||||||
|
a checkpoint file with **mscp** *-vvv -D -R CHECKOPOINT* command.
|
||||||
You can see contents of a checkpoint file with **mscp** *-vvv -D -R
|
|
||||||
CHECKOPOINT* command.
|
|
||||||
|
|
||||||
**-s MIN_CHUNK_SIZE**
|
**-s MIN_CHUNK_SIZE**
|
||||||
Specifies the minimum chunk size. **mscp** divides a file into chunks
|
Specifies the minimum chunk size. **mscp** divides a file into chunks
|
||||||
|
|||||||
@@ -11,6 +11,10 @@
|
|||||||
|
|
||||||
#include <checkpoint.h>
|
#include <checkpoint.h>
|
||||||
|
|
||||||
|
#define MSCP_CHECKPOINT_MAGIC 0x6d736370UL /* mscp in UTF-8 */
|
||||||
|
#define MSCP_CHECKPOINT_VERSION 0x1
|
||||||
|
|
||||||
|
|
||||||
enum {
|
enum {
|
||||||
OBJ_TYPE_META = 0x0A,
|
OBJ_TYPE_META = 0x0A,
|
||||||
OBJ_TYPE_PATH = 0x0B,
|
OBJ_TYPE_PATH = 0x0B,
|
||||||
@@ -23,8 +27,6 @@ struct checkpoint_obj_hdr {
|
|||||||
uint16_t len; /* length of an object including this hdr */
|
uint16_t len; /* length of an object including this hdr */
|
||||||
} __attribute__((packed));
|
} __attribute__((packed));
|
||||||
|
|
||||||
#define MSCP_CHECKPOINT_MAGIC 0x6d736370UL /* mscp in UTF-8 */
|
|
||||||
#define MSCP_CHECKPOINT_VERSION 0x1
|
|
||||||
|
|
||||||
struct checkpoint_obj_meta {
|
struct checkpoint_obj_meta {
|
||||||
struct checkpoint_obj_hdr hdr;
|
struct checkpoint_obj_hdr hdr;
|
||||||
@@ -41,17 +43,24 @@ struct checkpoint_obj_path {
|
|||||||
struct checkpoint_obj_hdr hdr;
|
struct checkpoint_obj_hdr hdr;
|
||||||
|
|
||||||
uint32_t idx;
|
uint32_t idx;
|
||||||
uint16_t src_off; /* offset to the src path
|
uint16_t src_off; /* offset to the src path string (including
|
||||||
* string (including \0) from
|
* \0) from the head of this object. */
|
||||||
* the head of this object. */
|
uint16_t dst_off; /* offset to the dst path string (including
|
||||||
|
* \0) from the head of this object */
|
||||||
uint16_t dst_off; /* offset to the dst path
|
|
||||||
* string (including \0) from
|
|
||||||
* the head of this object */
|
|
||||||
} __attribute__((packed));
|
} __attribute__((packed));
|
||||||
|
|
||||||
#define obj_path_src(obj) ((char *)(obj) + ntohs(obj->src_off))
|
#define obj_path_src(o) ((char *)(o) + ntohs(o->src_off))
|
||||||
#define obj_path_dst(obj) ((char *)(obj) + ntohs(obj->dst_off))
|
#define obj_path_dst(o) ((char *)(o) + ntohs(o->dst_off))
|
||||||
|
|
||||||
|
#define obj_path_src_len(o) (ntohs(o->dst_off) - ntohs(o->src_off))
|
||||||
|
#define obj_path_dst_len(o) (ntohs(o->hdr.len) - ntohs(o->dst_off))
|
||||||
|
|
||||||
|
#define obj_path_validate(o) \
|
||||||
|
((ntohs(o->hdr.len) > ntohs(o->dst_off)) && \
|
||||||
|
(ntohs(o->dst_off) > ntohs(o->src_off)) && \
|
||||||
|
(obj_path_src_len(o) < PATH_MAX) && \
|
||||||
|
(obj_path_dst_len(o) < PATH_MAX)) \
|
||||||
|
|
||||||
|
|
||||||
struct checkpoint_obj_chunk {
|
struct checkpoint_obj_chunk {
|
||||||
struct checkpoint_obj_hdr hdr;
|
struct checkpoint_obj_hdr hdr;
|
||||||
@@ -213,12 +222,17 @@ static int checkpoint_load_path(struct checkpoint_obj_hdr *hdr, pool *path_pool)
|
|||||||
struct path *p;
|
struct path *p;
|
||||||
char *s, *d;
|
char *s, *d;
|
||||||
|
|
||||||
if (!(s = strdup(obj_path_src(path)))) {
|
if (!obj_path_validate(path)) {
|
||||||
|
priv_set_errv("invalid path object");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!(s = strndup(obj_path_src(path), obj_path_src_len(path)))) {
|
||||||
priv_set_errv("strdup: %s", strerrno());
|
priv_set_errv("strdup: %s", strerrno());
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!(d = strdup(obj_path_dst(path)))) {
|
if (!(d = strndup(obj_path_dst(path), obj_path_dst_len(path)))) {
|
||||||
priv_set_errv("strdup: %s", strerrno());
|
priv_set_errv("strdup: %s", strerrno());
|
||||||
free(s);
|
free(s);
|
||||||
return -1;
|
return -1;
|
||||||
@@ -235,7 +249,7 @@ static int checkpoint_load_path(struct checkpoint_obj_hdr *hdr, pool *path_pool)
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
pr_info("checkpoint:path: %s -> %s", p->path, p->dst_path);
|
pr_info("checkpoint:file: %s -> %s", p->path, p->dst_path);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user