2 Unix SMB/CIFS implementation.
3 SMB client library implementation (Old interface compatibility)
4 Copyright (C) Andrew Tridgell 1998
5 Copyright (C) Richard Sharpe 2000
6 Copyright (C) John Terpstra 2000
7 Copyright (C) Tom Jansen (Ninja ISD) 2002
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.
28 * Define this to get the real SMBCFILE and SMBCSRV structures
30 #define _SMBC_INTERNAL
31 #include "../include/libsmbclient.h"
33 struct smbc_compat_fdlist {
36 struct smbc_compat_fdlist *next, *prev;
39 static SMBCCTX * statcont = NULL;
40 static int smbc_compat_initialized = 0;
41 static int smbc_currentfd = 10000;
42 static struct smbc_compat_fdlist * smbc_compat_fdlist = NULL;
45 /* Find an fd and return the SMBCFILE * or NULL on failure */
46 static SMBCFILE * find_fd(int fd)
48 struct smbc_compat_fdlist * f = smbc_compat_fdlist;
57 /* Add an fd, returns 0 on success, -1 on error with errno set */
58 static int add_fd(SMBCFILE * file)
60 struct smbc_compat_fdlist * f = malloc(sizeof(struct smbc_compat_fdlist));
66 f->fd = smbc_currentfd++;
69 DLIST_ADD(smbc_compat_fdlist, f);
76 /* Delete an fd, returns 0 on success */
77 static int del_fd(int fd)
79 struct smbc_compat_fdlist * f = smbc_compat_fdlist;
87 DLIST_REMOVE(smbc_compat_fdlist, f);
96 int smbc_init(smbc_get_auth_data_fn fn, int debug)
98 if (!smbc_compat_initialized) {
99 statcont = smbc_new_context();
103 statcont->debug = debug;
104 statcont->callbacks.auth_fn = fn;
106 if (!smbc_init_context(statcont)) {
107 smbc_free_context(statcont, False);
111 smbc_compat_initialized = 1;
119 int smbc_open(const char *furl, int flags, mode_t mode)
124 file = statcont->open(statcont, furl, flags, mode);
130 statcont->close(statcont, file);
135 int smbc_creat(const char *furl, mode_t mode)
140 file = statcont->creat(statcont, furl, mode);
146 /* Hmm... should we delete the file too ? I guess we could try */
147 statcont->close(statcont, file);
148 statcont->unlink(statcont, furl);
154 ssize_t smbc_read(int fd, void *buf, size_t bufsize)
156 SMBCFILE * file = find_fd(fd);
157 return statcont->read(statcont, file, buf, bufsize);
160 ssize_t smbc_write(int fd, void *buf, size_t bufsize)
162 SMBCFILE * file = find_fd(fd);
163 return statcont->write(statcont, file, buf, bufsize);
166 off_t smbc_lseek(int fd, off_t offset, int whence)
168 SMBCFILE * file = find_fd(fd);
169 return statcont->lseek(statcont, file, offset, whence);
172 int smbc_close(int fd)
174 SMBCFILE * file = find_fd(fd);
176 return statcont->close(statcont, file);
179 int smbc_unlink(const char *fname)
181 return statcont->unlink(statcont, fname);
184 int smbc_rename(const char *ourl, const char *nurl)
186 return statcont->rename(statcont, ourl, statcont, nurl);
189 int smbc_opendir(const char *durl)
194 file = statcont->opendir(statcont, durl);
200 statcont->closedir(statcont, file);
205 int smbc_closedir(int dh)
207 SMBCFILE * file = find_fd(dh);
209 return statcont->closedir(statcont, file);
212 int smbc_getdents(unsigned int dh, struct smbc_dirent *dirp, int count)
214 SMBCFILE * file = find_fd(dh);
215 return statcont->getdents(statcont, file,dirp, count);
218 struct smbc_dirent* smbc_readdir(unsigned int dh)
220 SMBCFILE * file = find_fd(dh);
221 return statcont->readdir(statcont, file);
224 off_t smbc_telldir(int dh)
226 SMBCFILE * file = find_fd(dh);
227 return statcont->telldir(statcont, file);
230 int smbc_lseekdir(int fd, off_t offset)
232 SMBCFILE * file = find_fd(fd);
233 return statcont->lseekdir(statcont, file, offset);
236 int smbc_mkdir(const char *durl, mode_t mode)
238 return statcont->mkdir(statcont, durl, mode);
241 int smbc_rmdir(const char *durl)
243 return statcont->rmdir(statcont, durl);
246 int smbc_stat(const char *url, struct stat *st)
248 return statcont->stat(statcont, url, st);
251 int smbc_fstat(int fd, struct stat *st)
253 SMBCFILE * file = find_fd(fd);
254 return statcont->fstat(statcont, file, st);
257 int smbc_chmod(const char *url, mode_t mode)
259 /* NOT IMPLEMENTED IN LIBSMBCLIENT YET */
263 int smbc_print_file(const char *fname, const char *printq)
265 return statcont->print_file(statcont, fname, statcont, printq);
268 int smbc_open_print_job(const char *fname)
270 SMBCFILE * file = statcont->open_print_job(statcont, fname);
271 if (!file) return -1;
275 int smbc_list_print_jobs(const char *purl, smbc_get_print_job_info fn)
277 return statcont->list_print_jobs(statcont, purl, fn);
280 int smbc_unlink_print_job(const char *purl, int id)
282 return statcont->unlink_print_job(statcont, purl, id);