示例#1
0
int spade_receivefile(const char *original_path, const char *original_ip, const char *local_path, const char *size, const char *mtime) {

	struct sock_info new_sock_info;
	get_sock_info(&new_sock_info);
	int client_socket = new_sock_info.client_socket;
	struct sockaddr_in client_addr = new_sock_info.client_addr;
	struct sockaddr_in server_addr = new_sock_info.server_addr;
	socklen_t server_addr_length = new_sock_info.server_addr_length;

	if(bind(client_socket, (struct sockaddr*)&client_addr, sizeof(client_addr))) {
		printf("Client bind port failed!\n");
		return 1;
	}

	if (connect(client_socket, (struct sockaddr*)&server_addr, server_addr_length) < 0) {
		printf("Cannot connect to %s\n", SERVER_IP);
		return 1;
	}

	char buffer[BUFFER_SIZE];
	char *oper = "receivefile";

	bzero(buffer, BUFFER_SIZE);
	strcpy(buffer, oper);
	send(client_socket, buffer, BUFFER_SIZE, 0);

	bzero(buffer, BUFFER_SIZE);
	strcpy(buffer, original_path);
	send(client_socket, buffer, BUFFER_SIZE, 0);

	bzero(buffer, BUFFER_SIZE);
	strcpy(buffer, original_ip);
	send(client_socket, buffer, BUFFER_SIZE, 0);

	bzero(buffer, BUFFER_SIZE);
	strcpy(buffer, local_path);
	send(client_socket, buffer, BUFFER_SIZE, 0);

	bzero(buffer, BUFFER_SIZE);
	strcpy(buffer, size);
	send(client_socket, buffer, BUFFER_SIZE, 0);

	bzero(buffer, BUFFER_SIZE);
	strcpy(buffer, mtime);
	send(client_socket, buffer, BUFFER_SIZE, 0);

	bzero(buffer, BUFFER_SIZE);
	int length = recv(client_socket, buffer, BUFFER_SIZE, 0);

	close(client_socket);

	return strlen(buffer);
}
示例#2
0
int spade_rename(const char *from, const char *to, pid_t pid, int link, int iotime) {

	struct sock_info new_sock_info;
	get_sock_info(&new_sock_info);
	int client_socket = new_sock_info.client_socket;
	struct sockaddr_in client_addr = new_sock_info.client_addr;
	struct sockaddr_in server_addr = new_sock_info.server_addr;
	socklen_t server_addr_length = new_sock_info.server_addr_length;

	printLog(new_sock_info);

	if(bind(client_socket, (struct sockaddr*)&client_addr, sizeof(client_addr))) {
		printf("Client bind port failed!\n");
		return 1;
	}

	if (connect(client_socket, (struct sockaddr*)&server_addr, server_addr_length) < 0) {
		printf("Cannot connect to %s\n", SERVER_IP);
		return 1;
	}

	char buffer[BUFFER_SIZE];
	char *oper = "rename";

	bzero(buffer, BUFFER_SIZE);
	strcpy(buffer, oper);
	send(client_socket, buffer, BUFFER_SIZE, 0);

	bzero(buffer, BUFFER_SIZE);
	strcpy(buffer, from);
	send(client_socket, buffer, BUFFER_SIZE, 0);

	bzero(buffer, BUFFER_SIZE);
	strcpy(buffer, to);
	send(client_socket, buffer, BUFFER_SIZE, 0);

	bzero(buffer, BUFFER_SIZE);
	int i_pid = (int) pid;
	sprintf(buffer, "%d", i_pid);
	send(client_socket, buffer, BUFFER_SIZE, 0);

	bzero(buffer, BUFFER_SIZE);
	sprintf(buffer, "%d", link);
	send(client_socket, buffer, BUFFER_SIZE, 0);

	bzero(buffer, BUFFER_SIZE);
	sprintf(buffer, "%d", iotime);
	send(client_socket, buffer, BUFFER_SIZE, 0);

	close(client_socket);

	return 0;
}
示例#3
0
ssize_t INTERPOSE(recvmsg)(int fd, struct msghdr *msg, int flags)
{
    __real_recvmsg_init();
    const bool bypass_filter =
        getenv("SIXJACK_BYPASS") != NULL || is_socket(fd) == false;        
    struct sockaddr_storage sa_local, *sa_local_ = &sa_local;
    socklen_t sa_local_len;
    get_sock_info(fd, &sa_local_, &sa_local_len, NULL, NULL);
    int ret = 0;
    int ret_errno = 0;    
    bool bypass_call = false;
    size_t nbyte = (size_t) 0U;
    struct iovec * const vecs = msg->msg_iov;
    size_t i_vecs = 0U;
    while (i_vecs < (size_t) msg->msg_iovlen) {
        assert(SIZE_MAX - nbyte >= vecs[i_vecs].iov_len);
        nbyte += vecs[i_vecs].iov_len;
        i_vecs++;
    }
    size_t new_nbyte = nbyte;
    FilterReplyResultBase rb = {
        .pre = true, .ret = &ret, .ret_errno = &ret_errno, .fd = fd
    };
    if (bypass_filter == false && (rb.filter = filter_get()) &&
        filter_apply(&rb, sa_local_, sa_local_len, msg,
                     &new_nbyte, &flags)
        == FILTER_REPLY_BYPASS) {
        bypass_call = true;
    }
    if (bypass_call == false) {
        ssize_t ret_ = __real_recvmsg(fd, msg, flags);
        ret_errno = errno;
        ret = (int) ret_;
        assert((ssize_t) ret_ == ret);
    }
    if (bypass_filter == false) {
        new_nbyte = ret;
        rb.pre = false;
        filter_apply(&rb, sa_local_, sa_local_len, msg,
                     &new_nbyte, &flags);
    }
    errno = ret_errno;
    
    return ret;
}
示例#4
0
int spade_sendfile(const char *source_path, const char *dist_path, const char *dist_ip) {

	struct sock_info new_sock_info;
	get_sock_info(&new_sock_info);
	int client_socket = new_sock_info.client_socket;
	struct sockaddr_in client_addr = new_sock_info.client_addr;
	struct sockaddr_in server_addr = new_sock_info.server_addr;
	socklen_t server_addr_length = new_sock_info.server_addr_length;

	if(bind(client_socket, (struct sockaddr*)&client_addr, sizeof(client_addr))) {
		printf("Client bind port failed!\n");
		return 1;
	}

	if (connect(client_socket, (struct sockaddr*)&server_addr, server_addr_length) < 0) {
		printf("Cannot connect to %s\n", SERVER_IP);
		return 1;
	}

	char buffer[BUFFER_SIZE];
	char *oper = "sendfile";

	bzero(buffer, BUFFER_SIZE);
	strcpy(buffer, oper);
	send(client_socket, buffer, BUFFER_SIZE, 0);

	bzero(buffer, BUFFER_SIZE);
	strcpy(buffer, source_path);
	send(client_socket, buffer, BUFFER_SIZE, 0);

	bzero(buffer, BUFFER_SIZE);
	strcpy(buffer, dist_path);
	send(client_socket, buffer, BUFFER_SIZE, 0);

	bzero(buffer, BUFFER_SIZE);
	strcpy(buffer, dist_ip);
	send(client_socket, buffer, BUFFER_SIZE, 0);

	close(client_socket);

	return 0;

}
示例#5
0
int spade_create(const char *path, pid_t pid) {

	struct sock_info new_sock_info;
	get_sock_info(&new_sock_info);
	int client_socket = new_sock_info.client_socket;
	struct sockaddr_in client_addr = new_sock_info.client_addr;
	struct sockaddr_in server_addr = new_sock_info.server_addr;
	socklen_t server_addr_length = new_sock_info.server_addr_length;

	if(bind(client_socket, (struct sockaddr*)&client_addr, sizeof(client_addr))) {
		printf("Client bind port failed!\n");
		return 1;
	}

	if (connect(client_socket, (struct sockaddr*)&server_addr, server_addr_length) < 0) {
		printf("Cannot connect to %s\n", SERVER_IP);
		return 1;
	}

	char buffer[BUFFER_SIZE];
	char *oper = "create";

	bzero(buffer, BUFFER_SIZE);
	strcpy(buffer, oper);
	send(client_socket, buffer, BUFFER_SIZE, 0);

	bzero(buffer, BUFFER_SIZE);
	strcpy(buffer, path);
	send(client_socket, buffer, BUFFER_SIZE, 0);

	bzero(buffer, BUFFER_SIZE);
	int i_pid = (int) pid;
	sprintf(buffer, "%d", i_pid);
	send(client_socket, buffer, BUFFER_SIZE, 0);

	bzero(buffer, BUFFER_SIZE);
	int length = recv(client_socket, buffer, BUFFER_SIZE, 0);
	close(client_socket);

	return strlen(buffer);
}
示例#6
0
ssize_t INTERPOSE(read)(int fd, void *buf, size_t nbyte)
{
    __real_read_init();
    const bool bypass_filter =
        getenv("SIXJACK_BYPASS") != NULL || is_socket(fd) == false;
    struct sockaddr_storage sa_local, *sa_local_ = &sa_local;
    struct sockaddr_storage sa_remote, *sa_remote_ = &sa_remote;
    socklen_t sa_local_len, sa_remote_len;
    get_sock_info(fd, &sa_local_, &sa_local_len, &sa_remote_, &sa_remote_len);
    int ret = 0;
    int ret_errno = 0;    
    bool bypass_call = false;
    size_t new_nbyte = nbyte;
    FilterReplyResultBase rb = {
        .pre = true, .ret = &ret, .ret_errno = &ret_errno, .fd = fd
    };    
    if (bypass_filter == false && (rb.filter = filter_get()) &&
        filter_apply(&rb, sa_local_, sa_local_len,
                     sa_remote_, sa_remote_len, NULL, &new_nbyte)
        == FILTER_REPLY_BYPASS) {
        bypass_call = true;
    }
    if (bypass_call == false) {
        ssize_t ret_ = __real_read(fd, buf, new_nbyte);
        ret_errno = errno;        
        ret = (int) ret_;
        assert((ssize_t) ret_ == ret);
    }
    if (bypass_filter == false) {
        rb.pre = false;
        filter_apply(&rb, sa_local_, sa_local_len,
                     sa_remote_, sa_remote_len, buf, &new_nbyte);
    }
    errno = ret_errno;
    
    return ret;
}