예제 #1
0
int
smbc_close(int fd)
{
	SMBCFILE * file = find_fd(fd);
	del_fd(fd);
        return smbc_getFunctionClose(statcont)(statcont, file);
}
예제 #2
0
int SmbFs::fs_release(const char *, struct fuse_file_info *fi)
{
	QMutexLocker locker(&_mutex);
	
	if((smbc_getFunctionClose(_ctx))(_ctx, (SMBCFILE *)fi->fh) == 0)
		return(0);
	else
		return(-errno);
}
예제 #3
0
static void rb_smbfile_close_by_data(RB_SMBFILE_DATA *data)
{
  if (data->smbcfile == NULL) {
    rb_raise(rb_eIOError, "Closed file object");
  }

  smbc_close_fn fn = smbc_getFunctionClose(data->smbcctx);

  if ((*fn)(data->smbcctx, data->smbcfile) != 0) {
    rb_sys_fail(data->url);
  }
}
예제 #4
0
int SmbFs::fs_mknod(const char *path, mode_t mode, dev_t dev)
{
	QMutexLocker locker(&_mutex);

	SMBCFILE *file;
	
	if(( file = (smbc_getFunctionCreat(_ctx))(_ctx, qPrintable(getPath(path)),mode) ) != NULL)
	{
		(smbc_getFunctionClose(_ctx))(_ctx, file);
		return(0);
	}
	else
		return(-errno);
}
예제 #5
0
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;
}
예제 #6
0
int
smbc_creat(const char *furl,
           mode_t mode)
{
	SMBCFILE * file;
	int fd;
        
        file = smbc_getFunctionCreat(statcont)(statcont, furl, mode);
	if (!file)
		return -1;
        
	fd = add_fd(file);
	if (fd == -1) {
		/* Hmm... should we delete the file too ? I guess we could try */
                smbc_getFunctionClose(statcont)(statcont, file);
                smbc_getFunctionUnlink(statcont)(statcont, furl);
	}
	return fd;
}
예제 #7
0
/*
 * Free a context
 *
 * Returns 0 on success. Otherwise returns 1, the SMBCCTX is _not_ freed
 * and thus you'll be leaking memory if not handled properly.
 *
 */
int
smbc_free_context(SMBCCTX *context,
                  int shutdown_ctx)
{
        if (!context) {
                errno = EBADF;
                return 1;
        }
        
        if (shutdown_ctx) {
                SMBCFILE * f;
                DEBUG(1,("Performing aggressive shutdown.\n"));
                
                f = context->internal->files;
                while (f) {
                        smbc_getFunctionClose(context)(context, f);
                        f = f->next;
                }
                context->internal->files = NULL;
                
                /* First try to remove the servers the nice way. */
                if (smbc_getFunctionPurgeCachedServers(context)(context)) {
                        SMBCSRV * s;
                        SMBCSRV * next;
                        DEBUG(1, ("Could not purge all servers, "
                                  "Nice way shutdown failed.\n"));
                        s = context->internal->servers;
                        while (s) {
                                DEBUG(1, ("Forced shutdown: %p (fd=%d)\n",
                                          s, s->cli->fd));
                                cli_shutdown(s->cli);
                                smbc_getFunctionRemoveCachedServer(context)(context,
                                                                         s);
                                next = s->next;
                                DLIST_REMOVE(context->internal->servers, s);
                                SAFE_FREE(s);
                                s = next;
                        }
                        context->internal->servers = NULL;
                }
        }
        else {
                /* This is the polite way */
                if (smbc_getFunctionPurgeCachedServers(context)(context)) {
                        DEBUG(1, ("Could not purge all servers, "
                                  "free_context failed.\n"));
                        errno = EBUSY;
                        return 1;
                }
                if (context->internal->servers) {
                        DEBUG(1, ("Active servers in context, "
                                  "free_context failed.\n"));
                        errno = EBUSY;
                        return 1;
                }
                if (context->internal->files) {
                        DEBUG(1, ("Active files in context, "
                                  "free_context failed.\n"));
                        errno = EBUSY;
                        return 1;
                }
        }
        
        /* Things we have to clean up */
        free(smbc_getWorkgroup(context));
        smbc_setWorkgroup(context, NULL);

        free(smbc_getNetbiosName(context));
        smbc_setNetbiosName(context, NULL);

        free(smbc_getUser(context));
        smbc_setUser(context, NULL);
        
        DEBUG(3, ("Context %p successfully freed\n", context));

	/* Free any DFS auth context. */
	TALLOC_FREE(context->internal->auth_info);

	SAFE_FREE(context->internal);
        SAFE_FREE(context);

        /* Protect access to the count of contexts in use */
	if (SMB_THREAD_LOCK(initialized_ctx_count_mutex) != 0) {
                smb_panic("error locking 'initialized_ctx_count'");
	}

	if (initialized_ctx_count) {
		initialized_ctx_count--;
	}

	if (initialized_ctx_count == 0) {
            SMBC_module_terminate();
	}

        /* Unlock the mutex */
	if (SMB_THREAD_UNLOCK(initialized_ctx_count_mutex) != 0) {
                smb_panic("error unlocking 'initialized_ctx_count'");
	}
        
        return 0;
}
예제 #8
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;
        
}
예제 #9
0
/*
 * Free a context
 *
 * Returns 0 on success. Otherwise returns 1, the SMBCCTX is _not_ freed
 * and thus you'll be leaking memory if not handled properly.
 *
 */
int
smbc_free_context(SMBCCTX *context,
                  int shutdown_ctx)
{
        if (!context) {
                errno = EBADF;
                return 1;
        }
        
        if (shutdown_ctx) {
                SMBCFILE * f;
                DEBUG(1,("Performing aggressive shutdown.\n"));
                
                f = context->internal->files;
                while (f) {
                        smbc_getFunctionClose(context)(context, f);
                        f = f->next;
                }
                context->internal->files = NULL;
                
                /* First try to remove the servers the nice way. */
                if (smbc_getFunctionPurgeCachedServers(context)(context)) {
                        SMBCSRV * s;
                        SMBCSRV * next;
                        DEBUG(1, ("Could not purge all servers, "
                                  "Nice way shutdown failed.\n"));
                        s = context->internal->servers;
                        while (s) {
                                DEBUG(1, ("Forced shutdown: %p (fd=%d)\n",
                                          s, s->cli->fd));
                                cli_shutdown(s->cli);
                                smbc_getFunctionRemoveCachedServer(context)(context,
                                                                         s);
                                next = s->next;
                                DLIST_REMOVE(context->internal->servers, s);
                                SAFE_FREE(s);
                                s = next;
                        }
                        context->internal->servers = NULL;
                }
        }
        else {
                /* This is the polite way */
                if (smbc_getFunctionPurgeCachedServers(context)(context)) {
                        DEBUG(1, ("Could not purge all servers, "
                                  "free_context failed.\n"));
                        errno = EBUSY;
                        return 1;
                }
                if (context->internal->servers) {
                        DEBUG(1, ("Active servers in context, "
                                  "free_context failed.\n"));
                        errno = EBUSY;
                        return 1;
                }
                if (context->internal->files) {
                        DEBUG(1, ("Active files in context, "
                                  "free_context failed.\n"));
                        errno = EBUSY;
                        return 1;
                }
        }
        
        /* Things we have to clean up */
        free(smbc_getWorkgroup(context));
        smbc_setWorkgroup(context, NULL);

        free(smbc_getNetbiosName(context));
        smbc_setNetbiosName(context, NULL);

        free(smbc_getUser(context));
        smbc_setUser(context, NULL);
        
        DEBUG(3, ("Context %p successfully freed\n", context));

	SAFE_FREE(context->internal);
        SAFE_FREE(context);

	if (initialized_ctx_count) {
		initialized_ctx_count--;
	}

	if (initialized_ctx_count == 0 && SMBC_initialized) {
		gencache_shutdown();
		secrets_shutdown();
		gfree_all();
		SMBC_initialized = false;
	}
        return 0;
}