Пример #1
0
bool
process_path(const std::string& path_actual,
	     const std::string& path_output,
	     std::ostream& os)
{
  struct stat s;
  if (lstat(path_actual.c_str(), &s) < 0) {
    std::cerr << progname
	      << ": error: " << strerror(errno)
	      << ": " << path_actual << std::endl;
    return false;
  }


  if (S_ISREG(s.st_mode)) {
    if (! process_file(path_actual, path_output, &s, os)) {
      return false;
    }

  } else if (S_ISDIR(s.st_mode)) {
    if (! process_dir(path_actual, path_output, os)) {
      return false;
    }

  } else if (S_ISLNK(s.st_mode)) {
    if (! process_symlink(path_actual, path_output, os)) {
      return false;
    }

  } else {
    std::cerr << progname
	      << ": error: unexpected file type: " << path_actual
	      << " (" << (s.st_mode & S_IFMT) << ")" << std::endl;
    return false;
  }

  // S_ISCHR character device
  // S_ISBLK block device
  // S_ISFIFO
  // S_ISSOCK

  if (! os) {
    std::cerr << progname
	      << ": error: write error" << std::endl;
    return false;
  }

  return true;
}
static void
process(void)
{
	u_int msg_len;
	u_int buf_len;
	u_int consumed;
	u_int type;
	u_char *cp;

	buf_len = buffer_len(&iqueue);
	if (buf_len < 5)
		return;		/* Incomplete message. */
	cp = buffer_ptr(&iqueue);
	msg_len = GET_32BIT(cp);
	if (msg_len > 256 * 1024) {
		error("bad message ");
		exit(11);
	}
	if (buf_len < msg_len + 4)
		return;
	buffer_consume(&iqueue, 4);
	buf_len -= 4;
	type = buffer_get_char(&iqueue);
	switch (type) {
	case SSH2_FXP_INIT:
		process_init();
		break;
	case SSH2_FXP_OPEN:
		process_open();
		break;
	case SSH2_FXP_CLOSE:
		process_close();
		break;
	case SSH2_FXP_READ:
		process_read();
		break;
	case SSH2_FXP_WRITE:
		process_write();
		break;
	case SSH2_FXP_LSTAT:
		process_lstat();
		break;
	case SSH2_FXP_FSTAT:
		process_fstat();
		break;
	case SSH2_FXP_SETSTAT:
		process_setstat();
		break;
	case SSH2_FXP_FSETSTAT:
		process_fsetstat();
		break;
	case SSH2_FXP_OPENDIR:
		process_opendir();
		break;
	case SSH2_FXP_READDIR:
		process_readdir();
		break;
	case SSH2_FXP_REMOVE:
		process_remove();
		break;
	case SSH2_FXP_MKDIR:
		process_mkdir();
		break;
	case SSH2_FXP_RMDIR:
		process_rmdir();
		break;
	case SSH2_FXP_REALPATH:
		process_realpath();
		break;
	case SSH2_FXP_STAT:
		process_stat();
		break;
	case SSH2_FXP_RENAME:
		process_rename();
		break;
	case SSH2_FXP_READLINK:
		process_readlink();
		break;
	case SSH2_FXP_SYMLINK:
		process_symlink();
		break;
	case SSH2_FXP_EXTENDED:
		process_extended();
		break;
	default:
		error("Unknown message %d", type);
		break;
	}
	/* discard the remaining bytes from the current packet */
	if (buf_len < buffer_len(&iqueue))
		fatal("iqueue grows");
	consumed = buf_len - buffer_len(&iqueue);
	if (msg_len < consumed)
		fatal("msg_len %d < consumed %d", msg_len, consumed);
	if (msg_len > consumed)
		buffer_consume(&iqueue, msg_len - consumed);
}
static void
process(void)
{
	u_int msg_len;
	u_int buf_len;
	u_int consumed;
	u_int type;
	u_char *cp;

	buf_len = buffer_len(&iqueue);
	if (buf_len < 5)
		return;		/* Incomplete message. */
	cp = buffer_ptr(&iqueue);
	msg_len = get_u32(cp);
	if (msg_len > SFTP_MAX_MSG_LENGTH) {
		error("bad message from %s local user %s",
		    client_addr, pw->pw_name);
		sftp_server_cleanup_exit(11);
	}
	if (buf_len < msg_len + 4)
		return;
	buffer_consume(&iqueue, 4);
	buf_len -= 4;
	type = buffer_get_char(&iqueue);
	switch (type) {
	case SSH2_FXP_INIT:
		process_init();
		break;
	case SSH2_FXP_OPEN:
		process_open();
		break;
	case SSH2_FXP_CLOSE:
		process_close();
		break;
	case SSH2_FXP_READ:
		process_read();
		break;
	case SSH2_FXP_WRITE:
		process_write();
		break;
	case SSH2_FXP_LSTAT:
		process_lstat();
		break;
	case SSH2_FXP_FSTAT:
		process_fstat();
		break;
	case SSH2_FXP_SETSTAT:
		process_setstat();
		break;
	case SSH2_FXP_FSETSTAT:
		process_fsetstat();
		break;
	case SSH2_FXP_OPENDIR:
		process_opendir();
		break;
	case SSH2_FXP_READDIR:
		process_readdir();
		break;
	case SSH2_FXP_REMOVE:
		process_remove();
		break;
	case SSH2_FXP_MKDIR:
		process_mkdir();
		break;
	case SSH2_FXP_RMDIR:
		process_rmdir();
		break;
	case SSH2_FXP_REALPATH:
		process_realpath();
		break;
	case SSH2_FXP_STAT:
		process_stat();
		break;
	case SSH2_FXP_RENAME:
		process_rename();
		break;
	case SSH2_FXP_READLINK:
		process_readlink();
		break;
	case SSH2_FXP_SYMLINK:
		process_symlink();
		break;
	case SSH2_FXP_EXTENDED:
		process_extended();
		break;
	default:
		error("Unknown message %d", type);
		break;
	}
	/* discard the remaining bytes from the current packet */
	if (buf_len < buffer_len(&iqueue)) {
		error("iqueue grew unexpectedly");
		sftp_server_cleanup_exit(255);
	}
	consumed = buf_len - buffer_len(&iqueue);
	if (msg_len < consumed) {
		error("msg_len %d < consumed %d", msg_len, consumed);
		sftp_server_cleanup_exit(255);
	}
	if (msg_len > consumed)
		buffer_consume(&iqueue, msg_len - consumed);
}
Пример #4
0
void SFTP::process(void)
{
  const u_int msg_len = buffer_get_int (&iqueue);
	const u_int type = buffer_get_char(&iqueue);
	switch (type) {
	case SSH2_FXP_INIT:
		process_init();
		break;
	case SSH2_FXP_OPEN:
		process_open();
		break;
	case SSH2_FXP_CLOSE:
		process_close();
		break;
	case SSH2_FXP_READ:
		process_read();
		break;
	case SSH2_FXP_WRITE:
		process_write();
		break;
	case SSH2_FXP_LSTAT:
		process_lstat();
		break;
	case SSH2_FXP_FSTAT:
		process_fstat();
		break;
	case SSH2_FXP_SETSTAT:
		process_setstat();
		break;
	case SSH2_FXP_FSETSTAT:
		process_fsetstat();
		break;
	case SSH2_FXP_OPENDIR:
		process_opendir();
		break;
	case SSH2_FXP_READDIR:
		process_readdir();
		break;
	case SSH2_FXP_REMOVE:
		process_remove();
		break;
	case SSH2_FXP_MKDIR:
		process_mkdir();
		break;
	case SSH2_FXP_RMDIR:
		process_rmdir();
		break;
	case SSH2_FXP_REALPATH:
		process_realpath();
		break;
	case SSH2_FXP_STAT:
		process_stat();
		break;
	case SSH2_FXP_RENAME:
		process_rename();
		break;
	case SSH2_FXP_READLINK:
		process_readlink();
		break;
	case SSH2_FXP_SYMLINK:
		process_symlink();
		break;
	case SSH2_FXP_EXTENDED:
		process_extended();
		break;
	default:
		error("Unknown message %d", type);
		break;
	}

  /* discard the remaining bytes from the current packet */
	
  if (msg_len < buffer_len(&iqueue)) {
		error("iqueue grew unexpectedly");
		sftp_server_cleanup_exit(255);
	}
	u_int consumed = msg_len - buffer_len(&iqueue);
	if (msg_len < consumed) {
		error("msg_len %d < consumed %d", msg_len, consumed);
		sftp_server_cleanup_exit(255);
	}
	if (msg_len > consumed)
		buffer_consume(&iqueue, msg_len - consumed);
}
Пример #5
0
int
process_entry (const char *path, const struct stat *sb,
               int typeflag, struct FTW *ftwbuf)
{
        int ret = 0;
        char *name = NULL;
        char *bname = NULL;
        char *dname = NULL;
        int  i = 0;

        /* The if condition below helps in ignoring some directories in
           the given path. If the name of the entry is one of the directory
           names that the user told to ignore, then that directory will not
           be processed and will return FTW_SKIP_SUBTREE to nftw which will
           not crawl this directory and move on to other siblings.
           Note that for nftw to recognize FTW_SKIP_TREE, FTW_ACTIONRETVAL
           should be passed as an argument to nftw.

           This mainly helps in calculating the checksum of network filesystems
           (client-server), where the server might have some hidden directories
           for managing the filesystem. So to calculate the sanity of filesytem
           one has to get the checksum of the client and then the export directory
           of server by telling arequal to ignore some of the directories which
           are not part of the namespace.
        */

        if (arequal_config.ignored_directory) {
#ifndef FTW_SKIP_SUBTREE
                char *cp;

                name = strdup (path);
                dname = dirname (name);

                for (cp = strtok(name, "/"); cp; cp = strtok(NULL, "/")) {
                        if (ignore_entry(cp, dname)) {
                                DBG ("ignoring %s\n", path);
                                if (name)
                                        free (name);
                                return 0;
                        }
                }
#else /* FTW_SKIP_SUBTREE */
                name = strdup (path);

                name[strlen(name)] = '\0';

                bname = strrchr (name, '/');
                if (bname)
                        bname++;

                dname = dirname (name);
                if (ignore_entry(bname, dname)) {
                                DBG ("ignoring %s\n", bname);
                                ret = FTW_SKIP_SUBTREE;
                                if (name)
                                        free (name);
                                return ret;
                }
#endif /* FTW_SKIP_SUBTREE */
        }

        DBG ("processing entry %s\n", path);

        switch ((S_IFMT & sb->st_mode)) {
        case S_IFDIR:
                ret = process_dir (path, sb);
                break;
        case S_IFREG:
                ret = process_file (path, sb);
                break;
        case S_IFLNK:
                ret = process_symlink (path, sb);
                break;
        default:
                ret = process_other (path, sb);
                break;
        }

        if (name)
                free (name);
        return ret;
}