示例#1
0
ssize_t
smbc_read(int fd,
          void *buf,
          size_t bufsize)
{
	SMBCFILE * file = find_fd(fd);
        return smbc_getFunctionRead(statcont)(statcont, file, buf, bufsize);
}
示例#2
0
int SmbFs::fs_read(const char *, char *buf, size_t size, off_t offset, struct fuse_file_info *fi)
{
	QMutexLocker locker(&_mutex);
	size_t s;
	
	if((smbc_getFunctionLseek(_ctx))(_ctx, (SMBCFILE *)fi->fh, offset, SEEK_SET) == (off_t)-1)
		return(-errno);
	
	if((s = (smbc_getFunctionRead(_ctx))(_ctx, (SMBCFILE *)fi->fh, buf,size)) < 0)
		return(-errno);
	
	return(s);
}
示例#3
0
/*
 * This function uses the input smb uri components to download a sysvol file
 * (e.g. INI file, policy file, etc) and store it to the GPO_CACHE directory.
 */
static errno_t
copy_smb_file_to_gpo_cache(SMBCCTX *smbc_ctx,
                           const char *smb_server,
                           const char *smb_share,
                           const char *smb_path,
                           const char *smb_cse_suffix)
{
    char *smb_uri = NULL;
    SMBCFILE *file;
    int ret;
    uint8_t *buf = NULL;
    int buflen = 0;

    TALLOC_CTX *tmp_ctx = NULL;

    tmp_ctx = talloc_new(NULL);
    if (tmp_ctx == NULL) {
        return ENOMEM;
    }

    smb_uri = talloc_asprintf(tmp_ctx, "%s%s%s%s", smb_server,
                              smb_share, smb_path, smb_cse_suffix);
    if (smb_uri == NULL) {
        DEBUG(SSSDBG_CRIT_FAILURE, "talloc_asprintf failed.\n");
        ret = ENOMEM;
        goto done;
    }

    DEBUG(SSSDBG_TRACE_FUNC, "smb_uri: %s\n", smb_uri);

    errno = 0;
    file = smbc_getFunctionOpen(smbc_ctx)(smbc_ctx, smb_uri, O_RDONLY, 0755);
    if (file == NULL) {
        ret = errno;
        DEBUG(SSSDBG_CRIT_FAILURE, "smbc_getFunctionOpen failed [%d][%s]\n",
              ret, strerror(ret));
        goto done;
    }

    buf = talloc_array(tmp_ctx, uint8_t, SMB_BUFFER_SIZE);
    if (buf == NULL) {
        DEBUG(SSSDBG_CRIT_FAILURE, "talloc_array failed.\n");
        ret = ENOMEM;
        goto done;
    }

    errno = 0;
    buflen = smbc_getFunctionRead(smbc_ctx)(smbc_ctx, file, buf, SMB_BUFFER_SIZE);
    if (buflen < 0) {
        ret = errno;
        DEBUG(SSSDBG_CRIT_FAILURE, "smbc_getFunctionRead failed [%d][%s]\n",
              ret, strerror(ret));
        goto done;
    }

    DEBUG(SSSDBG_TRACE_ALL, "smb_buflen: %d\n", buflen);

    ret = gpo_cache_store_file(smb_path, smb_cse_suffix, buf, buflen);
    if (ret != EOK) {
        DEBUG(SSSDBG_CRIT_FAILURE,
              "gpo_cache_store_file failed [%d][%s]\n",
              ret, strerror(ret));
        goto done;
    }

 done:
    talloc_free(tmp_ctx);
    return ret;
}
示例#4
0
int
SMBC_print_file_ctx(SMBCCTX *c_file,
                    const char *fname,
                    SMBCCTX *c_print,
                    const char *printq)
{
        SMBCFILE *fid1;
        SMBCFILE *fid2;
        int bytes;
        int saverr;
        int tot_bytes = 0;
        char buf[4096];
	TALLOC_CTX *frame = talloc_stackframe();
        
        if (!c_file || !c_file->internal->initialized ||
            !c_print || !c_print->internal->initialized) {
                
                errno = EINVAL;
		TALLOC_FREE(frame);
                return -1;
                
        }
        
        if (!fname && !printq) {
                
                errno = EINVAL;
		TALLOC_FREE(frame);
                return -1;
                
        }
        
        /* Try to open the file for reading ... */
        
        if ((long)(fid1 = smbc_getFunctionOpen(c_file)(c_file, fname,
                                                       O_RDONLY, 0666)) < 0) {
                DEBUG(3, ("Error, fname=%s, errno=%i\n", fname, errno));
		TALLOC_FREE(frame);
                return -1;  /* smbc_open sets errno */
        }
        
        /* Now, try to open the printer file for writing */
        
        if ((long)(fid2 = smbc_getFunctionOpenPrintJob(c_print)(c_print,
                                                                printq)) < 0) {
                
                saverr = errno;  /* Save errno */
                smbc_getFunctionClose(c_file)(c_file, fid1);
                errno = saverr;
		TALLOC_FREE(frame);
                return -1;
                
        }
        
        while ((bytes = smbc_getFunctionRead(c_file)(c_file, fid1,
                                                     buf, sizeof(buf))) > 0) {
                
                tot_bytes += bytes;
                
                if ((smbc_getFunctionWrite(c_print)(c_print, fid2,
                                                    buf, bytes)) < 0) {
                        
                        saverr = errno;
                        smbc_getFunctionClose(c_file)(c_file, fid1);
                        smbc_getFunctionClose(c_print)(c_print, fid2);
                        errno = saverr;
                        
                }
                
        }
        
        saverr = errno;
        
        smbc_getFunctionClose(c_file)(c_file, fid1);
        smbc_getFunctionClose(c_print)(c_print, fid2);
        
        if (bytes < 0) {
                
                errno = saverr;
		TALLOC_FREE(frame);
                return -1;
                
        }
        
	TALLOC_FREE(frame);
        return tot_bytes;
        
}
示例#5
0
static void rb_smbfile_read_by_data(RB_SMBFILE_DATA *data)
{
  smbc_read_fn fn;
  ssize_t read_size;
  char *buffer = data->buffer + data->buffer_used_size;
  size_t buffer_size = data->buffer_size - data->buffer_used_size;

  if (buffer_size == 0) {
    /* Buffer is full */
    if (data->buffer_pos < data->buffer_used_size) {
      /* But remained data exists */
      return;
    }

    /* Rewind */
    data->buffer_used_size = 0;
    data->buffer_pos = 0;
    buffer = data->buffer;
    buffer_size = data->buffer_size;
  }

  fn = smbc_getFunctionRead(data->smbcctx);

try:
  read_size = (*fn)(data->smbcctx, data->smbcfile, buffer, buffer_size);
  if (read_size < 0) {
    if (errno != EBADF) {
      rb_sys_fail("Bad SMBCFILE");
    }
    else {
      rb_smbfile_reopen_by_data(data);
      goto try;
    }
  }

  data->buffer_used_size += read_size;
  data->eof = (read_size == 0);
}

static VALUE rb_smbfile_close(VALUE self);

static VALUE rb_smbfile_initialize(int argc, VALUE *argv, VALUE self)
{
  RB_SMBFILE_DATA_FROM_OBJ(self, data);
  VALUE smb_obj, url_obj, mode_obj;

  rb_scan_args(argc, argv, "21", &smb_obj, &url_obj, &mode_obj);
  RB_SMB_DATA_FROM_OBJ(smb_obj, smb_data);

  if (NIL_P(mode_obj)) {
    data->fmode = FMODE_READABLE;
    // FIXME data->fmode = FMODE_READABLE | DEFAULT_TEXTMODE;
    data->oflags = O_RDONLY;
  }
  else if (FIXNUM_P(mode_obj)) {
    rb_raise(rb_eArgError, "FIXME");
    data->fmode = 0;
    data->oflags = NUM2INT(mode_obj);
  }
  else {
    const char *mode_str = StringValueCStr(mode_obj);
    data->fmode = rb_io_modestr_fmode(mode_str);
    data->oflags = rb_io_modestr_oflags(mode_str);
  }

  data->smb_obj = smb_obj;
  data->smb_data = smb_data;
  data->smbcctx = smb_data->smbcctx;
  data->url = ruby_strdup(RSTRING_PTR(url_obj));

  data->buffer = ruby_xmalloc(RB_SMBFILE_BUFFER_SIZE);
  data->buffer_size = RB_SMBFILE_BUFFER_SIZE;

  rb_smbfile_open_by_data(data);

  if (rb_block_given_p()) {
    return rb_ensure(rb_yield, self, rb_smbfile_close, self);
  }

  return self;
}