예제 #1
0
파일: testchmod.c 프로젝트: ElijahLuk/samba
int main(int argc, char * argv[])
{
    int             ret;
    int             debug = 0;
    int             mode = 0666;
    char            buffer[16384];
    char *          pSmbPath = NULL;
    struct stat     st;

    if (argc == 1)
    {
        pSmbPath = "smb://RANDOM/Public/small";
    }
    else if (argc == 2)
    {
        pSmbPath = argv[1];
    }
    else if (argc == 3)
    {
        pSmbPath = argv[1];
        mode = (int) strtol(argv[2], NULL, 8);
    }
    else
    {
        printf("usage: "
               "%s [ smb://path/to/file [ octal_mode ] ]\n",
               argv[0]);
        return 1;
    }

    smbc_init(get_auth_data_fn, debug);

    if (smbc_stat(pSmbPath, &st) < 0)
    {
        perror("smbc_stat");
        return 1;
    }

    printf("\nBefore chmod: mode = %04o\n", st.st_mode);

    if (smbc_chmod(pSmbPath, mode) < 0)
    {
        perror("smbc_chmod");
        return 1;
    }

    if (smbc_stat(pSmbPath, &st) < 0)
    {
        perror("smbc_stat");
        return 1;
    }

    printf("After chmod: mode = %04o\n", st.st_mode);

    return 0;
}
예제 #2
0
파일: teststat3.c 프로젝트: AIdrifter/samba
int main(int argc, char* argv[])
{
        int             fd;
        struct stat     st1;
        struct stat     st2;
        char *          pUrl = argv[1];

        if(argc != 2)
        {
                printf("usage: %s <file_url>\n", argv[0]);
                return 1;
        }

        
        smbc_init(get_auth_data_fn, 0);
        
        if (smbc_stat(pUrl, &st1) < 0)
        {
                perror("smbc_stat");
                return 1;
        }
        
        if ((fd = smbc_open(pUrl, O_RDONLY, 0)) < 0)
        {
                perror("smbc_open");
                return 1;
        }

        if (smbc_fstat(fd, &st2) < 0)
        {
                perror("smbc_fstat");
                return 1;
        }
        
        smbc_close(fd);

#define COMPARE(name, field)                                            \
        if (st1.field != st2.field)                                     \
        {                                                               \
                printf("Field " name " MISMATCH: st1=%lu, st2=%lu\n",   \
                       (unsigned long) st1.field,                       \
                       (unsigned long) st2.field);                      \
        }

        COMPARE("st_dev", st_dev);
        COMPARE("st_ino", st_ino);
        COMPARE("st_mode", st_mode);
        COMPARE("st_nlink", st_nlink);
        COMPARE("st_uid", st_uid);
        COMPARE("st_gid", st_gid);
        COMPARE("st_rdev", st_rdev);
        COMPARE("st_size", st_size);
        COMPARE("st_blksize", st_blksize);
        COMPARE("st_blocks", st_blocks);
        COMPARE("st_atime", st_atime);
        COMPARE("st_mtime", st_mtime);
        COMPARE("st_ctime", st_ctime);

        return 0;
}
예제 #3
0
파일: stat_1.c 프로젝트: srimalik/samba
int main(int argc, char** argv)
{
	int err = -1;
	char url[MAX_BUFF_SIZE];
	struct stat st;

	bzero(g_workgroup,MAX_BUFF_SIZE);
	bzero(url,MAX_BUFF_SIZE);

	if ( argc == 5 )
	{
		
		strncpy(g_workgroup,argv[1],strlen(argv[1]));
		strncpy(g_username,argv[2],strlen(argv[2]));
		strncpy(g_password,argv[3],strlen(argv[3]));
		strncpy(url,argv[4],strlen(argv[4]));

		smbc_init(auth_fn, 0);
		err = smbc_stat(url, &st);

		if ( err < 0 )
			err = 1;

		else
			err = 0;

		
	}

	return err;

}
예제 #4
0
int Stat(VFSURL* url, struct __stat64* buffer)
{
  CSMB2::Get().Init();
  std::string strFileName = GetAuthenticatedPath(url);
  PLATFORM::CLockObject lock(CSMB2::Get());

  struct stat tmpBuffer = {0};
  int iResult = smbc_stat(strFileName.c_str(), &tmpBuffer);

  if (buffer)
  {
    memset(buffer, 0, sizeof(struct __stat64));
    buffer->st_dev = tmpBuffer.st_dev;
    buffer->st_ino = tmpBuffer.st_ino;
    buffer->st_mode = tmpBuffer.st_mode;
    buffer->st_nlink = tmpBuffer.st_nlink;
    buffer->st_uid = tmpBuffer.st_uid;
    buffer->st_gid = tmpBuffer.st_gid;
    buffer->st_rdev = tmpBuffer.st_rdev;
    buffer->st_size = tmpBuffer.st_size;
    buffer->st_atime = tmpBuffer.st_atime;
    buffer->st_mtime = tmpBuffer.st_mtime;
    buffer->st_ctime = tmpBuffer.st_ctime;
  }

  return iResult;
}
예제 #5
0
void search_smb(char *url)
{
        struct smbc_dirent* dirptr;
        int dh = 0;
        dh = smbc_opendir(url);
        while((dirptr = smbc_readdir(dh)) != NULL){
                if(!strcmp(dirptr->name, ".") || !strcmp(dirptr->name, ".."))
                        continue;

                char buf[MAX_BUFF_SIZE] = {0};
                sprintf(buf, "%s%s", url, dirptr->name);
                struct stat info;
                smbc_stat(buf, &info);

                if(dirptr->smbc_type == SMBC_FILE) {
                        printf("FILE-------%s%s\n", url, dirptr->name);
                        printf("-----------mtime:%lu\n", info.st_mtime);
                        printf("-----------size :%lld\n", info.st_size);
                        printf("-----------mode :%d S_IDDIR :%d\n", info.st_mode, S_ISDIR(info.st_mode));
                }
                else if(dirptr->smbc_type == SMBC_DIR) {
                        printf("FOLDER-----%s%s\n", url, dirptr->name);
                        printf("-----------mode :%d S_IDDIR :%d\n", info.st_mode, S_ISDIR(info.st_mode));
                        char new_url[255] = {0};
                        sprintf(new_url, "%s%s/", url, dirptr->name);
                        search_smb(new_url);
                }
        }
        smbc_closedir(dh);
}
예제 #6
0
파일: main.cpp 프로젝트: aont/smbcfs
static int smbcfs_getattr(const char* const path, struct stat* const stbuf)
{

  const std::string smbcfs_path = smbcfs_root_path + path;

#ifdef MUTEX_LOCK
  pthread_mutex_lock(&mutex_lock);  
#endif

  const int ret_stat = smbc_stat(smbcfs_path.c_str(), stbuf);

#ifdef MUTEX_LOCK
  pthread_mutex_unlock(&mutex_lock);  
#endif

#ifdef SMBCFS_DEBUG
  fprintf(stderr, "[smbc_stat] %s %p => %d\n", smbcfs_path.c_str(), stbuf, ret_stat);
#endif



  switch(ret_stat) {
  case -1:
    return -ENOENT;
  default:
    return ret_stat;
  }
}
예제 #7
0
파일: stat_4.c 프로젝트: sprymak/samba
int main(int argc, char** argv)
{
	int err = -1;
	int fd = 0;
	char url[MAX_BUFF_SIZE];
	struct stat st;

	memset(g_workgroup, '\0', MAX_BUFF_SIZE);
	memset(url, '\0', MAX_BUFF_SIZE);

	if ( argc == 5 )
	{
		
		strncpy(g_workgroup,argv[1],strlen(argv[1]));
		strncpy(g_username,argv[2],strlen(argv[2]));
		strncpy(g_password,argv[3],strlen(argv[3]));
		strncpy(url,argv[4],strlen(argv[4]));

		smbc_init(auth_fn, 0);
		fd = smbc_open(url,O_RDWR | O_CREAT, 0666);
		smbc_close(fd);

		smbc_stat(url, &st);

		err = errno;

		
	}

	return err;

}
예제 #8
0
파일: smb2.c 프로젝트: Efreak/elinks
/** First information such as permissions is gathered for each directory entry.
 * All entries are then sorted. */
static struct directory_entry *
get_smb_directory_entries(int dir, struct string *prefix)
{
	struct directory_entry *entries = NULL;
	
	int size = 0;
	struct smbc_dirent *entry;

	while ((entry = smbc_readdir(dir))) {
		struct stat st, *stp;
		struct directory_entry *new_entries;
		struct string attrib;
		struct string name;

		if (!strcmp(entry->name, "."))
			continue;

		new_entries = mem_realloc(entries, (size + 2) * sizeof(*new_entries));
		if (!new_entries) continue;
		entries = new_entries;

		if (!init_string(&attrib)) {
			continue;
		}

		if (!init_string(&name)) {
			done_string(&attrib);
			continue;
		}

		add_string_to_string(&name, prefix);
		add_to_string(&name, entry->name);

		stp = (smbc_stat(name.source, &st)) ? NULL : &st;

		stat_type(&attrib, stp);
		stat_mode(&attrib, stp);
		stat_links(&attrib, stp);
		stat_user(&attrib, stp);
		stat_group(&attrib, stp);
		stat_size(&attrib, stp);
		stat_date(&attrib, stp);

		entries[size].name = stracpy(entry->name);
		entries[size].attrib = attrib.source;
		done_string(&name);
		size++;
	}
	smbc_closedir(dir);

	if (!size) {
		/* We may have allocated space for entries but added none. */
		mem_free_if(entries);
		return NULL;
	}
	qsort(entries, size, sizeof(*entries), compare_dir_entries);
	memset(&entries[size], 0, sizeof(*entries));
	return entries;
}
예제 #9
0
static int SMB_STAT( const char* url, struct stat* st )
{
	big_stat s;
	s.st = *st;
	int r = smbc_stat( url, &s.st );
	*st = s.st;
	return r;
}
예제 #10
0
bool CFile::Open(const CStdString& strFileName, unsigned int flags)
{
  Close();

  // we can't open files like smb://file.f or smb://server/file.f
  // if a file matches the if below return false, it can't exist on a samba share.
//  if (!IsValidFile(url.GetFileName()))
//  {
//      XBMC->Log(LOG_NOTICE,"FileSmb->Open: Bad URL : '%s'",url.GetFileName().c_str());
//      return false;
//  }
  m_fileName = strFileName;

  // opening a file to another computer share will create a new session
  // when opening smb://server xbms will try to find folder.jpg in all shares
  // listed, which will create lot's of open sessions.

  //CStdString strFileName;
  //m_fd = OpenFile(url, strFileName);
  m_fd = OpenFile();

  //XBMC->Log(LOG_DEBUG,"CFile::Open - opened %s, fd=%d",url.GetFileName().c_str(), m_fd);
  XBMC->Log(LOG_DEBUG,"CFile::Open - opened %s, fd=%d", m_fileName.c_str(), m_fd);
  if (m_fd == -1)
  {
    // write error to logfile
//#ifdef TARGET_WINDOWS
//    int nt_error = smb.ConvertUnixToNT(errno);
//    XBMC->Log(LOG_INFO, "FileSmb->Open: Unable to open file : '%s'\nunix_err:'%x' nt_err : '%x' error : '%s'", strFileName.c_str(), errno, nt_error, get_friendly_nt_error_msg(nt_error));
//#else
    XBMC->Log(LOG_INFO, "FileSmb->Open: Unable to open file : '%s'\nunix_err:'%x' error : '%s'", strFileName.c_str(), errno, strerror(errno));
//#endif
    return false;
  }

  CLockObject lock(smb);
  struct stat tmpBuffer;
  if (smbc_stat(strFileName, &tmpBuffer) < 0)
  {
    smbc_close(m_fd);
    m_fd = -1;
    return false;
  }

  m_fileSize = tmpBuffer.st_size;

  int64_t ret = smbc_lseek(m_fd, 0, SEEK_SET);
  if ( ret < 0 )
  {
    smbc_close(m_fd);
    m_fd = -1;
    return false;
  }
  // We've successfully opened the file!
  return true;
}
예제 #11
0
int smbc_wrapper_stat(connection* con, const char *url, struct stat *st)
{
	if(con->mode== SMB_BASIC){
		return smbc_stat(url, st);
	}
	else if(con->mode == SMB_NTLM)
		return smbc_cli_stat(con->smb_info->cli, url, st);

	return -1;
	
}
예제 #12
0
/*
 * Member functions
 */
static gboolean
xmms_samba_init (xmms_xform_t *xform)
{
	xmms_samba_data_t *data;
	const gchar *url;
	const gchar *metakey;
	struct stat st;
	gint fd, err;

	g_return_val_if_fail (xform, FALSE);

	url = xmms_xform_indata_get_str (xform, XMMS_STREAM_TYPE_URL);
	g_return_val_if_fail (url, FALSE);

	G_LOCK (mutex);
	err = smbc_stat (url, &st);
	G_UNLOCK (mutex);

	if (err < 0) {
		xmms_log_error ("%s", strerror (errno));
		return FALSE;
	}

	if (!S_ISREG (st.st_mode)) {
		xmms_log_error ("%s is not a regular file.", url);
		return FALSE;
	}

	G_LOCK (mutex);
	fd = smbc_open (url, O_RDONLY | O_NONBLOCK, 0);
	G_UNLOCK (mutex);

	if (fd == -1) {
		xmms_log_error ("%s", strerror (errno));
		return FALSE;
	}

	data = g_new0 (xmms_samba_data_t, 1);
	data->fd = fd;

	xmms_xform_private_data_set (xform, data);

	xmms_xform_outdata_type_add (xform, XMMS_STREAM_TYPE_MIMETYPE,
	                             "application/octet-stream",
	                             XMMS_STREAM_TYPE_END);

	metakey = XMMS_MEDIALIB_ENTRY_PROPERTY_SIZE;
	xmms_xform_metadata_set_int (xform, metakey, st.st_size);

	metakey = XMMS_MEDIALIB_ENTRY_PROPERTY_LMOD;
	xmms_xform_metadata_set_int (xform, metakey, st.st_mtime);

	return TRUE;
}
예제 #13
0
bool CFile::Exists(const CStdString& strFileName, bool bUseCache)
{
  // we can't open files like smb://file.f or smb://server/file.f
  // if a file matches the if below return false, it can't exist on a samba share.
  //if (!IsValidFile(url.GetFileName())) return false;

  smb.Init();

  struct stat info;

  CLockObject lock(smb);
  int iResult = smbc_stat(strFileName, &info);

  if (iResult < 0)
    return false;
  return true;
}
예제 #14
0
bool DirectoryExists(VFSURL* url)
{
  PLATFORM::CLockObject lock(CSMB2::Get());
  CSMB2::Get().Init();

  if (!XBMC->AuthenticateURL(url))
    return false;

  std::string strFileName = CSMB2::Get().URLEncode(url->domain, url->hostname, url->filename,
                                                  url->username, url->password);

  XBMC->FreeString((char*)url->username);
  XBMC->FreeString((char*)url->password);

  struct stat info;
  if (smbc_stat(strFileName.c_str(), &info) != 0)
    return false;

  return (info.st_mode & S_IFDIR) ? true : false;
}
예제 #15
0
bool Exists(VFSURL* url)
{
  // we can't open files like smb://file.f or smb://server/file.f
  // if a file matches the if below return false, it can't exist on a samba share.
  if (!IsValidFile(url->filename))
    return false;

  CSMB2::Get().Init();
  std::string strFileName = GetAuthenticatedPath(url);

  struct stat info;

  CSMB2& smb = CSMB2::Get();

  PLATFORM::CLockObject lock(smb);
  int iResult = smbc_stat(strFileName.c_str(), &info);

  if (iResult < 0)
    return false;

  return true;
}
예제 #16
0
bool CFile::Open(const CStdString& strFileName, unsigned int flags)
{
  Close();

  m_fileName = strFileName;

  m_fd = OpenFile();

  XBMC->Log(LOG_DEBUG,"CFile::Open - opened %s, fd=%d", m_fileName.c_str(), m_fd);
  if (m_fd == -1)
  {
    // write error to logfile
    XBMC->Log(LOG_INFO, "FileSmb->Open: Unable to open file : '%s'\nunix_err:'%x' error : '%s'", strFileName.c_str(), errno, strerror(errno));
    return false;
  }

  CLockObject lock(smb);
  struct stat tmpBuffer;
  if (smbc_stat(strFileName, &tmpBuffer) < 0)
  {
    smbc_close(m_fd);
    m_fd = -1;
    return false;
  }

  m_fileSize = tmpBuffer.st_size;

  int64_t ret = smbc_lseek(m_fd, 0, SEEK_SET);
  if ( ret < 0 )
  {
    smbc_close(m_fd);
    m_fd = -1;
    return false;
  }
  // We've successfully opened the file!
  return true;
}
예제 #17
0
static int gettime(const char * pUrl,
                   const char * pLocalPath)
{
        struct stat st;
        char m_time[32];
        char c_time[32];
        char a_time[32];
        
        smbc_init(get_auth_data_fn, 0);
        
        if (smbc_stat(pUrl, &st) < 0)
        {
                perror("smbc_stat");
                return 1;
        }
        
        printf("SAMBA\n mtime:%lld/%s ctime:%lld/%s atime:%lld/%s\n",
               (long long)st.st_mtime, ctime_r(&st.st_mtime, m_time),
               (long long)st.st_ctime, ctime_r(&st.st_ctime, c_time),
               (long long)st.st_atime, ctime_r(&st.st_atime, a_time));
        
        
        /* check the stat on this file */
        if (stat(pLocalPath, &st) < 0)
        {
                perror("stat");
                return 1;
        }
        
        printf("LOCAL\n mtime:%lld/%s ctime:%lld/%s atime:%lld/%s\n",
               (long long)st.st_mtime, ctime_r(&st.st_mtime, m_time),
               (long long)st.st_ctime, ctime_r(&st.st_ctime, c_time),
               (long long)st.st_atime, ctime_r(&st.st_atime, a_time));
        
        
        return 0;
}
예제 #18
0
void* Open(VFSURL* url)
{
  CSMB2::Get().Init();
  CSMB2::Get().AddActiveConnection();
  if (!IsValidFile(url->filename))
  {
    XBMC->Log(ADDON::LOG_INFO, "FileSmb->Open: Bad URL : '%s'",url->redacted);
    return NULL;
  }
  int fd = -1;
  std::string filename = GetAuthenticatedPath(url);
  PLATFORM::CLockObject lock(CSMB2::Get());
  fd = smbc_open(filename.c_str(), O_RDONLY, 0);
  if (fd == -1)
  {
    XBMC->Log(ADDON::LOG_INFO, "FileSmb->Open: Unable to open file : '%s'\nunix_err:'%x' error : '%s'", url->redacted, errno, strerror(errno));
    return NULL;
  }
  XBMC->Log(ADDON::LOG_DEBUG,"CSMB2File::Open - opened %s, fd=%d", url->filename, fd);
  struct stat tmpBuffer;
  if (smbc_stat(filename.c_str(), &tmpBuffer) < 0)
  {
    smbc_close(fd);
    return NULL;
  }
  int64_t ret = smbc_lseek(fd, 0, SEEK_SET);
  if (ret < 0)
  {
    smbc_close(fd);
    return NULL;
  }
  SMBContext* result = new SMBContext;
  result->fd = fd;
  result->size = tmpBuffer.st_size;
  return result;
}
예제 #19
0
int CFile::Stat(const CURL& url, struct stat64* buffer)
{
  smb.Init();
  CStdString strFileName = GetAuthenticatedPath(url);
  CLockObject lock(smb);

  struct stat tmpBuffer = {0};
  int iResult = smbc_stat(strFileName, &tmpBuffer);

  memset(buffer, 0, sizeof(struct stat64));
  buffer->st_dev = tmpBuffer.st_dev;
  buffer->st_ino = tmpBuffer.st_ino;
  buffer->st_mode = tmpBuffer.st_mode;
  buffer->st_nlink = tmpBuffer.st_nlink;
  buffer->st_uid = tmpBuffer.st_uid;
  buffer->st_gid = tmpBuffer.st_gid;
  buffer->st_rdev = tmpBuffer.st_rdev;
  buffer->st_size = tmpBuffer.st_size;
  buffer->st_atime = tmpBuffer.st_atime;
  buffer->st_mtime = tmpBuffer.st_mtime;
  buffer->st_ctime = tmpBuffer.st_ctime;

  return iResult;
}
예제 #20
0
int main(int argc, char *argv[])
{
  int err, fd, dh1, dsize, dirc;
  const char *file = "smb://samba/public/testfile.txt";
  const char *file2 = "smb://samba/public/testfile2.txt";
  char buff[256];
  char dirbuf[512];
  char *dirp;
  struct stat st1, st2;

  err = smbc_init(get_auth_data_fn,  10); /* Initialize things */

  if (err < 0) {

    fprintf(stderr, "Initializing the smbclient library ...: %s\n", strerror(errno));

  }

  if (argc > 1) {

    if ((dh1 = smbc_opendir(argv[1]))<1) {

      fprintf(stderr, "Could not open directory: %s: %s\n",
	      argv[1], strerror(errno));

      exit(1);

    }

    fprintf(stdout, "Directory handle: %u\n", dh1);

    /* Now, list those directories, but in funny ways ... */

    dirp = (char *)dirbuf;

    if ((dirc = smbc_getdents(dh1, (struct smbc_dirent *)dirp, 
			      sizeof(dirbuf))) < 0) {

      fprintf(stderr, "Problems getting directory entries: %s\n",
	      strerror(errno));

      exit(1);

    }

    /* Now, process the list of names ... */

    fprintf(stdout, "Directory listing, size = %u\n", dirc);

    while (dirc > 0) {

      dsize = ((struct smbc_dirent *)dirp)->dirlen;
      fprintf(stdout, "Dir Ent, Type: %u, Name: %s, Comment: %s\n",
	      ((struct smbc_dirent *)dirp)->smbc_type, 
	      ((struct smbc_dirent *)dirp)->name, 
	      ((struct smbc_dirent *)dirp)->comment);

      dirp += dsize;
      dirc -= dsize;

    }

    dirp = (char *)dirbuf;

    exit(1);

  }

  /* For now, open a file on a server that is hard coded ... later will
   * read from the command line ...
   */

  fd = smbc_open(file, O_RDWR | O_CREAT | O_TRUNC, 0666);

  if (fd < 0) {

    fprintf(stderr, "Creating file: %s: %s\n", file, strerror(errno));
    exit(0);

  }

  fprintf(stdout, "Opened or created file: %s\n", file);

  /* Now, write some date to the file ... */

  memset(buff, '\0', sizeof(buff));
  snprintf(buff, sizeof(buff), "%s", "Some test data for the moment ...");

  err = smbc_write(fd, buff, sizeof(buff));

  if (err < 0) {
    
    fprintf(stderr, "writing file: %s: %s\n", file, strerror(errno));
    exit(0);

  }

  fprintf(stdout, "Wrote %lu bytes to file: %s\n",
          (unsigned long) sizeof(buff), buff);

  /* Now, seek the file back to offset 0 */

  err = smbc_lseek(fd, SEEK_SET, 0);

  if (err < 0) {

    fprintf(stderr, "Seeking file: %s: %s\n", file, strerror(errno));
    exit(0);

  }

  fprintf(stdout, "Completed lseek on file: %s\n", file);

  /* Now, read the file contents back ... */

  err = smbc_read(fd, buff, sizeof(buff));

  if (err < 0) {

    fprintf(stderr, "Reading file: %s: %s\n", file, strerror(errno));
    exit(0);

  }

  fprintf(stdout, "Read file: %s\n", buff);  /* Should check the contents */

  fprintf(stdout, "Now fstat'ing file: %s\n", file);

  err = smbc_fstat(fd, &st1);

  if (err < 0) {

    fprintf(stderr, "Fstat'ing file: %s: %s\n", file, strerror(errno));
    exit(0);

  }


  /* Now, close the file ... */

  err = smbc_close(fd);

  if (err < 0) {

    fprintf(stderr, "Closing file: %s: %s\n", file, strerror(errno));

  }

  /* Now, rename the file ... */

  err = smbc_rename(file, file2);

  if (err < 0) {

    fprintf(stderr, "Renaming file: %s to %s: %s\n", file, file2, strerror(errno));

  }

  fprintf(stdout, "Renamed file %s to %s\n", file, file2);

  /* Now, create a file and delete it ... */

  fprintf(stdout, "Now, creating file: %s so we can delete it.\n", file);

  fd = smbc_open(file, O_RDWR | O_CREAT, 0666);

  if (fd < 0) {

    fprintf(stderr, "Creating file: %s: %s\n", file, strerror(errno));
    exit(0);

  }

  fprintf(stdout, "Opened or created file: %s\n", file);

  err = smbc_close(fd);

  if (err < 0) {

    fprintf(stderr, "Closing file: %s: %s\n", file, strerror(errno));
    exit(0);

  }
  
  /* Now, delete the file ... */

  fprintf(stdout, "File %s created, now deleting ...\n", file);

  err = smbc_unlink(file);

  if (err < 0) {

    fprintf(stderr, "Deleting file: %s: %s\n", file, strerror(errno));
    exit(0);

  }

  /* Now, stat the file, file 2 ... */

  fprintf(stdout, "Now stat'ing file: %s\n", file);

  err = smbc_stat(file2, &st2);

  if (err < 0) {

    fprintf(stderr, "Stat'ing file: %s: %s\n", file, strerror(errno));
    exit(0);

  }

  fprintf(stdout, "Stat'ed file:   %s. Size = %d, mode = %04X\n", file2, 
	  (int)st2.st_size, (unsigned int)st2.st_mode);
  fprintf(stdout, "    time: %s\n", ctime(&st2.st_atime));
  fprintf(stdout, "Earlier stat:   %s, Size = %d, mode = %04X\n", file, 
	  (int)st1.st_size, (unsigned int)st1.st_mode);
  fprintf(stdout, "    time: %s\n", ctime(&st1.st_atime));

  /* Now, make a directory ... */

  fprintf(stdout, "Making directory smb://samba/public/make-dir\n");

  if (smbc_mkdir("smb://samba/public/make-dir", 0666) < 0) {

    fprintf(stderr, "Error making directory: smb://samba/public/make-dir: %s\n", 
	    strerror(errno));

    if (errno == EEXIST) { /* Try to delete the directory */

      fprintf(stdout, "Trying to delete directory: smb://samba/public/make-dir\n");

      if (smbc_rmdir("smb://samba/public/make-dir") < 0) { /* Error */

	fprintf(stderr, "Error removing directory: smb://samba/public/make-dir: %s\n", strerror(errno));

	exit(0);

      }

      fprintf(stdout, "Making directory: smb://samba/public/make-dir\n");

      if (smbc_mkdir("smb://samba/public/make-dir", 666) < 0) {

	fprintf(stderr, "Error making directory: smb://samba/public/make-dir: %s\n",
		strerror(errno));

	fprintf(stderr, "I give up!\n");

	exit(1);

      }

    }

    exit(0);
    
  }

  fprintf(stdout, "Made dir: make-dir\n");
  return 0;
}
예제 #21
0
int main(int argc, char * argv[]) 
{ 
    int             i;
    int             fd;
    int             ret;
    int             debug = 0;
    char *          p;
    char            path[2048];
    struct stat     statbuf;
    struct statvfs  statvfsbuf;
    
    smbc_init(get_auth_data_fn, debug); 
    
    for (;;)
    {
        fprintf(stdout, "Path: ");
        *path = '\0';
        fgets(path, sizeof(path) - 1, stdin);
        if (strlen(path) == 0)
        {
            return 0;
        }

        p = path + strlen(path) - 1;
        if (*p == '\n')
        {
            *p = '\0';
        }
    
        /* Determine if it's a file or a folder */
        if (smbc_stat(path, &statbuf) < 0)
        {
            perror("smbc_stat");
            continue;
        }

        if (S_ISREG(statbuf.st_mode))
        {
            if ((fd = smbc_open(path, O_RDONLY, 0)) < 0)
            {
                perror("smbc_open");
                continue;
            }
        }
        else
        {
            if ((fd = smbc_opendir(path)) < 0)
            {
                perror("smbc_opendir");
                continue;
            }
        }

        ret = smbc_fstatvfs(fd, &statvfsbuf);

        smbc_close(fd);

        if (ret < 0)
        {
            perror("fstatvfs");
        }
        else
        {
            printf("\n");
            printf("Block Size: %lu\n", statvfsbuf.f_bsize);
            printf("Fragment Size: %lu\n", statvfsbuf.f_frsize);
            printf("Blocks: %llu\n",
                   (unsigned long long) statvfsbuf.f_blocks);
            printf("Free Blocks: %llu\n",
                   (unsigned long long) statvfsbuf.f_bfree);
            printf("Available Blocks: %llu\n",
                   (unsigned long long) statvfsbuf.f_bavail);
            printf("Files : %llu\n",
                   (unsigned long long) statvfsbuf.f_files);
            printf("Free Files: %llu\n",
                   (unsigned long long) statvfsbuf.f_ffree);
            printf("Available Files: %llu\n",
                   (unsigned long long) statvfsbuf.f_favail);
            printf("File System ID: %lu\n",
                   (unsigned long) statvfsbuf.f_fsid);
            printf("\n");

            printf("Flags: 0x%lx\n", statvfsbuf.f_flag);
            printf("Extended Features: ");

            if (statvfsbuf.f_flag & SMBC_VFS_FEATURE_NO_UNIXCIFS)
            {
                printf("NO_UNIXCIFS ");
            }
            else
            {
                printf("unixcifs ");
            }

            if (statvfsbuf.f_flag & SMBC_VFS_FEATURE_CASE_INSENSITIVE)
            {
                printf("CASE_INSENSITIVE ");
            }
            else
            {
                printf("case_sensitive ");
            }

            if (statvfsbuf.f_flag & SMBC_VFS_FEATURE_DFS)
            {
                printf("DFS ");
            }
            else
            {
                printf("no_dfs ");
            }

            printf("\n");
        }
    }

    return 0; 
}
예제 #22
0
파일: testacl.c 프로젝트: AIdrifter/samba
int main(int argc, const char *argv[])
{
    int opt;
    int flags;
    int debug = 0;
    int numeric = 0;
    int stat_and_retry = 0;
    int full_time_names = 0;
    enum acl_mode mode = SMB_ACL_LIST;
    static const char *the_acl = NULL;
    int ret;
    char *p;
    const char *debugstr;
    char path[1024];
    char value[1024];
    poptContext pc;
    struct stat st;
    struct poptOption long_options[] =
        {
            POPT_AUTOHELP
            {
                "numeric", 'n', POPT_ARG_NONE, &numeric,
                1, "Don't resolve sids or masks to names"
            },
            {
                "debug", 'd', POPT_ARG_INT, &debug,
                0, "Set debug level (0-100)"
            },
            {
                "full_time_names", 'f', POPT_ARG_NONE, &full_time_names,
                1,
                "Use new style xattr names, which include CREATE_TIME"
            },
            {
                "delete", 'D', POPT_ARG_STRING, NULL,
                'D', "Delete an acl", "ACL"
            },
            {
                "modify", 'M', POPT_ARG_STRING, NULL,
                'M', "Modify an acl", "ACL"
            },
            {
                "add", 'a', POPT_ARG_STRING, NULL,
                'a', "Add an acl", "ACL"
            },
            {
                "set", 'S', POPT_ARG_STRING, NULL,
                'S', "Set acls", "ACLS"
            },
            {
                "chown", 'C', POPT_ARG_STRING, NULL,
                'C', "Change ownership of a file", "USERNAME"
            },
            {
                "chgrp", 'G', POPT_ARG_STRING, NULL,
                'G', "Change group ownership of a file", "GROUPNAME"
            },
            {
                "get", 'g', POPT_ARG_STRING, NULL,
                'g', "Get a specific acl attribute", "ACL"
            },
            {
                "stat_and_retry", 'R', POPT_ARG_NONE, &stat_and_retry,
                1, "After 'get' do 'stat' and another 'get'"
            },
            {
                NULL
            }
        };
    
    setbuf(stdout, NULL);

    pc = poptGetContext("smbcacls", argc, argv, long_options, 0);
    
    poptSetOtherOptionHelp(pc, "smb://server1/share1/filename");
    
    while ((opt = poptGetNextOpt(pc)) != -1) {
        switch (opt) {
        case 'S':
            the_acl = strdup(poptGetOptArg(pc));
            mode = SMB_ACL_SET;
            break;
            
        case 'D':
            the_acl = strdup(poptGetOptArg(pc));
            mode = SMB_ACL_DELETE;
            break;
            
        case 'M':
            the_acl = strdup(poptGetOptArg(pc));
            mode = SMB_ACL_MODIFY;
            break;
            
        case 'a':
            the_acl = strdup(poptGetOptArg(pc));
            mode = SMB_ACL_ADD;
            break;

        case 'g':
            the_acl = strdup(poptGetOptArg(pc));
            mode = SMB_ACL_GET;
            break;

        case 'C':
            the_acl = strdup(poptGetOptArg(pc));
            mode = SMB_ACL_CHOWN;
            break;

        case 'G':
            the_acl = strdup(poptGetOptArg(pc));
            mode = SMB_ACL_CHGRP;
            break;
        }
    }
    
    /* Make connection to server */
    if(!poptPeekArg(pc)) { 
        poptPrintUsage(pc, stderr, 0);
        return 1;
    }
    
    strcpy(path, poptGetArg(pc));
    
    if (smbc_init(get_auth_data_fn, debug) != 0)
    {
        printf("Could not initialize smbc_ library\n");
        return 1;
    }

    if (full_time_names) {
        SMBCCTX *context = smbc_set_context(NULL);
        smbc_setOptionFullTimeNames(context, 1);
    }
    
    /* Perform requested action */
    
    switch(mode)
    {
    case SMB_ACL_LIST:
        ret = smbc_listxattr(path, value, sizeof(value)-2);
        if (ret < 0)
        {
            printf("Could not get attribute list for [%s] %d: %s\n",
                   path, errno, strerror(errno));
            return 1;
        }

        /*
         * The list of attributes has a series of null-terminated strings.
         * The list of strings terminates with an extra null byte, thus two in
         * a row.  Ensure that our buffer, which is conceivably shorter than
         * the list of attributes, actually ends with two null bytes in a row.
         */
        value[sizeof(value) - 2] = '\0';
        value[sizeof(value) - 1] = '\0';
        printf("Supported attributes:\n");
        for (p = value; *p; p += strlen(p) + 1)
        {
            printf("\t%s\n", p);
        }
        break;

    case SMB_ACL_GET:
        do
        {
            if (the_acl == NULL)
            {
                if (numeric)
                {
                    the_acl = "system.*";
                }
                else
                {
                    the_acl = "system.*+";
                }
            }
            ret = smbc_getxattr(path, the_acl, value, sizeof(value));
            if (ret < 0)
            {
                printf("Could not get attributes for [%s] %d: %s\n",
                       path, errno, strerror(errno));
                return 1;
            }
        
            printf("Attributes for [%s] are:\n%s\n", path, value);

            if (stat_and_retry)
            {
                if (smbc_stat(path, &st) < 0)
                {
                    perror("smbc_stat");
                    return 1;
                }
            }

            --stat_and_retry;
        } while (stat_and_retry >= 0);
        break;

    case SMB_ACL_ADD:
        flags = SMBC_XATTR_FLAG_CREATE;
        debugstr = "add attributes";
        goto do_set;
        
    case SMB_ACL_MODIFY:
        flags = SMBC_XATTR_FLAG_REPLACE;
        debugstr = "modify attributes";
        goto do_set;

    case SMB_ACL_CHOWN:
        snprintf(value, sizeof(value),
                 "system.nt_sec_desc.owner%s:%s",
                 numeric ? "" : "+", the_acl);
        the_acl = value;
        debugstr = "chown owner";
        goto do_set;

    case SMB_ACL_CHGRP:
        snprintf(value, sizeof(value),
                 "system.nt_sec_desc.group%s:%s",
                 numeric ? "" : "+", the_acl);
        the_acl = value;
        debugstr = "change group";
        goto do_set;

    case SMB_ACL_SET:
        flags = 0;
        debugstr = "set attributes";
        
      do_set:
        if ((p = strchr(the_acl, ':')) == NULL)
        {
            printf("Missing value.  ACL must be name:value pair\n");
            return 1;
        }

        *p++ = '\0';
        
        ret = smbc_setxattr(path, the_acl, p, strlen(p), flags);
        if (ret < 0)
        {
            printf("Could not %s for [%s] %d: %s\n",
                   debugstr, path, errno, strerror(errno));
            return 1;
        }
        break;

    case SMB_ACL_DELETE:
        ret = smbc_removexattr(path, the_acl);
        if (ret < 0)
        {
            printf("Could not remove attribute %s for [%s] %d:%s\n",
                   the_acl, path, errno, strerror(errno));
            return 1;
        }
        break;

    default:
        printf("operation not yet implemented\n");
        break;
    }
    
    return 0;
}
예제 #23
0
int main(int argc, char * argv[]) 
{ 
    int             debug = 0;
    char            m_time[32];
    char            c_time[32];
    char            a_time[32];
    const char *          pSmbPath = NULL;
    const char *          pLocalPath = NULL;
    struct stat     st; 
    
    if (argc == 1)
    {
        pSmbPath = "smb://RANDOM/Public/small";
        pLocalPath = "/random/home/samba/small";
    }
    else if (argc == 2)
    {
        pSmbPath = argv[1];
        pLocalPath = NULL;
    }
    else if (argc == 3)
    {
        pSmbPath = argv[1];
        pLocalPath = argv[2];
    }
    else
    {
        printf("usage: "
               "%s [ smb://path/to/file [ /nfs/or/local/path/to/file ] ]\n",
               argv[0]);
        return 1;
    }

    smbc_init(get_auth_data_fn, debug); 
    
    if (smbc_stat(pSmbPath, &st) < 0)
    {
        perror("smbc_stat");
        return 1;
    }
    
    printf("\nSAMBA\n mtime:%lld/%s ctime:%lld/%s atime:%lld/%s\n",
           (long long)st.st_mtime, ctime_r(&st.st_mtime, m_time),
           (long long)st.st_ctime, ctime_r(&st.st_ctime, c_time),
           (long long)st.st_atime, ctime_r(&st.st_atime, a_time));
    
    if (pLocalPath != NULL)
    {
        if (stat(pLocalPath, &st) < 0)
        {
            perror("stat");
            return 1;
        }
        
        printf("LOCAL\n mtime:%lld/%s ctime:%lld/%s atime:%lld/%s\n",
               (long long)st.st_mtime, ctime_r(&st.st_mtime, m_time),
               (long long)st.st_ctime, ctime_r(&st.st_ctime, c_time),
               (long long)st.st_atime, ctime_r(&st.st_atime, a_time));
    }

    return 0; 
}
예제 #24
0
파일: smb.c 프로젝트: tguillem/vlc
/****************************************************************************
 * Open: connect to smb server and ask for file
 ****************************************************************************/
static int Open( vlc_object_t *p_this )
{
    stream_t     *p_access = (stream_t*)p_this;
    access_sys_t *p_sys;
    struct stat  filestat;
    vlc_url_t    url;
    vlc_credential credential;
    char         *psz_decoded_path = NULL, *psz_uri = NULL,
                 *psz_var_domain = NULL;
    int          i_ret;
    int          i_smb;
    uint64_t     i_size;
    bool         b_is_dir = false;

#ifndef _WIN32
    if( smbc_init( smb_auth, 0 ) )
        return VLC_EGENERIC;
#endif

/*
** some version of glibc defines open as a macro, causing havoc
** with other macros using 'open' under the hood, such as the
** following one:
*/
#if defined(smbc_open) && defined(open)
# undef open
#endif

    vlc_UrlParse( &url, p_access->psz_url );
    if( url.psz_path )
    {
        psz_decoded_path = vlc_uri_decode_duplicate( url.psz_path );
        if( !psz_decoded_path )
        {
            vlc_UrlClean( &url );
            return VLC_EGENERIC;
        }
    }

    vlc_credential_init( &credential, &url );
    psz_var_domain = var_InheritString( p_access, "smb-domain" );
    credential.psz_realm = psz_var_domain;
    vlc_credential_get( &credential, p_access, "smb-user", "smb-pwd",
                        NULL, NULL );
    for (;;)
    {
        if( smb_get_uri( p_access, &psz_uri, credential.psz_realm,
                         credential.psz_username, credential.psz_password,
                         url.psz_host, psz_decoded_path, NULL ) == -1 )
        {
            vlc_credential_clean( &credential );
            free(psz_var_domain);
            free( psz_decoded_path );
            vlc_UrlClean( &url );
            return VLC_ENOMEM;
        }

        if( ( i_ret = smbc_stat( psz_uri, &filestat ) ) && errno == EACCES )
        {
            errno = 0;
            if( vlc_credential_get( &credential, p_access, "smb-user", "smb-pwd",
                                    SMB_LOGIN_DIALOG_TITLE,
                                    SMB_LOGIN_DIALOG_TEXT, url.psz_host) )
                continue;
        }

        /* smbc_stat fails with servers or shares. Assume they are directory */
        if( i_ret || S_ISDIR( filestat.st_mode ) )
            b_is_dir = true;
        break;
    }

    vlc_credential_store( &credential, p_access );
    vlc_credential_clean( &credential );
    free(psz_var_domain);
    free( psz_decoded_path );

    /* Init p_access */
    p_sys =
    p_access->p_sys = vlc_calloc( p_this, 1, sizeof( access_sys_t ) );
    if( !p_sys )
    {
        free( psz_uri );
        vlc_UrlClean( &url );
        return VLC_ENOMEM;
    }

    if( b_is_dir )
    {
        p_sys->url = url;
        p_access->pf_readdir = DirRead;
        p_access->pf_control = access_vaDirectoryControlHelper;
        i_size = 0;
#ifndef _WIN32
        i_smb = smbc_opendir( psz_uri );
        if( i_smb < 0 )
            vlc_UrlClean( &p_sys->url );
#endif
    }
    else
    {
        ACCESS_SET_CALLBACKS( Read, NULL, Control, Seek );
        i_smb = smbc_open( psz_uri, O_RDONLY, 0 );
        i_size = filestat.st_size;
        vlc_UrlClean( &url );
    }
    free( psz_uri );

#ifndef _WIN32
    if( i_smb < 0 )
    {
        msg_Err( p_access, "open failed for '%s' (%s)",
                 p_access->psz_location, vlc_strerror_c(errno) );
        return VLC_EGENERIC;
    }
#endif

    p_sys->size = i_size;
    p_sys->i_smb = i_smb;

    return VLC_SUCCESS;
}
예제 #25
0
int main(int argc, char * argv[]) 
{ 
    int             fd;
    int             ret;
    int             debug = 0;
    int             savedErrno;
    char            buffer[128];
    struct stat     st; 
    
    if (argc != 2)
    {
        printf("usage: "
               "%s smb://path/to/file\n",
               argv[0]);
        return 1;
    }

    smbc_init(get_auth_data_fn, debug); 
    
    if ((fd = smbc_open(argv[1], O_WRONLY | O_CREAT | O_TRUNC, 0)) < 0)
    {
        perror("smbc_open");
        return 1;
    }

    strcpy(buffer, "Hello world.\nThis is a test.\n");

    ret = smbc_write(fd, buffer, strlen(buffer));
    savedErrno = errno;
    smbc_close(fd);

    if (ret < 0)
    {
        errno = savedErrno;
        perror("write");
    }

    if (smbc_stat(argv[1], &st) < 0)
    {
        perror("smbc_stat");
        return 1;
    }
    
    printf("Original size: %lu\n", (unsigned long) st.st_size);
    
    if ((fd = smbc_open(argv[1], O_WRONLY, 0)) < 0)
    {
        perror("smbc_open");
        return 1;
    }

    ret = smbc_ftruncate(fd, 13);
    savedErrno = errno;
    smbc_close(fd);
    if (ret < 0)
    {
        errno = savedErrno;
        perror("smbc_ftruncate");
        return 1;
    }
    
    if (smbc_stat(argv[1], &st) < 0)
    {
        perror("smbc_stat");
        return 1;
    }
    
    printf("New size: %lu\n", (unsigned long) st.st_size);
    
    return 0; 
}
예제 #26
0
파일: stat_k.c 프로젝트: sprymak/samba
int main(int argc, char** argv)
{
	int err = -1;
	char url[MAX_BUFF_SIZE];
	struct stat st;
	char *user;
	SMBCCTX *ctx;

	memset(g_workgroup, '\0', MAX_BUFF_SIZE);
	memset(url, '\0', MAX_BUFF_SIZE);

	if ( argc == 2)
	{
		char *p;
		user = getenv("USER");
		if (!user) {
			printf("no user??\n");
			return 0;
		}

		printf("username: %s\n", user);

		p = strchr(user, '\\');
		if (! p) {
			printf("BAD username??\n");
			return 0;
		}
		strncpy(g_workgroup, user, strlen(user));
		g_workgroup[p - user] = 0;
		strncpy(g_username, p + 1, strlen(p + 1));
		memset(g_password, 0, sizeof(char) * MAX_BUFF_SIZE);
		strncpy(url,argv[1],strlen(argv[1]));

		err = smbc_init(auth_fn, 10);
		if (err) {
			printf("init smbclient context failed!!\n");
			return err;
		}
		/* Using null context actually get the old context. */
		ctx = smbc_set_context(NULL);
		smbc_setOptionUseKerberos(ctx, 1);
		smbc_setOptionFallbackAfterKerberos(ctx, 1);
		smbc_setWorkgroup(ctx, g_workgroup);
		smbc_setUser(ctx, g_username);
		err = smbc_stat(url, &st);

		if ( err < 0 ) {
			err = 1;
			printf("stat failed!!\n");
		}
		else {
			err = 0;
			printf("stat succeeded!!\n");
		}


	}

	return err;

}
예제 #27
0
int browse(int (*scan_found_share)(char share[]),char * path, int scan, int indent)
{
    char *                      p;
    char                        buf[1024];
    int                         dir;
    struct stat                 stat;
    struct smbc_dirent *        dirent;

    if (! scan)
    {
        bblog(INFO, "Opening (%s)...", path);
    }

    if ((dir = smbc_opendir(path)) < 0)
    {
        bblog(ERROR, "Could not open directory [%s] (%d:%s)", path, errno, strerror(errno));
        return 0;
    }

    while ((dirent = smbc_readdir(dir)) != NULL)
    {
        bblog(INFO, "%*.*s%-30s", indent, indent, "", dirent->name);

        switch(dirent->smbc_type)
        {
        case SMBC_WORKGROUP:
            bblog(INFO, "WORKGROUP");
            break;

        case SMBC_SERVER:
            bblog(INFO, "SERVER");
            break;

        case SMBC_FILE_SHARE:
            bblog(INFO, "FILE_SHARE");
            (*scan_found_share)(dirent->name);
            break;

        case SMBC_PRINTER_SHARE:
            bblog(INFO, "PRINTER_SHARE");
            break;

        case SMBC_COMMS_SHARE:
            bblog(INFO, "COMMS_SHARE");
            break;

        case SMBC_IPC_SHARE:
            bblog(INFO, "IPC_SHARE");
            break;

        case SMBC_DIR:
            bblog(INFO, "DIR");
            break;

        case SMBC_FILE:
            bblog(INFO, "FILE");

            p = path + strlen(path);
            strcat(p, "/");
            strcat(p+1, dirent->name);
            if (smbc_stat(path, &stat) < 0)
            {
                bblog(WARN, " unknown size (reason %d: %s)",
                      errno, strerror(errno));
            }
            else
            {
                bblog(INFO, " size %lu", (unsigned long) stat.st_size);
            }
            *p = '\0';

            break;

        case SMBC_LINK:
            bblog(INFO, "LINK");
            break;
        }

        if (scan &&
                (dirent->smbc_type == SMBC_WORKGROUP ||
                 dirent->smbc_type == SMBC_SERVER))
        {
            /*
             * don't append server name to workgroup; what we want is:
             *
             *   smb://workgroup_name
             * or
             *   smb://server_name
             *
             */
            snprintf(buf, sizeof(buf), "smb://%s", dirent->name);
            browse(scan_found_share,buf, scan, indent + 2);
        }
    }

    smbc_closedir(dir);

    return 1;
}
예제 #28
0
static void browse(char * path, int scan, int indent)
{
    char *                      p;
    char                        buf[1024];
    int                         dir;
    struct stat                 stat;
    struct smbc_dirent *        dirent;

    if (! scan)
    {
        printf("Opening (%s)...\n", path);
    }
        
    if ((dir = smbc_opendir(path)) < 0)
    {
        printf("Could not open directory [%s] (%d:%s)\n",
               path, errno, strerror(errno));
        return;
    }

    while ((dirent = smbc_readdir(dir)) != NULL)
    {
        printf("%*.*s%-30s", indent, indent, "", dirent->name);

        switch(dirent->smbc_type)
        {
        case SMBC_WORKGROUP:
            printf("WORKGROUP");
            break;
            
        case SMBC_SERVER:
            printf("SERVER");
            break;
            
        case SMBC_FILE_SHARE:
            printf("FILE_SHARE");
            break;
            
        case SMBC_PRINTER_SHARE:
            printf("PRINTER_SHARE");
            break;
            
        case SMBC_COMMS_SHARE:
            printf("COMMS_SHARE");
            break;
            
        case SMBC_IPC_SHARE:
            printf("IPC_SHARE");
            break;
            
        case SMBC_DIR:
            printf("DIR");
            break;
            
        case SMBC_FILE:
            printf("FILE");

            p = path + strlen(path);
            strcat(p, "/");
            strcat(p+1, dirent->name);
            if (smbc_stat(path, &stat) < 0)
            {
                printf(" unknown size (reason %d: %s)",
                       errno, strerror(errno));
            }
            else
            {
                printf(" size %lu", (unsigned int) stat.st_size);
            }
            *p = '\0';

            break;
            
        case SMBC_LINK:
            printf("LINK");
            break;
        }

        printf("\n");

        if (scan &&
            (dirent->smbc_type == SMBC_WORKGROUP ||
             dirent->smbc_type == SMBC_SERVER))
        {
            /*
             * don't append server name to workgroup; what we want is:
             *
             *   smb://workgroup_name
             * or
             *   smb://server_name
             *
             */
            snprintf(buf, sizeof(buf), "smb://%s", dirent->name);
            browse(buf, scan, indent + 2);
        }
    }

    smbc_closedir(dir);
}
예제 #29
0
static int _stat(const char *uri, csync_vio_file_stat_t *buf) {
  struct stat sb;

  if (smbc_stat(uri, &sb) < 0) {
    return -1;
  }

  buf->name = c_basename(uri);
  if (buf->name == NULL) {
    csync_vio_file_stat_destroy(buf);
    return -1;
  }
  buf->fields = CSYNC_VIO_FILE_STAT_FIELDS_NONE;

  switch(sb.st_mode & S_IFMT) {
    case S_IFBLK:
      buf->type = CSYNC_VIO_FILE_TYPE_BLOCK_DEVICE;
      break;
    case S_IFCHR:
      buf->type = CSYNC_VIO_FILE_TYPE_CHARACTER_DEVICE;
      break;
    case S_IFDIR:
      buf->type = CSYNC_VIO_FILE_TYPE_DIRECTORY;
      break;
    case S_IFIFO:
      buf->type = CSYNC_VIO_FILE_TYPE_FIFO;
      break;
    case S_IFLNK:
      buf->type = CSYNC_VIO_FILE_TYPE_SYMBOLIC_LINK;
      break;
    case S_IFREG:
      buf->type = CSYNC_VIO_FILE_TYPE_REGULAR;
      break;
    case S_IFSOCK:
      buf->type = CSYNC_VIO_FILE_TYPE_SYMBOLIC_LINK;
    default:
      buf->type = CSYNC_VIO_FILE_TYPE_UNKNOWN;
      break;
  }
  buf->fields |= CSYNC_VIO_FILE_STAT_FIELDS_TYPE;

  buf->mode = sb.st_mode;
  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->device = sb.st_dev;
  buf->fields |= CSYNC_VIO_FILE_STAT_FIELDS_DEVICE;

  buf->inode = sb.st_ino;
  buf->fields |= CSYNC_VIO_FILE_STAT_FIELDS_INODE;

  buf->nlink = sb.st_nlink;
  buf->fields |= CSYNC_VIO_FILE_STAT_FIELDS_LINK_COUNT;

  buf->uid = sb.st_uid;
  buf->fields |= CSYNC_VIO_FILE_STAT_FIELDS_UID;

  buf->gid = sb.st_gid;
  buf->fields |= CSYNC_VIO_FILE_STAT_FIELDS_GID;

  buf->size = sb.st_size;
  buf->fields |= CSYNC_VIO_FILE_STAT_FIELDS_SIZE;

  buf->blksize = sb.st_blksize;
  buf->fields |= CSYNC_VIO_FILE_STAT_FIELDS_BLOCK_SIZE;

  buf->blkcount = sb.st_blocks;
  buf->fields |= CSYNC_VIO_FILE_STAT_FIELDS_BLOCK_COUNT;

  buf->atime = sb.st_atime;
  buf->fields |= CSYNC_VIO_FILE_STAT_FIELDS_ATIME;

  buf->mtime = sb.st_mtime;
  buf->fields |= CSYNC_VIO_FILE_STAT_FIELDS_MTIME;

  buf->ctime = sb.st_ctime;
  buf->fields |= CSYNC_VIO_FILE_STAT_FIELDS_CTIME;

  return 0;
}
예제 #30
0
파일: testutime.c 프로젝트: AIdrifter/samba
int main(int argc, char * argv[]) 
{ 
    int             debug = 0;
    char            m_time[32];
    char            c_time[32];
    char            a_time[32];
    const char *          pSmbPath = NULL;
    time_t          t = time(NULL);
    struct stat     st;
    struct utimbuf  utimbuf;
    
    if (argc == 1)
    {
        pSmbPath = "smb://RANDOM/Public/small";
    }
    else if (argc == 2)
    {
        pSmbPath = argv[1];
    }
    else if (argc == 3)
    {
        pSmbPath = argv[1];
        t = (time_t) strtol(argv[2], NULL, 10);
    }
    else
    {
        printf("usage: "
               "%s [ smb://path/to/file [ mtime ] ]\n",
               argv[0]);
        return 1;
    }

    smbc_init(get_auth_data_fn, debug); 
    
    if (smbc_stat(pSmbPath, &st) < 0)
    {
        perror("smbc_stat");
        return 1;
    }
    
    printf("Before\n mtime:%lu/%s ctime:%lu/%s atime:%lu/%s\n",
           st.st_mtime, ctime_r(&st.st_mtime, m_time),
           st.st_ctime, ctime_r(&st.st_ctime, c_time),
           st.st_atime, ctime_r(&st.st_atime, a_time)); 
    
    utimbuf.actime = t;         /* unchangable (wont change) */
    utimbuf.modtime = t;        /* this one should succeed */
    if (smbc_utime(pSmbPath, &utimbuf) < 0)
    {
        perror("smbc_utime");
        return 1;
    }

    if (smbc_stat(pSmbPath, &st) < 0)
    {
        perror("smbc_stat");
        return 1;
    }
    
    printf("After\n mtime:%lu/%s ctime:%lu/%s atime:%lu/%s\n",
           st.st_mtime, ctime_r(&st.st_mtime, m_time),
           st.st_ctime, ctime_r(&st.st_ctime, c_time),
           st.st_atime, ctime_r(&st.st_atime, a_time)); 
    
    return 0; 
}