summaryrefslogtreecommitdiffstats
path: root/source3/include/libsmbclient.h
diff options
context:
space:
mode:
Diffstat (limited to 'source3/include/libsmbclient.h')
-rw-r--r--source3/include/libsmbclient.h248
1 files changed, 234 insertions, 14 deletions
diff --git a/source3/include/libsmbclient.h b/source3/include/libsmbclient.h
index e343b876d3..f269563996 100644
--- a/source3/include/libsmbclient.h
+++ b/source3/include/libsmbclient.h
@@ -1,9 +1,11 @@
/*=====================================================================
- Unix SMB/CIFS implementation.
+ Unix SMB/Netbios implementation.
SMB client library API definitions
Copyright (C) Andrew Tridgell 1998
Copyright (C) Richard Sharpe 2000
Copyright (C) John Terpsra 2000
+ Copyright (C) Tom Jansen (Ninja ISD) 2002
+
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -93,30 +95,28 @@ struct smbc_dirent
SMBC_DIR=7,
SMBC_FILE=8,
SMBC_LINK=9,*/
- uint smbc_type;
+ unsigned int smbc_type;
/** Length of this smbc_dirent in bytes
*/
- uint dirlen;
+ unsigned int dirlen;
/** The length of the comment string in bytes (includes null
* terminator)
*/
- uint commentlen;
+ unsigned int commentlen;
/** Points to the null terminated comment string
*/
char *comment;
/** The length of the name string in bytes (includes null
* terminator)
*/
- uint namelen;
+ unsigned int namelen;
/** Points to the null terminated name string
*/
char name[1];
};
-
#ifndef _CLIENT_H
-typedef unsigned short uint16;
/**@ingroup structure
* Structure that represents a print job.
@@ -126,11 +126,11 @@ struct print_job_info
{
/** numeric ID of the print job
*/
- uint16 id;
+ unsigned short id;
/** represents print job priority (lower numbers mean higher priority)
*/
- uint16 priority;
+ unsigned short priority;
/** Size of the print job
*/
@@ -149,8 +149,7 @@ struct print_job_info
*/
time_t t;
};
-#endif
-
+#endif /* ifndef _CLIENT_H */
/**@ingroup structure
* Authentication callback function type.
@@ -196,6 +195,227 @@ typedef void (*smbc_get_auth_data_fn)(const char *srv,
*/
typedef void (*smbc_get_print_job_info)(struct print_job_info *i);
+typedef struct _SMBCSRV {
+ struct cli_state cli;
+ dev_t dev;
+ BOOL no_pathinfo2;
+ int server_fd;
+
+ struct _SMBCSRV *next, *prev;
+
+} SMBCSRV;
+
+/*
+ * Keep directory entries in a list
+ */
+struct smbc_dir_list {
+ struct smbc_dir_list *next;
+ struct smbc_dirent *dirent;
+};
+
+/*
+ * Structure for open file management
+ */
+typedef struct _SMBCFILE {
+ int cli_fd;
+ char *fname;
+ off_t offset;
+ SMBCSRV *srv;
+ BOOL file;
+ struct smbc_dir_list *dir_list, *dir_end, *dir_next;
+ int dir_type, dir_error;
+
+ struct _SMBCFILE *next, *prev;
+} SMBCFILE;
+
+/**@ingroup structure
+ * Structure that contains a client context information
+ */
+typedef struct _SMBCCTX {
+ /** debug level
+ */
+ int debug;
+
+ /** netbios name used for making connections
+ */
+ char * netbios_name;
+
+ /** workgroup name used for making connections
+ */
+ char * workgroup;
+
+ /** username used for making connections
+ */
+ char * user;
+
+ /** timeout used for waiting on connections / response data (in milliseconds)
+ */
+ int timeout;
+
+ /** callable functions for files:
+ * For usage and return values see the smbc_* functions
+ */
+ SMBCFILE * (*open) (struct _SMBCCTX *c, const char *fname, int flags, mode_t mode);
+ SMBCFILE * (*creat) (struct _SMBCCTX *c, const char *path, mode_t mode);
+ ssize_t (*read) (struct _SMBCCTX *c, SMBCFILE *file, void *buf, size_t count);
+ ssize_t (*write) (struct _SMBCCTX *c, SMBCFILE *file, void *buf, size_t count);
+ int (*unlink) (struct _SMBCCTX *c, const char *fname);
+ int (*rename) (struct _SMBCCTX *ocontext, const char *oname,
+ struct _SMBCCTX *ncontext, const char *nname);
+ off_t (*lseek) (struct _SMBCCTX *c, SMBCFILE * file, off_t offset, int whence);
+ int (*stat) (struct _SMBCCTX *c, const char *fname, struct stat *st);
+ int (*fstat) (struct _SMBCCTX *c, SMBCFILE *file, struct stat *st);
+ int (*close) (struct _SMBCCTX *c, SMBCFILE *file);
+
+ /** callable functions for dirs
+ */
+ SMBCFILE * (*opendir) (struct _SMBCCTX *c, const char *fname);
+ int (*closedir)(struct _SMBCCTX *c, SMBCFILE *dir);
+ struct smbc_dirent * (*readdir)(struct _SMBCCTX *c, SMBCFILE *dir);
+ int (*getdents)(struct _SMBCCTX *c, SMBCFILE *dir,
+ struct smbc_dirent *dirp, int count);
+ int (*mkdir) (struct _SMBCCTX *c, const char *fname, mode_t mode);
+ int (*rmdir) (struct _SMBCCTX *c, const char *fname);
+ off_t (*telldir) (struct _SMBCCTX *c, SMBCFILE *dir);
+ int (*lseekdir)(struct _SMBCCTX *c, SMBCFILE *dir, off_t offset);
+ int (*fstatdir)(struct _SMBCCTX *c, SMBCFILE *dir, struct stat *st);
+
+ /** callable functions for printing
+ */
+ int (*print_file)(struct _SMBCCTX *c_file, const char *fname,
+ struct _SMBCCTX *c_print, const char *printq);
+ SMBCFILE * (*open_print_job)(struct _SMBCCTX *c, const char *fname);
+ int (*list_print_jobs)(struct _SMBCCTX *c, const char *fname, void (*fn)(struct print_job_info *));
+ int (*unlink_print_job)(struct _SMBCCTX *c, const char *fname, int id);
+
+
+ /** Callbacks
+ * These callbacks _always_ have to be intialized because they will not be checked
+ * at dereference for increased speed.
+ */
+ struct _smbc_callbacks {
+ /** authentication function callback: called upon auth requests
+ */
+ smbc_get_auth_data_fn auth_fn;
+
+ /** check if a server is still good
+ */
+ int (*check_server_fn)(struct _SMBCCTX * c, SMBCSRV *srv);
+
+ /** remove a server if unused
+ */
+ int (*remove_unused_server_fn)(struct _SMBCCTX * c, SMBCSRV *srv);
+
+ /** Cache subsystem
+ * For an example cache system see samba/source/libsmb/libsmb_cache.c
+ * Cache subsystem functions follow.
+ */
+
+ /** server cache addition
+ */
+ int (*add_cached_srv_fn) (struct _SMBCCTX * c, SMBCSRV *srv,
+ char * server, char * share,
+ char * workgroup, char * username);
+ /** server cache lookup
+ */
+ SMBCSRV * (*get_cached_srv_fn) (struct _SMBCCTX * c, char * server,
+ char * share, char * workgroup, char * username);
+ /** server cache removal
+ */
+ int (*remove_cached_srv_fn)(struct _SMBCCTX * c, SMBCSRV *srv);
+
+ /** server cache purging, try to remove all cached servers (disconnect)
+ */
+ int (*purge_cached_fn) (struct _SMBCCTX * c);
+
+ } callbacks;
+
+
+ /** Space to store private data of the server cache.
+ */
+ void * server_cache;
+
+ /** INTERNAL functions
+ * do _NOT_ touch these from your program !
+ */
+
+ /** INTERNAL: is this handle initialized ?
+ */
+ int _initialized;
+
+ /** INTERNAL: dirent pointer location
+ */
+ char _dirent[512];
+
+ /** INTERNAL: server connection list
+ */
+ SMBCSRV * _servers;
+
+ /** INTERNAL: open file/dir list
+ */
+ SMBCFILE * _files;
+
+} SMBCCTX;
+
+
+/**@ingroup misc
+ * Create a new SBMCCTX (a context).
+ *
+ * Must be called before the context is passed to smbc_context_init()
+ *
+ * @return The given SMBCCTX pointer on success, NULL on error with errno set:
+ * - ENOMEM Out of memory
+ *
+ * @see smbc_free_context(), smbc_init_context()
+ *
+ * @note Do not forget to smbc_init_context() the returned SMBCCTX pointer !
+ */
+SMBCCTX * smbc_new_context(void);
+
+/**@ingroup misc
+ * Delete a SBMCCTX (a context) acquired from smbc_new_context().
+ *
+ * The context will be deleted if possible.
+ *
+ * @param context A pointer to a SMBCCTX obtained from smbc_new_context()
+ *
+ * @param shutdown_ctx If 1, all connections and files will be closed even if they are busy.
+ *
+ *
+ * @return Returns 0 on succes. Returns 1 on failure with errno set:
+ * - EBUSY Server connections are still used, Files are open or cache
+ * could not be purged
+ * - EBADF context == NULL
+ *
+ * @see smbc_new_context()
+ *
+ * @note It is advised to clean up all the contexts with shutdown_ctx set to 1
+ * just before exit()'ing. When shutdown_ctx is 0, this function can be
+ * use in periodical cleanup functions for example.
+ */
+int smbc_free_context(SMBCCTX * context, int shutdown_ctx);
+
+
+/**@ingroup misc
+ * Initialize a SBMCCTX (a context).
+ *
+ * Must be called before using any SMBCCTX API function
+ *
+ * @param context A pointer to a SMBCCTX obtained from smbc_new_context()
+ *
+ * @return A pointer to the given SMBCCTX on success, NULL on error with errno set:
+ * - EBADF NULL context given
+ * - ENOMEM Out of memory
+ * - ENOENT The smb.conf file would not load
+ *
+ * @see smbc_new_context()
+ *
+ * @note my_context = smbc_init_context(smbc_new_context()) is perfectly safe,
+ * but it might leak memory on smbc_context_init() failure. Avoid this.
+ * You'll have to call smbc_free_context() yourself on failure.
+ */
+
+SMBCCTX * smbc_init_context(SMBCCTX * context);
/**@ingroup misc
* Initialize the samba client library.
@@ -214,8 +434,8 @@ typedef void (*smbc_get_print_job_info)(struct print_job_info *i);
* - ENOENT The smb.conf file would not load
*
*/
-int smbc_init(smbc_get_auth_data_fn fn, int debug);
+int smbc_init(smbc_get_auth_data_fn fn, int debug);
/**@ingroup file
* Open a file on an SMB server.
@@ -268,8 +488,8 @@ int smbc_init(smbc_get_auth_data_fn fn, int debug);
* try again with an empty username and password. This
* often gets mapped to the guest account on some machines.
*/
-int smbc_open(const char *furl, int flags, mode_t mode);
+int smbc_open(const char *furl, int flags, mode_t mode);
/**@ingroup file
* Create a file on an SMB server.
@@ -302,8 +522,8 @@ int smbc_open(const char *furl, int flags, mode_t mode);
* @see smbc_open()
*
*/
-int smbc_creat(const char *furl, mode_t mode);
+int smbc_creat(const char *furl, mode_t mode);
/**@ingroup file
* Read from a file using an opened file handle.