Add function for mapping NDR error codes to strings.
[Samba/ekacnet.git] / source3 / include / libsmbclient.h
blobb2d9483a0b9ad9098a7ed143dae521ec0012aaf4
1 /*=====================================================================
2 Unix SMB/Netbios implementation.
3 SMB client library API definitions
4 Copyright (C) Andrew Tridgell 1998
5 Copyright (C) Richard Sharpe 2000
6 Copyright (C) John Terpsra 2000
7 Copyright (C) Tom Jansen (Ninja ISD) 2002
8 Copyright (C) Derrell Lipman 2003-2008
11 This program is free software; you can redistribute it and/or modify
12 it under the terms of the GNU General Public License as published by
13 the Free Software Foundation; either version 3 of the License, or
14 (at your option) any later version.
16 This program is distributed in the hope that it will be useful,
17 but WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 GNU General Public License for more details.
21 You should have received a copy of the GNU General Public License
22 along with this program; if not, see <http://www.gnu.org/licenses/>.
23 =====================================================================*/
25 #ifndef SMBCLIENT_H_INCLUDED
26 #define SMBCLIENT_H_INCLUDED
28 #undef DEPRECATED_SMBC_INTERFACE
29 #if ! defined(__LIBSMBCLIENT_INTERNAL__) && defined(__GNUC__)
30 # define DEPRECATED_SMBC_INTERFACE __attribute__ ((deprecated))
31 #else
32 # define DEPRECATED_SMBC_INTERFACE
33 #endif
35 #ifdef __cplusplus
36 extern "C" {
37 #endif
39 /*-------------------------------------------------------------------*/
40 /* The following are special comments to instruct DOXYGEN (automated
41 * documentation tool:
43 /** \defgroup libsmbclient
45 /** \defgroup structure Data Structures Type and Constants
46 * \ingroup libsmbclient
47 * Data structures, types, and constants
49 /** \defgroup callback Callback function types
50 * \ingroup libsmbclient
51 * Callback functions
53 /** \defgroup file File Functions
54 * \ingroup libsmbclient
55 * Functions used to access individual file contents
57 /** \defgroup directory Directory Functions
58 * \ingroup libsmbclient
59 * Functions used to access directory entries
61 /** \defgroup attribute Attributes Functions
62 * \ingroup libsmbclient
63 * Functions used to view or change file and directory attributes
65 /** \defgroup print Print Functions
66 * \ingroup libsmbclient
67 * Functions used to access printing functionality
69 /** \defgroup misc Miscellaneous Functions
70 * \ingroup libsmbclient
71 * Functions that don't fit in to other categories
73 /*-------------------------------------------------------------------*/
75 /* Make sure we have the following includes for now ... */
76 #include <sys/types.h>
77 #include <sys/stat.h>
78 #include <fcntl.h>
79 #include <utime.h>
81 #define SMBC_BASE_FD 10000 /* smallest file descriptor returned */
83 #define SMBC_WORKGROUP 1
84 #define SMBC_SERVER 2
85 #define SMBC_FILE_SHARE 3
86 #define SMBC_PRINTER_SHARE 4
87 #define SMBC_COMMS_SHARE 5
88 #define SMBC_IPC_SHARE 6
89 #define SMBC_DIR 7
90 #define SMBC_FILE 8
91 #define SMBC_LINK 9
93 /**@ingroup structure
94 * Structure that represents a directory entry.
97 struct smbc_dirent
99 /** Type of entity.
100 SMBC_WORKGROUP=1,
101 SMBC_SERVER=2,
102 SMBC_FILE_SHARE=3,
103 SMBC_PRINTER_SHARE=4,
104 SMBC_COMMS_SHARE=5,
105 SMBC_IPC_SHARE=6,
106 SMBC_DIR=7,
107 SMBC_FILE=8,
108 SMBC_LINK=9,*/
109 unsigned int smbc_type;
111 /** Length of this smbc_dirent in bytes
113 unsigned int dirlen;
114 /** The length of the comment string in bytes (does not include
115 * null terminator)
117 unsigned int commentlen;
118 /** Points to the null terminated comment string
120 char *comment;
121 /** The length of the name string in bytes (does not include
122 * null terminator)
124 unsigned int namelen;
125 /** Points to the null terminated name string
127 char name[1];
131 * Flags for smbc_setxattr()
132 * Specify a bitwise OR of these, or 0 to add or replace as necessary
134 #define SMBC_XATTR_FLAG_CREATE 0x1 /* fail if attr already exists */
135 #define SMBC_XATTR_FLAG_REPLACE 0x2 /* fail if attr does not exist */
139 * Mappings of the DOS mode bits, as returned by smbc_getxattr() when the
140 * attribute name "system.dos_attr.mode" (or "system.dos_attr.*" or
141 * "system.*") is specified.
143 #define SMBC_DOS_MODE_READONLY 0x01
144 #define SMBC_DOS_MODE_HIDDEN 0x02
145 #define SMBC_DOS_MODE_SYSTEM 0x04
146 #define SMBC_DOS_MODE_VOLUME_ID 0x08
147 #define SMBC_DOS_MODE_DIRECTORY 0x10
148 #define SMBC_DOS_MODE_ARCHIVE 0x20
151 * Valid values for the option "open_share_mode", when calling
152 * smbc_setOptionOpenShareMode()
154 typedef enum smbc_share_mode
156 SMBC_SHAREMODE_DENY_DOS = 0,
157 SMBC_SHAREMODE_DENY_ALL = 1,
158 SMBC_SHAREMODE_DENY_WRITE = 2,
159 SMBC_SHAREMODE_DENY_READ = 3,
160 SMBC_SHAREMODE_DENY_NONE = 4,
161 SMBC_SHAREMODE_DENY_FCB = 7
162 } smbc_share_mode;
166 * Values for option SMB Encryption Level, as set and retrieved with
167 * smbc_setOptionSmbEncryptionLevel() and smbc_getOptionSmbEncryptionLevel()
169 typedef enum smbc_smb_encrypt_level
171 SMBC_ENCRYPTLEVEL_NONE = 0,
172 SMBC_ENCRYPTLEVEL_REQUEST = 1,
173 SMBC_ENCRYPTLEVEL_REQUIRE = 2
174 } smbc_smb_encrypt_level;
177 typedef int smbc_bool;
180 #ifndef ENOATTR
181 # define ENOATTR ENOENT /* No such attribute */
182 #endif
187 /**@ingroup structure
188 * Structure that represents a print job.
191 #ifndef _CLIENT_H
192 struct print_job_info
194 /** numeric ID of the print job
196 unsigned short id;
198 /** represents print job priority (lower numbers mean higher priority)
200 unsigned short priority;
202 /** Size of the print job
204 size_t size;
206 /** Name of the user that owns the print job
208 char user[128];
210 /** Name of the print job. This will have no name if an anonymous print
211 * file was opened. Ie smb://server/printer
213 char name[128];
215 /** Time the print job was spooled
217 time_t t;
219 #endif /* _CLIENT_H */
222 /**@ingroup structure
223 * Server handle
225 typedef struct _SMBCSRV SMBCSRV;
227 /**@ingroup structure
228 * File or directory handle
230 typedef struct _SMBCFILE SMBCFILE;
232 /**@ingroup structure
233 * File or directory handle
235 typedef struct _SMBCCTX SMBCCTX;
239 * Flags for SMBCCTX->flags
241 * NEW CODE SHOULD NOT DIRECTLY MANIPULATE THE CONTEXT STRUCTURE.
242 * Instead, use:
243 * smbc_setOptionUseKerberos()
244 * smbc_getOptionUseKerberos()
245 * smbc_setOptionFallbackAfterKerberos()
246 * smbc_getOptionFallbackAFterKerberos()
247 * smbc_setOptionNoAutoAnonymousLogin()
248 * smbc_getOptionNoAutoAnonymousLogin()
250 # define SMB_CTX_FLAG_USE_KERBEROS (1 << 0)
251 # define SMB_CTX_FLAG_FALLBACK_AFTER_KERBEROS (1 << 1)
252 # define SMBCCTX_FLAG_NO_AUTO_ANONYMOUS_LOGON (1 << 2)
256 /**@ingroup callback
257 * Authentication callback function type (traditional method)
259 * Type for the the authentication function called by the library to
260 * obtain authentication credentals
262 * For kerberos support the function should just be called without
263 * prompting the user for credentials. Which means a simple 'return'
264 * should work. Take a look at examples/libsmbclient/get_auth_data_fn.h
265 * and examples/libsmbclient/testbrowse.c.
267 * @param srv Server being authenticated to
269 * @param shr Share being authenticated to
271 * @param wg Pointer to buffer containing a "hint" for the
272 * workgroup to be authenticated. Should be filled in
273 * with the correct workgroup if the hint is wrong.
275 * @param wglen The size of the workgroup buffer in bytes
277 * @param un Pointer to buffer containing a "hint" for the
278 * user name to be use for authentication. Should be
279 * filled in with the correct workgroup if the hint is
280 * wrong.
282 * @param unlen The size of the username buffer in bytes
284 * @param pw Pointer to buffer containing to which password
285 * copied
287 * @param pwlen The size of the password buffer in bytes
290 typedef void (*smbc_get_auth_data_fn)(const char *srv,
291 const char *shr,
292 char *wg, int wglen,
293 char *un, int unlen,
294 char *pw, int pwlen);
295 /**@ingroup callback
296 * Authentication callback function type (method that includes context)
298 * Type for the the authentication function called by the library to
299 * obtain authentication credentals
301 * For kerberos support the function should just be called without
302 * prompting the user for credentials. Which means a simple 'return'
303 * should work. Take a look at examples/libsmbclient/get_auth_data_fn.h
304 * and examples/libsmbclient/testbrowse.c.
306 * @param c Pointer to the smb context
308 * @param srv Server being authenticated to
310 * @param shr Share being authenticated to
312 * @param wg Pointer to buffer containing a "hint" for the
313 * workgroup to be authenticated. Should be filled in
314 * with the correct workgroup if the hint is wrong.
316 * @param wglen The size of the workgroup buffer in bytes
318 * @param un Pointer to buffer containing a "hint" for the
319 * user name to be use for authentication. Should be
320 * filled in with the correct workgroup if the hint is
321 * wrong.
323 * @param unlen The size of the username buffer in bytes
325 * @param pw Pointer to buffer containing to which password
326 * copied
328 * @param pwlen The size of the password buffer in bytes
331 typedef void (*smbc_get_auth_data_with_context_fn)(SMBCCTX *c,
332 const char *srv,
333 const char *shr,
334 char *wg, int wglen,
335 char *un, int unlen,
336 char *pw, int pwlen);
339 /**@ingroup callback
340 * Print job info callback function type.
342 * @param i pointer to print job information structure
345 typedef void (*smbc_list_print_job_fn)(struct print_job_info *i);
348 /**@ingroup callback
349 * Check if a server is still good
351 * @param c pointer to smb context
353 * @param srv pointer to server to check
355 * @return 0 when connection is good. 1 on error.
358 typedef int (*smbc_check_server_fn)(SMBCCTX * c, SMBCSRV *srv);
360 /**@ingroup callback
361 * Remove a server if unused
363 * @param c pointer to smb context
365 * @param srv pointer to server to remove
367 * @return 0 on success. 1 on failure.
370 typedef int (*smbc_remove_unused_server_fn)(SMBCCTX * c, SMBCSRV *srv);
373 /**@ingroup callback
374 * Add a server to the cache system
376 * @param c pointer to smb context
378 * @param srv pointer to server to add
380 * @param server server name
382 * @param share share name
384 * @param workgroup workgroup used to connect
386 * @param username username used to connect
388 * @return 0 on success. 1 on failure.
391 typedef int (*smbc_add_cached_srv_fn) (SMBCCTX * c, SMBCSRV *srv,
392 const char * server, const char * share,
393 const char * workgroup, const char * username);
395 /**@ingroup callback
396 * Look up a server in the cache system
398 * @param c pointer to smb context
400 * @param server server name to match
402 * @param share share name to match
404 * @param workgroup workgroup to match
406 * @param username username to match
408 * @return pointer to SMBCSRV on success. NULL on failure.
411 typedef SMBCSRV * (*smbc_get_cached_srv_fn) (SMBCCTX * c, const char * server,
412 const char * share, const char * workgroup,
413 const char * username);
415 /**@ingroup callback
416 * Check if a server is still good
418 * @param c pointer to smb context
420 * @param srv pointer to server to remove
422 * @return 0 when found and removed. 1 on failure.
425 typedef int (*smbc_remove_cached_srv_fn)(SMBCCTX * c, SMBCSRV *srv);
428 /**@ingroup callback
429 * Try to remove all servers from the cache system and disconnect
431 * @param c pointer to smb context
433 * @return 0 when found and removed. 1 on failure.
436 typedef int (*smbc_purge_cached_fn) (SMBCCTX * c);
440 /*****************************************
441 * Getters and setters for CONFIGURATION *
442 *****************************************/
444 /** Get the debug level */
446 smbc_getDebug(SMBCCTX *c);
448 /** Set the debug level */
449 void
450 smbc_setDebug(SMBCCTX *c, int debug);
452 /** Get the netbios name used for making connections */
453 char *
454 smbc_getNetbiosName(SMBCCTX *c);
456 /** Set the netbios name used for making connections */
457 void
458 smbc_setNetbiosName(SMBCCTX *c, char * netbios_name);
460 /** Get the workgroup used for making connections */
461 char *
462 smbc_getWorkgroup(SMBCCTX *c);
464 /** Set the workgroup used for making connections */
465 void smbc_setWorkgroup(SMBCCTX *c, char * workgroup);
467 /** Get the username used for making connections */
468 char *
469 smbc_getUser(SMBCCTX *c);
471 /** Set the username used for making connections */
472 void
473 smbc_setUser(SMBCCTX *c, char * user);
476 * Get the timeout used for waiting on connections and response data
477 * (in milliseconds)
480 smbc_getTimeout(SMBCCTX *c);
483 * Set the timeout used for waiting on connections and response data
484 * (in milliseconds)
486 void
487 smbc_setTimeout(SMBCCTX *c, int timeout);
491 /***********************************
492 * Getters and setters for OPTIONS *
493 ***********************************/
495 /** Get whether to log to standard error instead of standard output */
496 smbc_bool
497 smbc_getOptionDebugToStderr(SMBCCTX *c);
499 /** Set whether to log to standard error instead of standard output */
500 void
501 smbc_setOptionDebugToStderr(SMBCCTX *c, smbc_bool b);
504 * Get whether to use new-style time attribute names, e.g. WRITE_TIME rather
505 * than the old-style names such as M_TIME. This allows also setting/getting
506 * CREATE_TIME which was previously unimplemented. (Note that the old C_TIME
507 * was supposed to be CHANGE_TIME but was confused and sometimes referred to
508 * CREATE_TIME.)
510 smbc_bool
511 smbc_getOptionFullTimeNames(SMBCCTX *c);
514 * Set whether to use new-style time attribute names, e.g. WRITE_TIME rather
515 * than the old-style names such as M_TIME. This allows also setting/getting
516 * CREATE_TIME which was previously unimplemented. (Note that the old C_TIME
517 * was supposed to be CHANGE_TIME but was confused and sometimes referred to
518 * CREATE_TIME.)
520 void
521 smbc_setOptionFullTimeNames(SMBCCTX *c, smbc_bool b);
524 * Get the share mode to use for files opened with SMBC_open_ctx(). The
525 * default is SMBC_SHAREMODE_DENY_NONE.
527 smbc_share_mode
528 smbc_getOptionOpenShareMode(SMBCCTX *c);
531 * Set the share mode to use for files opened with SMBC_open_ctx(). The
532 * default is SMBC_SHAREMODE_DENY_NONE.
534 void
535 smbc_setOptionOpenShareMode(SMBCCTX *c, smbc_share_mode share_mode);
537 /** Retrieve a previously saved user data handle */
538 void *
539 smbc_getOptionUserData(SMBCCTX *c);
541 /** Save a user data handle */
542 void
543 smbc_setOptionUserData(SMBCCTX *c, void *user_data);
545 /** Get the encoded value for encryption level. */
546 smbc_smb_encrypt_level
547 smbc_getOptionSmbEncryptionLevel(SMBCCTX *c);
549 /** Set the encoded value for encryption level. */
550 void
551 smbc_setOptionSmbEncryptionLevel(SMBCCTX *c, smbc_smb_encrypt_level level);
554 * Get whether to treat file names as case-sensitive if we can't determine
555 * when connecting to the remote share whether the file system is case
556 * sensitive. This defaults to FALSE since it's most likely that if we can't
557 * retrieve the file system attributes, it's a very old file system that does
558 * not support case sensitivity.
560 smbc_bool
561 smbc_getOptionCaseSensitive(SMBCCTX *c);
564 * Set whether to treat file names as case-sensitive if we can't determine
565 * when connecting to the remote share whether the file system is case
566 * sensitive. This defaults to FALSE since it's most likely that if we can't
567 * retrieve the file system attributes, it's a very old file system that does
568 * not support case sensitivity.
570 void
571 smbc_setOptionCaseSensitive(SMBCCTX *c, smbc_bool b);
575 * Get from how many local master browsers should the list of workgroups be
576 * retrieved. It can take up to 12 minutes or longer after a server becomes a
577 * local master browser, for it to have the entire browse list (the list of
578 * workgroups/domains) from an entire network. Since a client never knows
579 * which local master browser will be found first, the one which is found
580 * first and used to retrieve a browse list may have an incomplete or empty
581 * browse list. By requesting the browse list from multiple local master
582 * browsers, a more complete list can be generated. For small networks (few
583 * workgroups), it is recommended that this value be set to 0, causing the
584 * browse lists from all found local master browsers to be retrieved and
585 * merged. For networks with many workgroups, a suitable value for this
586 * variable is probably somewhere around 3. (Default: 3).
589 smbc_getOptionBrowseMaxLmbCount(SMBCCTX *c);
592 * Set from how many local master browsers should the list of workgroups be
593 * retrieved. It can take up to 12 minutes or longer after a server becomes a
594 * local master browser, for it to have the entire browse list (the list of
595 * workgroups/domains) from an entire network. Since a client never knows
596 * which local master browser will be found first, the one which is found
597 * first and used to retrieve a browse list may have an incomplete or empty
598 * browse list. By requesting the browse list from multiple local master
599 * browsers, a more complete list can be generated. For small networks (few
600 * workgroups), it is recommended that this value be set to 0, causing the
601 * browse lists from all found local master browsers to be retrieved and
602 * merged. For networks with many workgroups, a suitable value for this
603 * variable is probably somewhere around 3. (Default: 3).
605 void
606 smbc_setOptionBrowseMaxLmbCount(SMBCCTX *c, int count);
609 * Get whether to url-encode readdir entries.
611 * There is a difference in the desired return strings from
612 * smbc_readdir() depending upon whether the filenames are to
613 * be displayed to the user, or whether they are to be
614 * appended to the path name passed to smbc_opendir() to call
615 * a further smbc_ function (e.g. open the file with
616 * smbc_open()). In the former case, the filename should be
617 * in "human readable" form. In the latter case, the smbc_
618 * functions expect a URL which must be url-encoded. Those
619 * functions decode the URL. If, for example, smbc_readdir()
620 * returned a file name of "abc%20def.txt", passing a path
621 * with this file name attached to smbc_open() would cause
622 * smbc_open to attempt to open the file "abc def.txt" since
623 * the %20 is decoded into a space.
625 * Set this option to True if the names returned by
626 * smbc_readdir() should be url-encoded such that they can be
627 * passed back to another smbc_ call. Set it to False if the
628 * names returned by smbc_readdir() are to be presented to the
629 * user.
631 * For backwards compatibility, this option defaults to False.
633 smbc_bool
634 smbc_getOptionUrlEncodeReaddirEntries(SMBCCTX *c);
637 * Set whether to url-encode readdir entries.
639 * There is a difference in the desired return strings from
640 * smbc_readdir() depending upon whether the filenames are to
641 * be displayed to the user, or whether they are to be
642 * appended to the path name passed to smbc_opendir() to call
643 * a further smbc_ function (e.g. open the file with
644 * smbc_open()). In the former case, the filename should be
645 * in "human readable" form. In the latter case, the smbc_
646 * functions expect a URL which must be url-encoded. Those
647 * functions decode the URL. If, for example, smbc_readdir()
648 * returned a file name of "abc%20def.txt", passing a path
649 * with this file name attached to smbc_open() would cause
650 * smbc_open to attempt to open the file "abc def.txt" since
651 * the %20 is decoded into a space.
653 * Set this option to True if the names returned by
654 * smbc_readdir() should be url-encoded such that they can be
655 * passed back to another smbc_ call. Set it to False if the
656 * names returned by smbc_readdir() are to be presented to the
657 * user.
659 * For backwards compatibility, this option defaults to False.
661 void
662 smbc_setOptionUrlEncodeReaddirEntries(SMBCCTX *c, smbc_bool b);
665 * Get whether to use the same connection for all shares on a server.
667 * Some Windows versions appear to have a limit to the number
668 * of concurrent SESSIONs and/or TREE CONNECTions. In
669 * one-shot programs (i.e. the program runs and then quickly
670 * ends, thereby shutting down all connections), it is
671 * probably reasonable to establish a new connection for each
672 * share. In long-running applications, the limitation can be
673 * avoided by using only a single connection to each server,
674 * and issuing a new TREE CONNECT when the share is accessed.
676 smbc_bool
677 smbc_getOptionOneSharePerServer(SMBCCTX *c);
680 * Set whether to use the same connection for all shares on a server.
682 * Some Windows versions appear to have a limit to the number
683 * of concurrent SESSIONs and/or TREE CONNECTions. In
684 * one-shot programs (i.e. the program runs and then quickly
685 * ends, thereby shutting down all connections), it is
686 * probably reasonable to establish a new connection for each
687 * share. In long-running applications, the limitation can be
688 * avoided by using only a single connection to each server,
689 * and issuing a new TREE CONNECT when the share is accessed.
691 void
692 smbc_setOptionOneSharePerServer(SMBCCTX *c, smbc_bool b);
694 /** Get whether to enable use of kerberos */
695 smbc_bool
696 smbc_getOptionUseKerberos(SMBCCTX *c);
698 /** Set whether to enable use of kerberos */
699 void
700 smbc_setOptionUseKerberos(SMBCCTX *c, smbc_bool b);
702 /** Get whether to fallback after kerberos */
703 smbc_bool
704 smbc_getOptionFallbackAfterKerberos(SMBCCTX *c);
706 /** Set whether to fallback after kerberos */
707 void
708 smbc_setOptionFallbackAfterKerberos(SMBCCTX *c, smbc_bool b);
710 /** Get whether to automatically select anonymous login */
711 smbc_bool
712 smbc_getOptionNoAutoAnonymousLogin(SMBCCTX *c);
714 /** Set whether to automatically select anonymous login */
715 void
716 smbc_setOptionNoAutoAnonymousLogin(SMBCCTX *c, smbc_bool b);
720 /*************************************
721 * Getters and setters for FUNCTIONS *
722 *************************************/
724 /** Get the function for obtaining authentication data */
725 smbc_get_auth_data_fn smbc_getFunctionAuthData(SMBCCTX *c);
727 /** Set the function for obtaining authentication data */
728 void smbc_setFunctionAuthData(SMBCCTX *c, smbc_get_auth_data_fn fn);
730 /** Get the new-style authentication function which includes the context. */
731 smbc_get_auth_data_with_context_fn
732 smbc_getFunctionAuthDataWithContext(SMBCCTX *c);
734 /** Set the new-style authentication function which includes the context. */
735 void
736 smbc_setFunctionAuthDataWithContext(SMBCCTX *c,
737 smbc_get_auth_data_with_context_fn fn);
739 /** Get the function for checking if a server is still good */
740 smbc_check_server_fn smbc_getFunctionCheckServer(SMBCCTX *c);
742 /** Set the function for checking if a server is still good */
743 void smbc_setFunctionCheckServer(SMBCCTX *c, smbc_check_server_fn fn);
745 /** Get the function for removing a server if unused */
746 smbc_remove_unused_server_fn smbc_getFunctionRemoveUnusedServer(SMBCCTX *c);
748 /** Set the function for removing a server if unused */
749 void smbc_setFunctionRemoveUnusedServer(SMBCCTX *c,
750 smbc_remove_unused_server_fn fn);
752 /** Get the function for adding a cached server */
753 smbc_add_cached_srv_fn smbc_getFunctionAddCachedServer(SMBCCTX *c);
755 /** Set the function for adding a cached server */
756 void smbc_setFunctionAddCachedServer(SMBCCTX *c, smbc_add_cached_srv_fn fn);
758 /** Get the function for server cache lookup */
759 smbc_get_cached_srv_fn smbc_getFunctionGetCachedServer(SMBCCTX *c);
761 /** Set the function for server cache lookup */
762 void smbc_setFunctionGetCachedServer(SMBCCTX *c, smbc_get_cached_srv_fn fn);
764 /** Get the function for server cache removal */
765 smbc_remove_cached_srv_fn smbc_getFunctionRemoveCachedServer(SMBCCTX *c);
767 /** Set the function for server cache removal */
768 void smbc_setFunctionRemoveCachedServer(SMBCCTX *c,
769 smbc_remove_cached_srv_fn fn);
772 * Get the function for server cache purging. This function tries to
773 * remove all cached servers (e.g. on disconnect)
775 smbc_purge_cached_fn smbc_getFunctionPurgeCachedServers(SMBCCTX *c);
778 * Set the function for server cache purging. This function tries to
779 * remove all cached servers (e.g. on disconnect)
781 void smbc_setFunctionPurgeCachedServers(SMBCCTX *c,
782 smbc_purge_cached_fn fn);
784 /** Get the function to store private data of the server cache */
785 struct smbc_server_cache * smbc_getServerCacheData(SMBCCTX *c);
787 /** Set the function to store private data of the server cache */
788 void smbc_setServerCacheData(SMBCCTX *c, struct smbc_server_cache * cache);
792 /*****************************************************************
793 * Callable functions for files. *
794 * Each callable has a function signature typedef, a declaration *
795 * for the getter, and a declaration for the setter. *
796 *****************************************************************/
798 typedef SMBCFILE * (*smbc_open_fn)(SMBCCTX *c,
799 const char *fname,
800 int flags,
801 mode_t mode);
802 smbc_open_fn smbc_getFunctionOpen(SMBCCTX *c);
803 void smbc_setFunctionOpen(SMBCCTX *c, smbc_open_fn fn);
805 typedef SMBCFILE * (*smbc_creat_fn)(SMBCCTX *c,
806 const char *path,
807 mode_t mode);
808 smbc_creat_fn smbc_getFunctionCreat(SMBCCTX *c);
809 void smbc_setFunctionCreat(SMBCCTX *c, smbc_creat_fn);
811 typedef ssize_t (*smbc_read_fn)(SMBCCTX *c,
812 SMBCFILE *file,
813 void *buf,
814 size_t count);
815 smbc_read_fn smbc_getFunctionRead(SMBCCTX *c);
816 void smbc_setFunctionRead(SMBCCTX *c, smbc_read_fn fn);
818 typedef ssize_t (*smbc_write_fn)(SMBCCTX *c,
819 SMBCFILE *file,
820 const void *buf,
821 size_t count);
822 smbc_write_fn smbc_getFunctionWrite(SMBCCTX *c);
823 void smbc_setFunctionWrite(SMBCCTX *c, smbc_write_fn fn);
825 typedef int (*smbc_unlink_fn)(SMBCCTX *c,
826 const char *fname);
827 smbc_unlink_fn smbc_getFunctionUnlink(SMBCCTX *c);
828 void smbc_setFunctionUnlink(SMBCCTX *c, smbc_unlink_fn fn);
830 typedef int (*smbc_rename_fn)(SMBCCTX *ocontext,
831 const char *oname,
832 SMBCCTX *ncontext,
833 const char *nname);
834 smbc_rename_fn smbc_getFunctionRename(SMBCCTX *c);
835 void smbc_setFunctionRename(SMBCCTX *c, smbc_rename_fn fn);
837 typedef off_t (*smbc_lseek_fn)(SMBCCTX *c,
838 SMBCFILE * file,
839 off_t offset,
840 int whence);
841 smbc_lseek_fn smbc_getFunctionLseek(SMBCCTX *c);
842 void smbc_setFunctionLseek(SMBCCTX *c, smbc_lseek_fn fn);
844 typedef int (*smbc_stat_fn)(SMBCCTX *c,
845 const char *fname,
846 struct stat *st);
847 smbc_stat_fn smbc_getFunctionStat(SMBCCTX *c);
848 void smbc_setFunctionStat(SMBCCTX *c, smbc_stat_fn fn);
850 typedef int (*smbc_fstat_fn)(SMBCCTX *c,
851 SMBCFILE *file,
852 struct stat *st);
853 smbc_fstat_fn smbc_getFunctionFstat(SMBCCTX *c);
854 void smbc_setFunctionFstat(SMBCCTX *c, smbc_fstat_fn fn);
856 typedef int (*smbc_ftruncate_fn)(SMBCCTX *c,
857 SMBCFILE *f,
858 off_t size);
859 smbc_ftruncate_fn smbc_getFunctionFtruncate(SMBCCTX *c);
860 void smbc_setFunctionFtruncate(SMBCCTX *c, smbc_ftruncate_fn fn);
862 typedef int (*smbc_close_fn)(SMBCCTX *c,
863 SMBCFILE *file);
864 smbc_close_fn smbc_getFunctionClose(SMBCCTX *c);
865 void smbc_setFunctionClose(SMBCCTX *c, smbc_close_fn fn);
869 /*****************************************************************
870 * Callable functions for directories. *
871 * Each callable has a function signature typedef, a declaration *
872 * for the getter, and a declaration for the setter. *
873 *****************************************************************/
875 typedef SMBCFILE * (*smbc_opendir_fn)(SMBCCTX *c,
876 const char *fname);
877 smbc_opendir_fn smbc_getFunctionOpendir(SMBCCTX *c);
878 void smbc_setFunctionOpendir(SMBCCTX *c, smbc_opendir_fn fn);
880 typedef int (*smbc_closedir_fn)(SMBCCTX *c,
881 SMBCFILE *dir);
882 smbc_closedir_fn smbc_getFunctionClosedir(SMBCCTX *c);
883 void smbc_setFunctionClosedir(SMBCCTX *c, smbc_closedir_fn fn);
885 typedef struct smbc_dirent * (*smbc_readdir_fn)(SMBCCTX *c,
886 SMBCFILE *dir);
887 smbc_readdir_fn smbc_getFunctionReaddir(SMBCCTX *c);
888 void smbc_setFunctionReaddir(SMBCCTX *c, smbc_readdir_fn fn);
890 typedef int (*smbc_getdents_fn)(SMBCCTX *c,
891 SMBCFILE *dir,
892 struct smbc_dirent *dirp,
893 int count);
894 smbc_getdents_fn smbc_getFunctionGetdents(SMBCCTX *c);
895 void smbc_setFunctionGetdents(SMBCCTX *c, smbc_getdents_fn fn);
897 typedef int (*smbc_mkdir_fn)(SMBCCTX *c,
898 const char *fname,
899 mode_t mode);
900 smbc_mkdir_fn smbc_getFunctionMkdir(SMBCCTX *c);
901 void smbc_setFunctionMkdir(SMBCCTX *c, smbc_mkdir_fn fn);
903 typedef int (*smbc_rmdir_fn)(SMBCCTX *c,
904 const char *fname);
905 smbc_rmdir_fn smbc_getFunctionRmdir(SMBCCTX *c);
906 void smbc_setFunctionRmdir(SMBCCTX *c, smbc_rmdir_fn fn);
908 typedef off_t (*smbc_telldir_fn)(SMBCCTX *c,
909 SMBCFILE *dir);
910 smbc_telldir_fn smbc_getFunctionTelldir(SMBCCTX *c);
911 void smbc_setFunctionTelldir(SMBCCTX *c, smbc_telldir_fn fn);
913 typedef int (*smbc_lseekdir_fn)(SMBCCTX *c,
914 SMBCFILE *dir,
915 off_t offset);
916 smbc_lseekdir_fn smbc_getFunctionLseekdir(SMBCCTX *c);
917 void smbc_setFunctionLseekdir(SMBCCTX *c, smbc_lseekdir_fn fn);
919 typedef int (*smbc_fstatdir_fn)(SMBCCTX *c,
920 SMBCFILE *dir,
921 struct stat *st);
922 smbc_fstatdir_fn smbc_getFunctionFstatdir(SMBCCTX *c);
923 void smbc_setFunctionFstatdir(SMBCCTX *c, smbc_fstatdir_fn fn);
927 /*****************************************************************
928 * Callable functions applicable to both files and directories. *
929 * Each callable has a function signature typedef, a declaration *
930 * for the getter, and a declaration for the setter. *
931 *****************************************************************/
933 typedef int (*smbc_chmod_fn)(SMBCCTX *c,
934 const char *fname,
935 mode_t mode);
936 smbc_chmod_fn smbc_getFunctionChmod(SMBCCTX *c);
937 void smbc_setFunctionChmod(SMBCCTX *c, smbc_chmod_fn fn);
939 typedef int (*smbc_utimes_fn)(SMBCCTX *c,
940 const char *fname,
941 struct timeval *tbuf);
942 smbc_utimes_fn smbc_getFunctionUtimes(SMBCCTX *c);
943 void smbc_setFunctionUtimes(SMBCCTX *c, smbc_utimes_fn fn);
945 typedef int (*smbc_setxattr_fn)(SMBCCTX *context,
946 const char *fname,
947 const char *name,
948 const void *value,
949 size_t size,
950 int flags);
951 smbc_setxattr_fn smbc_getFunctionSetxattr(SMBCCTX *c);
952 void smbc_setFunctionSetxattr(SMBCCTX *c, smbc_setxattr_fn fn);
954 typedef int (*smbc_getxattr_fn)(SMBCCTX *context,
955 const char *fname,
956 const char *name,
957 const void *value,
958 size_t size);
959 smbc_getxattr_fn smbc_getFunctionGetxattr(SMBCCTX *c);
960 void smbc_setFunctionGetxattr(SMBCCTX *c, smbc_getxattr_fn fn);
962 typedef int (*smbc_removexattr_fn)(SMBCCTX *context,
963 const char *fname,
964 const char *name);
965 smbc_removexattr_fn smbc_getFunctionRemovexattr(SMBCCTX *c);
966 void smbc_setFunctionRemovexattr(SMBCCTX *c, smbc_removexattr_fn fn);
968 typedef int (*smbc_listxattr_fn)(SMBCCTX *context,
969 const char *fname,
970 char *list,
971 size_t size);
972 smbc_listxattr_fn smbc_getFunctionListxattr(SMBCCTX *c);
973 void smbc_setFunctionListxattr(SMBCCTX *c, smbc_listxattr_fn fn);
977 /*****************************************************************
978 * Callable functions for printing. *
979 * Each callable has a function signature typedef, a declaration *
980 * for the getter, and a declaration for the setter. *
981 *****************************************************************/
983 typedef int (*smbc_print_file_fn)(SMBCCTX *c_file,
984 const char *fname,
985 SMBCCTX *c_print,
986 const char *printq);
987 smbc_print_file_fn smbc_getFunctionPrintFile(SMBCCTX *c);
988 void smbc_setFunctionPrintFile(SMBCCTX *c, smbc_print_file_fn fn);
990 typedef SMBCFILE * (*smbc_open_print_job_fn)(SMBCCTX *c,
991 const char *fname);
992 smbc_open_print_job_fn smbc_getFunctionOpenPrintJob(SMBCCTX *c);
993 void smbc_setFunctionOpenPrintJob(SMBCCTX *c,
994 smbc_open_print_job_fn fn);
996 typedef int (*smbc_list_print_jobs_fn)(SMBCCTX *c,
997 const char *fname,
998 smbc_list_print_job_fn fn);
999 smbc_list_print_jobs_fn smbc_getFunctionListPrintJobs(SMBCCTX *c);
1000 void smbc_setFunctionListPrintJobs(SMBCCTX *c,
1001 smbc_list_print_jobs_fn fn);
1003 typedef int (*smbc_unlink_print_job_fn)(SMBCCTX *c,
1004 const char *fname,
1005 int id);
1006 smbc_unlink_print_job_fn smbc_getFunctionUnlinkPrintJob(SMBCCTX *c);
1007 void smbc_setFunctionUnlinkPrintJob(SMBCCTX *c,
1008 smbc_unlink_print_job_fn fn);
1011 /**@ingroup misc
1012 * Create a new SBMCCTX (a context).
1014 * Must be called before the context is passed to smbc_context_init()
1016 * @return The given SMBCCTX pointer on success, NULL on error with errno set:
1017 * - ENOMEM Out of memory
1019 * @see smbc_free_context(), smbc_init_context()
1021 * @note Do not forget to smbc_init_context() the returned SMBCCTX pointer !
1023 SMBCCTX * smbc_new_context(void);
1025 /**@ingroup misc
1026 * Delete a SBMCCTX (a context) acquired from smbc_new_context().
1028 * The context will be deleted if possible.
1030 * @param context A pointer to a SMBCCTX obtained from smbc_new_context()
1032 * @param shutdown_ctx If 1, all connections and files will be closed even if they are busy.
1035 * @return Returns 0 on succes. Returns 1 on failure with errno set:
1036 * - EBUSY Server connections are still used, Files are open or cache
1037 * could not be purged
1038 * - EBADF context == NULL
1040 * @see smbc_new_context()
1042 * @note It is advised to clean up all the contexts with shutdown_ctx set to 1
1043 * just before exit()'ing. When shutdown_ctx is 0, this function can be
1044 * use in periodical cleanup functions for example.
1046 int smbc_free_context(SMBCCTX * context, int shutdown_ctx);
1049 /**@ingroup misc
1051 * @deprecated. Use smbc_setOption*() functions instead.
1053 void
1054 smbc_option_set(SMBCCTX *context,
1055 char *option_name,
1056 ... /* option_value */);
1059 * @deprecated. Use smbc_getOption*() functions instead.
1061 void *
1062 smbc_option_get(SMBCCTX *context,
1063 char *option_name);
1065 /**@ingroup misc
1066 * Initialize a SBMCCTX (a context).
1068 * Must be called before using any SMBCCTX API function
1070 * @param context A pointer to a SMBCCTX obtained from smbc_new_context()
1072 * @return A pointer to the given SMBCCTX on success,
1073 * NULL on error with errno set:
1074 * - EBADF NULL context given
1075 * - ENOMEM Out of memory
1076 * - ENOENT The smb.conf file would not load
1078 * @see smbc_new_context()
1080 * @note my_context = smbc_init_context(smbc_new_context())
1081 * is perfectly safe, but it might leak memory on
1082 * smbc_context_init() failure. Avoid this.
1083 * You'll have to call smbc_free_context() yourself
1084 * on failure.
1087 SMBCCTX * smbc_init_context(SMBCCTX * context);
1089 /**@ingroup misc
1090 * Initialize the samba client library.
1092 * Must be called before using any of the smbclient API function
1094 * @param fn The function that will be called to obtaion
1095 * authentication credentials.
1097 * @param debug Allows caller to set the debug level. Can be
1098 * changed in smb.conf file. Allows caller to set
1099 * debugging if no smb.conf.
1101 * @return 0 on success, < 0 on error with errno set:
1102 * - ENOMEM Out of memory
1103 * - ENOENT The smb.conf file would not load
1107 int smbc_init(smbc_get_auth_data_fn fn, int debug);
1109 /**@ingroup misc
1110 * Set or retrieve the compatibility library's context pointer
1112 * @param context New context to use, or NULL. If a new context is provided,
1113 * it must have allocated with smbc_new_context() and
1114 * initialized with smbc_init_context(), followed, optionally,
1115 * by some manual changes to some of the non-internal fields.
1117 * @return The old context.
1119 * @see smbc_new_context(), smbc_init_context(), smbc_init()
1121 * @note This function may be called prior to smbc_init() to force
1122 * use of the next context without any internal calls to
1123 * smbc_new_context() or smbc_init_context(). It may also
1124 * be called after smbc_init() has already called those two
1125 * functions, to replace the existing context with a new one.
1126 * Care should be taken, in this latter case, to ensure that
1127 * the server cache and any data allocated by the
1128 * authentication functions have been freed, if necessary.
1131 SMBCCTX * smbc_set_context(SMBCCTX * new_context);
1133 /**@ingroup file
1134 * Open a file on an SMB server.
1136 * @param furl The smb url of the file to be opened.
1138 * @param flags Is one of O_RDONLY, O_WRONLY or O_RDWR which
1139 * request opening the file read-only,write-only
1140 * or read/write. flags may also be bitwise-or'd with
1141 * one or more of the following:
1142 * O_CREAT - If the file does not exist it will be
1143 * created.
1144 * O_EXCL - When used with O_CREAT, if the file
1145 * already exists it is an error and the open will
1146 * fail.
1147 * O_TRUNC - If the file already exists it will be
1148 * truncated.
1149 * O_APPEND The file is opened in append mode
1151 * @param mode mode specifies the permissions to use if a new
1152 * file is created. It is modified by the
1153 * process's umask in the usual way: the permissions
1154 * of the created file are (mode & ~umask)
1156 * Not currently use, but there for future use.
1157 * We will map this to SYSTEM, HIDDEN, etc bits
1158 * that reverses the mapping that smbc_fstat does.
1160 * @return Valid file handle, < 0 on error with errno set:
1161 * - ENOMEM Out of memory
1162 * - EINVAL if an invalid parameter passed, like no
1163 * file, or smbc_init not called.
1164 * - EEXIST pathname already exists and O_CREAT and
1165 * O_EXCL were used.
1166 * - EISDIR pathname refers to a directory and
1167 * the access requested involved writing.
1168 * - EACCES The requested access to the file is not
1169 * allowed
1170 * - ENODEV The requested share does not exist
1171 * - ENOTDIR A file on the path is not a directory
1172 * - ENOENT A directory component in pathname does
1173 * not exist.
1175 * @see smbc_creat()
1177 * @note This call uses an underlying routine that may create
1178 * a new connection to the server specified in the URL.
1179 * If the credentials supplied in the URL, or via the
1180 * auth_fn in the smbc_init call, fail, this call will
1181 * try again with an empty username and password. This
1182 * often gets mapped to the guest account on some machines.
1185 int smbc_open(const char *furl, int flags, mode_t mode);
1187 /**@ingroup file
1188 * Create a file on an SMB server.
1190 * Same as calling smbc_open() with flags = O_CREAT|O_WRONLY|O_TRUNC
1192 * @param furl The smb url of the file to be created
1194 * @param mode mode specifies the permissions to use if a new
1195 * file is created. It is modified by the
1196 * process's umask in the usual way: the permissions
1197 * of the created file are (mode & ~umask)
1199 * NOTE, the above is not true. We are dealing with
1200 * an SMB server, which has no concept of a umask!
1202 * @return Valid file handle, < 0 on error with errno set:
1203 * - ENOMEM Out of memory
1204 * - EINVAL if an invalid parameter passed, like no
1205 * file, or smbc_init not called.
1206 * - EEXIST pathname already exists and O_CREAT and
1207 * O_EXCL were used.
1208 * - EISDIR pathname refers to a directory and
1209 * the access requested involved writing.
1210 * - EACCES The requested access to the file is not
1211 * allowed
1212 * - ENOENT A directory component in pathname does
1213 * not exist.
1214 * - ENODEV The requested share does not exist.
1215 * @see smbc_open()
1219 int smbc_creat(const char *furl, mode_t mode);
1221 /**@ingroup file
1222 * Read from a file using an opened file handle.
1224 * @param fd Open file handle from smbc_open() or smbc_creat()
1226 * @param buf Pointer to buffer to recieve read data
1228 * @param bufsize Size of buf in bytes
1230 * @return Number of bytes read, < 0 on error with errno set:
1231 * - EISDIR fd refers to a directory
1232 * - EBADF fd is not a valid file descriptor or
1233 * is not open for reading.
1234 * - EINVAL fd is attached to an object which is
1235 * unsuitable for reading, or no buffer passed or
1236 * smbc_init not called.
1238 * @see smbc_open(), smbc_write()
1241 ssize_t smbc_read(int fd, void *buf, size_t bufsize);
1244 /**@ingroup file
1245 * Write to a file using an opened file handle.
1247 * @param fd Open file handle from smbc_open() or smbc_creat()
1249 * @param buf Pointer to buffer to recieve read data
1251 * @param bufsize Size of buf in bytes
1253 * @return Number of bytes written, < 0 on error with errno set:
1254 * - EISDIR fd refers to a directory.
1255 * - EBADF fd is not a valid file descriptor or
1256 * is not open for reading.
1257 * - EINVAL fd is attached to an object which is
1258 * unsuitable for reading, or no buffer passed or
1259 * smbc_init not called.
1261 * @see smbc_open(), smbc_read()
1264 ssize_t smbc_write(int fd, const void *buf, size_t bufsize);
1267 /**@ingroup file
1268 * Seek to a specific location in a file.
1270 * @param fd Open file handle from smbc_open() or smbc_creat()
1272 * @param offset Offset in bytes from whence
1274 * @param whence A location in the file:
1275 * - SEEK_SET The offset is set to offset bytes from
1276 * the beginning of the file
1277 * - SEEK_CUR The offset is set to current location
1278 * plus offset bytes.
1279 * - SEEK_END The offset is set to the size of the
1280 * file plus offset bytes.
1282 * @return Upon successful completion, lseek returns the
1283 * resulting offset location as measured in bytes
1284 * from the beginning of the file. Otherwise, a value
1285 * of (off_t)-1 is returned and errno is set to
1286 * indicate the error:
1287 * - EBADF Fildes is not an open file descriptor.
1288 * - EINVAL Whence is not a proper value or smbc_init
1289 * not called.
1291 * @todo Are all the whence values really supported?
1293 * @todo Are errno values complete and correct?
1295 off_t smbc_lseek(int fd, off_t offset, int whence);
1298 /**@ingroup file
1299 * Close an open file handle.
1301 * @param fd The file handle to close
1303 * @return 0 on success, < 0 on error with errno set:
1304 * - EBADF fd isn't a valid open file descriptor
1305 * - EINVAL smbc_init() failed or has not been called
1307 * @see smbc_open(), smbc_creat()
1309 int smbc_close(int fd);
1312 /**@ingroup directory
1313 * Unlink (delete) a file or directory.
1315 * @param furl The smb url of the file to delete
1317 * @return 0 on success, < 0 on error with errno set:
1318 * - EACCES or EPERM Write access to the directory
1319 * containing pathname is not allowed or one
1320 * of the directories in pathname did not allow
1321 * search (execute) permission
1322 * - ENOENT A directory component in pathname does
1323 * not exist
1324 * - EINVAL NULL was passed in the file param or
1325 * smbc_init not called.
1326 * - EACCES You do not have access to the file
1327 * - ENOMEM Insufficient kernel memory was available
1329 * @see smbc_rmdir()s
1331 * @todo Are errno values complete and correct?
1333 int smbc_unlink(const char *furl);
1336 /**@ingroup directory
1337 * Rename or move a file or directory.
1339 * @param ourl The original smb url (source url) of file or
1340 * directory to be moved
1342 * @param nurl The new smb url (destination url) of the file
1343 * or directory after the move. Currently nurl must
1344 * be on the same share as ourl.
1346 * @return 0 on success, < 0 on error with errno set:
1347 * - EISDIR nurl is an existing directory, but ourl is
1348 * not a directory.
1349 * - EEXIST nurl is a non-empty directory,
1350 * i.e., contains entries other than "." and ".."
1351 * - EINVAL The new url contained a path prefix
1352 * of the old, or, more generally, an attempt was
1353 * made to make a directory a subdirectory of itself
1354 * or smbc_init not called.
1355 * - ENOTDIR A component used as a directory in ourl
1356 * or nurl path is not, in fact, a directory. Or,
1357 * ourl is a directory, and newpath exists but is not
1358 * a directory.
1359 * - EACCES or EPERM Write access to the directory
1360 * containing ourl or nurl is not allowed for the
1361 * process's effective uid, or one of the
1362 * directories in ourl or nurl did not allow search
1363 * (execute) permission, or ourl was a directory
1364 * and did not allow write permission.
1365 * - ENOENT A directory component in ourl or nurl
1366 * does not exist.
1367 * - EXDEV Rename across shares not supported.
1368 * - ENOMEM Insufficient kernel memory was available.
1369 * - EEXIST The target file, nurl, already exists.
1372 * @todo Are we going to support copying when urls are not on the same
1373 * share? I say no... NOTE. I agree for the moment.
1376 int smbc_rename(const char *ourl, const char *nurl);
1379 /**@ingroup directory
1380 * Open a directory used to obtain directory entries.
1382 * @param durl The smb url of the directory to open
1384 * @return Valid directory handle. < 0 on error with errno set:
1385 * - EACCES Permission denied.
1386 * - EINVAL A NULL file/URL was passed, or the URL would
1387 * not parse, or was of incorrect form or smbc_init not
1388 * called.
1389 * - ENOENT durl does not exist, or name is an
1390 * - ENOMEM Insufficient memory to complete the
1391 * operation.
1392 * - ENOTDIR name is not a directory.
1393 * - EPERM the workgroup could not be found.
1394 * - ENODEV the workgroup or server could not be found.
1396 * @see smbc_getdents(), smbc_readdir(), smbc_closedir()
1399 int smbc_opendir(const char *durl);
1402 /**@ingroup directory
1403 * Close a directory handle opened by smbc_opendir().
1405 * @param dh Directory handle to close
1407 * @return 0 on success, < 0 on error with errno set:
1408 * - EBADF dh is an invalid directory handle
1410 * @see smbc_opendir()
1412 int smbc_closedir(int dh);
1415 /**@ingroup directory
1416 * Get multiple directory entries.
1418 * smbc_getdents() reads as many dirent structures from the an open
1419 * directory handle into a specified memory area as will fit.
1421 * @param dh Valid directory as returned by smbc_opendir()
1423 * @param dirp pointer to buffer that will receive the directory
1424 * entries.
1426 * @param count The size of the dirp buffer in bytes
1428 * @returns If any dirents returned, return will indicate the
1429 * total size. If there were no more dirents available,
1430 * 0 is returned. < 0 indicates an error.
1431 * - EBADF Invalid directory handle
1432 * - EINVAL Result buffer is too small or smbc_init
1433 * not called.
1434 * - ENOENT No such directory.
1435 * @see , smbc_dirent, smbc_readdir(), smbc_open()
1437 * @todo Are errno values complete and correct?
1439 * @todo Add example code so people know how to parse buffers.
1441 int smbc_getdents(unsigned int dh, struct smbc_dirent *dirp, int count);
1444 /**@ingroup directory
1445 * Get a single directory entry.
1447 * @param dh Valid directory as returned by smbc_opendir()
1449 * @return A pointer to a smbc_dirent structure, or NULL if an
1450 * error occurs or end-of-directory is reached:
1451 * - EBADF Invalid directory handle
1452 * - EINVAL smbc_init() failed or has not been called
1454 * @see smbc_dirent, smbc_getdents(), smbc_open()
1456 struct smbc_dirent* smbc_readdir(unsigned int dh);
1459 /**@ingroup directory
1460 * Get the current directory offset.
1462 * smbc_telldir() may be used in conjunction with smbc_readdir() and
1463 * smbc_lseekdir().
1465 * @param dh Valid directory as returned by smbc_opendir()
1467 * @return The current location in the directory stream or -1
1468 * if an error occur. The current location is not
1469 * an offset. Becuase of the implementation, it is a
1470 * handle that allows the library to find the entry
1471 * later.
1472 * - EBADF dh is not a valid directory handle
1473 * - EINVAL smbc_init() failed or has not been called
1474 * - ENOTDIR if dh is not a directory
1476 * @see smbc_readdir()
1479 off_t smbc_telldir(int dh);
1482 /**@ingroup directory
1483 * lseek on directories.
1485 * smbc_lseekdir() may be used in conjunction with smbc_readdir() and
1486 * smbc_telldir(). (rewind by smbc_lseekdir(fd, NULL))
1488 * @param fd Valid directory as returned by smbc_opendir()
1490 * @param offset The offset (as returned by smbc_telldir). Can be
1491 * NULL, in which case we will rewind
1493 * @return 0 on success, -1 on failure
1494 * - EBADF dh is not a valid directory handle
1495 * - ENOTDIR if dh is not a directory
1496 * - EINVAL offset did not refer to a valid dirent or
1497 * smbc_init not called.
1499 * @see smbc_telldir()
1502 * @todo In what does the reture and errno values mean?
1504 int smbc_lseekdir(int fd, off_t offset);
1506 /**@ingroup directory
1507 * Create a directory.
1509 * @param durl The url of the directory to create
1511 * @param mode Specifies the permissions to use. It is modified
1512 * by the process's umask in the usual way: the
1513 * permissions of the created file are (mode & ~umask).
1515 * @return 0 on success, < 0 on error with errno set:
1516 * - EEXIST directory url already exists
1517 * - EACCES The parent directory does not allow write
1518 * permission to the process, or one of the directories
1519 * - ENOENT A directory component in pathname does not
1520 * exist.
1521 * - EINVAL NULL durl passed or smbc_init not called.
1522 * - ENOMEM Insufficient memory was available.
1524 * @see smbc_rmdir()
1527 int smbc_mkdir(const char *durl, mode_t mode);
1530 /**@ingroup directory
1531 * Remove a directory.
1533 * @param durl The smb url of the directory to remove
1535 * @return 0 on success, < 0 on error with errno set:
1536 * - EACCES or EPERM Write access to the directory
1537 * containing pathname was not allowed.
1538 * - EINVAL durl is NULL or smbc_init not called.
1539 * - ENOENT A directory component in pathname does not
1540 * exist.
1541 * - ENOTEMPTY directory contains entries.
1542 * - ENOMEM Insufficient kernel memory was available.
1544 * @see smbc_mkdir(), smbc_unlink()
1546 * @todo Are errno values complete and correct?
1548 int smbc_rmdir(const char *durl);
1551 /**@ingroup attribute
1552 * Get information about a file or directory.
1554 * @param url The smb url to get information for
1556 * @param st pointer to a buffer that will be filled with
1557 * standard Unix struct stat information.
1559 * @return 0 on success, < 0 on error with errno set:
1560 * - ENOENT A component of the path file_name does not
1561 * exist.
1562 * - EINVAL a NULL url was passed or smbc_init not called.
1563 * - EACCES Permission denied.
1564 * - ENOMEM Out of memory
1565 * - ENOTDIR The target dir, url, is not a directory.
1567 * @see Unix stat()
1570 int smbc_stat(const char *url, struct stat *st);
1573 /**@ingroup attribute
1574 * Get file information via an file descriptor.
1576 * @param fd Open file handle from smbc_open() or smbc_creat()
1578 * @param st pointer to a buffer that will be filled with
1579 * standard Unix struct stat information.
1581 * @return EBADF filedes is bad.
1582 * - EACCES Permission denied.
1583 * - EBADF fd is not a valid file descriptor
1584 * - EINVAL Problems occurred in the underlying routines
1585 * or smbc_init not called.
1586 * - ENOMEM Out of memory
1588 * @see smbc_stat(), Unix stat()
1591 int smbc_fstat(int fd, struct stat *st);
1594 /**@ingroup attribute
1595 * Truncate a file given a file descriptor
1597 * @param fd Open file handle from smbc_open() or smbc_creat()
1599 * @param size size to truncate the file to
1601 * @return EBADF filedes is bad.
1602 * - EACCES Permission denied.
1603 * - EBADF fd is not a valid file descriptor
1604 * - EINVAL Problems occurred in the underlying routines
1605 * or smbc_init not called.
1606 * - ENOMEM Out of memory
1608 * @see , Unix ftruncate()
1611 int smbc_ftruncate(int fd, off_t size);
1614 /**@ingroup attribute
1615 * Change the permissions of a file.
1617 * @param url The smb url of the file or directory to change
1618 * permissions of
1620 * @param mode The permissions to set:
1621 * - Put good explaination of permissions here!
1623 * @return 0 on success, < 0 on error with errno set:
1624 * - EPERM The effective UID does not match the owner
1625 * of the file, and is not zero
1626 * - ENOENT The file does not exist.
1627 * - ENOMEM Insufficient was available.
1628 * - ENOENT file or directory does not exist
1630 * @todo Actually implement this fuction?
1632 * @todo Are errno values complete and correct?
1634 int smbc_chmod(const char *url, mode_t mode);
1637 * @ingroup attribute
1638 * Change the last modification time on a file
1640 * @param url The smb url of the file or directory to change
1641 * the modification time of
1643 * @param tbuf An array of two timeval structures which contains,
1644 * respectively, the desired access and modification times.
1645 * NOTE: Only the tv_sec field off each timeval structure is
1646 * used. The tv_usec (microseconds) portion is ignored.
1648 * @return 0 on success, < 0 on error with errno set:
1649 * - EINVAL The client library is not properly initialized
1650 * - EPERM Permission was denied.
1653 int smbc_utimes(const char *url, struct timeval *tbuf);
1655 #ifdef HAVE_UTIME_H
1657 * @ingroup attribute
1658 * Change the last modification time on a file
1660 * @param url The smb url of the file or directory to change
1661 * the modification time of
1663 * @param utbuf A pointer to a utimebuf structure which contains the
1664 * desired access and modification times.
1666 * @return 0 on success, < 0 on error with errno set:
1667 * - EINVAL The client library is not properly initialized
1668 * - ENOMEM No memory was available for internal needs
1669 * - EPERM Permission was denied.
1672 int smbc_utime(const char *fname, struct utimbuf *utbuf);
1673 #endif
1675 /**@ingroup attribute
1676 * Set extended attributes for a file. This is used for modifying a file's
1677 * security descriptor (i.e. owner, group, and access control list)
1679 * @param url The smb url of the file or directory to set extended
1680 * attributes for.
1682 * @param name The name of an attribute to be changed. Names are of
1683 * one of the following forms:
1685 * system.nt_sec_desc.<attribute name>
1686 * system.nt_sec_desc.*
1687 * system.nt_sec_desc.*+
1689 * where <attribute name> is one of:
1691 * revision
1692 * owner
1693 * owner+
1694 * group
1695 * group+
1696 * acl:<name or sid>
1697 * acl+:<name or sid>
1699 * In the forms "system.nt_sec_desc.*" and
1700 * "system.nt_sec_desc.*+", the asterisk and plus signs are
1701 * literal, i.e. the string is provided exactly as shown, and
1702 * the value parameter should contain a complete security
1703 * descriptor with name:value pairs separated by tabs,
1704 * commas, or newlines (not spaces!).
1706 * The plus sign ('+') indicates that SIDs should be mapped
1707 * to names. Without the plus sign, SIDs are not mapped;
1708 * rather they are simply converted to a string format.
1710 * @param value The value to be assigned to the specified attribute name.
1711 * This buffer should contain only the attribute value if the
1712 * name was of the "system.nt_sec_desc.<attribute_name>"
1713 * form. If the name was of the "system.nt_sec_desc.*" form
1714 * then a complete security descriptor, with name:value pairs
1715 * separated by tabs, commas, or newlines (not spaces!),
1716 * should be provided in this value buffer. A complete
1717 * security descriptor will contain one or more entries
1718 * selected from the following:
1720 * REVISION:<revision number>
1721 * OWNER:<sid or name>
1722 * GROUP:<sid or name>
1723 * ACL:<sid or name>:<type>/<flags>/<mask>
1725 * The revision of the ACL specifies the internal Windows NT
1726 * ACL revision for the security descriptor. If not specified
1727 * it defaults to 1. Using values other than 1 may cause
1728 * strange behaviour.
1730 * The owner and group specify the owner and group sids for
1731 * the object. If the attribute name (either '*+' with a
1732 * complete security descriptor, or individual 'owner+' or
1733 * 'group+' attribute names) ended with a plus sign, the
1734 * specified name is resolved to a SID value, using the
1735 * server on which the file or directory resides. Otherwise,
1736 * the value should be provided in SID-printable format as
1737 * S-1-x-y-z, and is used directly. The <sid or name>
1738 * associated with the ACL: attribute should be provided
1739 * similarly.
1741 * @param size The number of the bytes of data in the value buffer
1743 * @param flags A bit-wise OR of zero or more of the following:
1744 * SMBC_XATTR_FLAG_CREATE -
1745 * fail if the named attribute already exists
1746 * SMBC_XATTR_FLAG_REPLACE -
1747 * fail if the attribute does not already exist
1749 * If neither flag is specified, the specified attributes
1750 * will be added or replace existing attributes of the same
1751 * name, as necessary.
1753 * @return 0 on success, < 0 on error with errno set:
1754 * - EINVAL The client library is not properly initialized
1755 * or one of the parameters is not of a correct
1756 * form
1757 * - ENOMEM No memory was available for internal needs
1758 * - EEXIST If the attribute already exists and the flag
1759 * SMBC_XATTR_FLAG_CREAT was specified
1760 * - ENOATTR If the attribute does not exist and the flag
1761 * SMBC_XATTR_FLAG_REPLACE was specified
1762 * - EPERM Permission was denied.
1763 * - ENOTSUP The referenced file system does not support
1764 * extended attributes
1766 * @note Attribute names are compared in a case-insensitive
1767 * fashion. All of the following are equivalent, although
1768 * the all-lower-case name is the preferred format:
1769 * system.nt_sec_desc.owner
1770 * SYSTEM.NT_SEC_DESC.OWNER
1771 * sYsTeM.nt_sEc_desc.owNER
1774 int smbc_setxattr(const char *url,
1775 const char *name,
1776 const void *value,
1777 size_t size,
1778 int flags);
1781 /**@ingroup attribute
1782 * Set extended attributes for a file. This is used for modifying a file's
1783 * security descriptor (i.e. owner, group, and access control list). The
1784 * POSIX function which this maps to would act on a symbolic link rather than
1785 * acting on what the symbolic link points to, but with no symbolic links in
1786 * SMB file systems, this function is functionally identical to
1787 * smbc_setxattr().
1789 * @param url The smb url of the file or directory to set extended
1790 * attributes for.
1792 * @param name The name of an attribute to be changed. Names are of
1793 * one of the following forms:
1795 * system.nt_sec_desc.<attribute name>
1796 * system.nt_sec_desc.*
1797 * system.nt_sec_desc.*+
1799 * where <attribute name> is one of:
1801 * revision
1802 * owner
1803 * owner+
1804 * group
1805 * group+
1806 * acl:<name or sid>
1807 * acl+:<name or sid>
1809 * In the forms "system.nt_sec_desc.*" and
1810 * "system.nt_sec_desc.*+", the asterisk and plus signs are
1811 * literal, i.e. the string is provided exactly as shown, and
1812 * the value parameter should contain a complete security
1813 * descriptor with name:value pairs separated by tabs,
1814 * commas, or newlines (not spaces!).
1816 * The plus sign ('+') indicates that SIDs should be mapped
1817 * to names. Without the plus sign, SIDs are not mapped;
1818 * rather they are simply converted to a string format.
1820 * @param value The value to be assigned to the specified attribute name.
1821 * This buffer should contain only the attribute value if the
1822 * name was of the "system.nt_sec_desc.<attribute_name>"
1823 * form. If the name was of the "system.nt_sec_desc.*" form
1824 * then a complete security descriptor, with name:value pairs
1825 * separated by tabs, commas, or newlines (not spaces!),
1826 * should be provided in this value buffer. A complete
1827 * security descriptor will contain one or more entries
1828 * selected from the following:
1830 * REVISION:<revision number>
1831 * OWNER:<sid or name>
1832 * GROUP:<sid or name>
1833 * ACL:<sid or name>:<type>/<flags>/<mask>
1835 * The revision of the ACL specifies the internal Windows NT
1836 * ACL revision for the security descriptor. If not specified
1837 * it defaults to 1. Using values other than 1 may cause
1838 * strange behaviour.
1840 * The owner and group specify the owner and group sids for
1841 * the object. If the attribute name (either '*+' with a
1842 * complete security descriptor, or individual 'owner+' or
1843 * 'group+' attribute names) ended with a plus sign, the
1844 * specified name is resolved to a SID value, using the
1845 * server on which the file or directory resides. Otherwise,
1846 * the value should be provided in SID-printable format as
1847 * S-1-x-y-z, and is used directly. The <sid or name>
1848 * associated with the ACL: attribute should be provided
1849 * similarly.
1851 * @param size The number of the bytes of data in the value buffer
1853 * @param flags A bit-wise OR of zero or more of the following:
1854 * SMBC_XATTR_FLAG_CREATE -
1855 * fail if the named attribute already exists
1856 * SMBC_XATTR_FLAG_REPLACE -
1857 * fail if the attribute does not already exist
1859 * If neither flag is specified, the specified attributes
1860 * will be added or replace existing attributes of the same
1861 * name, as necessary.
1863 * @return 0 on success, < 0 on error with errno set:
1864 * - EINVAL The client library is not properly initialized
1865 * or one of the parameters is not of a correct
1866 * form
1867 * - ENOMEM No memory was available for internal needs
1868 * - EEXIST If the attribute already exists and the flag
1869 * SMBC_XATTR_FLAG_CREAT was specified
1870 * - ENOATTR If the attribute does not exist and the flag
1871 * SMBC_XATTR_FLAG_REPLACE was specified
1872 * - EPERM Permission was denied.
1873 * - ENOTSUP The referenced file system does not support
1874 * extended attributes
1876 * @note Attribute names are compared in a case-insensitive
1877 * fashion. All of the following are equivalent, although
1878 * the all-lower-case name is the preferred format:
1879 * system.nt_sec_desc.owner
1880 * SYSTEM.NT_SEC_DESC.OWNER
1881 * sYsTeM.nt_sEc_desc.owNER
1884 int smbc_lsetxattr(const char *url,
1885 const char *name,
1886 const void *value,
1887 size_t size,
1888 int flags);
1891 /**@ingroup attribute
1892 * Set extended attributes for a file. This is used for modifying a file's
1893 * security descriptor (i.e. owner, group, and access control list)
1895 * @param fd A file descriptor associated with an open file (as
1896 * previously returned by smbc_open(), to get extended
1897 * attributes for.
1899 * @param name The name of an attribute to be changed. Names are of
1900 * one of the following forms:
1902 * system.nt_sec_desc.<attribute name>
1903 * system.nt_sec_desc.*
1904 * system.nt_sec_desc.*+
1906 * where <attribute name> is one of:
1908 * revision
1909 * owner
1910 * owner+
1911 * group
1912 * group+
1913 * acl:<name or sid>
1914 * acl+:<name or sid>
1916 * In the forms "system.nt_sec_desc.*" and
1917 * "system.nt_sec_desc.*+", the asterisk and plus signs are
1918 * literal, i.e. the string is provided exactly as shown, and
1919 * the value parameter should contain a complete security
1920 * descriptor with name:value pairs separated by tabs,
1921 * commas, or newlines (not spaces!).
1923 * The plus sign ('+') indicates that SIDs should be mapped
1924 * to names. Without the plus sign, SIDs are not mapped;
1925 * rather they are simply converted to a string format.
1927 * @param value The value to be assigned to the specified attribute name.
1928 * This buffer should contain only the attribute value if the
1929 * name was of the "system.nt_sec_desc.<attribute_name>"
1930 * form. If the name was of the "system.nt_sec_desc.*" form
1931 * then a complete security descriptor, with name:value pairs
1932 * separated by tabs, commas, or newlines (not spaces!),
1933 * should be provided in this value buffer. A complete
1934 * security descriptor will contain one or more entries
1935 * selected from the following:
1937 * REVISION:<revision number>
1938 * OWNER:<sid or name>
1939 * GROUP:<sid or name>
1940 * ACL:<sid or name>:<type>/<flags>/<mask>
1942 * The revision of the ACL specifies the internal Windows NT
1943 * ACL revision for the security descriptor. If not specified
1944 * it defaults to 1. Using values other than 1 may cause
1945 * strange behaviour.
1947 * The owner and group specify the owner and group sids for
1948 * the object. If the attribute name (either '*+' with a
1949 * complete security descriptor, or individual 'owner+' or
1950 * 'group+' attribute names) ended with a plus sign, the
1951 * specified name is resolved to a SID value, using the
1952 * server on which the file or directory resides. Otherwise,
1953 * the value should be provided in SID-printable format as
1954 * S-1-x-y-z, and is used directly. The <sid or name>
1955 * associated with the ACL: attribute should be provided
1956 * similarly.
1958 * @param size The number of the bytes of data in the value buffer
1960 * @param flags A bit-wise OR of zero or more of the following:
1961 * SMBC_XATTR_FLAG_CREATE -
1962 * fail if the named attribute already exists
1963 * SMBC_XATTR_FLAG_REPLACE -
1964 * fail if the attribute does not already exist
1966 * If neither flag is specified, the specified attributes
1967 * will be added or replace existing attributes of the same
1968 * name, as necessary.
1970 * @return 0 on success, < 0 on error with errno set:
1971 * - EINVAL The client library is not properly initialized
1972 * or one of the parameters is not of a correct
1973 * form
1974 * - ENOMEM No memory was available for internal needs
1975 * - EEXIST If the attribute already exists and the flag
1976 * SMBC_XATTR_FLAG_CREAT was specified
1977 * - ENOATTR If the attribute does not exist and the flag
1978 * SMBC_XATTR_FLAG_REPLACE was specified
1979 * - EPERM Permission was denied.
1980 * - ENOTSUP The referenced file system does not support
1981 * extended attributes
1983 * @note Attribute names are compared in a case-insensitive
1984 * fashion. All of the following are equivalent, although
1985 * the all-lower-case name is the preferred format:
1986 * system.nt_sec_desc.owner
1987 * SYSTEM.NT_SEC_DESC.OWNER
1988 * sYsTeM.nt_sEc_desc.owNER
1991 int smbc_fsetxattr(int fd,
1992 const char *name,
1993 const void *value,
1994 size_t size,
1995 int flags);
1998 /**@ingroup attribute
1999 * Get extended attributes for a file.
2001 * @param url The smb url of the file or directory to get extended
2002 * attributes for.
2004 * @param name The name of an attribute to be retrieved. Names are of
2005 * one of the following forms:
2007 * system.nt_sec_desc.<attribute name>
2008 * system.nt_sec_desc.*
2009 * system.nt_sec_desc.*+
2011 * where <attribute name> is one of:
2013 * revision
2014 * owner
2015 * owner+
2016 * group
2017 * group+
2018 * acl:<name or sid>
2019 * acl+:<name or sid>
2021 * In the forms "system.nt_sec_desc.*" and
2022 * "system.nt_sec_desc.*+", the asterisk and plus signs are
2023 * literal, i.e. the string is provided exactly as shown, and
2024 * the value parameter will return a complete security
2025 * descriptor with name:value pairs separated by tabs,
2026 * commas, or newlines (not spaces!).
2028 * The plus sign ('+') indicates that SIDs should be mapped
2029 * to names. Without the plus sign, SIDs are not mapped;
2030 * rather they are simply converted to a string format.
2032 * @param value A pointer to a buffer in which the value of the specified
2033 * attribute will be placed (unless size is zero).
2035 * @param size The size of the buffer pointed to by value. This parameter
2036 * may also be zero, in which case the size of the buffer
2037 * required to hold the attribute value will be returned,
2038 * but nothing will be placed into the value buffer.
2040 * @return 0 on success, < 0 on error with errno set:
2041 * - EINVAL The client library is not properly initialized
2042 * or one of the parameters is not of a correct
2043 * form
2044 * - ENOMEM No memory was available for internal needs
2045 * - EEXIST If the attribute already exists and the flag
2046 * SMBC_XATTR_FLAG_CREAT was specified
2047 * - ENOATTR If the attribute does not exist and the flag
2048 * SMBC_XATTR_FLAG_REPLACE was specified
2049 * - EPERM Permission was denied.
2050 * - ENOTSUP The referenced file system does not support
2051 * extended attributes
2054 int smbc_getxattr(const char *url,
2055 const char *name,
2056 const void *value,
2057 size_t size);
2060 /**@ingroup attribute
2061 * Get extended attributes for a file. The POSIX function which this maps to
2062 * would act on a symbolic link rather than acting on what the symbolic link
2063 * points to, but with no symbolic links in SMB file systems, this function
2064 * is functionally identical to smbc_getxattr().
2066 * @param url The smb url of the file or directory to get extended
2067 * attributes for.
2069 * @param name The name of an attribute to be retrieved. Names are of
2070 * one of the following forms:
2072 * system.nt_sec_desc.<attribute name>
2073 * system.nt_sec_desc.*
2074 * system.nt_sec_desc.*+
2076 * where <attribute name> is one of:
2078 * revision
2079 * owner
2080 * owner+
2081 * group
2082 * group+
2083 * acl:<name or sid>
2084 * acl+:<name or sid>
2086 * In the forms "system.nt_sec_desc.*" and
2087 * "system.nt_sec_desc.*+", the asterisk and plus signs are
2088 * literal, i.e. the string is provided exactly as shown, and
2089 * the value parameter will return a complete security
2090 * descriptor with name:value pairs separated by tabs,
2091 * commas, or newlines (not spaces!).
2093 * The plus sign ('+') indicates that SIDs should be mapped
2094 * to names. Without the plus sign, SIDs are not mapped;
2095 * rather they are simply converted to a string format.
2097 * @param value A pointer to a buffer in which the value of the specified
2098 * attribute will be placed (unless size is zero).
2100 * @param size The size of the buffer pointed to by value. This parameter
2101 * may also be zero, in which case the size of the buffer
2102 * required to hold the attribute value will be returned,
2103 * but nothing will be placed into the value buffer.
2105 * @return 0 on success, < 0 on error with errno set:
2106 * - EINVAL The client library is not properly initialized
2107 * or one of the parameters is not of a correct
2108 * form
2109 * - ENOMEM No memory was available for internal needs
2110 * - EEXIST If the attribute already exists and the flag
2111 * SMBC_XATTR_FLAG_CREAT was specified
2112 * - ENOATTR If the attribute does not exist and the flag
2113 * SMBC_XATTR_FLAG_REPLACE was specified
2114 * - EPERM Permission was denied.
2115 * - ENOTSUP The referenced file system does not support
2116 * extended attributes
2119 int smbc_lgetxattr(const char *url,
2120 const char *name,
2121 const void *value,
2122 size_t size);
2125 /**@ingroup attribute
2126 * Get extended attributes for a file.
2128 * @param fd A file descriptor associated with an open file (as
2129 * previously returned by smbc_open(), to get extended
2130 * attributes for.
2132 * @param name The name of an attribute to be retrieved. Names are of
2133 * one of the following forms:
2135 * system.nt_sec_desc.<attribute name>
2136 * system.nt_sec_desc.*
2137 * system.nt_sec_desc.*+
2139 * where <attribute name> is one of:
2141 * revision
2142 * owner
2143 * owner+
2144 * group
2145 * group+
2146 * acl:<name or sid>
2147 * acl+:<name or sid>
2149 * In the forms "system.nt_sec_desc.*" and
2150 * "system.nt_sec_desc.*+", the asterisk and plus signs are
2151 * literal, i.e. the string is provided exactly as shown, and
2152 * the value parameter will return a complete security
2153 * descriptor with name:value pairs separated by tabs,
2154 * commas, or newlines (not spaces!).
2156 * The plus sign ('+') indicates that SIDs should be mapped
2157 * to names. Without the plus sign, SIDs are not mapped;
2158 * rather they are simply converted to a string format.
2160 * @param value A pointer to a buffer in which the value of the specified
2161 * attribute will be placed (unless size is zero).
2163 * @param size The size of the buffer pointed to by value. This parameter
2164 * may also be zero, in which case the size of the buffer
2165 * required to hold the attribute value will be returned,
2166 * but nothing will be placed into the value buffer.
2168 * @return 0 on success, < 0 on error with errno set:
2169 * - EINVAL The client library is not properly initialized
2170 * or one of the parameters is not of a correct
2171 * form
2172 * - ENOMEM No memory was available for internal needs
2173 * - EEXIST If the attribute already exists and the flag
2174 * SMBC_XATTR_FLAG_CREAT was specified
2175 * - ENOATTR If the attribute does not exist and the flag
2176 * SMBC_XATTR_FLAG_REPLACE was specified
2177 * - EPERM Permission was denied.
2178 * - ENOTSUP The referenced file system does not support
2179 * extended attributes
2182 int smbc_fgetxattr(int fd,
2183 const char *name,
2184 const void *value,
2185 size_t size);
2188 /**@ingroup attribute
2189 * Remove extended attributes for a file. This is used for modifying a file's
2190 * security descriptor (i.e. owner, group, and access control list)
2192 * @param url The smb url of the file or directory to remove the extended
2193 * attributes for.
2195 * @param name The name of an attribute to be removed. Names are of
2196 * one of the following forms:
2198 * system.nt_sec_desc.<attribute name>
2199 * system.nt_sec_desc.*
2200 * system.nt_sec_desc.*+
2202 * where <attribute name> is one of:
2204 * revision
2205 * owner
2206 * owner+
2207 * group
2208 * group+
2209 * acl:<name or sid>
2210 * acl+:<name or sid>
2212 * In the forms "system.nt_sec_desc.*" and
2213 * "system.nt_sec_desc.*+", the asterisk and plus signs are
2214 * literal, i.e. the string is provided exactly as shown, and
2215 * the value parameter will return a complete security
2216 * descriptor with name:value pairs separated by tabs,
2217 * commas, or newlines (not spaces!).
2219 * The plus sign ('+') indicates that SIDs should be mapped
2220 * to names. Without the plus sign, SIDs are not mapped;
2221 * rather they are simply converted to a string format.
2223 * @return 0 on success, < 0 on error with errno set:
2224 * - EINVAL The client library is not properly initialized
2225 * - ENOMEM No memory was available for internal needs
2226 * - EPERM Permission was denied.
2227 * - ENOTSUP The referenced file system does not support
2228 * extended attributes
2231 int smbc_removexattr(const char *url,
2232 const char *name);
2235 /**@ingroup attribute
2236 * Remove extended attributes for a file. This is used for modifying a file's
2237 * security descriptor (i.e. owner, group, and access control list) The POSIX
2238 * function which this maps to would act on a symbolic link rather than acting
2239 * on what the symbolic link points to, but with no symbolic links in SMB file
2240 * systems, this function is functionally identical to smbc_removexattr().
2242 * @param url The smb url of the file or directory to remove the extended
2243 * attributes for.
2245 * @param name The name of an attribute to be removed. Names are of
2246 * one of the following forms:
2248 * system.nt_sec_desc.<attribute name>
2249 * system.nt_sec_desc.*
2250 * system.nt_sec_desc.*+
2252 * where <attribute name> is one of:
2254 * revision
2255 * owner
2256 * owner+
2257 * group
2258 * group+
2259 * acl:<name or sid>
2260 * acl+:<name or sid>
2262 * In the forms "system.nt_sec_desc.*" and
2263 * "system.nt_sec_desc.*+", the asterisk and plus signs are
2264 * literal, i.e. the string is provided exactly as shown, and
2265 * the value parameter will return a complete security
2266 * descriptor with name:value pairs separated by tabs,
2267 * commas, or newlines (not spaces!).
2269 * The plus sign ('+') indicates that SIDs should be mapped
2270 * to names. Without the plus sign, SIDs are not mapped;
2271 * rather they are simply converted to a string format.
2273 * @return 0 on success, < 0 on error with errno set:
2274 * - EINVAL The client library is not properly initialized
2275 * - ENOMEM No memory was available for internal needs
2276 * - EPERM Permission was denied.
2277 * - ENOTSUP The referenced file system does not support
2278 * extended attributes
2281 int smbc_lremovexattr(const char *url,
2282 const char *name);
2285 /**@ingroup attribute
2286 * Remove extended attributes for a file. This is used for modifying a file's
2287 * security descriptor (i.e. owner, group, and access control list)
2289 * @param fd A file descriptor associated with an open file (as
2290 * previously returned by smbc_open(), to get extended
2291 * attributes for.
2293 * @param name The name of an attribute to be removed. Names are of
2294 * one of the following forms:
2296 * system.nt_sec_desc.<attribute name>
2297 * system.nt_sec_desc.*
2298 * system.nt_sec_desc.*+
2300 * where <attribute name> is one of:
2302 * revision
2303 * owner
2304 * owner+
2305 * group
2306 * group+
2307 * acl:<name or sid>
2308 * acl+:<name or sid>
2310 * In the forms "system.nt_sec_desc.*" and
2311 * "system.nt_sec_desc.*+", the asterisk and plus signs are
2312 * literal, i.e. the string is provided exactly as shown, and
2313 * the value parameter will return a complete security
2314 * descriptor with name:value pairs separated by tabs,
2315 * commas, or newlines (not spaces!).
2317 * The plus sign ('+') indicates that SIDs should be mapped
2318 * to names. Without the plus sign, SIDs are not mapped;
2319 * rather they are simply converted to a string format.
2321 * @return 0 on success, < 0 on error with errno set:
2322 * - EINVAL The client library is not properly initialized
2323 * - ENOMEM No memory was available for internal needs
2324 * - EPERM Permission was denied.
2325 * - ENOTSUP The referenced file system does not support
2326 * extended attributes
2329 int smbc_fremovexattr(int fd,
2330 const char *name);
2333 /**@ingroup attribute
2334 * List the supported extended attribute names associated with a file
2336 * @param url The smb url of the file or directory to list the extended
2337 * attributes for.
2339 * @param list A pointer to a buffer in which the list of attributes for
2340 * the specified file or directory will be placed (unless
2341 * size is zero).
2343 * @param size The size of the buffer pointed to by list. This parameter
2344 * may also be zero, in which case the size of the buffer
2345 * required to hold all of the attribute names will be
2346 * returned, but nothing will be placed into the list buffer.
2348 * @return 0 on success, < 0 on error with errno set:
2349 * - EINVAL The client library is not properly initialized
2350 * - ENOMEM No memory was available for internal needs
2351 * - EPERM Permission was denied.
2352 * - ENOTSUP The referenced file system does not support
2353 * extended attributes
2355 * @note This function always returns all attribute names supported
2356 * by NT file systems, regardless of whether the referenced
2357 * file system supports extended attributes (e.g. a Windows
2358 * 2000 machine supports extended attributes if NTFS is used,
2359 * but not if FAT is used, and Windows 98 doesn't support
2360 * extended attributes at all. Whether this is a feature or
2361 * a bug is yet to be decided.
2363 int smbc_listxattr(const char *url,
2364 char *list,
2365 size_t size);
2367 /**@ingroup attribute
2368 * List the supported extended attribute names associated with a file The
2369 * POSIX function which this maps to would act on a symbolic link rather than
2370 * acting on what the symbolic link points to, but with no symbolic links in
2371 * SMB file systems, this function is functionally identical to
2372 * smbc_listxattr().
2374 * @param url The smb url of the file or directory to list the extended
2375 * attributes for.
2377 * @param list A pointer to a buffer in which the list of attributes for
2378 * the specified file or directory will be placed (unless
2379 * size is zero).
2381 * @param size The size of the buffer pointed to by list. This parameter
2382 * may also be zero, in which case the size of the buffer
2383 * required to hold all of the attribute names will be
2384 * returned, but nothing will be placed into the list buffer.
2386 * @return 0 on success, < 0 on error with errno set:
2387 * - EINVAL The client library is not properly initialized
2388 * - ENOMEM No memory was available for internal needs
2389 * - EPERM Permission was denied.
2390 * - ENOTSUP The referenced file system does not support
2391 * extended attributes
2393 * @note This function always returns all attribute names supported
2394 * by NT file systems, regardless of wether the referenced
2395 * file system supports extended attributes (e.g. a Windows
2396 * 2000 machine supports extended attributes if NTFS is used,
2397 * but not if FAT is used, and Windows 98 doesn't support
2398 * extended attributes at all. Whether this is a feature or
2399 * a bug is yet to be decided.
2401 int smbc_llistxattr(const char *url,
2402 char *list,
2403 size_t size);
2405 /**@ingroup attribute
2406 * List the supported extended attribute names associated with a file
2408 * @param fd A file descriptor associated with an open file (as
2409 * previously returned by smbc_open(), to get extended
2410 * attributes for.
2412 * @param list A pointer to a buffer in which the list of attributes for
2413 * the specified file or directory will be placed (unless
2414 * size is zero).
2416 * @param size The size of the buffer pointed to by list. This parameter
2417 * may also be zero, in which case the size of the buffer
2418 * required to hold all of the attribute names will be
2419 * returned, but nothing will be placed into the list buffer.
2421 * @return 0 on success, < 0 on error with errno set:
2422 * - EINVAL The client library is not properly initialized
2423 * - ENOMEM No memory was available for internal needs
2424 * - EPERM Permission was denied.
2425 * - ENOTSUP The referenced file system does not support
2426 * extended attributes
2428 * @note This function always returns all attribute names supported
2429 * by NT file systems, regardless of wether the referenced
2430 * file system supports extended attributes (e.g. a Windows
2431 * 2000 machine supports extended attributes if NTFS is used,
2432 * but not if FAT is used, and Windows 98 doesn't support
2433 * extended attributes at all. Whether this is a feature or
2434 * a bug is yet to be decided.
2436 int smbc_flistxattr(int fd,
2437 char *list,
2438 size_t size);
2440 /**@ingroup print
2441 * Print a file given the name in fname. It would be a URL ...
2443 * @param fname The URL of a file on a remote SMB server that the
2444 * caller wants printed
2446 * @param printq The URL of the print share to print the file to.
2448 * @return 0 on success, < 0 on error with errno set:
2450 * - EINVAL fname or printq was NULL or smbc_init not
2451 * not called.
2452 * and errors returned by smbc_open
2455 int smbc_print_file(const char *fname, const char *printq);
2457 /**@ingroup print
2458 * Open a print file that can be written to by other calls. This simply
2459 * does an smbc_open call after checking if there is a file name on the
2460 * URI. If not, a temporary name is added ...
2462 * @param fname The URL of the print share to print to?
2464 * @returns A file handle for the print file if successful.
2465 * Returns -1 if an error ocurred and errno has the values
2466 * - EINVAL fname was NULL or smbc_init not called.
2467 * - all errors returned by smbc_open
2470 int smbc_open_print_job(const char *fname);
2472 /**@ingroup print
2473 * List the print jobs on a print share, for the moment, pass a callback
2475 * @param purl The url of the print share to list the jobs of
2477 * @param fn Callback function the receives printjob info
2479 * @return 0 on success, < 0 on error with errno set:
2480 * - EINVAL fname was NULL or smbc_init not called
2481 * - EACCES ???
2483 int smbc_list_print_jobs(const char *purl, smbc_list_print_job_fn fn);
2485 /**@ingroup print
2486 * Delete a print job
2488 * @param purl Url of the print share
2490 * @param id The id of the job to delete
2492 * @return 0 on success, < 0 on error with errno set:
2493 * - EINVAL fname was NULL or smbc_init not called
2495 * @todo what errno values are possible here?
2497 int smbc_unlink_print_job(const char *purl, int id);
2499 /**@ingroup callback
2500 * Remove a server from the cached server list it's unused.
2502 * @param context pointer to smb context
2504 * @param srv pointer to server to remove
2506 * @return On success, 0 is returned. 1 is returned if the server could not
2507 * be removed. Also useable outside libsmbclient.
2509 int smbc_remove_unused_server(SMBCCTX * context, SMBCSRV * srv);
2511 #ifdef __cplusplus
2513 #endif
2515 /**@ingroup directory
2516 * Convert strings of %xx to their single character equivalent.
2518 * @param dest A pointer to a buffer in which the resulting decoded
2519 * string should be placed. This may be a pointer to the
2520 * same buffer as src_segment.
2522 * @param src A pointer to the buffer containing the URL to be decoded.
2523 * Any %xx sequences herein are converted to their single
2524 * character equivalent. Each 'x' must be a valid hexadecimal
2525 * digit, or that % sequence is left undecoded.
2527 * @param max_dest_len
2528 * The size of the buffer pointed to by dest_segment.
2530 * @return The number of % sequences which could not be converted
2531 * due to lack of two following hexadecimal digits.
2533 #ifdef __cplusplus
2534 extern "C" {
2535 #endif
2537 smbc_urldecode(char *dest, char * src, size_t max_dest_len);
2538 #ifdef __cplusplus
2540 #endif
2544 * Convert any characters not specifically allowed in a URL into their %xx
2545 * equivalent.
2547 * @param dest A pointer to a buffer in which the resulting encoded
2548 * string should be placed. Unlike smbc_urldecode(), this
2549 * must be a buffer unique from src.
2551 * @param src A pointer to the buffer containing the string to be encoded.
2552 * Any character not specifically allowed in a URL is converted
2553 * into its hexadecimal value and encoded as %xx.
2555 * @param max_dest_len
2556 * The size of the buffer pointed to by dest_segment.
2558 * @returns The remaining buffer length.
2560 #ifdef __cplusplus
2561 extern "C" {
2562 #endif
2564 smbc_urlencode(char * dest, char * src, int max_dest_len);
2565 #ifdef __cplusplus
2567 #endif
2570 /**@ingroup directory
2571 * Return the version of the linked Samba code, and thus the version of the
2572 * libsmbclient code.
2574 * @return The version string.
2576 #ifdef __cplusplus
2577 extern "C" {
2578 #endif
2579 const char *
2580 smbc_version(void);
2581 #ifdef __cplusplus
2583 #endif
2585 /**@ingroup misc
2586 * Set the users credentials globally so they can be used for DFS
2587 * referrals. Probably best to use this function in the smbc_get_auth_data_fn
2588 * callback.
2590 * @param workgroup Workgroup of the user.
2592 * @param user Username of user.
2594 * @param password Password of user.
2596 * @param use_kerberos Whether to use Kerberos
2598 * @param signing_state One of these strings (all equivalents on same line):
2599 * "off", "no", "false"
2600 * "on", "yes", "true", "auto"
2601 * "force", "required", "forced"
2604 void
2605 smbc_set_credentials(char *workgroup,
2606 char *user,
2607 char *password,
2608 smbc_bool use_kerberos,
2609 char *signing_state);
2613 * @ingroup structure
2614 * Structure that contains a client context information
2615 * This structure is known as SMBCCTX
2617 * DO NOT DIRECTLY MANIPULATE THE CONTEXT STRUCTURE! The data in the context
2618 * structure should all be considered private to the library. It remains here
2619 * only for backward compatibility.
2621 * See the comments herein for use of the setter and getter functions which
2622 * should now be used for manipulating these values. New features, functions,
2623 * etc., are not added here but rather in _internal where they are not
2624 * directly visible to applications. This makes it much easier to maintain
2625 * ABI compatibility.
2627 struct _SMBCCTX
2630 * debug level
2632 * DEPRECATED:
2633 * Use smbc_getDebug() and smbc_setDebug()
2635 int debug DEPRECATED_SMBC_INTERFACE;
2638 * netbios name used for making connections
2640 * DEPRECATED:
2641 * Use smbc_getNetbiosName() and smbc_setNetbiosName()
2643 char * netbios_name DEPRECATED_SMBC_INTERFACE;
2646 * workgroup name used for making connections
2648 * DEPRECATED:
2649 * Use smbc_getWorkgroup() and smbc_setWorkgroup()
2651 char * workgroup DEPRECATED_SMBC_INTERFACE;
2654 * username used for making connections
2656 * DEPRECATED:
2657 * Use smbc_getUser() and smbc_setUser()
2659 char * user DEPRECATED_SMBC_INTERFACE;
2662 * timeout used for waiting on connections / response data (in
2663 * milliseconds)
2665 * DEPRECATED:
2666 * Use smbc_getTimeout() and smbc_setTimeout()
2668 int timeout DEPRECATED_SMBC_INTERFACE;
2671 * callable functions for files:
2672 * For usage and return values see the SMBC_* functions
2674 * DEPRECATED:
2676 * Use smbc_getFunction*() and smbc_setFunction*(), e.g.
2677 * smbc_getFunctionOpen(), smbc_setFunctionUnlink(), etc.
2679 smbc_open_fn open DEPRECATED_SMBC_INTERFACE;
2680 smbc_creat_fn creat DEPRECATED_SMBC_INTERFACE;
2681 smbc_read_fn read DEPRECATED_SMBC_INTERFACE;
2682 smbc_write_fn write DEPRECATED_SMBC_INTERFACE;
2683 smbc_unlink_fn unlink DEPRECATED_SMBC_INTERFACE;
2684 smbc_rename_fn rename DEPRECATED_SMBC_INTERFACE;
2685 smbc_lseek_fn lseek DEPRECATED_SMBC_INTERFACE;
2686 smbc_stat_fn stat DEPRECATED_SMBC_INTERFACE;
2687 smbc_fstat_fn fstat DEPRECATED_SMBC_INTERFACE;
2688 #if 0 /* internal */
2689 smbc_ftruncate_fn ftruncate_fn;
2690 #endif
2691 smbc_close_fn close_fn DEPRECATED_SMBC_INTERFACE;
2692 smbc_opendir_fn opendir DEPRECATED_SMBC_INTERFACE;
2693 smbc_closedir_fn closedir DEPRECATED_SMBC_INTERFACE;
2694 smbc_readdir_fn readdir DEPRECATED_SMBC_INTERFACE;
2695 smbc_getdents_fn getdents DEPRECATED_SMBC_INTERFACE;
2696 smbc_mkdir_fn mkdir DEPRECATED_SMBC_INTERFACE;
2697 smbc_rmdir_fn rmdir DEPRECATED_SMBC_INTERFACE;
2698 smbc_telldir_fn telldir DEPRECATED_SMBC_INTERFACE;
2699 smbc_lseekdir_fn lseekdir DEPRECATED_SMBC_INTERFACE;
2700 smbc_fstatdir_fn fstatdir DEPRECATED_SMBC_INTERFACE;
2701 smbc_chmod_fn chmod DEPRECATED_SMBC_INTERFACE;
2702 smbc_utimes_fn utimes DEPRECATED_SMBC_INTERFACE;
2703 smbc_setxattr_fn setxattr DEPRECATED_SMBC_INTERFACE;
2704 smbc_getxattr_fn getxattr DEPRECATED_SMBC_INTERFACE;
2705 smbc_removexattr_fn removexattr DEPRECATED_SMBC_INTERFACE;
2706 smbc_listxattr_fn listxattr DEPRECATED_SMBC_INTERFACE;
2708 /* Printing-related functions */
2709 smbc_print_file_fn print_file DEPRECATED_SMBC_INTERFACE;
2710 smbc_open_print_job_fn open_print_job DEPRECATED_SMBC_INTERFACE;
2711 smbc_list_print_jobs_fn list_print_jobs DEPRECATED_SMBC_INTERFACE;
2712 smbc_unlink_print_job_fn unlink_print_job DEPRECATED_SMBC_INTERFACE;
2715 ** Callbacks
2717 * DEPRECATED:
2719 * See the comment above each field, for the getter and setter
2720 * functions that should now be used.
2722 struct _smbc_callbacks
2725 * authentication function callback: called upon auth requests
2727 * DEPRECATED:
2728 * Use smbc_getFunctionAuthData(), smbc_setFunctionAuthData()
2730 smbc_get_auth_data_fn auth_fn DEPRECATED_SMBC_INTERFACE;
2733 * check if a server is still good
2735 * DEPRECATED:
2736 * Use smbc_getFunctionCheckServer(),
2737 * smbc_setFunctionCheckServer()
2739 smbc_check_server_fn check_server_fn DEPRECATED_SMBC_INTERFACE;
2742 * remove a server if unused
2744 * DEPRECATED:
2745 * Use smbc_getFunctionRemoveUnusedServer(),
2746 * smbc_setFunctionCheckServer()
2748 smbc_remove_unused_server_fn remove_unused_server_fn DEPRECATED_SMBC_INTERFACE;
2750 /** Cache subsystem
2752 * For an example cache system see
2753 * samba/source/libsmb/libsmb_cache.c
2755 * Cache subsystem * functions follow.
2759 * server cache addition
2761 * DEPRECATED:
2762 * Use smbc_getFunctionAddCachedServer(),
2763 * smbc_setFunctionAddCachedServer()
2765 smbc_add_cached_srv_fn add_cached_srv_fn DEPRECATED_SMBC_INTERFACE;
2768 * server cache lookup
2770 * DEPRECATED:
2771 * Use smbc_getFunctionGetCachedServer(),
2772 * smbc_setFunctionGetCachedServer()
2774 smbc_get_cached_srv_fn get_cached_srv_fn DEPRECATED_SMBC_INTERFACE;
2777 * server cache removal
2779 * DEPRECATED:
2780 * Use smbc_getFunctionRemoveCachedServer(),
2781 * smbc_setFunctionRemoveCachedServer()
2783 smbc_remove_cached_srv_fn remove_cached_srv_fn DEPRECATED_SMBC_INTERFACE;
2786 * server cache purging, try to remove all cached servers
2787 * (disconnect)
2789 * DEPRECATED:
2790 * Use smbc_getFunctionPurgeCachedServers(),
2791 * smbc_setFunctionPurgeCachedServers()
2793 smbc_purge_cached_fn purge_cached_fn DEPRECATED_SMBC_INTERFACE;
2794 } callbacks;
2797 * Space where the private data of the server cache used to be
2799 * DEPRECATED:
2800 * Use smbc_getServerCacheData(), smbc_setServerCacheData()
2802 void * reserved DEPRECATED_SMBC_INTERFACE;
2805 * Very old configuration options.
2807 * DEPRECATED:
2808 * Use one of the following functions instead:
2809 * smbc_setOptionUseKerberos()
2810 * smbc_getOptionUseKerberos()
2811 * smbc_setOptionFallbackAfterKerberos()
2812 * smbc_getOptionFallbackAfterKerberos()
2813 * smbc_setOptionNoAutoAnonymousLogin()
2814 * smbc_getOptionNoAutoAnonymousLogin()
2816 int flags DEPRECATED_SMBC_INTERFACE;
2819 * user options selections that apply to this session
2821 * NEW OPTIONS ARE NOT ADDED HERE!
2823 * DEPRECATED:
2824 * To set and retrieve options, use the smbc_setOption*() and
2825 * smbc_getOption*() functions.
2827 struct _smbc_options {
2828 int browse_max_lmb_count DEPRECATED_SMBC_INTERFACE;
2829 int urlencode_readdir_entries DEPRECATED_SMBC_INTERFACE;
2830 int one_share_per_server DEPRECATED_SMBC_INTERFACE;
2831 } options DEPRECATED_SMBC_INTERFACE;
2833 /** INTERNAL DATA
2834 * do _NOT_ touch this from your program !
2836 struct SMBC_internal_data * internal;
2840 #endif /* SMBCLIENT_H_INCLUDED */