faaab2e36889a1a7d064cba18ac57d977a86ec71
[garming/samba-autobuild/.git] / source3 / include / libsmbclient.h
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
9
10
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.
15
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.
20
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   =====================================================================*/
24
25 #ifndef SMBCLIENT_H_INCLUDED
26 #define SMBCLIENT_H_INCLUDED
27
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
34
35 #ifdef __cplusplus
36 extern "C" {
37 #endif
38
39 /*-------------------------------------------------------------------*/
40 /* The following are special comments to instruct DOXYGEN (automated
41  * documentation tool:
42 */
43 /** \defgroup libsmbclient
44 */
45 /** \defgroup structure Data Structures Type and Constants
46 *   \ingroup libsmbclient
47 *   Data structures, types, and constants
48 */
49 /** \defgroup callback Callback function types
50 *   \ingroup libsmbclient
51 *   Callback functions
52 */
53 /** \defgroup file File Functions
54 *   \ingroup libsmbclient
55 *   Functions used to access individual file contents
56 */
57 /** \defgroup directory Directory Functions
58 *   \ingroup libsmbclient
59 *   Functions used to access directory entries
60 */
61 /** \defgroup attribute Attributes Functions
62 *   \ingroup libsmbclient
63 *   Functions used to view or change file and directory attributes
64 */
65 /** \defgroup print Print Functions
66 *   \ingroup libsmbclient
67 *   Functions used to access printing functionality
68 */
69 /** \defgroup misc Miscellaneous Functions
70 *   \ingroup libsmbclient
71 *   Functions that don't fit in to other categories
72 */
73 /*-------------------------------------------------------------------*/
74
75 /* Make sure we have the following includes for now ... */
76 #include <sys/types.h>
77 #include <sys/stat.h>
78 #include <sys/statvfs.h>
79 #include <stdint.h>
80 #include <fcntl.h>
81 #include <utime.h>
82
83 #define SMBC_BASE_FD        10000 /* smallest file descriptor returned */
84
85 #define SMBC_WORKGROUP      1
86 #define SMBC_SERVER         2
87 #define SMBC_FILE_SHARE     3
88 #define SMBC_PRINTER_SHARE  4
89 #define SMBC_COMMS_SHARE    5
90 #define SMBC_IPC_SHARE      6
91 #define SMBC_DIR            7
92 #define SMBC_FILE           8
93 #define SMBC_LINK           9
94
95 /**@ingroup structure
96  * Structure that represents a directory entry.
97  *
98  */
99 struct smbc_dirent
100 {
101         /** Type of entity.
102             SMBC_WORKGROUP=1,
103             SMBC_SERVER=2,
104             SMBC_FILE_SHARE=3,
105             SMBC_PRINTER_SHARE=4,
106             SMBC_COMMS_SHARE=5,
107             SMBC_IPC_SHARE=6,
108             SMBC_DIR=7,
109             SMBC_FILE=8,
110             SMBC_LINK=9,*/
111         unsigned int smbc_type;
112
113         /** Length of this smbc_dirent in bytes
114          */
115         unsigned int dirlen;
116         /** The length of the comment string in bytes (does not include
117          *  null terminator)
118          */
119         unsigned int commentlen;
120         /** Points to the null terminated comment string
121          */
122         char *comment;
123         /** The length of the name string in bytes (does not include
124          *  null terminator)
125          */
126         unsigned int namelen;
127         /** Points to the null terminated name string
128          */
129         char name[1];
130 };
131
132 /*
133  * Flags for smbc_setxattr()
134  *   Specify a bitwise OR of these, or 0 to add or replace as necessary
135  */
136 #define SMBC_XATTR_FLAG_CREATE       0x1 /* fail if attr already exists */
137 #define SMBC_XATTR_FLAG_REPLACE      0x2 /* fail if attr does not exist */
138
139
140 /*
141  * Mappings of the DOS mode bits, as returned by smbc_getxattr() when the
142  * attribute name "system.dos_attr.mode" (or "system.dos_attr.*" or
143  * "system.*") is specified.
144  */
145 #define SMBC_DOS_MODE_READONLY       0x01
146 #define SMBC_DOS_MODE_HIDDEN         0x02
147 #define SMBC_DOS_MODE_SYSTEM         0x04
148 #define SMBC_DOS_MODE_VOLUME_ID      0x08
149 #define SMBC_DOS_MODE_DIRECTORY      0x10
150 #define SMBC_DOS_MODE_ARCHIVE        0x20
151
152 /*
153  * Valid values for the option "open_share_mode", when calling
154  * smbc_setOptionOpenShareMode()
155  */
156 typedef enum smbc_share_mode
157 {
158     SMBC_SHAREMODE_DENY_DOS     = 0,
159     SMBC_SHAREMODE_DENY_ALL     = 1,
160     SMBC_SHAREMODE_DENY_WRITE   = 2,
161     SMBC_SHAREMODE_DENY_READ    = 3,
162     SMBC_SHAREMODE_DENY_NONE    = 4,
163     SMBC_SHAREMODE_DENY_FCB     = 7
164 } smbc_share_mode;
165
166
167 /**
168  * Values for option SMB Encryption Level, as set and retrieved with
169  * smbc_setOptionSmbEncryptionLevel() and smbc_getOptionSmbEncryptionLevel()
170  */
171 typedef enum smbc_smb_encrypt_level
172 {
173     SMBC_ENCRYPTLEVEL_NONE      = 0,
174     SMBC_ENCRYPTLEVEL_REQUEST   = 1,
175     SMBC_ENCRYPTLEVEL_REQUIRE   = 2
176 } smbc_smb_encrypt_level;
177
178
179 /**
180  * Capabilities set in the f_flag field of struct statvfs, from
181  * smbc_statvfs(). These may be OR-ed together to reflect a full set of
182  * available capabilities.
183  */
184 typedef enum smbc_vfs_feature
185 {
186     /* Defined by POSIX or in Linux include files (low-order bits) */
187     SMBC_VFS_FEATURE_RDONLY         = (1 << 0),
188
189     /* Specific to libsmbclient (high-order bits) */
190     SMBC_VFS_FEATURE_DFS              = (1 << 28),
191     SMBC_VFS_FEATURE_CASE_INSENSITIVE = (1 << 29),
192     SMBC_VFS_FEATURE_NO_UNIXCIFS      = (1 << 30)
193 } smbc_vfs_feature;
194
195 typedef int smbc_bool;
196
197
198 #ifndef ENOATTR
199 # define ENOATTR ENOENT        /* No such attribute */
200 #endif
201
202
203
204
205 /**@ingroup structure
206  * Structure that represents a print job.
207  *
208  */
209 #ifndef _CLIENT_H
210 struct print_job_info
211 {
212         /** numeric ID of the print job
213          */
214         unsigned short id;
215
216         /** represents print job priority (lower numbers mean higher priority)
217          */
218         unsigned short priority;
219
220         /** Size of the print job
221          */
222         size_t size;
223
224         /** Name of the user that owns the print job
225          */
226         char user[128];
227
228         /** Name of the print job. This will have no name if an anonymous print
229          *  file was opened. Ie smb://server/printer
230          */
231         char name[128];
232
233         /** Time the print job was spooled
234          */
235         time_t t;
236 };
237 #endif /* _CLIENT_H */
238
239
240 /**@ingroup structure
241  * Server handle
242  */
243 typedef struct _SMBCSRV  SMBCSRV;
244
245 /**@ingroup structure
246  * File or directory handle
247  */
248 typedef struct _SMBCFILE SMBCFILE;
249
250 /**@ingroup structure
251  * File or directory handle
252  */
253 typedef struct _SMBCCTX SMBCCTX;
254
255
256 /*
257  * Flags for SMBCCTX->flags
258  *
259  * NEW CODE SHOULD NOT DIRECTLY MANIPULATE THE CONTEXT STRUCTURE.
260  * Instead, use:
261  *   smbc_setOptionUseKerberos()
262  *   smbc_getOptionUseKerberos()
263  *   smbc_setOptionFallbackAfterKerberos()
264  *   smbc_getOptionFallbackAFterKerberos()
265  *   smbc_setOptionNoAutoAnonymousLogin()
266  *   smbc_getOptionNoAutoAnonymousLogin()
267  *   smbc_setOptionUseCCache()
268  *   smbc_getOptionUseCCache()
269  */
270 # define SMB_CTX_FLAG_USE_KERBEROS (1 << 0)
271 # define SMB_CTX_FLAG_FALLBACK_AFTER_KERBEROS (1 << 1)
272 # define SMBCCTX_FLAG_NO_AUTO_ANONYMOUS_LOGON (1 << 2)
273 # define SMB_CTX_FLAG_USE_CCACHE (1 << 3)
274
275
276
277 /**@ingroup callback
278  * Authentication callback function type (traditional method)
279  *
280  * Type for the the authentication function called by the library to
281  * obtain authentication credentials
282  *
283  * For kerberos support the function should just be called without
284  * prompting the user for credentials. Which means a simple 'return'
285  * should work. Take a look at examples/libsmbclient/get_auth_data_fn.h
286  * and examples/libsmbclient/testbrowse.c.
287  *
288  * @param srv       Server being authenticated to
289  *
290  * @param shr       Share being authenticated to
291  *
292  * @param wg        Pointer to buffer containing a "hint" for the
293  *                  workgroup to be authenticated.  Should be filled in
294  *                  with the correct workgroup if the hint is wrong.
295  *
296  * @param wglen     The size of the workgroup buffer in bytes
297  *
298  * @param un        Pointer to buffer containing a "hint" for the
299  *                  user name to be use for authentication. Should be
300  *                  filled in with the correct workgroup if the hint is
301  *                  wrong.
302  *
303  * @param unlen     The size of the username buffer in bytes
304  *
305  * @param pw        Pointer to buffer containing to which password
306  *                  copied
307  *
308  * @param pwlen     The size of the password buffer in bytes
309  *
310  */
311 typedef void (*smbc_get_auth_data_fn)(const char *srv,
312                                       const char *shr,
313                                       char *wg, int wglen,
314                                       char *un, int unlen,
315                                       char *pw, int pwlen);
316 /**@ingroup callback
317  * Authentication callback function type (method that includes context)
318  *
319  * Type for the the authentication function called by the library to
320  * obtain authentication credentials
321  *
322  * For kerberos support the function should just be called without
323  * prompting the user for credentials. Which means a simple 'return'
324  * should work. Take a look at examples/libsmbclient/get_auth_data_fn.h
325  * and examples/libsmbclient/testbrowse.c.
326  *
327  * @param c         Pointer to the smb context
328  *
329  * @param srv       Server being authenticated to
330  *
331  * @param shr       Share being authenticated to
332  *
333  * @param wg        Pointer to buffer containing a "hint" for the
334  *                  workgroup to be authenticated.  Should be filled in
335  *                  with the correct workgroup if the hint is wrong.
336  *
337  * @param wglen     The size of the workgroup buffer in bytes
338  *
339  * @param un        Pointer to buffer containing a "hint" for the
340  *                  user name to be use for authentication. Should be
341  *                  filled in with the correct workgroup if the hint is
342  *                  wrong.
343  *
344  * @param unlen     The size of the username buffer in bytes
345  *
346  * @param pw        Pointer to buffer containing to which password
347  *                  copied
348  *
349  * @param pwlen     The size of the password buffer in bytes
350  *
351  */
352 typedef void (*smbc_get_auth_data_with_context_fn)(SMBCCTX *c,
353                                                    const char *srv,
354                                                    const char *shr,
355                                                    char *wg, int wglen,
356                                                    char *un, int unlen,
357                                                    char *pw, int pwlen);
358
359
360 /**@ingroup callback
361  * Print job info callback function type.
362  *
363  * @param i         pointer to print job information structure
364  *
365  */
366 typedef void (*smbc_list_print_job_fn)(struct print_job_info *i);
367
368
369 /**@ingroup callback
370  * Check if a server is still good
371  *
372  * @param c         pointer to smb context
373  *
374  * @param srv       pointer to server to check
375  *
376  * @return          0 when connection is good. 1 on error.
377  *
378  */
379 typedef int (*smbc_check_server_fn)(SMBCCTX * c, SMBCSRV *srv);
380
381 /**@ingroup callback
382  * Remove a server if unused
383  *
384  * @param c         pointer to smb context
385  *
386  * @param srv       pointer to server to remove
387  *
388  * @return          0 on success. 1 on failure.
389  *
390  */
391 typedef int (*smbc_remove_unused_server_fn)(SMBCCTX * c, SMBCSRV *srv);
392
393
394 /**@ingroup callback
395  * Add a server to the cache system
396  *
397  * @param c         pointer to smb context
398  *
399  * @param srv       pointer to server to add
400  *
401  * @param server    server name
402  *
403  * @param share     share name
404  *
405  * @param workgroup workgroup used to connect
406  *
407  * @param username  username used to connect
408  *
409  * @return          0 on success. 1 on failure.
410  *
411  */
412 typedef int (*smbc_add_cached_srv_fn)   (SMBCCTX * c, SMBCSRV *srv,
413                                     const char * server, const char * share,
414                                     const char * workgroup, const char * username);
415
416 /**@ingroup callback
417  * Look up a server in the cache system
418  *
419  * @param c         pointer to smb context
420  *
421  * @param server    server name to match
422  *
423  * @param share     share name to match
424  *
425  * @param workgroup workgroup to match
426  *
427  * @param username  username to match
428  *
429  * @return          pointer to SMBCSRV on success. NULL on failure.
430  *
431  */
432 typedef SMBCSRV * (*smbc_get_cached_srv_fn)   (SMBCCTX * c, const char * server,
433                                                const char * share, const char * workgroup,
434                                                const char * username);
435
436 /**@ingroup callback
437  * Check if a server is still good
438  *
439  * @param c         pointer to smb context
440  *
441  * @param srv       pointer to server to remove
442  *
443  * @return          0 when found and removed. 1 on failure.
444  *
445  */
446 typedef int (*smbc_remove_cached_srv_fn)(SMBCCTX * c, SMBCSRV *srv);
447
448
449 /**@ingroup callback
450  * Try to remove all servers from the cache system and disconnect
451  *
452  * @param c         pointer to smb context
453  *
454  * @return          0 when found and removed. 1 on failure.
455  *
456  */
457 typedef int (*smbc_purge_cached_fn)     (SMBCCTX * c);
458
459
460
461 /*****************************************
462  * Getters and setters for CONFIGURATION *
463  *****************************************/
464
465 /** Get the debug level */
466 int
467 smbc_getDebug(SMBCCTX *c);
468
469 /** Set the debug level */
470 void
471 smbc_setDebug(SMBCCTX *c, int debug);
472
473 /** Get the netbios name used for making connections */
474 char *
475 smbc_getNetbiosName(SMBCCTX *c);
476
477 /** Set the netbios name used for making connections */
478 void
479 smbc_setNetbiosName(SMBCCTX *c, char * netbios_name);
480
481 /** Get the workgroup used for making connections */
482 char *
483 smbc_getWorkgroup(SMBCCTX *c);
484
485 /** Set the workgroup used for making connections */
486 void smbc_setWorkgroup(SMBCCTX *c, char * workgroup);
487
488 /** Get the username used for making connections */
489 char *
490 smbc_getUser(SMBCCTX *c);
491
492 /** Set the username used for making connections */
493 void
494 smbc_setUser(SMBCCTX *c, char * user);
495
496 /**
497  * Get the timeout used for waiting on connections and response data
498  * (in milliseconds)
499  */
500 int
501 smbc_getTimeout(SMBCCTX *c);
502
503 /**
504  * Set the timeout used for waiting on connections and response data
505  * (in milliseconds)
506  */
507 void
508 smbc_setTimeout(SMBCCTX *c, int timeout);
509
510
511 /**
512  * Get the TCP port used to connect (0 means default).
513  */
514 uint16_t
515 smbc_getPort(SMBCCTX *c);
516
517 /**
518  * Set the TCP port used to connect (0 means default).
519  */
520 void
521 smbc_setPort(SMBCCTX *c, uint16_t port);
522
523
524
525 /***********************************
526  * Getters and setters for OPTIONS *
527  ***********************************/
528
529 /** Get whether to log to standard error instead of standard output */
530 smbc_bool
531 smbc_getOptionDebugToStderr(SMBCCTX *c);
532
533 /** Set whether to log to standard error instead of standard output */
534 void
535 smbc_setOptionDebugToStderr(SMBCCTX *c, smbc_bool b);
536
537 /**
538  * Get whether to use new-style time attribute names, e.g. WRITE_TIME rather
539  * than the old-style names such as M_TIME.  This allows also setting/getting
540  * CREATE_TIME which was previously unimplemented.  (Note that the old C_TIME
541  * was supposed to be CHANGE_TIME but was confused and sometimes referred to
542  * CREATE_TIME.)
543  */
544 smbc_bool
545 smbc_getOptionFullTimeNames(SMBCCTX *c);
546
547 /**
548  * Set whether to use new-style time attribute names, e.g. WRITE_TIME rather
549  * than the old-style names such as M_TIME.  This allows also setting/getting
550  * CREATE_TIME which was previously unimplemented.  (Note that the old C_TIME
551  * was supposed to be CHANGE_TIME but was confused and sometimes referred to
552  * CREATE_TIME.)
553  */
554 void
555 smbc_setOptionFullTimeNames(SMBCCTX *c, smbc_bool b);
556
557 /**
558  * Get the share mode to use for files opened with SMBC_open_ctx().  The
559  * default is SMBC_SHAREMODE_DENY_NONE.
560  */
561 smbc_share_mode
562 smbc_getOptionOpenShareMode(SMBCCTX *c);
563
564 /**
565  * Set the share mode to use for files opened with SMBC_open_ctx().  The
566  * default is SMBC_SHAREMODE_DENY_NONE.
567  */
568 void
569 smbc_setOptionOpenShareMode(SMBCCTX *c, smbc_share_mode share_mode);
570
571 /** Retrieve a previously saved user data handle */
572 void *
573 smbc_getOptionUserData(SMBCCTX *c);
574
575 /** Save a user data handle */
576 void
577 smbc_setOptionUserData(SMBCCTX *c, void *user_data);
578
579 /** Get the encoded value for encryption level. */
580 smbc_smb_encrypt_level
581 smbc_getOptionSmbEncryptionLevel(SMBCCTX *c);
582
583 /** Set the encoded value for encryption level. */
584 void
585 smbc_setOptionSmbEncryptionLevel(SMBCCTX *c, smbc_smb_encrypt_level level);
586
587 /**
588  * Get whether to treat file names as case-sensitive if we can't determine
589  * when connecting to the remote share whether the file system is case
590  * sensitive. This defaults to FALSE since it's most likely that if we can't
591  * retrieve the file system attributes, it's a very old file system that does
592  * not support case sensitivity.
593  */
594 smbc_bool
595 smbc_getOptionCaseSensitive(SMBCCTX *c);
596
597 /**
598  * Set whether to treat file names as case-sensitive if we can't determine
599  * when connecting to the remote share whether the file system is case
600  * sensitive. This defaults to FALSE since it's most likely that if we can't
601  * retrieve the file system attributes, it's a very old file system that does
602  * not support case sensitivity.
603  */
604 void
605 smbc_setOptionCaseSensitive(SMBCCTX *c, smbc_bool b);
606
607
608 /**
609  * Get from how many local master browsers should the list of workgroups be
610  * retrieved.  It can take up to 12 minutes or longer after a server becomes a
611  * local master browser, for it to have the entire browse list (the list of
612  * workgroups/domains) from an entire network.  Since a client never knows
613  * which local master browser will be found first, the one which is found
614  * first and used to retrieve a browse list may have an incomplete or empty
615  * browse list.  By requesting the browse list from multiple local master
616  * browsers, a more complete list can be generated.  For small networks (few
617  * workgroups), it is recommended that this value be set to 0, causing the
618  * browse lists from all found local master browsers to be retrieved and
619  * merged.  For networks with many workgroups, a suitable value for this
620  * variable is probably somewhere around 3. (Default: 3).
621  */
622 int
623 smbc_getOptionBrowseMaxLmbCount(SMBCCTX *c);
624
625 /**
626  * Set from how many local master browsers should the list of workgroups be
627  * retrieved.  It can take up to 12 minutes or longer after a server becomes a
628  * local master browser, for it to have the entire browse list (the list of
629  * workgroups/domains) from an entire network.  Since a client never knows
630  * which local master browser will be found first, the one which is found
631  * first and used to retrieve a browse list may have an incomplete or empty
632  * browse list.  By requesting the browse list from multiple local master
633  * browsers, a more complete list can be generated.  For small networks (few
634  * workgroups), it is recommended that this value be set to 0, causing the
635  * browse lists from all found local master browsers to be retrieved and
636  * merged.  For networks with many workgroups, a suitable value for this
637  * variable is probably somewhere around 3. (Default: 3).
638  */
639 void
640 smbc_setOptionBrowseMaxLmbCount(SMBCCTX *c, int count);
641
642 /**
643  * Get whether to url-encode readdir entries.
644  *
645  * There is a difference in the desired return strings from
646  * smbc_readdir() depending upon whether the filenames are to
647  * be displayed to the user, or whether they are to be
648  * appended to the path name passed to smbc_opendir() to call
649  * a further smbc_ function (e.g. open the file with
650  * smbc_open()).  In the former case, the filename should be
651  * in "human readable" form.  In the latter case, the smbc_
652  * functions expect a URL which must be url-encoded.  Those
653  * functions decode the URL.  If, for example, smbc_readdir()
654  * returned a file name of "abc%20def.txt", passing a path
655  * with this file name attached to smbc_open() would cause
656  * smbc_open to attempt to open the file "abc def.txt" since
657  * the %20 is decoded into a space.
658  *
659  * Set this option to True if the names returned by
660  * smbc_readdir() should be url-encoded such that they can be
661  * passed back to another smbc_ call.  Set it to False if the
662  * names returned by smbc_readdir() are to be presented to the
663  * user.
664  *
665  * For backwards compatibility, this option defaults to False.
666  */
667 smbc_bool
668 smbc_getOptionUrlEncodeReaddirEntries(SMBCCTX *c);
669
670 /**
671  * Set whether to url-encode readdir entries.
672  *
673  * There is a difference in the desired return strings from
674  * smbc_readdir() depending upon whether the filenames are to
675  * be displayed to the user, or whether they are to be
676  * appended to the path name passed to smbc_opendir() to call
677  * a further smbc_ function (e.g. open the file with
678  * smbc_open()).  In the former case, the filename should be
679  * in "human readable" form.  In the latter case, the smbc_
680  * functions expect a URL which must be url-encoded.  Those
681  * functions decode the URL.  If, for example, smbc_readdir()
682  * returned a file name of "abc%20def.txt", passing a path
683  * with this file name attached to smbc_open() would cause
684  * smbc_open to attempt to open the file "abc def.txt" since
685  * the %20 is decoded into a space.
686  *
687  * Set this option to True if the names returned by
688  * smbc_readdir() should be url-encoded such that they can be
689  * passed back to another smbc_ call.  Set it to False if the
690  * names returned by smbc_readdir() are to be presented to the
691  * user.
692  *
693  * For backwards compatibility, this option defaults to False.
694  */
695 void
696 smbc_setOptionUrlEncodeReaddirEntries(SMBCCTX *c, smbc_bool b);
697
698 /**
699  * Get whether to use the same connection for all shares on a server.
700  *
701  * Some Windows versions appear to have a limit to the number
702  * of concurrent SESSIONs and/or TREE CONNECTions.  In
703  * one-shot programs (i.e. the program runs and then quickly
704  * ends, thereby shutting down all connections), it is
705  * probably reasonable to establish a new connection for each
706  * share.  In long-running applications, the limitation can be
707  * avoided by using only a single connection to each server,
708  * and issuing a new TREE CONNECT when the share is accessed.
709  */
710 smbc_bool
711 smbc_getOptionOneSharePerServer(SMBCCTX *c);
712
713 /**
714  * Set whether to use the same connection for all shares on a server.
715  *
716  * Some Windows versions appear to have a limit to the number
717  * of concurrent SESSIONs and/or TREE CONNECTions.  In
718  * one-shot programs (i.e. the program runs and then quickly
719  * ends, thereby shutting down all connections), it is
720  * probably reasonable to establish a new connection for each
721  * share.  In long-running applications, the limitation can be
722  * avoided by using only a single connection to each server,
723  * and issuing a new TREE CONNECT when the share is accessed.
724  */
725 void
726 smbc_setOptionOneSharePerServer(SMBCCTX *c, smbc_bool b);
727
728 /** Get whether to enable use of kerberos */
729 smbc_bool
730 smbc_getOptionUseKerberos(SMBCCTX *c);
731
732 /** Set whether to enable use of kerberos */
733 void
734 smbc_setOptionUseKerberos(SMBCCTX *c, smbc_bool b);
735
736 /** Get whether to fallback after kerberos */
737 smbc_bool
738 smbc_getOptionFallbackAfterKerberos(SMBCCTX *c);
739
740 /** Set whether to fallback after kerberos */
741 void
742 smbc_setOptionFallbackAfterKerberos(SMBCCTX *c, smbc_bool b);
743
744 /** Get whether to automatically select anonymous login */
745 smbc_bool
746 smbc_getOptionNoAutoAnonymousLogin(SMBCCTX *c);
747
748 /** Set whether to automatically select anonymous login */
749 void
750 smbc_setOptionNoAutoAnonymousLogin(SMBCCTX *c, smbc_bool b);
751
752 /** Get whether to enable use of the winbind ccache */
753 smbc_bool
754 smbc_getOptionUseCCache(SMBCCTX *c);
755
756 /** Set whether to enable use of the winbind ccache */
757 void
758 smbc_setOptionUseCCache(SMBCCTX *c, smbc_bool b);
759
760 /** Get indication that the password supplied is the NT hash */
761 smbc_bool
762 smbc_getOptionUseNTHash(SMBCCTX *c);
763
764 /** Set indication that the password supplied is the NT hash */
765 void
766 smbc_setOptionUseNTHash(SMBCCTX *c, smbc_bool b);
767
768
769
770 /*************************************
771  * Getters and setters for FUNCTIONS *
772  *************************************/
773
774 /** Get the function for obtaining authentication data */
775 smbc_get_auth_data_fn smbc_getFunctionAuthData(SMBCCTX *c);
776
777 /** Set the function for obtaining authentication data */
778 void smbc_setFunctionAuthData(SMBCCTX *c, smbc_get_auth_data_fn fn);
779
780 /** Get the new-style authentication function which includes the context. */
781 smbc_get_auth_data_with_context_fn
782 smbc_getFunctionAuthDataWithContext(SMBCCTX *c);
783
784 /** Set the new-style authentication function which includes the context. */
785 void
786 smbc_setFunctionAuthDataWithContext(SMBCCTX *c,
787                                     smbc_get_auth_data_with_context_fn fn);
788
789 /** Get the function for checking if a server is still good */
790 smbc_check_server_fn smbc_getFunctionCheckServer(SMBCCTX *c);
791
792 /** Set the function for checking if a server is still good */
793 void smbc_setFunctionCheckServer(SMBCCTX *c, smbc_check_server_fn fn);
794
795 /** Get the function for removing a server if unused */
796 smbc_remove_unused_server_fn smbc_getFunctionRemoveUnusedServer(SMBCCTX *c);
797
798 /** Set the function for removing a server if unused */
799 void smbc_setFunctionRemoveUnusedServer(SMBCCTX *c,
800                                         smbc_remove_unused_server_fn fn);
801
802 /** Get the function for adding a cached server */
803 smbc_add_cached_srv_fn smbc_getFunctionAddCachedServer(SMBCCTX *c);
804
805 /** Set the function for adding a cached server */
806 void smbc_setFunctionAddCachedServer(SMBCCTX *c, smbc_add_cached_srv_fn fn);
807
808 /** Get the function for server cache lookup */
809 smbc_get_cached_srv_fn smbc_getFunctionGetCachedServer(SMBCCTX *c);
810
811 /** Set the function for server cache lookup */
812 void smbc_setFunctionGetCachedServer(SMBCCTX *c, smbc_get_cached_srv_fn fn);
813
814 /** Get the function for server cache removal */
815 smbc_remove_cached_srv_fn smbc_getFunctionRemoveCachedServer(SMBCCTX *c);
816
817 /** Set the function for server cache removal */
818 void smbc_setFunctionRemoveCachedServer(SMBCCTX *c,
819                                         smbc_remove_cached_srv_fn fn);
820
821 /**
822  * Get the function for server cache purging.  This function tries to
823  * remove all cached servers (e.g. on disconnect)
824  */
825 smbc_purge_cached_fn smbc_getFunctionPurgeCachedServers(SMBCCTX *c);
826
827 /**
828  * Set the function for server cache purging.  This function tries to
829  * remove all cached servers (e.g. on disconnect)
830  */
831 void smbc_setFunctionPurgeCachedServers(SMBCCTX *c,
832                                         smbc_purge_cached_fn fn);
833
834 /** Get the function to store private data of the server cache */
835 struct smbc_server_cache * smbc_getServerCacheData(SMBCCTX *c);
836
837 /** Set the function to store private data of the server cache */
838 void smbc_setServerCacheData(SMBCCTX *c, struct smbc_server_cache * cache);
839
840
841
842 /*****************************************************************
843  * Callable functions for files.                                 *
844  * Each callable has a function signature typedef, a declaration *
845  * for the getter, and a declaration for the setter.             *
846  *****************************************************************/
847
848 typedef SMBCFILE * (*smbc_open_fn)(SMBCCTX *c,
849                                    const char *fname,
850                                    int flags,
851                                    mode_t mode);
852 smbc_open_fn smbc_getFunctionOpen(SMBCCTX *c);
853 void smbc_setFunctionOpen(SMBCCTX *c, smbc_open_fn fn);
854
855 typedef SMBCFILE * (*smbc_creat_fn)(SMBCCTX *c,
856                                     const char *path,
857                                     mode_t mode);
858 smbc_creat_fn smbc_getFunctionCreat(SMBCCTX *c);
859 void smbc_setFunctionCreat(SMBCCTX *c, smbc_creat_fn);
860
861 typedef ssize_t (*smbc_read_fn)(SMBCCTX *c,
862                                 SMBCFILE *file,
863                                 void *buf,
864                                 size_t count);
865 smbc_read_fn smbc_getFunctionRead(SMBCCTX *c);
866 void smbc_setFunctionRead(SMBCCTX *c, smbc_read_fn fn);
867
868 typedef ssize_t (*smbc_write_fn)(SMBCCTX *c,
869                                  SMBCFILE *file,
870                                  const void *buf,
871                                  size_t count);
872 smbc_write_fn smbc_getFunctionWrite(SMBCCTX *c);
873 void smbc_setFunctionWrite(SMBCCTX *c, smbc_write_fn fn);
874
875 typedef off_t (*smbc_splice_fn)(SMBCCTX *c,
876                                 SMBCFILE *srcfile,
877                                 SMBCFILE *dstfile,
878                                 off_t count,
879                                 int (*splice_cb)(off_t n, void *priv),
880                                 void *priv);
881 smbc_splice_fn smbc_getFunctionSplice(SMBCCTX *c);
882 void smbc_setFunctionSplice(SMBCCTX *c, smbc_splice_fn fn);
883
884 typedef int (*smbc_unlink_fn)(SMBCCTX *c,
885                               const char *fname);
886 smbc_unlink_fn smbc_getFunctionUnlink(SMBCCTX *c);
887 void smbc_setFunctionUnlink(SMBCCTX *c, smbc_unlink_fn fn);
888
889 typedef int (*smbc_rename_fn)(SMBCCTX *ocontext,
890                               const char *oname,
891                               SMBCCTX *ncontext,
892                               const char *nname);
893 smbc_rename_fn smbc_getFunctionRename(SMBCCTX *c);
894 void smbc_setFunctionRename(SMBCCTX *c, smbc_rename_fn fn);
895
896 typedef off_t (*smbc_lseek_fn)(SMBCCTX *c,
897                                SMBCFILE * file,
898                                off_t offset,
899                                int whence);
900 smbc_lseek_fn smbc_getFunctionLseek(SMBCCTX *c);
901 void smbc_setFunctionLseek(SMBCCTX *c, smbc_lseek_fn fn);
902
903 typedef int (*smbc_stat_fn)(SMBCCTX *c,
904                             const char *fname,
905                             struct stat *st);
906 smbc_stat_fn smbc_getFunctionStat(SMBCCTX *c);
907 void smbc_setFunctionStat(SMBCCTX *c, smbc_stat_fn fn);
908
909 typedef int (*smbc_fstat_fn)(SMBCCTX *c,
910                              SMBCFILE *file,
911                              struct stat *st);
912 smbc_fstat_fn smbc_getFunctionFstat(SMBCCTX *c);
913 void smbc_setFunctionFstat(SMBCCTX *c, smbc_fstat_fn fn);
914
915 typedef int (*smbc_statvfs_fn)(SMBCCTX *c,
916                                char *path,
917                                struct statvfs *st);
918 smbc_statvfs_fn smbc_getFunctionStatVFS(SMBCCTX *c);
919 void smbc_setFunctionStatVFS(SMBCCTX *c, smbc_statvfs_fn fn);
920
921 typedef int (*smbc_fstatvfs_fn)(SMBCCTX *c,
922                                 SMBCFILE *file,
923                                 struct statvfs *st);
924 smbc_fstatvfs_fn smbc_getFunctionFstatVFS(SMBCCTX *c);
925 void smbc_setFunctionFstatVFS(SMBCCTX *c, smbc_fstatvfs_fn fn);
926
927 typedef int (*smbc_ftruncate_fn)(SMBCCTX *c,
928                                  SMBCFILE *f,
929                                  off_t size);
930 smbc_ftruncate_fn smbc_getFunctionFtruncate(SMBCCTX *c);
931 void smbc_setFunctionFtruncate(SMBCCTX *c, smbc_ftruncate_fn fn);
932
933 typedef int (*smbc_close_fn)(SMBCCTX *c,
934                              SMBCFILE *file);
935 smbc_close_fn smbc_getFunctionClose(SMBCCTX *c);
936 void smbc_setFunctionClose(SMBCCTX *c, smbc_close_fn fn);
937
938
939
940 /*****************************************************************
941  * Callable functions for directories.                           *
942  * Each callable has a function signature typedef, a declaration *
943  * for the getter, and a declaration for the setter.             *
944  *****************************************************************/
945
946 typedef SMBCFILE * (*smbc_opendir_fn)(SMBCCTX *c,
947                                       const char *fname);
948 smbc_opendir_fn smbc_getFunctionOpendir(SMBCCTX *c);
949 void smbc_setFunctionOpendir(SMBCCTX *c, smbc_opendir_fn fn);
950
951 typedef int (*smbc_closedir_fn)(SMBCCTX *c,
952                                 SMBCFILE *dir);
953 smbc_closedir_fn smbc_getFunctionClosedir(SMBCCTX *c);
954 void smbc_setFunctionClosedir(SMBCCTX *c, smbc_closedir_fn fn);
955
956 typedef struct smbc_dirent * (*smbc_readdir_fn)(SMBCCTX *c,
957                                                 SMBCFILE *dir);
958 smbc_readdir_fn smbc_getFunctionReaddir(SMBCCTX *c);
959 void smbc_setFunctionReaddir(SMBCCTX *c, smbc_readdir_fn fn);
960
961 typedef int (*smbc_getdents_fn)(SMBCCTX *c,
962                                 SMBCFILE *dir,
963                                 struct smbc_dirent *dirp,
964                                 int count);
965 smbc_getdents_fn smbc_getFunctionGetdents(SMBCCTX *c);
966 void smbc_setFunctionGetdents(SMBCCTX *c, smbc_getdents_fn fn);
967
968 typedef int (*smbc_mkdir_fn)(SMBCCTX *c,
969                              const char *fname,
970                              mode_t mode);
971 smbc_mkdir_fn smbc_getFunctionMkdir(SMBCCTX *c);
972 void smbc_setFunctionMkdir(SMBCCTX *c, smbc_mkdir_fn fn);
973
974 typedef int (*smbc_rmdir_fn)(SMBCCTX *c,
975                              const char *fname);
976 smbc_rmdir_fn smbc_getFunctionRmdir(SMBCCTX *c);
977 void smbc_setFunctionRmdir(SMBCCTX *c, smbc_rmdir_fn fn);
978
979 typedef off_t (*smbc_telldir_fn)(SMBCCTX *c,
980                                  SMBCFILE *dir);
981 smbc_telldir_fn smbc_getFunctionTelldir(SMBCCTX *c);
982 void smbc_setFunctionTelldir(SMBCCTX *c, smbc_telldir_fn fn);
983
984 typedef int (*smbc_lseekdir_fn)(SMBCCTX *c,
985                                 SMBCFILE *dir,
986                                 off_t offset);
987 smbc_lseekdir_fn smbc_getFunctionLseekdir(SMBCCTX *c);
988 void smbc_setFunctionLseekdir(SMBCCTX *c, smbc_lseekdir_fn fn);
989
990 typedef int (*smbc_fstatdir_fn)(SMBCCTX *c,
991                                 SMBCFILE *dir,
992                                 struct stat *st);
993 smbc_fstatdir_fn smbc_getFunctionFstatdir(SMBCCTX *c);
994 void smbc_setFunctionFstatdir(SMBCCTX *c, smbc_fstatdir_fn fn);
995
996
997
998 /*****************************************************************
999  * Callable functions applicable to both files and directories.  *
1000  * Each callable has a function signature typedef, a declaration *
1001  * for the getter, and a declaration for the setter.             *
1002  *****************************************************************/
1003
1004 typedef int (*smbc_chmod_fn)(SMBCCTX *c,
1005                              const char *fname,
1006                              mode_t mode);
1007 smbc_chmod_fn smbc_getFunctionChmod(SMBCCTX *c);
1008 void smbc_setFunctionChmod(SMBCCTX *c, smbc_chmod_fn fn);
1009
1010 typedef int (*smbc_utimes_fn)(SMBCCTX *c,
1011                               const char *fname,
1012                               struct timeval *tbuf);
1013 smbc_utimes_fn smbc_getFunctionUtimes(SMBCCTX *c);
1014 void smbc_setFunctionUtimes(SMBCCTX *c, smbc_utimes_fn fn);
1015
1016 typedef int (*smbc_setxattr_fn)(SMBCCTX *context,
1017                                 const char *fname,
1018                                 const char *name,
1019                                 const void *value,
1020                                 size_t size,
1021                                 int flags);
1022 smbc_setxattr_fn smbc_getFunctionSetxattr(SMBCCTX *c);
1023 void smbc_setFunctionSetxattr(SMBCCTX *c, smbc_setxattr_fn fn);
1024
1025 typedef int (*smbc_getxattr_fn)(SMBCCTX *context,
1026                                 const char *fname,
1027                                 const char *name,
1028                                 const void *value,
1029                                 size_t size);
1030 smbc_getxattr_fn smbc_getFunctionGetxattr(SMBCCTX *c);
1031 void smbc_setFunctionGetxattr(SMBCCTX *c, smbc_getxattr_fn fn);
1032
1033 typedef int (*smbc_removexattr_fn)(SMBCCTX *context,
1034                                    const char *fname,
1035                                    const char *name);
1036 smbc_removexattr_fn smbc_getFunctionRemovexattr(SMBCCTX *c);
1037 void smbc_setFunctionRemovexattr(SMBCCTX *c, smbc_removexattr_fn fn);
1038
1039 typedef int (*smbc_listxattr_fn)(SMBCCTX *context,
1040                                  const char *fname,
1041                                  char *list,
1042                                  size_t size);
1043 smbc_listxattr_fn smbc_getFunctionListxattr(SMBCCTX *c);
1044 void smbc_setFunctionListxattr(SMBCCTX *c, smbc_listxattr_fn fn);
1045
1046
1047
1048 /*****************************************************************
1049  * Callable functions for printing.                              *
1050  * Each callable has a function signature typedef, a declaration *
1051  * for the getter, and a declaration for the setter.             *
1052  *****************************************************************/
1053
1054 typedef int (*smbc_print_file_fn)(SMBCCTX *c_file,
1055                                   const char *fname,
1056                                   SMBCCTX *c_print,
1057                                   const char *printq);
1058 smbc_print_file_fn smbc_getFunctionPrintFile(SMBCCTX *c);
1059 void smbc_setFunctionPrintFile(SMBCCTX *c, smbc_print_file_fn fn);
1060
1061 typedef SMBCFILE * (*smbc_open_print_job_fn)(SMBCCTX *c,
1062                                              const char *fname);
1063 smbc_open_print_job_fn smbc_getFunctionOpenPrintJob(SMBCCTX *c);
1064 void smbc_setFunctionOpenPrintJob(SMBCCTX *c,
1065                                   smbc_open_print_job_fn fn);
1066
1067 typedef int (*smbc_list_print_jobs_fn)(SMBCCTX *c,
1068                                        const char *fname,
1069                                        smbc_list_print_job_fn fn);
1070 smbc_list_print_jobs_fn smbc_getFunctionListPrintJobs(SMBCCTX *c);
1071 void smbc_setFunctionListPrintJobs(SMBCCTX *c,
1072                                    smbc_list_print_jobs_fn fn);
1073
1074 typedef int (*smbc_unlink_print_job_fn)(SMBCCTX *c,
1075                                         const char *fname,
1076                                         int id);
1077 smbc_unlink_print_job_fn smbc_getFunctionUnlinkPrintJob(SMBCCTX *c);
1078 void smbc_setFunctionUnlinkPrintJob(SMBCCTX *c,
1079                                     smbc_unlink_print_job_fn fn);
1080
1081
1082 /**@ingroup misc
1083  * Create a new SBMCCTX (a context).
1084  *
1085  * Must be called before the context is passed to smbc_context_init()
1086  *
1087  * @return          The given SMBCCTX pointer on success, NULL on error with errno set:
1088  *                  - ENOMEM Out of memory
1089  *
1090  * @see             smbc_free_context(), smbc_init_context()
1091  *
1092  * @note            Do not forget to smbc_init_context() the returned SMBCCTX pointer !
1093  */
1094 SMBCCTX * smbc_new_context(void);
1095
1096 /**@ingroup misc
1097  * Delete a SBMCCTX (a context) acquired from smbc_new_context().
1098  *
1099  * The context will be deleted if possible.
1100  *
1101  * @param context   A pointer to a SMBCCTX obtained from smbc_new_context()
1102  *
1103  * @param shutdown_ctx   If 1, all connections and files will be closed even if they are busy.
1104  *
1105  *
1106  * @return          Returns 0 on succes. Returns 1 on failure with errno set:
1107  *                  - EBUSY Server connections are still used, Files are open or cache
1108  *                          could not be purged
1109  *                  - EBADF context == NULL
1110  *
1111  * @see             smbc_new_context()
1112  *
1113  * @note            It is advised to clean up all the contexts with shutdown_ctx set to 1
1114  *                  just before exit()'ing. When shutdown_ctx is 0, this function can be
1115  *                  use in periodical cleanup functions for example.
1116  */
1117 int smbc_free_context(SMBCCTX * context, int shutdown_ctx);
1118
1119
1120 /**@ingroup misc
1121  *
1122  * @deprecated.  Use smbc_setOption*() functions instead.
1123  */
1124 void
1125 smbc_option_set(SMBCCTX *context,
1126                 char *option_name,
1127                 ... /* option_value */);
1128
1129 /*
1130  * @deprecated.  Use smbc_getOption*() functions instead.
1131  */
1132 void *
1133 smbc_option_get(SMBCCTX *context,
1134                 char *option_name);
1135
1136 /**@ingroup misc
1137  * Initialize a SBMCCTX (a context).
1138  *
1139  * Must be called before using any SMBCCTX API function
1140  *
1141  * @param context   A pointer to a SMBCCTX obtained from smbc_new_context()
1142  *
1143  * @return          A pointer to the given SMBCCTX on success,
1144  *                  NULL on error with errno set:
1145  *                  - EBADF  NULL context given
1146  *                  - ENOMEM Out of memory
1147  *                  - ENOENT The smb.conf file would not load
1148  *
1149  * @see             smbc_new_context()
1150  *
1151  * @note            my_context = smbc_init_context(smbc_new_context())
1152  *                  is perfectly safe, but it might leak memory on
1153  *                  smbc_context_init() failure. Avoid this.
1154  *                  You'll have to call smbc_free_context() yourself
1155  *                  on failure.
1156  */
1157
1158 SMBCCTX * smbc_init_context(SMBCCTX * context);
1159
1160 /**@ingroup misc
1161  * Initialize the samba client library.
1162  *
1163  * Must be called before using any of the smbclient API function
1164  *
1165  * @param fn        The function that will be called to obtaion
1166  *                  authentication credentials.
1167  *
1168  * @param debug     Allows caller to set the debug level. Can be
1169  *                  changed in smb.conf file. Allows caller to set
1170  *                  debugging if no smb.conf.
1171  *
1172  * @return          0 on success, < 0 on error with errno set:
1173  *                  - ENOMEM Out of memory
1174  *                  - ENOENT The smb.conf file would not load
1175  *
1176  */
1177
1178 int smbc_init(smbc_get_auth_data_fn fn, int debug);
1179
1180 /**@ingroup misc
1181  * Set or retrieve the compatibility library's context pointer
1182  *
1183  * @param context   New context to use, or NULL.  If a new context is provided,
1184  *                  it must have allocated with smbc_new_context() and
1185  *                  initialized with smbc_init_context(), followed, optionally,
1186  *                  by some manual changes to some of the non-internal fields.
1187  *
1188  * @return          The old context.
1189  *
1190  * @see             smbc_new_context(), smbc_init_context(), smbc_init()
1191  *
1192  * @note            This function may be called prior to smbc_init() to force
1193  *                  use of the next context without any internal calls to
1194  *                  smbc_new_context() or smbc_init_context().  It may also
1195  *                  be called after smbc_init() has already called those two
1196  *                  functions, to replace the existing context with a new one.
1197  *                  Care should be taken, in this latter case, to ensure that
1198  *                  the server cache and any data allocated by the
1199  *                  authentication functions have been freed, if necessary.
1200  */
1201
1202 SMBCCTX * smbc_set_context(SMBCCTX * new_context);
1203
1204 /**@ingroup file
1205  * Open a file on an SMB server.
1206  *
1207  * @param furl      The smb url of the file to be opened.
1208  *
1209  * @param flags     Is one of O_RDONLY, O_WRONLY or O_RDWR which
1210  *                  request opening  the  file  read-only,write-only
1211  *                  or read/write. flags may also be bitwise-or'd with
1212  *                  one or  more of  the following:
1213  *                  O_CREAT - If the file does not exist it will be
1214  *                  created.
1215  *                  O_EXCL - When  used with O_CREAT, if the file
1216  *                  already exists it is an error and the open will
1217  *                  fail.
1218  *                  O_TRUNC - If the file already exists it will be
1219  *                  truncated.
1220  *                  O_APPEND The  file  is  opened  in  append mode
1221  *
1222  * @param mode      mode specifies the permissions to use if a new
1223  *                  file is created.  It  is  modified  by  the
1224  *                  process's umask in the usual way: the permissions
1225  *                  of the created file are (mode & ~umask)
1226  *
1227  *                  Not currently use, but there for future use.
1228  *                  We will map this to SYSTEM, HIDDEN, etc bits
1229  *                  that reverses the mapping that smbc_fstat does.
1230  *
1231  * @return          Valid file handle, < 0 on error with errno set:
1232  *                  - ENOMEM  Out of memory
1233  *                  - EINVAL if an invalid parameter passed, like no
1234  *                  file, or smbc_init not called.
1235  *                  - EEXIST  pathname already exists and O_CREAT and
1236  *                  O_EXCL were used.
1237  *                  - EISDIR  pathname  refers  to  a  directory  and
1238  *                  the access requested involved writing.
1239  *                  - EACCES  The requested access to the file is not
1240  *                  allowed
1241  *                  - ENODEV The requested share does not exist
1242  *                  - ENOTDIR A file on the path is not a directory
1243  *                  - ENOENT  A directory component in pathname does
1244  *                  not exist.
1245  *
1246  * @see             smbc_creat()
1247  *
1248  * @note            This call uses an underlying routine that may create
1249  *                  a new connection to the server specified in the URL.
1250  *                  If the credentials supplied in the URL, or via the
1251  *                  auth_fn in the smbc_init call, fail, this call will
1252  *                  try again with an empty username and password. This
1253  *                  often gets mapped to the guest account on some machines.
1254  */
1255
1256 int smbc_open(const char *furl, int flags, mode_t mode);
1257
1258 /**@ingroup file
1259  * Create a file on an SMB server.
1260  *
1261  * Same as calling smbc_open() with flags = O_CREAT|O_WRONLY|O_TRUNC
1262  *
1263  * @param furl      The smb url of the file to be created
1264  *
1265  * @param mode      mode specifies the permissions to use if  a  new
1266  *                  file is created.  It  is  modified  by  the
1267  *                  process's umask in the usual way: the permissions
1268  *                  of the created file are (mode & ~umask)
1269  *
1270  *                  NOTE, the above is not true. We are dealing with
1271  *                  an SMB server, which has no concept of a umask!
1272  *
1273  * @return          Valid file handle, < 0 on error with errno set:
1274  *                  - ENOMEM  Out of memory
1275  *                  - EINVAL if an invalid parameter passed, like no
1276  *                  file, or smbc_init not called.
1277  *                  - EEXIST  pathname already exists and O_CREAT and
1278  *                  O_EXCL were used.
1279  *                  - EISDIR  pathname  refers  to  a  directory  and
1280  *                  the access requested involved writing.
1281  *                  - EACCES  The requested access to the file is not
1282  *                  allowed
1283  *                  - ENOENT  A directory component in pathname does
1284  *                  not exist.
1285  *                  - ENODEV The requested share does not exist.
1286  * @see             smbc_open()
1287  *
1288  */
1289
1290 int smbc_creat(const char *furl, mode_t mode);
1291
1292 /**@ingroup file
1293  * Read from a file using an opened file handle.
1294  *
1295  * @param fd        Open file handle from smbc_open() or smbc_creat()
1296  *
1297  * @param buf       Pointer to buffer to receive read data
1298  *
1299  * @param bufsize   Size of buf in bytes
1300  *
1301  * @return          Number of bytes read;
1302  *                  0 upon EOF;
1303  *                  < 0 on error, with errno set:
1304  *                  - EISDIR fd refers to a directory
1305  *                  - EBADF  fd  is  not  a valid file descriptor or
1306  *                    is not open for reading.
1307  *                  - EINVAL fd is attached to an object which is
1308  *                    unsuitable for reading, or no buffer passed or
1309  *                    smbc_init not called.
1310  *
1311  * @see             smbc_open(), smbc_write()
1312  *
1313  */
1314 ssize_t smbc_read(int fd, void *buf, size_t bufsize);
1315
1316
1317 /**@ingroup file
1318  * Write to a file using an opened file handle.
1319  *
1320  * @param fd        Open file handle from smbc_open() or smbc_creat()
1321  *
1322  * @param buf       Pointer to buffer to recieve read data
1323  *
1324  * @param bufsize   Size of buf in bytes
1325  *
1326  * @return          Number of bytes written, < 0 on error with errno set:
1327  *                  - EISDIR fd refers to a directory.
1328  *                  - EBADF  fd  is  not  a valid file descriptor or
1329  *                  is not open for reading.
1330  *                  - EINVAL fd is attached to an object which is
1331  *                  unsuitable for reading, or no buffer passed or
1332  *                  smbc_init not called.
1333  *
1334  * @see             smbc_open(), smbc_read()
1335  *
1336  */
1337 ssize_t smbc_write(int fd, const void *buf, size_t bufsize);
1338
1339
1340 /**@ingroup file
1341  * Seek to a specific location in a file.
1342  *
1343  * @param fd        Open file handle from smbc_open() or smbc_creat()
1344  *
1345  * @param offset    Offset in bytes from whence
1346  *
1347  * @param whence    A location in the file:
1348  *                  - SEEK_SET The offset is set to offset bytes from
1349  *                  the beginning of the file
1350  *                  - SEEK_CUR The offset is set to current location
1351  *                  plus offset bytes.
1352  *                  - SEEK_END The offset is set to the size of the
1353  *                  file plus offset bytes.
1354  *
1355  * @return          Upon successful completion, lseek returns the
1356  *                  resulting offset location as measured in bytes
1357  *                  from the beginning  of the file. Otherwise, a value
1358  *                  of (off_t)-1 is returned and errno is set to
1359  *                  indicate the error:
1360  *                  - EBADF  Fildes is not an open file descriptor.
1361  *                  - EINVAL Whence is not a proper value or smbc_init
1362  *                    not called.
1363  *
1364  * @todo Are all the whence values really supported?
1365  *
1366  * @todo Are errno values complete and correct?
1367  */
1368 off_t smbc_lseek(int fd, off_t offset, int whence);
1369
1370
1371 /**@ingroup file
1372  * Close an open file handle.
1373  *
1374  * @param fd        The file handle to close
1375  *
1376  * @return          0 on success, < 0 on error with errno set:
1377  *                  - EBADF  fd isn't a valid open file descriptor
1378  *                  - EINVAL smbc_init() failed or has not been called
1379  *
1380  * @see             smbc_open(), smbc_creat()
1381  */
1382 int smbc_close(int fd);
1383
1384
1385 /**@ingroup directory
1386  * Unlink (delete) a file or directory.
1387  *
1388  * @param furl      The smb url of the file to delete
1389  *
1390  * @return          0 on success, < 0 on error with errno set:
1391  *                  - EACCES or EPERM Write  access  to the directory
1392  *                  containing pathname is not allowed or one
1393  *                  of  the  directories in pathname did not allow
1394  *                  search (execute) permission
1395  *                  - ENOENT A directory component in pathname does
1396  *                  not exist
1397  *                  - EINVAL NULL was passed in the file param or
1398  *                    smbc_init not called.
1399  *                  - EACCES You do not have access to the file
1400  *                  - ENOMEM Insufficient kernel memory was available
1401  *
1402  * @see             smbc_rmdir()s
1403  *
1404  * @todo Are errno values complete and correct?
1405  */
1406 int smbc_unlink(const char *furl);
1407
1408
1409 /**@ingroup directory
1410  * Rename or move a file or directory.
1411  *
1412  * @param ourl      The original smb url (source url) of file or
1413  *                  directory to be moved
1414  *
1415  * @param nurl      The new smb url (destination url) of the file
1416  *                  or directory after the move.  Currently nurl must
1417  *                  be on the same share as ourl.
1418  *
1419  * @return          0 on success, < 0 on error with errno set:
1420  *                  - EISDIR nurl is an existing directory, but ourl is
1421  *                  not a directory.
1422  *                  - EEXIST nurl is  a  non-empty directory,
1423  *                  i.e., contains entries other than "." and ".."
1424  *                  - EINVAL The  new  url  contained  a path prefix
1425  *                  of the old, or, more generally, an  attempt was
1426  *                  made  to make a directory a subdirectory of itself
1427  *                  or smbc_init not called.
1428  *                  - ENOTDIR A component used as a directory in ourl
1429  *                  or nurl path is not, in fact, a directory.  Or,
1430  *                  ourl  is a directory, and newpath exists but is not
1431  *                  a directory.
1432  *                  - EACCES or EPERM Write access to the directory
1433  *                  containing ourl or nurl is not allowed for the
1434  *                  process's effective uid,  or  one of the
1435  *                  directories in ourl or nurl did not allow search
1436  *                  (execute) permission,  or ourl  was  a  directory
1437  *                  and did not allow write permission.
1438  *                  - ENOENT A  directory component in ourl or nurl
1439  *                  does not exist.
1440  *                  - EXDEV Rename across shares not supported.
1441  *                  - ENOMEM Insufficient kernel memory was available.
1442  *                  - EEXIST The target file, nurl, already exists.
1443  *
1444  *
1445  * @todo Are we going to support copying when urls are not on the same
1446  *       share?  I say no... NOTE. I agree for the moment.
1447  *
1448  */
1449 int smbc_rename(const char *ourl, const char *nurl);
1450
1451
1452 /**@ingroup directory
1453  * Open a directory used to obtain directory entries.
1454  *
1455  * @param durl      The smb url of the directory to open
1456  *
1457  * @return          Valid directory handle. < 0 on error with errno set:
1458  *                  - EACCES Permission denied.
1459  *                  - EINVAL A NULL file/URL was passed, or the URL would
1460  *                  not parse, or was of incorrect form or smbc_init not
1461  *                  called.
1462  *                  - ENOENT durl does not exist, or name is an
1463  *                  - ENOMEM Insufficient memory to complete the
1464  *                  operation.
1465  *                  - ENOTDIR name is not a directory.
1466  *                  - EPERM the workgroup could not be found.
1467  *                  - ENODEV the workgroup or server could not be found.
1468  *
1469  * @see             smbc_getdents(), smbc_readdir(), smbc_closedir()
1470  *
1471  */
1472 int smbc_opendir(const char *durl);
1473
1474
1475 /**@ingroup directory
1476  * Close a directory handle opened by smbc_opendir().
1477  *
1478  * @param dh        Directory handle to close
1479  *
1480  * @return          0 on success, < 0 on error with errno set:
1481  *                  - EBADF dh is an invalid directory handle
1482  *
1483  * @see             smbc_opendir()
1484  */
1485 int smbc_closedir(int dh);
1486
1487
1488 /**@ingroup directory
1489  * Get multiple directory entries.
1490  *
1491  * smbc_getdents() reads as many dirent structures from the an open
1492  * directory handle into a specified memory area as will fit.
1493  *
1494  * @param dh        Valid directory as returned by smbc_opendir()
1495  *
1496  * @param dirp      pointer to buffer that will receive the directory
1497  *                  entries.
1498  *
1499  * @param count     The size of the dirp buffer in bytes
1500  *
1501  * @returns         If any dirents returned, return will indicate the
1502  *                  total size. If there were no more dirents available,
1503  *                  0 is returned. < 0 indicates an error.
1504  *                  - EBADF  Invalid directory handle
1505  *                  - EINVAL Result buffer is too small or smbc_init
1506  *                  not called.
1507  *                  - ENOENT No such directory.
1508  * @see             , smbc_dirent, smbc_readdir(), smbc_open()
1509  *
1510  * @todo Are errno values complete and correct?
1511  *
1512  * @todo Add example code so people know how to parse buffers.
1513  */
1514 int smbc_getdents(unsigned int dh, struct smbc_dirent *dirp, int count);
1515
1516
1517 /**@ingroup directory
1518  * Get a single directory entry.
1519  *
1520  * @param dh        Valid directory as returned by smbc_opendir()
1521  *
1522  * @return          A pointer to a smbc_dirent structure, or NULL if an
1523  *                  error occurs or end-of-directory is reached:
1524  *                  - EBADF Invalid directory handle
1525  *                  - EINVAL smbc_init() failed or has not been called
1526  *
1527  * @see             smbc_dirent, smbc_getdents(), smbc_open()
1528  */
1529 struct smbc_dirent* smbc_readdir(unsigned int dh);
1530
1531
1532 /**@ingroup directory
1533  * Get the current directory offset.
1534  *
1535  * smbc_telldir() may be used in conjunction with smbc_readdir() and
1536  * smbc_lseekdir().
1537  *
1538  * @param dh        Valid directory as returned by smbc_opendir()
1539  *
1540  * @return          The current location in the directory stream or -1
1541  *                  if an error occur.  The current location is not
1542  *                  an offset. Becuase of the implementation, it is a
1543  *                  handle that allows the library to find the entry
1544  *                  later.
1545  *                  - EBADF dh is not a valid directory handle
1546  *                  - EINVAL smbc_init() failed or has not been called
1547  *                  - ENOTDIR if dh is not a directory
1548  *
1549  * @see             smbc_readdir()
1550  *
1551  */
1552 off_t smbc_telldir(int dh);
1553
1554
1555 /**@ingroup directory
1556  * lseek on directories.
1557  *
1558  * smbc_lseekdir() may be used in conjunction with smbc_readdir() and
1559  * smbc_telldir(). (rewind by smbc_lseekdir(fd, NULL))
1560  *
1561  * @param fd        Valid directory as returned by smbc_opendir()
1562  *
1563  * @param offset    The offset (as returned by smbc_telldir). Can be
1564  *                  NULL, in which case we will rewind
1565  *
1566  * @return          0 on success, -1 on failure
1567  *                  - EBADF dh is not a valid directory handle
1568  *                  - ENOTDIR if dh is not a directory
1569  *                  - EINVAL offset did not refer to a valid dirent or
1570  *                    smbc_init not called.
1571  *
1572  * @see             smbc_telldir()
1573  *
1574  *
1575  * @todo In what does the reture and errno values mean?
1576  */
1577 int smbc_lseekdir(int fd, off_t offset);
1578
1579 /**@ingroup directory
1580  * Create a directory.
1581  *
1582  * @param durl      The url of the directory to create
1583  *
1584  * @param mode      Specifies  the  permissions to use. It is modified
1585  *                  by the process's umask in the usual way: the
1586  *                  permissions of the created file are (mode & ~umask).
1587  *
1588  * @return          0 on success, < 0 on error with errno set:
1589  *                  - EEXIST directory url already exists
1590  *                  - EACCES The parent directory does not allow write
1591  *                  permission to the process, or one of the directories
1592  *                  - ENOENT A directory component in pathname does not
1593  *                  exist.
1594  *                  - EINVAL NULL durl passed or smbc_init not called.
1595  *                  - ENOMEM Insufficient memory was available.
1596  *
1597  * @see             smbc_rmdir()
1598  *
1599  */
1600 int smbc_mkdir(const char *durl, mode_t mode);
1601
1602
1603 /**@ingroup directory
1604  * Remove a directory.
1605  *
1606  * @param durl      The smb url of the directory to remove
1607  *
1608  * @return          0 on success, < 0 on error with errno set:
1609  *                  - EACCES or EPERM Write access to the directory
1610  *                  containing pathname was not allowed.
1611  *                  - EINVAL durl is NULL or smbc_init not called.
1612  *                  - ENOENT A directory component in pathname does not
1613  *                  exist.
1614  *                  - ENOTEMPTY directory contains entries.
1615  *                  - ENOMEM Insufficient kernel memory was available.
1616  *
1617  * @see             smbc_mkdir(), smbc_unlink()
1618  *
1619  * @todo Are errno values complete and correct?
1620  */
1621 int smbc_rmdir(const char *durl);
1622
1623
1624 /**@ingroup attribute
1625  * Get information about a file or directory.
1626  *
1627  * @param url       The smb url to get information for
1628  *
1629  * @param st        pointer to a buffer that will be filled with
1630  *                  standard Unix struct stat information.
1631  *
1632  * @return          0 on success, < 0 on error with errno set:
1633  *                  - ENOENT A component of the path file_name does not
1634  *                  exist.
1635  *                  - EINVAL a NULL url was passed or smbc_init not called.
1636  *                  - EACCES Permission denied.
1637  *                  - ENOMEM Out of memory
1638  *                  - ENOTDIR The target dir, url, is not a directory.
1639  *
1640  * @see             Unix stat()
1641  *
1642  */
1643 int smbc_stat(const char *url, struct stat *st);
1644
1645
1646 /**@ingroup attribute
1647  * Get file information via an file descriptor.
1648  *
1649  * @param fd        Open file handle from smbc_open() or smbc_creat()
1650  *
1651  * @param st        pointer to a buffer that will be filled with
1652  *                  standard Unix struct stat information.
1653  *
1654  * @return          0 on success, < 0 on error with errno set:
1655  *                  - EBADF  filedes is bad.
1656  *                  - EACCES Permission denied.
1657  *                  - EBADF fd is not a valid file descriptor
1658  *                  - EINVAL Problems occurred in the underlying routines
1659  *                    or smbc_init not called.
1660  *                  - ENOMEM Out of memory
1661  *
1662  * @see             smbc_stat(), Unix stat()
1663  *
1664  */
1665 int smbc_fstat(int fd, struct stat *st);
1666
1667
1668 /**@ingroup attribute
1669  * Get file system information for a specified path.
1670  *
1671  * @param url       The smb url to get information for
1672  *
1673  * @param st        pointer to a buffer that will be filled with
1674  *                  standard Unix struct statvfs information.
1675  *
1676  * @return          0 on success, < 0 on error with errno set:
1677  *                  - EBADF  filedes is bad.
1678  *                  - EACCES Permission denied.
1679  *                  - EBADF fd is not a valid file descriptor
1680  *                  - EINVAL Problems occurred in the underlying routines
1681  *                    or smbc_init not called.
1682  *                  - ENOMEM Out of memory
1683  *
1684  * @see             Unix fstatvfs()
1685  *
1686  */
1687 int
1688 smbc_statvfs(char *url,
1689              struct statvfs *st);
1690
1691 /**@ingroup attribute
1692  * Get file system information via an file descriptor.
1693  *
1694  * @param fd        Open file handle from smbc_open(), smbc_creat(),
1695  *                  or smbc_opendir()
1696  *
1697  * @param st        pointer to a buffer that will be filled with
1698  *                  standard Unix struct statvfs information.
1699  *
1700  * @return          0 on success, < 0 on error with errno set:
1701  *                  - EBADF  filedes is bad.
1702  *                  - EACCES Permission denied.
1703  *                  - EBADF fd is not a valid file descriptor
1704  *                  - EINVAL Problems occurred in the underlying routines
1705  *                    or smbc_init not called.
1706  *                  - ENOMEM Out of memory
1707  *
1708  * @see             Unix fstatvfs()
1709  *
1710  */
1711 int
1712 smbc_fstatvfs(int fd,
1713               struct statvfs *st);
1714
1715
1716 /**@ingroup attribute
1717  * Truncate a file given a file descriptor
1718  *
1719  * @param fd        Open file handle from smbc_open() or smbc_creat()
1720  *
1721  * @param size      size to truncate the file to
1722  *
1723  * @return          0 on success, < 0 on error with errno set:
1724  *                  - EBADF  filedes is bad.
1725  *                  - EACCES Permission denied.
1726  *                  - EBADF fd is not a valid file descriptor
1727  *                  - EINVAL Problems occurred in the underlying routines
1728  *                    or smbc_init not called.
1729  *                  - ENOMEM Out of memory
1730  *
1731  * @see             , Unix ftruncate()
1732  *
1733  */
1734 int smbc_ftruncate(int fd, off_t size);
1735
1736
1737 /**@ingroup attribute
1738  * Change the permissions of a file.
1739  *
1740  * @param url       The smb url of the file or directory to change
1741  *                  permissions of
1742  *
1743  * @param mode      The permissions to set:
1744  *                  - Put good explaination of permissions here!
1745  *
1746  * @return          0 on success, < 0 on error with errno set:
1747  *                  - EPERM  The effective UID does not match the owner
1748  *                  of the file, and is not zero
1749  *                  - ENOENT The file does not exist.
1750  *                  - ENOMEM Insufficient was available.
1751  *                  - ENOENT file or directory does not exist
1752  *
1753  * @todo Actually implement this fuction?
1754  *
1755  * @todo Are errno values complete and correct?
1756  */
1757 int smbc_chmod(const char *url, mode_t mode);
1758
1759 /**
1760  * @ingroup attribute
1761  * Change the last modification time on a file
1762  *
1763  * @param url       The smb url of the file or directory to change
1764  *                  the modification time of
1765  *
1766  * @param tbuf      An array of two timeval structures which contains,
1767  *                  respectively, the desired access and modification times.
1768  *                  NOTE: Only the tv_sec field off each timeval structure is
1769  *                  used.  The tv_usec (microseconds) portion is ignored.
1770  *
1771  * @return          0 on success, < 0 on error with errno set:
1772  *                  - EINVAL The client library is not properly initialized
1773  *                  - EPERM  Permission was denied.
1774  *
1775  */
1776 int smbc_utimes(const char *url, struct timeval *tbuf);
1777
1778 #ifdef HAVE_UTIME_H
1779 /**
1780  * @ingroup attribute
1781  * Change the last modification time on a file
1782  *
1783  * @param url       The smb url of the file or directory to change
1784  *                  the modification time of
1785  *
1786  * @param utbuf     A pointer to a utimebuf structure which contains the
1787  *                  desired access and modification times.
1788  *
1789  * @return          0 on success, < 0 on error with errno set:
1790  *                  - EINVAL The client library is not properly initialized
1791  *                  - ENOMEM No memory was available for internal needs
1792  *                  - EPERM  Permission was denied.
1793  *
1794  */
1795 int smbc_utime(const char *fname, struct utimbuf *utbuf);
1796 #endif
1797
1798 /**@ingroup attribute
1799  * Set extended attributes for a file.  This is used for modifying a file's
1800  * security descriptor (i.e. owner, group, and access control list)
1801  *
1802  * @param url       The smb url of the file or directory to set extended
1803  *                  attributes for.
1804  *
1805  * @param name      The name of an attribute to be changed.  Names are of
1806  *                  one of the following forms:
1807  *
1808  *                     system.nt_sec_desc.<attribute name>
1809  *                     system.nt_sec_desc.*
1810  *                     system.nt_sec_desc.*+
1811  *
1812  *                  where <attribute name> is one of:
1813  *
1814  *                     revision
1815  *                     owner
1816  *                     owner+
1817  *                     group
1818  *                     group+
1819  *                     acl:<name or sid>
1820  *                     acl+:<name or sid>
1821  *
1822  *                  In the forms "system.nt_sec_desc.*" and
1823  *                  "system.nt_sec_desc.*+", the asterisk and plus signs are
1824  *                  literal, i.e. the string is provided exactly as shown, and
1825  *                  the value parameter should contain a complete security
1826  *                  descriptor with name:value pairs separated by tabs,
1827  *                  commas, or newlines (not spaces!).
1828  *
1829  *                  The plus sign ('+') indicates that SIDs should be mapped
1830  *                  to names.  Without the plus sign, SIDs are not mapped;
1831  *                  rather they are simply converted to a string format.
1832  *
1833  * @param value     The value to be assigned to the specified attribute name.
1834  *                  This buffer should contain only the attribute value if the
1835  *                  name was of the "system.nt_sec_desc.<attribute_name>"
1836  *                  form.  If the name was of the "system.nt_sec_desc.*" form
1837  *                  then a complete security descriptor, with name:value pairs
1838  *                  separated by tabs, commas, or newlines (not spaces!),
1839  *                  should be provided in this value buffer.  A complete
1840  *                  security descriptor will contain one or more entries
1841  *                  selected from the following:
1842  *
1843  *                    REVISION:<revision number>
1844  *                    OWNER:<sid or name>
1845  *                    GROUP:<sid or name>
1846  *                    ACL:<sid or name>:<type>/<flags>/<mask>
1847  *
1848  *                  The  revision of the ACL specifies the internal Windows NT
1849  *                  ACL revision for the security descriptor. If not specified
1850  *                  it defaults to  1.  Using values other than 1 may cause
1851  *                  strange behaviour.
1852  *
1853  *                  The owner and group specify the owner and group sids for
1854  *                  the object. If the attribute name (either '*+' with a
1855  *                  complete security descriptor, or individual 'owner+' or
1856  *                  'group+' attribute names) ended with a plus sign, the
1857  *                  specified name is resolved to a SID value, using the
1858  *                  server on which the file or directory resides.  Otherwise,
1859  *                  the value should be provided in SID-printable format as
1860  *                  S-1-x-y-z, and is used directly.  The <sid or name>
1861  *                  associated with the ACL: attribute should be provided
1862  *                  similarly.
1863  *
1864  * @param size      The number of the bytes of data in the value buffer
1865  *
1866  * @param flags     A bit-wise OR of zero or more of the following:
1867  *                    SMBC_XATTR_FLAG_CREATE -
1868  *                      fail if the named attribute already exists
1869  *                    SMBC_XATTR_FLAG_REPLACE -
1870  *                      fail if the attribute does not already exist
1871  *
1872  *                  If neither flag is specified, the specified attributes
1873  *                  will be added or replace existing attributes of the same
1874  *                  name, as necessary.
1875  *
1876  * @return          0 on success, < 0 on error with errno set:
1877  *                  - EINVAL  The client library is not properly initialized
1878  *                            or one of the parameters is not of a correct
1879  *                            form
1880  *                  - ENOMEM No memory was available for internal needs
1881  *                  - EEXIST  If the attribute already exists and the flag
1882  *                            SMBC_XATTR_FLAG_CREAT was specified
1883  *                  - ENOATTR If the attribute does not exist and the flag
1884  *                            SMBC_XATTR_FLAG_REPLACE was specified
1885  *                  - EPERM   Permission was denied.
1886  *                  - ENOTSUP The referenced file system does not support
1887  *                            extended attributes
1888  *
1889  * @note            Attribute names are compared in a case-insensitive
1890  *                  fashion.  All of the following are equivalent, although
1891  *                  the all-lower-case name is the preferred format:
1892  *                    system.nt_sec_desc.owner
1893  *                    SYSTEM.NT_SEC_DESC.OWNER
1894  *                    sYsTeM.nt_sEc_desc.owNER
1895  *
1896  */
1897 int smbc_setxattr(const char *url,
1898                   const char *name,
1899                   const void *value,
1900                   size_t size,
1901                   int flags);
1902
1903
1904 /**@ingroup attribute
1905  * Set extended attributes for a file.  This is used for modifying a file's
1906  * security descriptor (i.e. owner, group, and access control list).  The
1907  * POSIX function which this maps to would act on a symbolic link rather than
1908  * acting on what the symbolic link points to, but with no symbolic links in
1909  * SMB file systems, this function is functionally identical to
1910  * smbc_setxattr().
1911  *
1912  * @param url       The smb url of the file or directory to set extended
1913  *                  attributes for.
1914  *
1915  * @param name      The name of an attribute to be changed.  Names are of
1916  *                  one of the following forms:
1917  *
1918  *                     system.nt_sec_desc.<attribute name>
1919  *                     system.nt_sec_desc.*
1920  *                     system.nt_sec_desc.*+
1921  *
1922  *                  where <attribute name> is one of:
1923  *
1924  *                     revision
1925  *                     owner
1926  *                     owner+
1927  *                     group
1928  *                     group+
1929  *                     acl:<name or sid>
1930  *                     acl+:<name or sid>
1931  *
1932  *                  In the forms "system.nt_sec_desc.*" and
1933  *                  "system.nt_sec_desc.*+", the asterisk and plus signs are
1934  *                  literal, i.e. the string is provided exactly as shown, and
1935  *                  the value parameter should contain a complete security
1936  *                  descriptor with name:value pairs separated by tabs,
1937  *                  commas, or newlines (not spaces!).
1938  *
1939  *                  The plus sign ('+') indicates that SIDs should be mapped
1940  *                  to names.  Without the plus sign, SIDs are not mapped;
1941  *                  rather they are simply converted to a string format.
1942  *
1943  * @param value     The value to be assigned to the specified attribute name.
1944  *                  This buffer should contain only the attribute value if the
1945  *                  name was of the "system.nt_sec_desc.<attribute_name>"
1946  *                  form.  If the name was of the "system.nt_sec_desc.*" form
1947  *                  then a complete security descriptor, with name:value pairs
1948  *                  separated by tabs, commas, or newlines (not spaces!),
1949  *                  should be provided in this value buffer.  A complete
1950  *                  security descriptor will contain one or more entries
1951  *                  selected from the following:
1952  *
1953  *                    REVISION:<revision number>
1954  *                    OWNER:<sid or name>
1955  *                    GROUP:<sid or name>
1956  *                    ACL:<sid or name>:<type>/<flags>/<mask>
1957  *
1958  *                  The  revision of the ACL specifies the internal Windows NT
1959  *                  ACL revision for the security descriptor. If not specified
1960  *                  it defaults to  1.  Using values other than 1 may cause
1961  *                  strange behaviour.
1962  *
1963  *                  The owner and group specify the owner and group sids for
1964  *                  the object. If the attribute name (either '*+' with a
1965  *                  complete security descriptor, or individual 'owner+' or
1966  *                  'group+' attribute names) ended with a plus sign, the
1967  *                  specified name is resolved to a SID value, using the
1968  *                  server on which the file or directory resides.  Otherwise,
1969  *                  the value should be provided in SID-printable format as
1970  *                  S-1-x-y-z, and is used directly.  The <sid or name>
1971  *                  associated with the ACL: attribute should be provided
1972  *                  similarly.
1973  *
1974  * @param size      The number of the bytes of data in the value buffer
1975  *
1976  * @param flags     A bit-wise OR of zero or more of the following:
1977  *                    SMBC_XATTR_FLAG_CREATE -
1978  *                      fail if the named attribute already exists
1979  *                    SMBC_XATTR_FLAG_REPLACE -
1980  *                      fail if the attribute does not already exist
1981  *
1982  *                  If neither flag is specified, the specified attributes
1983  *                  will be added or replace existing attributes of the same
1984  *                  name, as necessary.
1985  *
1986  * @return          0 on success, < 0 on error with errno set:
1987  *                  - EINVAL  The client library is not properly initialized
1988  *                            or one of the parameters is not of a correct
1989  *                            form
1990  *                  - ENOMEM No memory was available for internal needs
1991  *                  - EEXIST  If the attribute already exists and the flag
1992  *                            SMBC_XATTR_FLAG_CREAT was specified
1993  *                  - ENOATTR If the attribute does not exist and the flag
1994  *                            SMBC_XATTR_FLAG_REPLACE was specified
1995  *                  - EPERM   Permission was denied.
1996  *                  - ENOTSUP The referenced file system does not support
1997  *                            extended attributes
1998  *
1999  * @note            Attribute names are compared in a case-insensitive
2000  *                  fashion.  All of the following are equivalent, although
2001  *                  the all-lower-case name is the preferred format:
2002  *                    system.nt_sec_desc.owner
2003  *                    SYSTEM.NT_SEC_DESC.OWNER
2004  *                    sYsTeM.nt_sEc_desc.owNER
2005  *
2006  */
2007 int smbc_lsetxattr(const char *url,
2008                    const char *name,
2009                    const void *value,
2010                    size_t size,
2011                    int flags);
2012
2013
2014 /**@ingroup attribute
2015  * Set extended attributes for a file.  This is used for modifying a file's
2016  * security descriptor (i.e. owner, group, and access control list)
2017  *
2018  * @param fd        A file descriptor associated with an open file (as
2019  *                  previously returned by smbc_open(), to get extended
2020  *                  attributes for.
2021  *
2022  * @param name      The name of an attribute to be changed.  Names are of
2023  *                  one of the following forms:
2024  *
2025  *                     system.nt_sec_desc.<attribute name>
2026  *                     system.nt_sec_desc.*
2027  *                     system.nt_sec_desc.*+
2028  *
2029  *                  where <attribute name> is one of:
2030  *
2031  *                     revision
2032  *                     owner
2033  *                     owner+
2034  *                     group
2035  *                     group+
2036  *                     acl:<name or sid>
2037  *                     acl+:<name or sid>
2038  *
2039  *                  In the forms "system.nt_sec_desc.*" and
2040  *                  "system.nt_sec_desc.*+", the asterisk and plus signs are
2041  *                  literal, i.e. the string is provided exactly as shown, and
2042  *                  the value parameter should contain a complete security
2043  *                  descriptor with name:value pairs separated by tabs,
2044  *                  commas, or newlines (not spaces!).
2045  *
2046  *                  The plus sign ('+') indicates that SIDs should be mapped
2047  *                  to names.  Without the plus sign, SIDs are not mapped;
2048  *                  rather they are simply converted to a string format.
2049  *
2050  * @param value     The value to be assigned to the specified attribute name.
2051  *                  This buffer should contain only the attribute value if the
2052  *                  name was of the "system.nt_sec_desc.<attribute_name>"
2053  *                  form.  If the name was of the "system.nt_sec_desc.*" form
2054  *                  then a complete security descriptor, with name:value pairs
2055  *                  separated by tabs, commas, or newlines (not spaces!),
2056  *                  should be provided in this value buffer.  A complete
2057  *                  security descriptor will contain one or more entries
2058  *                  selected from the following:
2059  *
2060  *                    REVISION:<revision number>
2061  *                    OWNER:<sid or name>
2062  *                    GROUP:<sid or name>
2063  *                    ACL:<sid or name>:<type>/<flags>/<mask>
2064  *
2065  *                  The  revision of the ACL specifies the internal Windows NT
2066  *                  ACL revision for the security descriptor. If not specified
2067  *                  it defaults to  1.  Using values other than 1 may cause
2068  *                  strange behaviour.
2069  *
2070  *                  The owner and group specify the owner and group sids for
2071  *                  the object. If the attribute name (either '*+' with a
2072  *                  complete security descriptor, or individual 'owner+' or
2073  *                  'group+' attribute names) ended with a plus sign, the
2074  *                  specified name is resolved to a SID value, using the
2075  *                  server on which the file or directory resides.  Otherwise,
2076  *                  the value should be provided in SID-printable format as
2077  *                  S-1-x-y-z, and is used directly.  The <sid or name>
2078  *                  associated with the ACL: attribute should be provided
2079  *                  similarly.
2080  *
2081  * @param size      The number of the bytes of data in the value buffer
2082  *
2083  * @param flags     A bit-wise OR of zero or more of the following:
2084  *                    SMBC_XATTR_FLAG_CREATE -
2085  *                      fail if the named attribute already exists
2086  *                    SMBC_XATTR_FLAG_REPLACE -
2087  *                      fail if the attribute does not already exist
2088  *
2089  *                  If neither flag is specified, the specified attributes
2090  *                  will be added or replace existing attributes of the same
2091  *                  name, as necessary.
2092  *
2093  * @return          0 on success, < 0 on error with errno set:
2094  *                  - EINVAL  The client library is not properly initialized
2095  *                            or one of the parameters is not of a correct
2096  *                            form
2097  *                  - ENOMEM No memory was available for internal needs
2098  *                  - EEXIST  If the attribute already exists and the flag
2099  *                            SMBC_XATTR_FLAG_CREAT was specified
2100  *                  - ENOATTR If the attribute does not exist and the flag
2101  *                            SMBC_XATTR_FLAG_REPLACE was specified
2102  *                  - EPERM   Permission was denied.
2103  *                  - ENOTSUP The referenced file system does not support
2104  *                            extended attributes
2105  *
2106  * @note            Attribute names are compared in a case-insensitive
2107  *                  fashion.  All of the following are equivalent, although
2108  *                  the all-lower-case name is the preferred format:
2109  *                    system.nt_sec_desc.owner
2110  *                    SYSTEM.NT_SEC_DESC.OWNER
2111  *                    sYsTeM.nt_sEc_desc.owNER
2112  *
2113  */
2114 int smbc_fsetxattr(int fd,
2115                    const char *name,
2116                    const void *value,
2117                    size_t size,
2118                    int flags);
2119
2120
2121 /**@ingroup attribute
2122  * Get extended attributes for a file.
2123  *
2124  * @param url       The smb url of the file or directory to get extended
2125  *                  attributes for.
2126  *
2127  * @param name      The name of an attribute to be retrieved.  Names are of
2128  *                  one of the following forms:
2129  *
2130  *                     system.nt_sec_desc.<attribute name>
2131  *                     system.nt_sec_desc.*
2132  *                     system.nt_sec_desc.*+
2133  *
2134  *                  where <attribute name> is one of:
2135  *
2136  *                     revision
2137  *                     owner
2138  *                     owner+
2139  *                     group
2140  *                     group+
2141  *                     acl:<name or sid>
2142  *                     acl+:<name or sid>
2143  *
2144  *                  In the forms "system.nt_sec_desc.*" and
2145  *                  "system.nt_sec_desc.*+", the asterisk and plus signs are
2146  *                  literal, i.e. the string is provided exactly as shown, and
2147  *                  the value parameter will return a complete security
2148  *                  descriptor with name:value pairs separated by tabs,
2149  *                  commas, or newlines (not spaces!).
2150  *
2151  *                  The plus sign ('+') indicates that SIDs should be mapped
2152  *                  to names.  Without the plus sign, SIDs are not mapped;
2153  *                  rather they are simply converted to a string format.
2154  *
2155  * @param value     A pointer to a buffer in which the value of the specified
2156  *                  attribute will be placed (unless size is zero).
2157  *
2158  * @param size      The size of the buffer pointed to by value.  This parameter
2159  *                  may also be zero, in which case the size of the buffer
2160  *                  required to hold the attribute value will be returned,
2161  *                  but nothing will be placed into the value buffer.
2162  *
2163  * @return          0 on success, < 0 on error with errno set:
2164  *                  - EINVAL  The client library is not properly initialized
2165  *                            or one of the parameters is not of a correct
2166  *                            form
2167  *                  - ENOMEM No memory was available for internal needs
2168  *                  - EEXIST  If the attribute already exists and the flag
2169  *                            SMBC_XATTR_FLAG_CREAT was specified
2170  *                  - ENOATTR If the attribute does not exist and the flag
2171  *                            SMBC_XATTR_FLAG_REPLACE was specified
2172  *                  - EPERM   Permission was denied.
2173  *                  - ENOTSUP The referenced file system does not support
2174  *                            extended attributes
2175  *
2176  */
2177 int smbc_getxattr(const char *url,
2178                   const char *name,
2179                   const void *value,
2180                   size_t size);
2181
2182
2183 /**@ingroup attribute
2184  * Get extended attributes for a file.  The POSIX function which this maps to
2185  * would act on a symbolic link rather than acting on what the symbolic link
2186  * points to, but with no symbolic links in SMB file systems, this function
2187  * is functionally identical to smbc_getxattr().
2188  *
2189  * @param url       The smb url of the file or directory to get extended
2190  *                  attributes for.
2191  *
2192  * @param name      The name of an attribute to be retrieved.  Names are of
2193  *                  one of the following forms:
2194  *
2195  *                     system.nt_sec_desc.<attribute name>
2196  *                     system.nt_sec_desc.*
2197  *                     system.nt_sec_desc.*+
2198  *
2199  *                  where <attribute name> is one of:
2200  *
2201  *                     revision
2202  *                     owner
2203  *                     owner+
2204  *                     group
2205  *                     group+
2206  *                     acl:<name or sid>
2207  *                     acl+:<name or sid>
2208  *
2209  *                  In the forms "system.nt_sec_desc.*" and
2210  *                  "system.nt_sec_desc.*+", the asterisk and plus signs are
2211  *                  literal, i.e. the string is provided exactly as shown, and
2212  *                  the value parameter will return a complete security
2213  *                  descriptor with name:value pairs separated by tabs,
2214  *                  commas, or newlines (not spaces!).
2215  *
2216  *                  The plus sign ('+') indicates that SIDs should be mapped
2217  *                  to names.  Without the plus sign, SIDs are not mapped;
2218  *                  rather they are simply converted to a string format.
2219  *
2220  * @param value     A pointer to a buffer in which the value of the specified
2221  *                  attribute will be placed (unless size is zero).
2222  *
2223  * @param size      The size of the buffer pointed to by value.  This parameter
2224  *                  may also be zero, in which case the size of the buffer
2225  *                  required to hold the attribute value will be returned,
2226  *                  but nothing will be placed into the value buffer.
2227  *
2228  * @return          0 on success, < 0 on error with errno set:
2229  *                  - EINVAL  The client library is not properly initialized
2230  *                            or one of the parameters is not of a correct
2231  *                            form
2232  *                  - ENOMEM No memory was available for internal needs
2233  *                  - EEXIST  If the attribute already exists and the flag
2234  *                            SMBC_XATTR_FLAG_CREAT was specified
2235  *                  - ENOATTR If the attribute does not exist and the flag
2236  *                            SMBC_XATTR_FLAG_REPLACE was specified
2237  *                  - EPERM   Permission was denied.
2238  *                  - ENOTSUP The referenced file system does not support
2239  *                            extended attributes
2240  *
2241  */
2242 int smbc_lgetxattr(const char *url,
2243                    const char *name,
2244                    const void *value,
2245                    size_t size);
2246
2247
2248 /**@ingroup attribute
2249  * Get extended attributes for a file.
2250  *
2251  * @param fd        A file descriptor associated with an open file (as
2252  *                  previously returned by smbc_open(), to get extended
2253  *                  attributes for.
2254  *
2255  * @param name      The name of an attribute to be retrieved.  Names are of
2256  *                  one of the following forms:
2257  *
2258  *                     system.nt_sec_desc.<attribute name>
2259  *                     system.nt_sec_desc.*
2260  *                     system.nt_sec_desc.*+
2261  *
2262  *                  where <attribute name> is one of:
2263  *
2264  *                     revision
2265  *                     owner
2266  *                     owner+
2267  *                     group
2268  *                     group+
2269  *                     acl:<name or sid>
2270  *                     acl+:<name or sid>
2271  *
2272  *                  In the forms "system.nt_sec_desc.*" and
2273  *                  "system.nt_sec_desc.*+", the asterisk and plus signs are
2274  *                  literal, i.e. the string is provided exactly as shown, and
2275  *                  the value parameter will return a complete security
2276  *                  descriptor with name:value pairs separated by tabs,
2277  *                  commas, or newlines (not spaces!).
2278  *
2279  *                  The plus sign ('+') indicates that SIDs should be mapped
2280  *                  to names.  Without the plus sign, SIDs are not mapped;
2281  *                  rather they are simply converted to a string format.
2282  *
2283  * @param value     A pointer to a buffer in which the value of the specified
2284  *                  attribute will be placed (unless size is zero).
2285  *
2286  * @param size      The size of the buffer pointed to by value.  This parameter
2287  *                  may also be zero, in which case the size of the buffer
2288  *                  required to hold the attribute value will be returned,
2289  *                  but nothing will be placed into the value buffer.
2290  *
2291  * @return          0 on success, < 0 on error with errno set:
2292  *                  - EINVAL  The client library is not properly initialized
2293  *                            or one of the parameters is not of a correct
2294  *                            form
2295  *                  - ENOMEM No memory was available for internal needs
2296  *                  - EEXIST  If the attribute already exists and the flag
2297  *                            SMBC_XATTR_FLAG_CREAT was specified
2298  *                  - ENOATTR If the attribute does not exist and the flag
2299  *                            SMBC_XATTR_FLAG_REPLACE was specified
2300  *                  - EPERM   Permission was denied.
2301  *                  - ENOTSUP The referenced file system does not support
2302  *                            extended attributes
2303  *
2304  */
2305 int smbc_fgetxattr(int fd,
2306                    const char *name,
2307                    const void *value,
2308                    size_t size);
2309
2310
2311 /**@ingroup attribute
2312  * Remove extended attributes for a file.  This is used for modifying a file's
2313  * security descriptor (i.e. owner, group, and access control list)
2314  *
2315  * @param url       The smb url of the file or directory to remove the extended
2316  *                  attributes for.
2317  *
2318  * @param name      The name of an attribute to be removed.  Names are of
2319  *                  one of the following forms:
2320  *
2321  *                     system.nt_sec_desc.<attribute name>
2322  *                     system.nt_sec_desc.*
2323  *                     system.nt_sec_desc.*+
2324  *
2325  *                  where <attribute name> is one of:
2326  *
2327  *                     revision
2328  *                     owner
2329  *                     owner+
2330  *                     group
2331  *                     group+
2332  *                     acl:<name or sid>
2333  *                     acl+:<name or sid>
2334  *
2335  *                  In the forms "system.nt_sec_desc.*" and
2336  *                  "system.nt_sec_desc.*+", the asterisk and plus signs are
2337  *                  literal, i.e. the string is provided exactly as shown, and
2338  *                  the value parameter will return a complete security
2339  *                  descriptor with name:value pairs separated by tabs,
2340  *                  commas, or newlines (not spaces!).
2341  *
2342  *                  The plus sign ('+') indicates that SIDs should be mapped
2343  *                  to names.  Without the plus sign, SIDs are not mapped;
2344  *                  rather they are simply converted to a string format.
2345  *
2346  * @return          0 on success, < 0 on error with errno set:
2347  *                  - EINVAL The client library is not properly initialized
2348  *                  - ENOMEM No memory was available for internal needs
2349  *                  - EPERM  Permission was denied.
2350  *                  - ENOTSUP The referenced file system does not support
2351  *                            extended attributes
2352  *
2353  */
2354 int smbc_removexattr(const char *url,
2355                      const char *name);
2356
2357
2358 /**@ingroup attribute
2359  * Remove extended attributes for a file.  This is used for modifying a file's
2360  * security descriptor (i.e. owner, group, and access control list) The POSIX
2361  * function which this maps to would act on a symbolic link rather than acting
2362  * on what the symbolic link points to, but with no symbolic links in SMB file
2363  * systems, this function is functionally identical to smbc_removexattr().
2364  *
2365  * @param url       The smb url of the file or directory to remove the extended
2366  *                  attributes for.
2367  *
2368  * @param name      The name of an attribute to be removed.  Names are of
2369  *                  one of the following forms:
2370  *
2371  *                     system.nt_sec_desc.<attribute name>
2372  *                     system.nt_sec_desc.*
2373  *                     system.nt_sec_desc.*+
2374  *
2375  *                  where <attribute name> is one of:
2376  *
2377  *                     revision
2378  *                     owner
2379  *                     owner+
2380  *                     group
2381  *                     group+
2382  *                     acl:<name or sid>
2383  *                     acl+:<name or sid>
2384  *
2385  *                  In the forms "system.nt_sec_desc.*" and
2386  *                  "system.nt_sec_desc.*+", the asterisk and plus signs are
2387  *                  literal, i.e. the string is provided exactly as shown, and
2388  *                  the value parameter will return a complete security
2389  *                  descriptor with name:value pairs separated by tabs,
2390  *                  commas, or newlines (not spaces!).
2391  *
2392  *                  The plus sign ('+') indicates that SIDs should be mapped
2393  *                  to names.  Without the plus sign, SIDs are not mapped;
2394  *                  rather they are simply converted to a string format.
2395  *
2396  * @return          0 on success, < 0 on error with errno set:
2397  *                  - EINVAL The client library is not properly initialized
2398  *                  - ENOMEM No memory was available for internal needs
2399  *                  - EPERM  Permission was denied.
2400  *                  - ENOTSUP The referenced file system does not support
2401  *                            extended attributes
2402  *
2403  */
2404 int smbc_lremovexattr(const char *url,
2405                       const char *name);
2406
2407
2408 /**@ingroup attribute
2409  * Remove extended attributes for a file.  This is used for modifying a file's
2410  * security descriptor (i.e. owner, group, and access control list)
2411  *
2412  * @param fd        A file descriptor associated with an open file (as
2413  *                  previously returned by smbc_open(), to get extended
2414  *                  attributes for.
2415  *
2416  * @param name      The name of an attribute to be removed.  Names are of
2417  *                  one of the following forms:
2418  *
2419  *                     system.nt_sec_desc.<attribute name>
2420  *                     system.nt_sec_desc.*
2421  *                     system.nt_sec_desc.*+
2422  *
2423  *                  where <attribute name> is one of:
2424  *
2425  *                     revision
2426  *                     owner
2427  *                     owner+
2428  *                     group
2429  *                     group+
2430  *                     acl:<name or sid>
2431  *                     acl+:<name or sid>
2432  *
2433  *                  In the forms "system.nt_sec_desc.*" and
2434  *                  "system.nt_sec_desc.*+", the asterisk and plus signs are
2435  *                  literal, i.e. the string is provided exactly as shown, and
2436  *                  the value parameter will return a complete security
2437  *                  descriptor with name:value pairs separated by tabs,
2438  *                  commas, or newlines (not spaces!).
2439  *
2440  *                  The plus sign ('+') indicates that SIDs should be mapped
2441  *                  to names.  Without the plus sign, SIDs are not mapped;
2442  *                  rather they are simply converted to a string format.
2443  *
2444  * @return          0 on success, < 0 on error with errno set:
2445  *                  - EINVAL The client library is not properly initialized
2446  *                  - ENOMEM No memory was available for internal needs
2447  *                  - EPERM  Permission was denied.
2448  *                  - ENOTSUP The referenced file system does not support
2449  *                            extended attributes
2450  *
2451  */
2452 int smbc_fremovexattr(int fd,
2453                       const char *name);
2454
2455
2456 /**@ingroup attribute
2457  * List the supported extended attribute names associated with a file
2458  *
2459  * @param url       The smb url of the file or directory to list the extended
2460  *                  attributes for.
2461  *
2462  * @param list      A pointer to a buffer in which the list of attributes for
2463  *                  the specified file or directory will be placed (unless
2464  *                  size is zero).
2465  *
2466  * @param size      The size of the buffer pointed to by list.  This parameter
2467  *                  may also be zero, in which case the size of the buffer
2468  *                  required to hold all of the attribute names will be
2469  *                  returned, but nothing will be placed into the list buffer.
2470  *
2471  * @return          0 on success, < 0 on error with errno set:
2472  *                  - EINVAL The client library is not properly initialized
2473  *                  - ENOMEM No memory was available for internal needs
2474  *                  - EPERM  Permission was denied.
2475  *                  - ENOTSUP The referenced file system does not support
2476  *                            extended attributes
2477  *
2478  * @note            This function always returns all attribute names supported
2479  *                  by NT file systems, regardless of whether the referenced
2480  *                  file system supports extended attributes (e.g. a Windows
2481  *                  2000 machine supports extended attributes if NTFS is used,
2482  *                  but not if FAT is used, and Windows 98 doesn't support
2483  *                  extended attributes at all.  Whether this is a feature or
2484  *                  a bug is yet to be decided.
2485  */
2486 int smbc_listxattr(const char *url,
2487                    char *list,
2488                    size_t size);
2489
2490 /**@ingroup attribute
2491  * List the supported extended attribute names associated with a file The
2492  * POSIX function which this maps to would act on a symbolic link rather than
2493  * acting on what the symbolic link points to, but with no symbolic links in
2494  * SMB file systems, this function is functionally identical to
2495  * smbc_listxattr().
2496  *
2497  * @param url       The smb url of the file or directory to list the extended
2498  *                  attributes for.
2499  *
2500  * @param list      A pointer to a buffer in which the list of attributes for
2501  *                  the specified file or directory will be placed (unless
2502  *                  size is zero).
2503  *
2504  * @param size      The size of the buffer pointed to by list.  This parameter
2505  *                  may also be zero, in which case the size of the buffer
2506  *                  required to hold all of the attribute names will be
2507  *                  returned, but nothing will be placed into the list buffer.
2508  *
2509  * @return          0 on success, < 0 on error with errno set:
2510  *                  - EINVAL The client library is not properly initialized
2511  *                  - ENOMEM No memory was available for internal needs
2512  *                  - EPERM  Permission was denied.
2513  *                  - ENOTSUP The referenced file system does not support
2514  *                            extended attributes
2515  *
2516  * @note            This function always returns all attribute names supported
2517  *                  by NT file systems, regardless of wether the referenced
2518  *                  file system supports extended attributes (e.g. a Windows
2519  *                  2000 machine supports extended attributes if NTFS is used,
2520  *                  but not if FAT is used, and Windows 98 doesn't support
2521  *                  extended attributes at all.  Whether this is a feature or
2522  *                  a bug is yet to be decided.
2523  */
2524 int smbc_llistxattr(const char *url,
2525                     char *list,
2526                     size_t size);
2527
2528 /**@ingroup attribute
2529  * List the supported extended attribute names associated with a file
2530  *
2531  * @param fd        A file descriptor associated with an open file (as
2532  *                  previously returned by smbc_open(), to get extended
2533  *                  attributes for.
2534  *
2535  * @param list      A pointer to a buffer in which the list of attributes for
2536  *                  the specified file or directory will be placed (unless
2537  *                  size is zero).
2538  *
2539  * @param size      The size of the buffer pointed to by list.  This parameter
2540  *                  may also be zero, in which case the size of the buffer
2541  *                  required to hold all of the attribute names will be
2542  *                  returned, but nothing will be placed into the list buffer.
2543  *
2544  * @return          0 on success, < 0 on error with errno set:
2545  *                  - EINVAL The client library is not properly initialized
2546  *                  - ENOMEM No memory was available for internal needs
2547  *                  - EPERM  Permission was denied.
2548  *                  - ENOTSUP The referenced file system does not support
2549  *                            extended attributes
2550  *
2551  * @note            This function always returns all attribute names supported
2552  *                  by NT file systems, regardless of wether the referenced
2553  *                  file system supports extended attributes (e.g. a Windows
2554  *                  2000 machine supports extended attributes if NTFS is used,
2555  *                  but not if FAT is used, and Windows 98 doesn't support
2556  *                  extended attributes at all.  Whether this is a feature or
2557  *                  a bug is yet to be decided.
2558  */
2559 int smbc_flistxattr(int fd,
2560                     char *list,
2561                     size_t size);
2562
2563 /**@ingroup print
2564  * Print a file given the name in fname. It would be a URL ...
2565  *
2566  * @param fname     The URL of a file on a remote SMB server that the
2567  *                  caller wants printed
2568  *
2569  * @param printq    The URL of the print share to print the file to.
2570  *
2571  * @return          0 on success, < 0 on error with errno set:
2572  *
2573  *                  - EINVAL fname or printq was NULL or smbc_init not
2574  *                    not called.
2575  *                  and errors returned by smbc_open
2576  *
2577  */
2578 int smbc_print_file(const char *fname, const char *printq);
2579
2580 /**@ingroup print
2581  * Open a print file that can be written to by other calls. This simply
2582  * does an smbc_open call after checking if there is a file name on the
2583  * URI. If not, a temporary name is added ...
2584  *
2585  * @param fname     The URL of the print share to print to?
2586  *
2587  * @returns         A file handle for the print file if successful.
2588  *                  Returns -1 if an error ocurred and errno has the values
2589  *                  - EINVAL fname was NULL or smbc_init not called.
2590  *                  - all errors returned by smbc_open
2591  *
2592  */
2593 int smbc_open_print_job(const char *fname);
2594
2595 /**@ingroup print
2596  * List the print jobs on a print share, for the moment, pass a callback
2597  *
2598  * @param purl      The url of the print share to list the jobs of
2599  *
2600  * @param fn        Callback function the receives printjob info
2601  *
2602  * @return          0 on success, < 0 on error with errno set:
2603  *                  - EINVAL fname was NULL or smbc_init not called
2604  *                  - EACCES ???
2605  */
2606 int smbc_list_print_jobs(const char *purl, smbc_list_print_job_fn fn);
2607
2608 /**@ingroup print
2609  * Delete a print job
2610  *
2611  * @param purl      Url of the print share
2612  *
2613  * @param id        The id of the job to delete
2614  *
2615  * @return          0 on success, < 0 on error with errno set:
2616  *                  - EINVAL fname was NULL or smbc_init not called
2617  *
2618  * @todo    what errno values are possible here?
2619  */
2620 int smbc_unlink_print_job(const char *purl, int id);
2621
2622 /**@ingroup callback
2623  * Remove a server from the cached server list it's unused.
2624  *
2625  * @param context    pointer to smb context
2626  *
2627  * @param srv        pointer to server to remove
2628  *
2629  * @return On success, 0 is returned. 1 is returned if the server could not
2630  *         be removed. Also useable outside libsmbclient.
2631  */
2632 int smbc_remove_unused_server(SMBCCTX * context, SMBCSRV * srv);
2633
2634 #ifdef __cplusplus
2635 }
2636 #endif
2637
2638 /**@ingroup directory
2639  * Convert strings of %xx to their single character equivalent.
2640  *
2641  * @param dest      A pointer to a buffer in which the resulting decoded
2642  *                  string should be placed.  This may be a pointer to the
2643  *                  same buffer as src_segment.
2644  *
2645  * @param src       A pointer to the buffer containing the URL to be decoded.
2646  *                  Any %xx sequences herein are converted to their single
2647  *                  character equivalent.  Each 'x' must be a valid hexadecimal
2648  *                  digit, or that % sequence is left undecoded.
2649  *
2650  * @param max_dest_len
2651  *                  The size of the buffer pointed to by dest_segment.
2652  *
2653  * @return          The number of % sequences which could not be converted
2654  *                  due to lack of two following hexadecimal digits.
2655  */
2656 #ifdef __cplusplus
2657 extern "C" {
2658 #endif
2659 int
2660 smbc_urldecode(char *dest, char * src, size_t max_dest_len);
2661 #ifdef __cplusplus
2662 }
2663 #endif
2664
2665
2666 /*
2667  * Convert any characters not specifically allowed in a URL into their %xx
2668  * equivalent.
2669  *
2670  * @param dest      A pointer to a buffer in which the resulting encoded
2671  *                  string should be placed.  Unlike smbc_urldecode(), this
2672  *                  must be a buffer unique from src.
2673  *
2674  * @param src       A pointer to the buffer containing the string to be encoded.
2675  *                  Any character not specifically allowed in a URL is converted
2676  *                  into its hexadecimal value and encoded as %xx.
2677  *
2678  * @param max_dest_len
2679  *                  The size of the buffer pointed to by dest_segment.
2680  *
2681  * @returns         The remaining buffer length.
2682  */
2683 #ifdef __cplusplus
2684 extern "C" {
2685 #endif
2686 int
2687 smbc_urlencode(char * dest, char * src, int max_dest_len);
2688 #ifdef __cplusplus
2689 }
2690 #endif
2691
2692
2693 /**@ingroup directory
2694  * Return the version of the linked Samba code, and thus the version of the
2695  * libsmbclient code.
2696  *
2697  * @return          The version string.
2698  */
2699 #ifdef __cplusplus
2700 extern "C" {
2701 #endif
2702 const char *
2703 smbc_version(void);
2704 #ifdef __cplusplus
2705 }
2706 #endif
2707
2708 /**@ingroup misc
2709  * Set the users credentials globally so they can be used for DFS
2710  * referrals. Probably best to use this function in the smbc_get_auth_data_fn
2711  * callback.
2712  *
2713  * @param workgroup      Workgroup of the user.
2714  *
2715  * @param user           Username of user.
2716  *
2717  * @param password       Password of user.
2718  *
2719  * @param use_kerberos   Whether to use Kerberos
2720  *
2721  * @param signing_state  One of these strings (all equivalents on same line):
2722  *                         "off", "no", "false"
2723  *                         "on", "yes", "true", "auto"
2724  *                         "force", "required", "forced"
2725  */
2726
2727 void
2728 smbc_set_credentials(const char *workgroup,
2729                      const char *user,
2730                      const char *password,
2731                      smbc_bool use_kerberos,
2732                      const char *signing_state);
2733
2734 /*
2735  * Wrapper around smbc_set_credentials.
2736  * Used to set correct credentials that will
2737  * be used to connect to DFS target share
2738  * in libsmbclient
2739  */
2740
2741 void
2742 smbc_set_credentials_with_fallback(SMBCCTX *ctx,
2743                                    const char *workgroup,
2744                                    const char *user,
2745                                    const char *password);
2746
2747
2748 /**
2749  * @ingroup threads
2750  *
2751  * Initialize for threads using the Posix Threads (pthread)
2752  * implementation. This is a built-in implementation, avoiding the need to
2753  * implement the component functions of the thread interface. If this function
2754  * is used, it is not necessary to call smbc_thread_impl().
2755  *
2756  * @return {void}
2757  */
2758 void
2759 smbc_thread_posix(void);
2760
2761 /**
2762  * @ingroup threads
2763  *
2764  * Initialize for an arbitrary thread implementation. The caller should
2765  * provide, as parameters, pointers to functions to implement the requisite
2766  * low-level thread functionality. A function must be provided for each
2767  * parameter; none may be null.
2768  *
2769  * If the thread implementation is POSIX Threads (pthreads), then the much
2770  * simpler smbc_thread_pthread() function may be used instead of this one.
2771  *
2772  * @param create_mutex
2773  *   Create a mutex. This function should expect three parameters: lockname,
2774  *   pplock, and location. It should create a unique mutex for each unique
2775  *   lockname it is provided, and return the mutex identifier in *pplock. The
2776  *   location parameter can be used for debugging, as it contains the
2777  *   compiler-provided __location__ of the call.
2778  *
2779  * @param destroy_mutex
2780  *   Destroy a mutex. This function should expect two parameters: plock and
2781  *   location. It should destroy the mutex associated with the identifier
2782  *   plock. The location parameter can be used for debugging, as it contains
2783  *   the compiler-provided __location__ of the call.
2784  *
2785  * @param lock_mutex
2786  *   Lock a mutex. This function should expect three parameters: plock,
2787  *   lock_type, and location. The mutex aassociated with identifier plock
2788  *   should be locked if lock_type is 1, and unlocked if lock_type is 2. The
2789  *   location parameter can be used for debugging, as it contains the
2790  *   compiler-provided __location__ of the call.
2791  *
2792  * @param create_tls
2793  *   Create thread local storage. This function should expect three
2794  *   parameters: keyname, ppkey, and location. It should allocate an
2795  *   implementation-specific amount of memory and assign the pointer to that
2796  *   allocated memory to *ppkey. The location parameter can be used for
2797  *   debugging, as it contains the compiler-provided __location__ of the
2798  *   call. This function should return 0 upon success, non-zero upon failure.
2799  *
2800  * @param destroy_tls
2801  *   Destroy thread local storage. This function should expect two parameters:
2802  *   ppkey and location. The ppkey parameter points to a variable containing a
2803  *   thread local storage key previously provided by the create_tls
2804  *   function. The location parameter can be used for debugging, as it
2805  *   contains the compiler-provided __location__ of the call.
2806  *
2807  * @param set_tls
2808  *   Set a thread local storage variable's value. This function should expect
2809  *   three parameters: pkey, pval, and location. The pkey parameter is a
2810  *   thread local storage key previously provided by the create_tls
2811  *   function. The (void *) pval parameter contains the value to be placed in
2812  *   the thread local storage variable identified by pkey. The location
2813  *   parameter can be used for debugging, as it contains the compiler-provided
2814  *   __location__ of the call. This function should return 0 upon success;
2815  *   non-zero otherwise.
2816  *
2817  * @param get_tls
2818  *   Retrieve a thread local storage variable's value. This function should
2819  *   expect two parameters: pkey and location. The pkey parameter is a thread
2820  *   local storage key previously provided by the create_tls function, and
2821  *   which has previously been used in a call to the set_tls function to
2822  *   initialize a thread local storage variable. The location parameter can be
2823  *   used for debugging, as it contains the compiler-provided __location__ of
2824  *   the call. This function should return the (void *) value stored in the
2825  *   variable identified by pkey.
2826  *
2827  * @return {void}
2828  */
2829 void
2830 smbc_thread_impl(
2831         /* Mutex functions. */
2832         int (*create_mutex)(const char *lockname,
2833                             void **pplock,
2834                             const char *location),
2835         void (*destroy_mutex)(void *plock,
2836                               const char *location),
2837         int (*lock_mutex)(void *plock,
2838                           int lock_type,
2839                           const char *location),
2840
2841         /* Thread local storage. */
2842         int (*create_tls)(const char *keyname,
2843                           void **ppkey,
2844                           const char *location),
2845         void (*destroy_tls)(void **ppkey,
2846                             const char *location),
2847         int (*set_tls)(void *pkey,
2848                        const void *pval,
2849                        const char *location),
2850         void *(*get_tls)(void *pkey,
2851                          const char *location)
2852         );
2853
2854
2855
2856 /**
2857  * @ingroup structure
2858  * Structure that contains a client context information
2859  * This structure is known as SMBCCTX
2860  *
2861  * DO NOT DIRECTLY MANIPULATE THE CONTEXT STRUCTURE!  The data in the context
2862  * structure should all be considered private to the library.  It remains here
2863  * only for backward compatibility.
2864  *
2865  * See the comments herein for use of the setter and getter functions which
2866  * should now be used for manipulating these values.  New features, functions,
2867  * etc., are not added here but rather in _internal where they are not
2868  * directly visible to applications.  This makes it much easier to maintain
2869  * ABI compatibility.
2870  */
2871 struct _SMBCCTX
2872 {
2873         /**
2874          * debug level
2875          *
2876          * DEPRECATED:
2877          * Use smbc_getDebug() and smbc_setDebug()
2878          */
2879         int     debug DEPRECATED_SMBC_INTERFACE;
2880
2881         /**
2882          * netbios name used for making connections
2883          *
2884          * DEPRECATED:
2885          * Use smbc_getNetbiosName() and smbc_setNetbiosName()
2886          */
2887         char * netbios_name DEPRECATED_SMBC_INTERFACE;
2888
2889         /**
2890          * workgroup name used for making connections
2891          *
2892          * DEPRECATED:
2893          * Use smbc_getWorkgroup() and smbc_setWorkgroup()
2894          */
2895         char * workgroup DEPRECATED_SMBC_INTERFACE;
2896
2897         /**
2898          * username used for making connections
2899          *
2900          * DEPRECATED:
2901          * Use smbc_getUser() and smbc_setUser()
2902          */
2903         char * user DEPRECATED_SMBC_INTERFACE;
2904
2905         /**
2906          * timeout used for waiting on connections / response data (in
2907          * milliseconds)
2908          *
2909          * DEPRECATED:
2910          * Use smbc_getTimeout() and smbc_setTimeout()
2911          */
2912         int timeout DEPRECATED_SMBC_INTERFACE;
2913
2914         /**
2915          * callable functions for files:
2916          * For usage and return values see the SMBC_* functions
2917          *
2918          * DEPRECATED:
2919          *
2920          * Use smbc_getFunction*() and smbc_setFunction*(), e.g.
2921          * smbc_getFunctionOpen(), smbc_setFunctionUnlink(), etc.
2922          */
2923         smbc_open_fn                    open DEPRECATED_SMBC_INTERFACE;
2924         smbc_creat_fn                   creat DEPRECATED_SMBC_INTERFACE;
2925         smbc_read_fn                    read DEPRECATED_SMBC_INTERFACE;
2926         smbc_write_fn                   write DEPRECATED_SMBC_INTERFACE;
2927         smbc_unlink_fn                  unlink DEPRECATED_SMBC_INTERFACE;
2928         smbc_rename_fn                  rename DEPRECATED_SMBC_INTERFACE;
2929         smbc_lseek_fn                   lseek DEPRECATED_SMBC_INTERFACE;
2930         smbc_stat_fn                    stat DEPRECATED_SMBC_INTERFACE;
2931         smbc_fstat_fn                   fstat DEPRECATED_SMBC_INTERFACE;
2932 #if 0 /* internal */
2933         smbc_ftruncate_fn               ftruncate_fn;
2934 #endif
2935         smbc_close_fn                   close_fn DEPRECATED_SMBC_INTERFACE;
2936         smbc_opendir_fn                 opendir DEPRECATED_SMBC_INTERFACE;
2937         smbc_closedir_fn                closedir DEPRECATED_SMBC_INTERFACE;
2938         smbc_readdir_fn                 readdir DEPRECATED_SMBC_INTERFACE;
2939         smbc_getdents_fn                getdents DEPRECATED_SMBC_INTERFACE;
2940         smbc_mkdir_fn                   mkdir DEPRECATED_SMBC_INTERFACE;
2941         smbc_rmdir_fn                   rmdir DEPRECATED_SMBC_INTERFACE;
2942         smbc_telldir_fn                 telldir DEPRECATED_SMBC_INTERFACE;
2943         smbc_lseekdir_fn                lseekdir DEPRECATED_SMBC_INTERFACE;
2944         smbc_fstatdir_fn                fstatdir DEPRECATED_SMBC_INTERFACE;
2945         smbc_chmod_fn                   chmod DEPRECATED_SMBC_INTERFACE;
2946         smbc_utimes_fn                  utimes DEPRECATED_SMBC_INTERFACE;
2947         smbc_setxattr_fn                setxattr DEPRECATED_SMBC_INTERFACE;
2948         smbc_getxattr_fn                getxattr DEPRECATED_SMBC_INTERFACE;
2949         smbc_removexattr_fn             removexattr DEPRECATED_SMBC_INTERFACE;
2950         smbc_listxattr_fn               listxattr DEPRECATED_SMBC_INTERFACE;
2951
2952         /* Printing-related functions */
2953         smbc_print_file_fn              print_file DEPRECATED_SMBC_INTERFACE;
2954         smbc_open_print_job_fn          open_print_job DEPRECATED_SMBC_INTERFACE;
2955         smbc_list_print_jobs_fn         list_print_jobs DEPRECATED_SMBC_INTERFACE;
2956         smbc_unlink_print_job_fn        unlink_print_job DEPRECATED_SMBC_INTERFACE;
2957
2958         /*
2959         ** Callbacks
2960         *
2961         * DEPRECATED:
2962         *
2963         * See the comment above each field, for the getter and setter
2964         * functions that should now be used.
2965         */
2966         struct _smbc_callbacks
2967         {
2968                 /**
2969                  * authentication function callback: called upon auth requests
2970                  *
2971                  * DEPRECATED:
2972                  * Use smbc_getFunctionAuthData(), smbc_setFunctionAuthData()
2973                  */
2974                 smbc_get_auth_data_fn auth_fn DEPRECATED_SMBC_INTERFACE;
2975
2976                 /**
2977                  * check if a server is still good
2978                  *
2979                  * DEPRECATED:
2980                  * Use smbc_getFunctionCheckServer(),
2981                  * smbc_setFunctionCheckServer()
2982                  */
2983                 smbc_check_server_fn check_server_fn DEPRECATED_SMBC_INTERFACE;
2984
2985                 /**
2986                  * remove a server if unused
2987                  *
2988                  * DEPRECATED:
2989                  * Use smbc_getFunctionRemoveUnusedServer(),
2990                  * smbc_setFunctionCheckServer()
2991                  */
2992                 smbc_remove_unused_server_fn remove_unused_server_fn DEPRECATED_SMBC_INTERFACE;
2993
2994                 /** Cache subsystem
2995                  *
2996                  * For an example cache system see
2997                  * samba/source/libsmb/libsmb_cache.c
2998                  *
2999                  * Cache subsystem * functions follow.
3000                  */
3001
3002                 /**
3003                  * server cache addition
3004                  *
3005                  * DEPRECATED:
3006                  * Use smbc_getFunctionAddCachedServer(),
3007                  * smbc_setFunctionAddCachedServer()
3008                  */
3009                 smbc_add_cached_srv_fn add_cached_srv_fn DEPRECATED_SMBC_INTERFACE;
3010
3011                 /**
3012                  * server cache lookup
3013                  *
3014                  * DEPRECATED:
3015                  * Use smbc_getFunctionGetCachedServer(),
3016                  * smbc_setFunctionGetCachedServer()
3017                  */
3018                 smbc_get_cached_srv_fn get_cached_srv_fn DEPRECATED_SMBC_INTERFACE;
3019
3020                 /**
3021                  * server cache removal
3022                  *
3023                  * DEPRECATED:
3024                  * Use smbc_getFunctionRemoveCachedServer(),
3025                  * smbc_setFunctionRemoveCachedServer()
3026                  */
3027                 smbc_remove_cached_srv_fn remove_cached_srv_fn DEPRECATED_SMBC_INTERFACE;
3028
3029                 /**
3030                  * server cache purging, try to remove all cached servers
3031                  * (disconnect)
3032                  *
3033                  * DEPRECATED:
3034                  * Use smbc_getFunctionPurgeCachedServers(),
3035                  * smbc_setFunctionPurgeCachedServers()
3036                  */
3037                 smbc_purge_cached_fn purge_cached_fn DEPRECATED_SMBC_INTERFACE;
3038         } callbacks;
3039
3040         /**
3041          * Space where the private data of the server cache used to be
3042          *
3043          * DEPRECATED:
3044          * Use smbc_getServerCacheData(), smbc_setServerCacheData()
3045          */
3046         void * reserved DEPRECATED_SMBC_INTERFACE;
3047
3048         /*
3049          * Very old configuration options.
3050          *
3051          * DEPRECATED:
3052          * Use one of the following functions instead:
3053          *   smbc_setOptionUseKerberos()
3054          *   smbc_getOptionUseKerberos()
3055          *   smbc_setOptionFallbackAfterKerberos()
3056          *   smbc_getOptionFallbackAfterKerberos()
3057          *   smbc_setOptionNoAutoAnonymousLogin()
3058          *   smbc_getOptionNoAutoAnonymousLogin()
3059          */
3060         int flags DEPRECATED_SMBC_INTERFACE;
3061
3062         /**
3063          * user options selections that apply to this session
3064          *
3065          * NEW OPTIONS ARE NOT ADDED HERE!
3066          *
3067          * DEPRECATED:
3068          * To set and retrieve options, use the smbc_setOption*() and
3069          * smbc_getOption*() functions.
3070          */
3071         struct _smbc_options {
3072                 int browse_max_lmb_count DEPRECATED_SMBC_INTERFACE;
3073                 int urlencode_readdir_entries DEPRECATED_SMBC_INTERFACE;
3074                 int one_share_per_server DEPRECATED_SMBC_INTERFACE;
3075         } options DEPRECATED_SMBC_INTERFACE;
3076
3077         /** INTERNAL DATA
3078          * do _NOT_ touch this from your program !
3079          */
3080         struct SMBC_internal_data * internal;
3081 };
3082
3083
3084 #endif /* SMBCLIENT_H_INCLUDED */