static void rb_smbfile_open_by_data(RB_SMBFILE_DATA *data) { smbc_open_fn fn = smbc_getFunctionOpen(data->smbcctx); data->smbcfile = (*fn)(data->smbcctx, data->url, data->oflags, data->fmode); if (data->smbcfile == NULL) { rb_sys_fail(data->url); } RB_SMB_DEBUG("smbcctx=%p smbcfile=%p\n", data->smbcctx, data->smbcfile); }
int SmbFs::fs_open(const char *path, struct fuse_file_info *fi) { QMutexLocker locker(&_mutex); SMBCFILE *file = (smbc_getFunctionOpen(_ctx))(_ctx, qPrintable(getPath(path)),fi->flags,0); if(file != NULL) { fi->fh = (unsigned long)file; return(0); } else return(-errno); }
static PyObject * Context_open (Context *self, PyObject *args) { PyObject *largs, *lkwlist; char *uri; File *file; int flags = 0; int mode = 0; smbc_open_fn fn; debugprintf ("%p -> Context_open()\n", self->context); if (!PyArg_ParseTuple (args, "s|ii", &uri, &flags, &mode)) { debugprintf ("%p <- Context_open() EXCEPTION\n", self->context); return NULL; } largs = Py_BuildValue ("()"); lkwlist = PyDict_New (); PyDict_SetItemString (lkwlist, "context", (PyObject *) self); file = (File *)smbc_FileType.tp_new (&smbc_FileType, largs, lkwlist); if (!file) { return PyErr_NoMemory (); } if (smbc_FileType.tp_init ((PyObject *)file, largs, lkwlist) < 0) { smbc_FileType.tp_dealloc ((PyObject *)file); debugprintf ("%p <- Context_open() EXCEPTION\n", self->context); // already set error return NULL; } fn = smbc_getFunctionOpen (self->context); errno = 0; file->file = (*fn) (self->context, uri, (int)flags, (mode_t)mode); if (!file->file) { pysmbc_SetFromErrno (); smbc_FileType.tp_dealloc ((PyObject *)file); file = NULL; } Py_DECREF (largs); Py_DECREF (lkwlist); debugprintf ("%p <- Context_open() = File\n", self->context); return (PyObject *)file; }
SMBCFILE * SMBC_open_print_job_ctx(SMBCCTX *context, const char *fname) { char *server = NULL; char *share = NULL; char *user = NULL; char *password = NULL; char *path = NULL; TALLOC_CTX *frame = talloc_stackframe(); if (!context || !context->internal->initialized) { errno = EINVAL; TALLOC_FREE(frame); return NULL; } if (!fname) { errno = EINVAL; TALLOC_FREE(frame); return NULL; } DEBUG(4, ("SMBC_open_print_job_ctx(%s)\n", fname)); if (SMBC_parse_path(frame, context, fname, NULL, &server, &share, &path, &user, &password, NULL)) { errno = EINVAL; TALLOC_FREE(frame); return NULL; } /* What if the path is empty, or the file exists? */ TALLOC_FREE(frame); return smbc_getFunctionOpen(context)(context, fname, O_WRONLY, 666); }
int smbc_open(const char *furl, int flags, mode_t mode) { SMBCFILE * file; int fd; file = smbc_getFunctionOpen(statcont)(statcont, furl, flags, mode); if (!file) return -1; fd = add_fd(file); if (fd == -1) smbc_getFunctionClose(statcont)(statcont, file); return fd; }
/* * 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; }
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; }