1 /*=====================================================================
2 Unix SMB/Netbios implementation.
4 SMB client library API definitions
5 Copyright (C) Andrew Tridgell 1998
6 Copyright (C) Richard Sharpe 2000
7 Copyright (C) John Terpsra 2000
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 2 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with this program; if not, write to the Free Software
21 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22 =====================================================================*/
24 #ifndef SMBCLIENT_H_INCLUDED
25 #define SMBCLIENT_H_INCLUDED
27 /*-------------------------------------------------------------------*/
28 /* The following are special comments to instruct DOXYGEN (automated
31 /** \defgroup structure Data Structures Type and Constants
32 * Data structures, types, and constants
34 /** \defgroup file File Functions
35 * Functions used to access individual file contents
37 /** \defgroup directory Directory Functions
38 * Functions used to access directory entries
40 /** \defgroup attribute Attributes Functions
41 * Functions used to view or change file and directory attributes
43 /** \defgroup print Print Functions
44 * Functions used to access printing functionality
46 /** \defgroup attribute Miscellaneous Functions
47 * Functions that don't fit in to other categories
49 /*-------------------------------------------------------------------*/
51 /* Make sure we have the following includes for now ... */
52 #include <sys/types.h>
56 #define SMBC_MAX_NAME 1023
57 #define SMBC_WORKGROUP 1
59 #define SMBC_FILE_SHARE 3
60 #define SMBC_PRINTER_SHARE 4
61 #define SMBC_COMMS_SHARE 5
62 #define SMBC_IPC_SHARE 6
67 #define SMBC_FILE_MODE (S_IFREG | 0444)
68 #define SMBC_DIR_MODE (S_IFDIR | 0555)
71 * Structure that represents a directory entry.
88 /** Length of this smbc_dirent in bytes
91 /** The length of the comment string in bytes (includes null
95 /** Points to the null terminated comment string
98 /** The length of the name string in bytes (includes null
102 /** Points to the null terminated name string
109 typedef unsigned short uint16;
111 /**@ingroup structure
112 * Structure that represents a print job.
114 * @todo Make sure the discriptions of structure members are correct.
116 struct print_job_info
118 /** numeric ID of the print job
122 /** represents print job priority (lower numbers mean higher priority?)
126 /** Size of the print job
130 /** Name of the user that owns the print job
134 /** Name of the print job
138 /** Time the print job was spooled?
145 /**@ingroup structure
146 * Authentication callback function type.
148 * Type for the the authentication function called by the library to
149 * obtain authentication credentals
151 * @param srv Server being authenticated to
153 * @param shr Share being authenticated to
155 * @param wg Pointer to buffer containing a "hint" for the
156 * workgroup to be authenticated. Should be filled
157 * with the correct workgroup if the hint is wrong.
159 * @param wglen The size of the workgroup buffer in bytes
161 * @param un Pointer to buffer containing a "hint" for the
162 * user name to be use for authentication. Should be
163 * filled with the correct workgroup if the hint is
166 * @param unlen The size of the username buffer in bytes
168 * @param pw Pointer to buffer containing to which password
171 * @param pwlen The size of the password buffer in bytes
174 typedef void (*smbc_get_auth_data_fn)(const char *srv,
178 char *pw, int pwlen);
181 /**@ingroup structure
182 * Print job info callback function type.
184 * @param i pointer to print job information structure
187 typedef void (*smbc_get_print_job_info)(struct print_job_info *i);
191 * Initialize the samba client library.
193 * Must be called before using any of the smbclient API function
195 * @param fn The function that will be called to obtaion
196 * authentication credentials.
198 * @param debug Allows caller to set the debug level. Can be
199 * changed in smb.conf file.
201 * @return 0 on success, < 0 on error with errno set:
202 * - ENOMEM Out of memory
204 * @todo Why do we need to pass in debug information?
206 int smbc_init(smbc_get_auth_data_fn fn, int debug);
210 * Open a file on an SMB server.
212 * @param furl The smb url of the file to be opened.
214 * @param flags Is one of O_RDONLY, O_WRONLY or O_RDWR which
215 * request opening the file read-only,write-only
216 * or read/write. flags may also be bitwise-or'd with
217 * one or more of the following:
218 * O_CREAT - If the file does not exist it will be
220 * O_EXCL - When used with O_CREAT, if the file
221 * already exists it is an error and the open will
223 * O_TRUNC - If the file already exists it will be
225 * O_APPEND The file is opened in append mode
227 * @param mode mode specifies the permissions to use if a new
228 * file is created. It is modified by the
229 * process's umask in the usual way: the permissions
230 * of the created file are (mode & ~umask)
232 * Not currently use, but there for future use
233 * when we figure this out.
235 * @return Valid file handle, < 0 on error with errno set:
236 * - ENOMEM Out of memory
237 * - EEXIST pathname already exists and O_CREAT and
239 * - EISDIR pathname refers to a directory and
240 * the access requested involved writing.
241 * - EACCES The requested access to the file is not
243 * - ENOENT A directory component in pathname does
245 * - EUCLEAN smbc_init() failed or has not been called
249 * @todo Mode needs to be better explained if there is any differences
250 * from standard open().
252 * @todo Are errno values complete and correct? They look OK.
255 int smbc_open(const char *furl, int flags, mode_t mode);
259 * Create a file on an SMB server.
261 * Same as calling smbc_open() with flags = O_CREAT|O_WRONLY|O_TRUNC
263 * @param furl The smb url of the file to be created
265 * @param mode mode specifies the permissions to use if a new
266 * file is created. It is modified by the
267 * process's umask in the usual way: the permissions
268 * of the created file are (mode & ~umask)
270 * @return Valid file handle, < 0 on error with errno set:
271 * - ENOMEM Out of memory
272 * - EEXIST pathname already exists and O_CREAT and
274 * - EISDIR pathname refers to a directory and
275 * the access requested involved writing.
276 * - EACCES The requested access to the file is not
278 * - ENOENT A directory component in pathname does
280 * - EUCLEAN smbc_init() failed or has not been called
283 * @todo Are errno values complete and correct?
285 int smbc_creat(const char *furl, mode_t mode);
289 * Read from a file using an opened file handle.
291 * @param fd Open file handle from smbc_open() or smbc_creat()
293 * @param buf Pointer to buffer to recieve read data
295 * @param bufsize Size of buf in bytes
297 * @return Number of bytes read, < 0 on error with errno set:
298 * - EISDIR fd refers to a directory
299 * - EBADF fd is not a valid file descriptor or
300 * is not open for reading.
301 * - EINVAL fd is attached to an object which is
302 * unsuitable for reading.
303 * - EUCLEAN smbc_init() failed or has not been called
305 * @see smbc_open(), smbc_write()
307 * @todo Are errno values complete and correct?
309 ssize_t smbc_read(int fd, void *buf, size_t bufsize);
313 * Write to a file using an opened file handle.
315 * @param fd Open file handle from smbc_open() or smbc_creat()
317 * @param buf Pointer to buffer to recieve read data
319 * @param bufsize Size of buf in bytes
321 * @return Number of bytes written, < 0 on error with errno set:
322 * - EISDIR fd refers to a directory.
323 * - EBADF fd is not a valid file descriptor or
324 * is not open for reading.
325 * - EINVAL fd is attached to an object which is
326 * unsuitable for reading.
327 * - EUCLEAN smbc_init() failed or has not been called
328 * @see smbc_open(), smbc_read()
330 * @todo Are errno values complete and correct?
332 ssize_t smbc_write(int fd, void *buf, size_t bufsize);
336 * Seek to a specific location in a file.
338 * @param fd Open file handle from smbc_open() or smbc_creat()
340 * @param offset Offset in bytes from whence
342 * @param whence A location in the file:
343 * - SEEK_SET The offset is set to offset bytes from
344 * the beginning of the file
345 * - SEEK_CUR The offset is set to current location
347 * - SEEK_END The offset is set to the size of the
348 * file plus offset bytes.
350 * @return Upon successful completion, lseek returns the
351 * resulting offset location as measured in bytes
352 * from the beginning of the file. Otherwise, a value
353 * of (off_t)-1 is returned and errno is set to
354 * indicate the error:
355 * - EBADF Fildes is not an open file descriptor.
356 * - EINVAL Whence is not a proper value.
357 * - EUCLEAN smbc_init() failed or has not been called
359 * @todo Are all the whence values really supported?
361 * @todo Are errno values complete and correct?
363 off_t smbc_lseek(int fd, off_t offset, int whence);
367 * Close an open file handle.
369 * @param fd The file handle to close
371 * @return 0 on success, < 0 on error with errno set:
372 * - EBADF fd isn't a valid open file descriptor
373 * - EUCLEAN smbc_init() failed or has not been called
375 * @see smbc_open(), smbc_creat()
377 int smbc_close(int fd);
380 /**@ingroup directory
381 * Unlink (delete) a file or directory.
383 * @param furl The smb url of the file to delete
385 * @return 0 on success, < 0 on error with errno set:
386 * - EACCES or EPERM Write access to the directory
387 * containing pathname is not allowed or one
388 * of the directories in pathname did not allow
389 * search (execute) permission
390 * - ENOENT A directory component in pathname does
392 * - ENOMEM Insufficient kernel memory was availabl
393 * - EUCLEAN smbc_init() failed or has not been called
397 * @todo Are errno values complete and correct?
399 int smbc_unlink(const char *furl);
402 /**@ingroup directory
403 * Rename or move a file or directory.
405 * @param ourl The original smb url (source url) of file or
406 * directory to be moved
408 * @param nurl The new smb url (destination url) of the file
409 * or directory after the move. Currently nurl must
410 * be on the same share as ourl.
412 * @return 0 on success, < 0 on error with errno set:
413 * - EISDIR nurl is an existing directory, but ourl is
415 * - EEXIST nurl is a non-empty directory,
416 * i.e., contains entries other than "." and ".."
417 * - EINVAL The new url contained a path prefix
418 * of the old, or, more generally, an attempt was
419 * made to make a directory a subdirectory of itself.
420 * - ENOTDIR A component used as a directory in ourl
421 * or nurl path is not, in fact, a directory. Or,
422 * ourl is a directory, and newpath exists but is not
424 * - EACCES or EPERM Write access to the directory
425 * containing ourl or nurl is not allowed for the
426 * process's effective uid, or one of the
427 * directories in ourl or nurl did not allow search
428 * (execute) permission, or ourl was a directory
429 * and did not allow write permission.
430 * - ENOENT A directory component in ourl or nurl
432 * - ENOMEM Insufficient kernel memory was available.
433 * - EUCLEAN smbc_init() failed or has not been called
435 * @todo Are errno values complete and correct?
437 * @todo Are we going to support copying when urls are not on the same
441 int smbc_rename(const char *ourl, const char *nurl);
444 /**@ingroup directory
445 * Open a directory used to obtain directory entries.
447 * @param durl The smb url of the directory to open
449 * @return Valid directory handle. < 0 on error with errno set:
450 * - EACCES Permission denied.
451 * - ENOENT durl does not exist, or name is an
452 * - ENOMEM Insufficient memory to complete the
454 * - ENOTDIR name is not a directory.
455 * - EUCLEAN smbc_init() failed or has not been called
457 * @see smbc_getdents(), smbc_readdir(), smbc_closedir()
459 * @todo Are errno values complete and correct?
461 int smbc_opendir(const char *durl);
464 /**@ingroup directory
465 * Close a directory handle opened by smbc_opendir().
467 * @param dh Directory handle to close
469 * @return 0 on success, < 0 on error with errno set:
470 * - EBADF dh is an invalid directory handle
472 * @see smbc_opendir()
474 int smbc_closedir(int dh);
477 /**@ingroup directory
478 * Get multiple directory entries.
480 * smbc_getdents() reads several dirent structures from the an open
481 * directory handle into a specified memory area.
483 * @param dh Valid directory as returned by smbc_opendir()
485 * @param dirp pointer to buffer that will receive the directory
488 * @param count The size of the dirp buffer in bytes
490 * @returns - EBADF Invalid directory handle
491 * - EINVAL Result buffer is too small
492 * - ENOENT No such directory.
493 * - EUCLEAN smbc_init() failed or has not been called
494 * @see , smbc_dirent, smbc_readdir(), smbc_open()
496 * @todo Are errno values complete and correct?
498 * @todo Add example code so people know how to parse buffers.
500 int smbc_getdents(unsigned int dh, struct smbc_dirent *dirp, int count);
503 /**@ingroup directory
504 * Get a single directory entry.
506 * @param dh Valid directory as returned by smbc_opendir()
508 * @return A pointer to a smbc_dirent structure, or NULL if an
509 * error occurs or end-of-directory is reached:
510 * - EBADF Invalid directory handle
511 * - EUCLEAN smbc_init() failed or has not been called
513 * @see smbc_dirent, smbc_getdents(), smbc_open()
515 struct smbc_dirent* smbc_readdir(unsigned int dh);
518 /**@ingroup directory
519 * Get the current directory offset.
521 * smbc_telldir() may be used in conjunction with smbc_readdir() and
524 * @param dh Valid directory as returned by smbc_opendir()
526 * @return The current location in the directory stream or -1
528 * - EBADF dh is not a valid directory handle
530 * @see smbc_readdir()
532 * @todo What in the is the offset related to bytes or directory entry
535 off_t smbc_telldir(int dh);
538 /**@ingroup directory
539 * lseek on directories.
541 * smbc_lseekdir() may be used in conjunction with smbc_readdir() and
542 * smbc_telldir(). (rewind by smbc_lseekdir(fd, 0, SEEK_SET))
544 * @param dh Valid directory as returned by smbc_opendir()
546 * @param offset The offset (as returned by smbc_telldir) from
549 * @param whence A location in the directory stream:
550 * - SEEK_SET this is the only one that makes sense...
554 * @return I have no idea?
556 * @see smbc_telldir()
558 * @todo What in the is the offset related to? Bytes or directory
561 * @todo In what do SEEK_SET and friends really mean?
563 * @todo In what does the reture and errno values mean?
565 int smbc_lseekdir(int dh, off_t offset, int whence);
568 /**@ingroup directory
569 * Create a directory.
571 * @param durl The url of the directory to create
573 * @param mode Specifies the permissions to use. It is modified
574 * by the process's umask in the usual way: the
575 * permissions of the created file are (mode & ~umask).
577 * @return 0 on success, < 0 on error with errno set:
578 * - EEXIST directory url already exists
579 * - EACCES The parent directory does not allow write
580 * permission to the process, or one of the directories
581 * - ENOENT A directory component in pathname does not
583 * - ENOMEM Insufficient memory was available.
584 * - EUCLEAN smbc_init() failed or has not been called
588 * @todo Are errno values complete and correct?
590 int smbc_mkdir(const char *durl, mode_t mode);
593 /**@ingroup directory
594 * Remove a directory.
596 * @param durl The smb url of the directory to remove
598 * @return 0 on success, < 0 on error with errno set:
599 * - EACCES or EPERM Write access to the directory
600 * containing pathname was not allowed.
601 * - ENOENT A directory component in pathname does not
603 * - ENOTEMPTY directory contains entries.
604 * - ENOMEM Insufficient kernel memory was available.
605 * - EUCLEAN smbc_init() failed or has not been called
607 * @see smbc_mkdir(), smbc_unlink()
609 * @todo Are errno values complete and correct?
611 int smbc_rmdir(const char *durl);
614 /**@ingroup attribute
615 * Get information about a file or directory.
617 * @param url The smb url to get information for
619 * @param st pointer to a buffer that will be filled with
620 * standard Unix struct stat information.
622 * @return 0 on success, < 0 on error with errno set:
623 * - ENOENT A component of the path file_name does not
625 * - EACCES Permission denied.
626 * - ENOMEM Out of memory
627 * - EUCLEAN smbc_init() failed or has not been called
631 * @todo Are errno values complete and correct?
633 int smbc_stat(const char *url, struct stat *st);
636 /**@ingroup attribute
637 * Get file information via an file descriptor.
639 * @param fd Open file handle from smbc_open() or smbc_creat()
641 * @param st pointer to a buffer that will be filled with
642 * standard Unix struct stat information.
644 * @return EBADF filedes is bad.
645 * -EACCES Permission denied.
646 * -ENOMEM Out of memory
647 * - EUCLEAN smbc_init() failed or has not been called
649 * @see smbc_stat(), Unix stat()
651 int smbc_fstat(int fd, struct stat *st);
655 * Change the ownership of a file or directory.
657 * @param url The smb url of the file or directory to change
660 * @param owner I have no idea?
662 * @param group I have not idea?
664 * @return 0 on success, < 0 on error with errno set:
665 * - EPERM The effective UID does not match the owner
666 * of the file, and is not zero; or the owner or group
667 * were specified incorrectly.
668 * - ENOENT The file does not exist.
669 * - ENOMEM Insufficient was available.
670 * - ENOENT file or directory does not exist
672 * @todo Are we actually going to be able to implement this function
674 * @todo How do we abstract owner and group uid and gid?
677 int smbc_chown(const char *url, uid_t owner, gid_t group);
680 /**@ingroup attribute
681 * Change the permissions of a file.
683 * @param url The smb url of the file or directory to change
686 * @param mode The permissions to set:
687 * - Put good explaination of permissions here!
689 * @return 0 on success, < 0 on error with errno set:
690 * - EPERM The effective UID does not match the owner
691 * of the file, and is not zero
692 * - ENOENT The file does not exist.
693 * - ENOMEM Insufficient was available.
694 * - ENOENT file or directory does not exist
696 * @todo Actually implement this fuction?
698 * @todo Are errno values complete and correct?
700 int smbc_chmod(const char *url, mode_t mode);
704 * Print a file given the name in fname. It would be a URL ...
706 * @param fname I do not know what this is it the url of the file
709 * @param printq I do not know what this is, is it the url of the
710 * printer to print to?
712 * @return 0 on success, < 0 on error with errno set:
714 * @todo I have no idea what this does. What is fname? What is
717 * @todo What errno values are possible here
719 int smbc_print_file(const char *fname, const char *printq);
722 * Open a print file that can be written to by other calls. This simply
723 * does an smbc_open call after checking if there is a file name on the
724 * URI. If not, a temporary name is added ...
726 * @param fname Is this the url of a print share?
728 * @returns A file handle right?
730 * @todo What errno values are possible here
732 * @todo What is fname is it the url of a print share?
734 int smbc_open_print_job(const char *fname);
737 * List the print jobs on a print share, for the moment, pass a callback
739 * @param purl The url of the print share to list the jobs of
741 * @param fn Callback function the receives printjob info
743 * @return 0 on success, < 0 on error with errno set:
745 * @todo what errno values are possible here?
748 int smbc_list_print_jobs(const char *purl, smbc_get_print_job_info fn);
753 * @param purl Url of the print share
755 * @param id The id of the job to delete
757 * @return 0 on success, < 0 on error with errno set:
759 * @todo what errno values are possible here?
761 int smbc_unlink_print_job(const char *purl, int id);
764 #endif /* SMBCLIENT_H_INCLUDED */