Ejemplo n.º 1
0
static int ggnfs_getattr(const char *path, struct stat *stbuf)
{
 
    int res = 0;
    char filePath[PATH_MAX];
    strcpy(filePath, remotePath);
    strcat(filePath,"/");
    strcat(filePath,path);

    sftp_dir dir;
    sftp_attributes attributes;
    attributes = sftp_lstat(ggnfs_data.sftp, filePath); 
    
    if (attributes != NULL) 
    {
        res = 1;
        // setting struct stat
	memset(stbuf, 0, sizeof(struct stat));

        stbuf->st_uid   = attributes->uid; 
        stbuf->st_gid   = attributes->gid;
        stbuf->st_atime = attributes->atime;
        stbuf->st_ctime = attributes->createtime;
        stbuf->st_mtime = attributes->mtime;
        stbuf->st_size  = attributes->size;
        stbuf->st_mode  = attributes->permissions;

        sftp_attributes_free(attributes);
	res = SSH_OK;
     }
    return EXIT_SUCCESS;    

}
Ejemplo n.º 2
0
int FSSftp::Stat  ( FSPath& path, FSStat* st, int* err, FSCInfo* info )
{
	MutexLock lock( &mutex );
	int ret = CheckSession( err, info );

	if ( ret ) { return ret; }

	char* fullPath = ( char* ) path.GetString( _operParam.charset );

	sftp_attributes la = sftp_lstat( sftpSession, fullPath );

	if ( !la )
	{
		if ( err ) { *err = sftp_get_error( sftpSession ); }

		return -1;
	}

	if ( la->type == SSH_FILEXFER_TYPE_SYMLINK )
	{
		char* s = sftp_readlink( sftpSession, fullPath );

		if ( s ) { st->link.Set( _operParam.charset, s ); }

		sftp_attributes_free( la ); //!!!
	}
	else
	{
		st->mode  = la->permissions;
		st->size  = la->size;
		st->uid   = la->uid;
		st->gid   = la->gid;
		st->mtime = la->mtime;

		sftp_attributes_free( la ); //!!!

		return 0;
	}

	sftp_attributes a = sftp_stat( sftpSession, fullPath );

	if ( !a )
	{
		if ( err ) { *err = sftp_get_error( sftpSession ); }

		return -1;
	}

	st->mode  = la->permissions;
	st->size  = la->size;
	st->uid   = la->uid;
	st->gid   = la->gid;
	st->mtime = la->mtime;

	sftp_attributes_free( a ); //!!!

	return 0;
}
Ejemplo n.º 3
0
static int xmp_getattr(const char *path, struct stat *stbuf)
{
	umask(0);
        int res = 0;
	//sftp_session sftp = create_sftp_session();

	/*perror("Inside getattr");
        sftp_session sftp = sftp_new(con.my_ssh_session);
        if (sftp == NULL)
            {
                fprintf(stderr, "Error allocating SFTP session: %s\n",
                ssh_get_error(con.my_ssh_session));
                return SSH_ERROR;
             }
        perror("sftp established");

        int rc = sftp_init(sftp);
        perror("after init");
        if (rc != SSH_OK)
        {
                fprintf(stderr, "Error initializing SFTP session: %s.\n",
                sftp_get_error(sftp));
                sftp_free(sftp);
                return rc;
        }*/

        fprintf(stderr,"path %s \n", path);
        
        sftp_attributes attr = sftp_lstat(con.sftp, path);
        perror("after lstat");
        if( attr !=NULL){
                fprintf(stderr, "attr size %d", sizeof(attr));
                memset(stbuf, 0, sizeof(struct stat));
                perror("after stbuf memset");
                stbuf->st_uid = attr->uid;
                stbuf->st_gid = attr->gid;
                stbuf->st_atime = attr->atime;
                stbuf->st_ctime = attr->createtime;
                stbuf->st_mtime = attr->mtime;
                stbuf->st_size = attr->size;
                stbuf->st_mode = attr->permissions;
                perror("after assignment to stbuf");
                fprintf(stderr, "stbuf size %d", sizeof(stbuf));
                perror("after stbuf initialization");
                res = SSH_OK;
        } else{
                res = SSH_ERROR;
        }

	//sftp_free(sftp);
	return res;
/*	int res;
	res = lstat(path, stbuf);
	if (res == -1)
		return -errno;
*/
}
Ejemplo n.º 4
0
int FSSftp::OpenCreate  ( FSPath& path, bool overwrite, int mode, int* err, FSCInfo* info )
{
	MutexLock lock( &mutex );
	int ret = CheckSession( err, info );

	if ( ret ) { return ret; }

	if ( !overwrite )
	{
		/*
		   заебался выяснять почему sftp_open  с  O_EXCL выдает "generc error" при наличии файла, а не EEXIST какой нибудь
		   поэтому встанил эту дурацкую проверку на наличие
		*/
		sftp_attributes a = sftp_lstat( sftpSession, ( char* ) path.GetString( _operParam.charset, '/' ) );

		if ( a )
		{
			sftp_attributes_free( a ); //!!!

			if ( err ) { *err = SSH_FX_FILE_ALREADY_EXISTS; }

			return -1;
		}
	}


	int n = 0;

	for ( ; n < MAX_FILES; n++ )
		if ( !fileTable[n] ) { break; }

	if ( n >= MAX_FILES )
	{
		if ( err ) { *err = SSH_INTERROR_OUTOF; }

		return -1;
	}

	sftp_file f = sftp_open( sftpSession, ( char* ) path.GetString( _operParam.charset, '/' ),
	                         O_CREAT | O_WRONLY | ( overwrite ? O_TRUNC : O_EXCL ),
	                         mode );

	if ( !f )
	{
//printf("ssh-err:'%s'\n",ssh_get_error(sshSession));
		if ( err ) { *err = sftp_get_error( sftpSession ); }

		return -1;
	}

	fileTable[n] = f;

	return n;
}
Ejemplo n.º 5
0
static int _sftp_stat(const char *uri, csync_vio_file_stat_t *buf) {
  sftp_attributes attrs;
  char *path = NULL;
  int rc = -1;

  if (_sftp_connect(uri) < 0) {
    return -1;
  }

  if (c_parse_uri(uri, NULL, NULL, NULL, NULL, NULL, &path) < 0) {
    return -1;
  }

  attrs = sftp_lstat(_sftp_session, path);
  if (attrs == NULL) {
    rc = -1;
    goto out;
  }

  buf->name = c_basename(path);
  if (buf->name == NULL) {
    csync_vio_file_stat_destroy(buf);
    goto out;
  }
  buf->fields = CSYNC_VIO_FILE_STAT_FIELDS_NONE;

  switch (attrs->type) {
    case SSH_FILEXFER_TYPE_REGULAR:
      buf->type = CSYNC_VIO_FILE_TYPE_REGULAR;
      break;
    case SSH_FILEXFER_TYPE_DIRECTORY:
      buf->type = CSYNC_VIO_FILE_TYPE_DIRECTORY;
      break;
    case SSH_FILEXFER_TYPE_SYMLINK:
      buf->type = CSYNC_VIO_FILE_TYPE_SYMBOLIC_LINK;
      break;
    case SSH_FILEXFER_TYPE_SPECIAL:
    case SSH_FILEXFER_TYPE_UNKNOWN:
      buf->type = CSYNC_VIO_FILE_TYPE_UNKNOWN;
      break;
  }
  buf->fields |= CSYNC_VIO_FILE_STAT_FIELDS_TYPE;

  buf->mode = attrs->permissions;
  buf->fields |= CSYNC_VIO_FILE_STAT_FIELDS_PERMISSIONS;

  if (buf->type == CSYNC_VIO_FILE_TYPE_SYMBOLIC_LINK) {
    /* FIXME: handle symlink */
    buf->flags = CSYNC_VIO_FILE_FLAGS_SYMLINK;
  } else {
    buf->flags = CSYNC_VIO_FILE_FLAGS_NONE;
  }
  buf->fields |= CSYNC_VIO_FILE_STAT_FIELDS_FLAGS;

  buf->uid = attrs->uid;
  buf->fields |= CSYNC_VIO_FILE_STAT_FIELDS_UID;

  buf->uid = attrs->gid;
  buf->fields |= CSYNC_VIO_FILE_STAT_FIELDS_GID;

  buf->size = attrs->size;
  buf->fields |= CSYNC_VIO_FILE_STAT_FIELDS_SIZE;

  buf->atime = attrs->atime;
  buf->fields |= CSYNC_VIO_FILE_STAT_FIELDS_ATIME;

  buf->mtime = attrs->mtime;
  buf->fields |= CSYNC_VIO_FILE_STAT_FIELDS_MTIME;

  buf->ctime = attrs->createtime;
  buf->fields |= CSYNC_VIO_FILE_STAT_FIELDS_CTIME;

  rc = 0;
out:
  if (rc < 0) {
    errno = _sftp_portable_to_errno(sftp_get_error(_sftp_session));
  }
  SAFE_FREE(path);
  sftp_attributes_free(attrs);

  return rc;
}