Add support for the new modules system to auth/ (merge from HEAD)
[samba.git] / source / 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
9    
10   This program is free software; you can redistribute it and/or modify
11   it under the terms of the GNU General Public License as published by
12   the Free Software Foundation; either version 2 of the License, or
13   (at your option) any later version.
14    
15   This program is distributed in the hope that it will be useful,
16   but WITHOUT ANY WARRANTY; without even the implied warranty of
17   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18   GNU General Public License for more details.
19    
20   You should have received a copy of the GNU General Public License
21   along with this program; if not, write to the Free Software
22   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23   =====================================================================*/
24
25 #ifndef SMBCLIENT_H_INCLUDED
26 #define SMBCLIENT_H_INCLUDED
27
28 /*-------------------------------------------------------------------*/
29 /* The following are special comments to instruct DOXYGEN (automated 
30  * documentation tool:
31 */
32 /** \defgroup libsmbclient
33 */
34 /** \defgroup structure Data Structures Type and Constants
35 *   \ingroup libsmbclient
36 *   Data structures, types, and constants
37 */
38 /** \defgroup callback Callback function types
39 *   \ingroup libsmbclient
40 *   Callback functions
41 */
42 /** \defgroup file File Functions
43 *   \ingroup libsmbclient
44 *   Functions used to access individual file contents
45 */
46 /** \defgroup directory Directory Functions
47 *   \ingroup libsmbclient
48 *   Functions used to access directory entries
49 */
50 /** \defgroup attribute Attributes Functions
51 *   \ingroup libsmbclient
52 *   Functions used to view or change file and directory attributes
53 */
54 /** \defgroup print Print Functions
55 *   \ingroup libsmbclient
56 *   Functions used to access printing functionality
57 */
58 /** \defgroup misc Miscellaneous Functions
59 *   \ingroup libsmbclient
60 *   Functions that don't fit in to other categories
61 */
62 /*-------------------------------------------------------------------*/   
63
64 /* Make sure we have the following includes for now ... */
65 #include <sys/types.h>
66 #include <sys/stat.h>
67 #include <fcntl.h>
68
69 #define SMBC_WORKGROUP      1
70 #define SMBC_SERVER         2
71 #define SMBC_FILE_SHARE     3
72 #define SMBC_PRINTER_SHARE  4
73 #define SMBC_COMMS_SHARE    5
74 #define SMBC_IPC_SHARE      6
75 #define SMBC_DIR            7
76 #define SMBC_FILE           8
77 #define SMBC_LINK           9
78
79 /**@ingroup structure
80  * Structure that represents a directory entry.
81  *
82  */
83 struct smbc_dirent 
84 {
85         /** Type of entity.
86             SMBC_WORKGROUP=1,
87             SMBC_SERVER=2, 
88             SMBC_FILE_SHARE=3,
89             SMBC_PRINTER_SHARE=4,
90             SMBC_COMMS_SHARE=5,
91             SMBC_IPC_SHARE=6,
92             SMBC_DIR=7,
93             SMBC_FILE=8,
94             SMBC_LINK=9,*/ 
95         unsigned int smbc_type; 
96
97         /** Length of this smbc_dirent in bytes
98          */
99         unsigned int dirlen;
100         /** The length of the comment string in bytes (includes null 
101          *  terminator)
102          */
103         unsigned int commentlen;
104         /** Points to the null terminated comment string 
105          */
106         char *comment;
107         /** The length of the name string in bytes (includes null 
108          *  terminator)
109          */
110         unsigned int namelen;
111         /** Points to the null terminated name string 
112          */
113         char name[1];
114 };
115
116
117 /**@ingroup structure
118  * Structure that represents a print job.
119  *
120  */
121 #ifndef _CLIENT_H
122 struct print_job_info 
123 {
124         /** numeric ID of the print job
125          */
126         unsigned short id;
127     
128         /** represents print job priority (lower numbers mean higher priority)
129          */
130         unsigned short priority;
131     
132         /** Size of the print job
133          */
134         size_t size;
135     
136         /** Name of the user that owns the print job
137          */
138         char user[128];
139   
140         /** Name of the print job. This will have no name if an anonymous print
141          *  file was opened. Ie smb://server/printer
142          */
143         char name[128];
144
145         /** Time the print job was spooled
146          */
147         time_t t;
148 };
149 #endif /* _CLIENT_H */
150
151
152 /**@ingroup structure
153  * Server handle 
154  */
155 typedef struct _SMBCSRV  SMBCSRV;
156
157 /**@ingroup structure
158  * File or directory handle 
159  */
160 typedef struct _SMBCFILE SMBCFILE;
161
162 /**@ingroup structure
163  * File or directory handle 
164  */
165 typedef struct _SMBCCTX SMBCCTX;
166
167
168
169
170
171 /**@ingroup callback
172  * Authentication callback function type.
173  * 
174  * Type for the the authentication function called by the library to
175  * obtain authentication credentals
176  *
177  * @param srv       Server being authenticated to
178  *
179  * @param shr       Share being authenticated to
180  *
181  * @param wg        Pointer to buffer containing a "hint" for the
182  *                  workgroup to be authenticated.  Should be filled in
183  *                  with the correct workgroup if the hint is wrong.
184  * 
185  * @param wglen     The size of the workgroup buffer in bytes
186  *
187  * @param un        Pointer to buffer containing a "hint" for the
188  *                  user name to be use for authentication. Should be
189  *                  filled in with the correct workgroup if the hint is
190  *                  wrong.
191  * 
192  * @param unlen     The size of the username buffer in bytes
193  *
194  * @param pw        Pointer to buffer containing to which password 
195  *                  copied
196  * 
197  * @param pwlen     The size of the password buffer in bytes
198  *           
199  */
200 typedef void (*smbc_get_auth_data_fn)(const char *srv, 
201                                       const char *shr,
202                                       char *wg, int wglen, 
203                                       char *un, int unlen,
204                                       char *pw, int pwlen);
205
206
207 /**@ingroup callback
208  * Print job info callback function type.
209  *
210  * @param i         pointer to print job information structure
211  *
212  */ 
213 typedef void (*smbc_list_print_job_fn)(struct print_job_info *i);
214                 
215
216 /**@ingroup callback
217  * Check if a server is still good
218  *
219  * @param c         pointer to smb context
220  *
221  * @param srv       pointer to server to check
222  *
223  * @return          0 when connection is good. 1 on error.
224  *
225  */ 
226 typedef int (*smbc_check_server_fn)(SMBCCTX * c, SMBCSRV *srv);
227
228 /**@ingroup callback
229  * Remove a server if unused
230  *
231  * @param c         pointer to smb context
232  *
233  * @param srv       pointer to server to remove
234  *
235  * @return          0 on success. 1 on failure.
236  *
237  */ 
238 typedef int (*smbc_remove_unused_server_fn)(SMBCCTX * c, SMBCSRV *srv);
239
240
241 /**@ingroup callback
242  * Add a server to the cache system
243  *
244  * @param c         pointer to smb context
245  *
246  * @param srv       pointer to server to add
247  *
248  * @param server    server name 
249  *
250  * @param share     share name
251  *
252  * @param workgroup workgroup used to connect
253  *
254  * @param username  username used to connect
255  *
256  * @return          0 on success. 1 on failure.
257  *
258  */ 
259 typedef int (*smbc_add_cached_srv_fn)   (SMBCCTX * c, SMBCSRV *srv, 
260                                     const char * server, const char * share,
261                                     const char * workgroup, const char * username);
262
263 /**@ingroup callback
264  * Look up a server in the cache system
265  *
266  * @param c         pointer to smb context
267  *
268  * @param server    server name to match
269  *
270  * @param share     share name to match
271  *
272  * @param workgroup workgroup to match
273  *
274  * @param username  username to match
275  *
276  * @return          pointer to SMBCSRV on success. NULL on failure.
277  *
278  */ 
279 typedef SMBCSRV * (*smbc_get_cached_srv_fn)   (SMBCCTX * c, const char * server,
280                                                const char * share, const char * workgroup,
281                                                const char * username);
282
283 /**@ingroup callback
284  * Check if a server is still good
285  *
286  * @param c         pointer to smb context
287  *
288  * @param srv       pointer to server to remove
289  *
290  * @return          0 when found and removed. 1 on failure.
291  *
292  */ 
293 typedef int (*smbc_remove_cached_srv_fn)(SMBCCTX * c, SMBCSRV *srv);
294
295
296 /**@ingroup callback
297  * Try to remove all servers from the cache system and disconnect
298  *
299  * @param c         pointer to smb context
300  *
301  * @return          0 when found and removed. 1 on failure.
302  *
303  */ 
304 typedef int (*smbc_purge_cached_fn)     (SMBCCTX * c);
305
306
307
308
309 /**@ingroup structure
310  * Structure that contains a client context information 
311  * This structure is know as SMBCCTX
312  */
313 struct _SMBCCTX {
314         /** debug level 
315          */
316         int     debug;
317         
318         /** netbios name used for making connections
319          */
320         char * netbios_name;
321
322         /** workgroup name used for making connections 
323          */
324         char * workgroup;
325
326         /** username used for making connections 
327          */
328         char * user;
329
330         /** timeout used for waiting on connections / response data (in milliseconds)
331          */
332         int timeout;
333
334         /** callable functions for files:
335          * For usage and return values see the smbc_* functions
336          */ 
337         SMBCFILE * (*open)    (SMBCCTX *c, const char *fname, int flags, mode_t mode);
338         SMBCFILE * (*creat)   (SMBCCTX *c, const char *path, mode_t mode);
339         ssize_t    (*read)    (SMBCCTX *c, SMBCFILE *file, void *buf, size_t count);
340         ssize_t    (*write)   (SMBCCTX *c, SMBCFILE *file, void *buf, size_t count);
341         int        (*unlink)  (SMBCCTX *c, const char *fname);
342         int        (*rename)  (SMBCCTX *ocontext, const char *oname, 
343                                SMBCCTX *ncontext, const char *nname);
344         off_t      (*lseek)   (SMBCCTX *c, SMBCFILE * file, off_t offset, int whence);
345         int        (*stat)    (SMBCCTX *c, const char *fname, struct stat *st);
346         int        (*fstat)   (SMBCCTX *c, SMBCFILE *file, struct stat *st);
347         int        (*close)   (SMBCCTX *c, SMBCFILE *file);
348
349         /** callable functions for dirs
350          */ 
351         SMBCFILE * (*opendir) (SMBCCTX *c, const char *fname);
352         int        (*closedir)(SMBCCTX *c, SMBCFILE *dir);
353         struct smbc_dirent * (*readdir)(SMBCCTX *c, SMBCFILE *dir);
354         int        (*getdents)(SMBCCTX *c, SMBCFILE *dir, 
355                                struct smbc_dirent *dirp, int count);
356         int        (*mkdir)   (SMBCCTX *c, const char *fname, mode_t mode);
357         int        (*rmdir)   (SMBCCTX *c, const char *fname);
358         off_t      (*telldir) (SMBCCTX *c, SMBCFILE *dir);
359         int        (*lseekdir)(SMBCCTX *c, SMBCFILE *dir, off_t offset);
360         int        (*fstatdir)(SMBCCTX *c, SMBCFILE *dir, struct stat *st);
361
362         /** callable functions for printing
363          */ 
364         int        (*print_file)(SMBCCTX *c_file, const char *fname, 
365                                  SMBCCTX *c_print, const char *printq);
366         SMBCFILE * (*open_print_job)(SMBCCTX *c, const char *fname);
367         int        (*list_print_jobs)(SMBCCTX *c, const char *fname, smbc_list_print_job_fn fn);
368         int        (*unlink_print_job)(SMBCCTX *c, const char *fname, int id);
369
370
371         /** Callbacks
372          * These callbacks _always_ have to be initialized because they will not be checked
373          * at dereference for increased speed.
374          */
375         struct _smbc_callbacks {
376                 /** authentication function callback: called upon auth requests
377                  */
378                 smbc_get_auth_data_fn auth_fn;
379                 
380                 /** check if a server is still good
381                  */
382                 smbc_check_server_fn check_server_fn;
383
384                 /** remove a server if unused
385                  */
386                 smbc_remove_unused_server_fn remove_unused_server_fn;
387
388                 /** Cache subsystem
389                  * For an example cache system see samba/source/libsmb/libsmb_cache.c
390                  * Cache subsystem functions follow.
391                  */
392
393                 /** server cache addition 
394                  */
395                 smbc_add_cached_srv_fn add_cached_srv_fn;
396
397                 /** server cache lookup 
398                  */
399                 smbc_get_cached_srv_fn get_cached_srv_fn;
400
401                 /** server cache removal
402                  */
403                 smbc_remove_cached_srv_fn remove_cached_srv_fn;
404                 
405                 /** server cache purging, try to remove all cached servers (disconnect)
406                  */
407                 smbc_purge_cached_fn purge_cached_fn;
408         } callbacks;
409
410
411         /** Space to store private data of the server cache.
412          */
413         struct smbc_server_cache * server_cache;
414
415         /** INTERNAL DATA
416          * do _NOT_ touch this from your program !
417          */
418         struct smbc_internal_data * internal;
419         
420 };
421
422
423 /**@ingroup misc
424  * Create a new SBMCCTX (a context).
425  *
426  * Must be called before the context is passed to smbc_context_init()
427  *
428  * @return          The given SMBCCTX pointer on success, NULL on error with errno set:
429  *                  - ENOMEM Out of memory
430  *
431  * @see             smbc_free_context(), smbc_init_context()
432  *
433  * @note            Do not forget to smbc_init_context() the returned SMBCCTX pointer !
434  */
435 SMBCCTX * smbc_new_context(void);
436
437 /**@ingroup misc
438  * Delete a SBMCCTX (a context) acquired from smbc_new_context().
439  *
440  * The context will be deleted if possible.
441  *
442  * @param context   A pointer to a SMBCCTX obtained from smbc_new_context()
443  *
444  * @param shutdown_ctx   If 1, all connections and files will be closed even if they are busy.
445  *
446  *
447  * @return          Returns 0 on succes. Returns 1 on failure with errno set:
448  *                  - EBUSY Server connections are still used, Files are open or cache 
449  *                          could not be purged
450  *                  - EBADF context == NULL
451  *
452  * @see             smbc_new_context()
453  *
454  * @note            It is advised to clean up all the contexts with shutdown_ctx set to 1
455  *                  just before exit()'ing. When shutdown_ctx is 0, this function can be
456  *                  use in periodical cleanup functions for example.
457  */
458 int smbc_free_context(SMBCCTX * context, int shutdown_ctx);
459
460
461 /**@ingroup misc
462  * Initialize a SBMCCTX (a context).
463  *
464  * Must be called before using any SMBCCTX API function
465  *
466  * @param context   A pointer to a SMBCCTX obtained from smbc_new_context()
467  *
468  * @return          A pointer to the given SMBCCTX on success, NULL on error with errno set:
469  *                  - EBADF  NULL context given
470  *                  - ENOMEM Out of memory
471  *                  - ENOENT The smb.conf file would not load
472  *
473  * @see             smbc_new_context()
474  *
475  * @note            my_context = smbc_init_context(smbc_new_context()) is perfectly safe, 
476  *                  but it might leak memory on smbc_context_init() failure. Avoid this.
477  *                  You'll have to call smbc_free_context() yourself on failure.  
478  */
479
480 SMBCCTX * smbc_init_context(SMBCCTX * context);
481
482 /**@ingroup misc
483  * Initialize the samba client library.
484  *
485  * Must be called before using any of the smbclient API function
486  *  
487  * @param fn        The function that will be called to obtaion 
488  *                  authentication credentials.
489  *
490  * @param debug     Allows caller to set the debug level. Can be
491  *                  changed in smb.conf file. Allows caller to set
492  *                  debugging if no smb.conf.
493  *   
494  * @return          0 on success, < 0 on error with errno set:
495  *                  - ENOMEM Out of memory
496  *                  - ENOENT The smb.conf file would not load
497  *
498  */
499
500 int smbc_init(smbc_get_auth_data_fn fn, int debug);
501
502 /**@ingroup file
503  * Open a file on an SMB server.
504  *
505  * @param furl      The smb url of the file to be opened. 
506  *
507  * @param flags     Is one of O_RDONLY, O_WRONLY or O_RDWR which 
508  *                  request opening  the  file  read-only,write-only
509  *                  or read/write. flags may also be bitwise-or'd with
510  *                  one or  more of  the following: 
511  *                  O_CREAT - If the file does not exist it will be 
512  *                  created.
513  *                  O_EXCL - When  used with O_CREAT, if the file 
514  *                  already exists it is an error and the open will 
515  *                  fail. 
516  *                  O_TRUNC - If the file already exists it will be
517  *                  truncated.
518  *                  O_APPEND The  file  is  opened  in  append mode 
519  *
520  * @param mode      mode specifies the permissions to use if a new 
521  *                  file is created.  It  is  modified  by  the 
522  *                  process's umask in the usual way: the permissions
523  *                  of the created file are (mode & ~umask) 
524  *
525  *                  Not currently use, but there for future use.
526  *                  We will map this to SYSTEM, HIDDEN, etc bits
527  *                  that reverses the mapping that smbc_fstat does.
528  *
529  * @return          Valid file handle, < 0 on error with errno set:
530  *                  - ENOMEM  Out of memory
531  *                  - EINVAL if an invalid parameter passed, like no 
532  *                  file, or smbc_init not called.
533  *                  - EEXIST  pathname already exists and O_CREAT and 
534  *                  O_EXCL were used.
535  *                  - EISDIR  pathname  refers  to  a  directory  and  
536  *                  the access requested involved writing.
537  *                  - EACCES  The requested access to the file is not 
538  *                  allowed 
539  *                  - ENODEV The requested share does not exist
540  *                  - ENOTDIR A file on the path is not a directory
541  *                  - ENOENT  A directory component in pathname does 
542  *                  not exist.
543  *
544  * @see             smbc_creat()
545  *
546  * @note            This call uses an underlying routine that may create
547  *                  a new connection to the server specified in the URL.
548  *                  If the credentials supplied in the URL, or via the
549  *                  auth_fn in the smbc_init call, fail, this call will
550  *                  try again with an empty username and password. This 
551  *                  often gets mapped to the guest account on some machines.
552  */
553
554 int smbc_open(const char *furl, int flags, mode_t mode);
555
556 /**@ingroup file
557  * Create a file on an SMB server.
558  *
559  * Same as calling smbc_open() with flags = O_CREAT|O_WRONLY|O_TRUNC 
560  *   
561  * @param furl      The smb url of the file to be created
562  *  
563  * @param mode      mode specifies the permissions to use if  a  new  
564  *                  file is created.  It  is  modified  by  the 
565  *                  process's umask in the usual way: the permissions
566  *                  of the created file are (mode & ~umask)
567  *
568  *                  NOTE, the above is not true. We are dealing with 
569  *                  an SMB server, which has no concept of a umask!
570  *      
571  * @return          Valid file handle, < 0 on error with errno set:
572  *                  - ENOMEM  Out of memory
573  *                  - EINVAL if an invalid parameter passed, like no 
574  *                  file, or smbc_init not called.
575  *                  - EEXIST  pathname already exists and O_CREAT and
576  *                  O_EXCL were used.
577  *                  - EISDIR  pathname  refers  to  a  directory  and
578  *                  the access requested involved writing.
579  *                  - EACCES  The requested access to the file is not
580  *                  allowed 
581  *                  - ENOENT  A directory component in pathname does 
582  *                  not exist.
583  *                  - ENODEV The requested share does not exist.
584  * @see             smbc_open()
585  *
586  */
587
588 int smbc_creat(const char *furl, mode_t mode);
589
590 /**@ingroup file
591  * Read from a file using an opened file handle.
592  *
593  * @param fd        Open file handle from smbc_open() or smbc_creat()
594  *
595  * @param buf       Pointer to buffer to recieve read data
596  *
597  * @param bufsize   Size of buf in bytes
598  *
599  * @return          Number of bytes read, < 0 on error with errno set:
600  *                  - EISDIR fd refers to a directory
601  *                  - EBADF  fd  is  not  a valid file descriptor or 
602  *                  is not open for reading.
603  *                  - EINVAL fd is attached to an object which is 
604  *                  unsuitable for reading, or no buffer passed or
605  *                  smbc_init not called.
606  *
607  * @see             smbc_open(), smbc_write()
608  *
609  */
610 ssize_t smbc_read(int fd, void *buf, size_t bufsize);
611
612
613 /**@ingroup file
614  * Write to a file using an opened file handle.
615  *
616  * @param fd        Open file handle from smbc_open() or smbc_creat()
617  *
618  * @param buf       Pointer to buffer to recieve read data
619  *
620  * @param bufsize   Size of buf in bytes
621  *
622  * @return          Number of bytes written, < 0 on error with errno set:
623  *                  - EISDIR fd refers to a directory.
624  *                  - EBADF  fd  is  not  a valid file descriptor or 
625  *                  is not open for reading.
626  *                  - EINVAL fd is attached to an object which is 
627  *                  unsuitable for reading, or no buffer passed or
628  *                  smbc_init not called.
629  *
630  * @see             smbc_open(), smbc_read()
631  *
632  */
633 ssize_t smbc_write(int fd, void *buf, size_t bufsize);
634
635
636 /**@ingroup file
637  * Seek to a specific location in a file.
638  *
639  * @param fd        Open file handle from smbc_open() or smbc_creat()
640  * 
641  * @param offset    Offset in bytes from whence
642  * 
643  * @param whence    A location in the file:
644  *                  - SEEK_SET The offset is set to offset bytes from
645  *                  the beginning of the file
646  *                  - SEEK_CUR The offset is set to current location 
647  *                  plus offset bytes.
648  *                  - SEEK_END The offset is set to the size of the 
649  *                  file plus offset bytes.
650  *
651  * @return          Upon successful completion, lseek returns the 
652  *                  resulting offset location as measured in bytes 
653  *                  from the beginning  of the file. Otherwise, a value
654  *                  of (off_t)-1 is returned and errno is set to 
655  *                  indicate the error:
656  *                  - EBADF  Fildes is not an open file descriptor.
657  *                  - EINVAL Whence is not a proper value or smbc_init
658  *                    not called.
659  *
660  * @todo Are all the whence values really supported?
661  * 
662  * @todo Are errno values complete and correct?
663  */
664 off_t smbc_lseek(int fd, off_t offset, int whence);
665
666
667 /**@ingroup file
668  * Close an open file handle.
669  *
670  * @param fd        The file handle to close
671  *
672  * @return          0 on success, < 0 on error with errno set:
673  *                  - EBADF  fd isn't a valid open file descriptor
674  *                  - EINVAL smbc_init() failed or has not been called
675  *
676  * @see             smbc_open(), smbc_creat()
677  */
678 int smbc_close(int fd);
679
680
681 /**@ingroup directory
682  * Unlink (delete) a file or directory.
683  *
684  * @param furl      The smb url of the file to delete
685  *
686  * @return          0 on success, < 0 on error with errno set:
687  *                  - EACCES or EPERM Write  access  to the directory 
688  *                  containing pathname is not allowed or one  
689  *                  of  the  directories in pathname did not allow
690  *                  search (execute) permission
691  *                  - ENOENT A directory component in pathname does
692  *                  not exist
693  *                  - EINVAL NULL was passed in the file param or
694  *                    smbc_init not called.
695  *                  - EACCES You do not have access to the file
696  *                  - ENOMEM Insufficient kernel memory was available
697  *
698  * @see             smbc_rmdir()s
699  *
700  * @todo Are errno values complete and correct?
701  */
702 int smbc_unlink(const char *furl);
703
704
705 /**@ingroup directory
706  * Rename or move a file or directory.
707  * 
708  * @param ourl      The original smb url (source url) of file or 
709  *                  directory to be moved
710  * 
711  * @param nurl      The new smb url (destination url) of the file
712  *                  or directory after the move.  Currently nurl must
713  *                  be on the same share as ourl.
714  *
715  * @return          0 on success, < 0 on error with errno set:
716  *                  - EISDIR nurl is an existing directory, but ourl is
717  *                  not a directory.
718  *                  - EEXIST nurl is  a  non-empty directory, 
719  *                  i.e., contains entries other than "." and ".."
720  *                  - EINVAL The  new  url  contained  a path prefix 
721  *                  of the old, or, more generally, an  attempt was
722  *                  made  to make a directory a subdirectory of itself
723  *                  or smbc_init not called.
724  *                  - ENOTDIR A component used as a directory in ourl 
725  *                  or nurl path is not, in fact, a directory.  Or, 
726  *                  ourl  is a directory, and newpath exists but is not
727  *                  a directory.
728  *                  - EACCES or EPERM Write access to the directory 
729  *                  containing ourl or nurl is not allowed for the 
730  *                  process's effective uid,  or  one of the 
731  *                  directories in ourl or nurl did not allow search
732  *                  (execute) permission,  or ourl  was  a  directory
733  *                  and did not allow write permission.
734  *                  - ENOENT A  directory component in ourl or nurl 
735  *                  does not exist.
736  *                  - EXDEV Rename across shares not supported.
737  *                  - ENOMEM Insufficient kernel memory was available.
738  *                  - EEXIST The target file, nurl, already exists.
739  *
740  *
741  * @todo Are we going to support copying when urls are not on the same
742  *       share?  I say no... NOTE. I agree for the moment.
743  *
744  */
745 int smbc_rename(const char *ourl, const char *nurl);
746
747
748 /**@ingroup directory
749  * Open a directory used to obtain directory entries.
750  *
751  * @param durl      The smb url of the directory to open
752  *
753  * @return          Valid directory handle. < 0 on error with errno set:
754  *                  - EACCES Permission denied.
755  *                  - EINVAL A NULL file/URL was passed, or the URL would
756  *                  not parse, or was of incorrect form or smbc_init not
757  *                  called.
758  *                  - ENOENT durl does not exist, or name is an 
759  *                  - ENOMEM Insufficient memory to complete the 
760  *                  operation.                              
761  *                  - ENOTDIR name is not a directory.
762  *                  - EPERM the workgroup could not be found.
763  *                  - ENODEV the workgroup or server could not be found.
764  *
765  * @see             smbc_getdents(), smbc_readdir(), smbc_closedir()
766  *
767  */
768 int smbc_opendir(const char *durl);
769
770
771 /**@ingroup directory
772  * Close a directory handle opened by smbc_opendir().
773  *
774  * @param dh        Directory handle to close
775  *
776  * @return          0 on success, < 0 on error with errno set:
777  *                  - EBADF dh is an invalid directory handle
778  *
779  * @see             smbc_opendir()
780  */
781 int smbc_closedir(int dh);
782
783
784 /**@ingroup directory
785  * Get multiple directory entries.
786  *
787  * smbc_getdents() reads as many dirent structures from the an open 
788  * directory handle into a specified memory area as will fit.
789  *
790  * @param dh        Valid directory as returned by smbc_opendir()
791  *
792  * @param dirp      pointer to buffer that will receive the directory
793  *                  entries.
794  * 
795  * @param count     The size of the dirp buffer in bytes
796  *
797  * @returns         If any dirents returned, return will indicate the
798  *                  total size. If there were no more dirents available,
799  *                  0 is returned. < 0 indicates an error.
800  *                  - EBADF  Invalid directory handle
801  *                  - EINVAL Result buffer is too small or smbc_init
802  *                  not called.
803  *                  - ENOENT No such directory.
804  * @see             , smbc_dirent, smbc_readdir(), smbc_open()
805  *
806  * @todo Are errno values complete and correct?
807  *
808  * @todo Add example code so people know how to parse buffers.
809  */
810 int smbc_getdents(unsigned int dh, struct smbc_dirent *dirp, int count);
811
812
813 /**@ingroup directory
814  * Get a single directory entry.
815  *
816  * @param dh        Valid directory as returned by smbc_opendir()
817  *
818  * @return          A pointer to a smbc_dirent structure, or NULL if an
819  *                  error occurs or end-of-directory is reached:
820  *                  - EBADF Invalid directory handle
821  *                  - EINVAL smbc_init() failed or has not been called
822  *
823  * @see             smbc_dirent, smbc_getdents(), smbc_open()
824  */
825 struct smbc_dirent* smbc_readdir(unsigned int dh);
826
827
828 /**@ingroup directory
829  * Get the current directory offset.
830  *
831  * smbc_telldir() may be used in conjunction with smbc_readdir() and
832  * smbc_lseekdir().
833  *
834  * @param dh        Valid directory as returned by smbc_opendir()
835  *
836  * @return          The current location in the directory stream or -1
837  *                  if an error occur.  The current location is not
838  *                  an offset. Becuase of the implementation, it is a 
839  *                  handle that allows the library to find the entry
840  *                  later.
841  *                  - EBADF dh is not a valid directory handle
842  *                  - EINVAL smbc_init() failed or has not been called
843  *                  - ENOTDIR if dh is not a directory
844  *
845  * @see             smbc_readdir()
846  *
847  */
848 off_t smbc_telldir(int dh);
849
850
851 /**@ingroup directory
852  * lseek on directories.
853  *
854  * smbc_lseekdir() may be used in conjunction with smbc_readdir() and
855  * smbc_telldir(). (rewind by smbc_lseekdir(fd, NULL))
856  *
857  * @param fd        Valid directory as returned by smbc_opendir()
858  * 
859  * @param offset    The offset (as returned by smbc_telldir). Can be
860  *                  NULL, in which case we will rewind
861  *
862  * @return          0 on success, -1 on failure
863  *                  - EBADF dh is not a valid directory handle
864  *                  - ENOTDIR if dh is not a directory
865  *                  - EINVAL offset did not refer to a valid dirent or
866  *                    smbc_init not called.
867  *
868  * @see             smbc_telldir()
869  *
870  *
871  * @todo In what does the reture and errno values mean?
872  */
873 int smbc_lseekdir(int fd, off_t offset);
874
875 /**@ingroup directory
876  * Create a directory.
877  *
878  * @param durl      The url of the directory to create
879  *
880  * @param mode      Specifies  the  permissions to use. It is modified
881  *                  by the process's umask in the usual way: the 
882  *                  permissions of the created file are (mode & ~umask).
883  * 
884  * @return          0 on success, < 0 on error with errno set:
885  *                  - EEXIST directory url already exists
886  *                  - EACCES The parent directory does not allow write
887  *                  permission to the process, or one of the directories
888  *                  - ENOENT A directory component in pathname does not
889  *                  exist.
890  *                  - EINVAL NULL durl passed or smbc_init not called.
891  *                  - ENOMEM Insufficient memory was available.
892  *
893  * @see             smbc_rmdir()
894  *
895  */
896 int smbc_mkdir(const char *durl, mode_t mode);
897
898
899 /**@ingroup directory
900  * Remove a directory.
901  * 
902  * @param durl      The smb url of the directory to remove
903  *
904  * @return          0 on success, < 0 on error with errno set:
905  *                  - EACCES or EPERM Write access to the directory
906  *                  containing pathname was not allowed.
907  *                  - EINVAL durl is NULL or smbc_init not called.
908  *                  - ENOENT A directory component in pathname does not
909  *                  exist.
910  *                  - ENOTEMPTY directory contains entries.
911  *                  - ENOMEM Insufficient kernel memory was available.
912  *
913  * @see             smbc_mkdir(), smbc_unlink() 
914  *
915  * @todo Are errno values complete and correct?
916  */
917 int smbc_rmdir(const char *durl);
918
919
920 /**@ingroup attribute
921  * Get information about a file or directory.
922  *
923  * @param url       The smb url to get information for
924  *
925  * @param st        pointer to a buffer that will be filled with 
926  *                  standard Unix struct stat information.
927  *
928  * @return          0 on success, < 0 on error with errno set:
929  *                  - ENOENT A component of the path file_name does not
930  *                  exist.
931  *                  - EINVAL a NULL url was passed or smbc_init not called.
932  *                  - EACCES Permission denied.
933  *                  - ENOMEM Out of memory
934  *                  - ENOTDIR The target dir, url, is not a directory.
935  *
936  * @see             Unix stat()
937  *
938  */
939 int smbc_stat(const char *url, struct stat *st);
940
941
942 /**@ingroup attribute
943  * Get file information via an file descriptor.
944  * 
945  * @param fd        Open file handle from smbc_open() or smbc_creat()
946  *
947  * @param st        pointer to a buffer that will be filled with 
948  *                  standard Unix struct stat information.
949  * 
950  * @return          EBADF  filedes is bad.
951  *                  - EACCES Permission denied.
952  *                  - EBADF fd is not a valid file descriptor
953  *                  - EINVAL Problems occurred in the underlying routines
954  *                    or smbc_init not called.
955  *                  - ENOMEM Out of memory
956  *
957  * @see             smbc_stat(), Unix stat()
958  *
959  */
960 int smbc_fstat(int fd, struct stat *st);
961
962
963 /**@ingroup attribue
964  * Change the ownership of a file or directory.
965  *
966  * @param url       The smb url of the file or directory to change 
967  *                  ownership of.
968  *
969  * @param owner     I have no idea?
970  *
971  * @param group     I have not idea?
972  *
973  * @return          0 on success, < 0 on error with errno set:
974  *                  - EPERM  The effective UID does not match the owner
975  *                  of the file, and is not zero; or the owner or group
976  *                  were specified incorrectly.
977  *                  - ENOENT The file does not exist.
978  *                  - ENOMEM Insufficient was available.
979  *                  - ENOENT file or directory does not exist
980  *
981  * @todo Are we actually going to be able to implement this function
982  *
983  * @todo How do we abstract owner and group uid and gid?
984  *
985  */
986 int smbc_chown(const char *url, uid_t owner, gid_t group);
987
988
989 /**@ingroup attribute
990  * Change the permissions of a file.
991  *
992  * @param url       The smb url of the file or directory to change
993  *                  permissions of
994  * 
995  * @param mode      The permissions to set:
996  *                  - Put good explaination of permissions here!
997  *
998  * @return          0 on success, < 0 on error with errno set:
999  *                  - EPERM  The effective UID does not match the owner
1000  *                  of the file, and is not zero
1001  *                  - ENOENT The file does not exist.
1002  *                  - ENOMEM Insufficient was available.
1003  *                  - ENOENT file or directory does not exist
1004  *
1005  * @todo Actually implement this fuction?
1006  *
1007  * @todo Are errno values complete and correct?
1008  */
1009 int smbc_chmod(const char *url, mode_t mode);
1010
1011
1012 /**@ingroup print
1013  * Print a file given the name in fname. It would be a URL ...
1014  * 
1015  * @param fname     The URL of a file on a remote SMB server that the
1016  *                  caller wants printed
1017  *
1018  * @param printq    The URL of the print share to print the file to.
1019  *
1020  * @return          0 on success, < 0 on error with errno set:         
1021  *
1022  *                  - EINVAL fname or printq was NULL or smbc_init not
1023  *                    not called.
1024  *                  and errors returned by smbc_open
1025  *
1026  */                                     
1027 int smbc_print_file(const char *fname, const char *printq);
1028
1029 /**@ingroup print
1030  * Open a print file that can be written to by other calls. This simply
1031  * does an smbc_open call after checking if there is a file name on the
1032  * URI. If not, a temporary name is added ...
1033  *
1034  * @param fname     The URL of the print share to print to?
1035  *
1036  * @returns         A file handle for the print file if successful.
1037  *                  Returns -1 if an error ocurred and errno has the values
1038  *                  - EINVAL fname was NULL or smbc_init not called.
1039  *                  - all errors returned by smbc_open
1040  *
1041  */
1042 int smbc_open_print_job(const char *fname);
1043
1044 /**@ingroup print
1045  * List the print jobs on a print share, for the moment, pass a callback 
1046  *
1047  * @param purl      The url of the print share to list the jobs of
1048  * 
1049  * @param fn        Callback function the receives printjob info
1050  * 
1051  * @return          0 on success, < 0 on error with errno set: 
1052  *                  - EINVAL fname was NULL or smbc_init not called
1053  *                  - EACCES ???
1054  */
1055 int smbc_list_print_jobs(const char *purl, smbc_list_print_job_fn fn);
1056
1057 /**@ingroup print
1058  * Delete a print job 
1059  *
1060  * @param purl      Url of the print share
1061  *
1062  * @param id        The id of the job to delete
1063  *
1064  * @return          0 on success, < 0 on error with errno set: 
1065  *                  - EINVAL fname was NULL or smbc_init not called
1066  *
1067  * @todo    what errno values are possible here?
1068  */
1069 int smbc_unlink_print_job(const char *purl, int id);
1070
1071
1072 #endif /* SMBCLIENT_H_INCLUDED */