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.
27 #include "../include/libsmb_internal.h"
29 struct smbc_compat_fdlist
{
32 struct smbc_compat_fdlist
*next
, *prev
;
35 static SMBCCTX
* statcont
= NULL
;
36 static int smbc_compat_initialized
= 0;
37 static int smbc_currentfd
= 10000;
38 static struct smbc_compat_fdlist
* smbc_compat_fdlist
= NULL
;
41 /* Find an fd and return the SMBCFILE * or NULL on failure */
42 static SMBCFILE
* find_fd(int fd
)
44 struct smbc_compat_fdlist
* f
= smbc_compat_fdlist
;
53 /* Add an fd, returns 0 on success, -1 on error with errno set */
54 static int add_fd(SMBCFILE
* file
)
56 struct smbc_compat_fdlist
* f
= malloc(sizeof(struct smbc_compat_fdlist
));
62 f
->fd
= smbc_currentfd
++;
65 DLIST_ADD(smbc_compat_fdlist
, f
);
72 /* Delete an fd, returns 0 on success */
73 static int del_fd(int fd
)
75 struct smbc_compat_fdlist
* f
= smbc_compat_fdlist
;
83 DLIST_REMOVE(smbc_compat_fdlist
, f
);
92 int smbc_init(smbc_get_auth_data_fn fn
, int debug
)
94 if (!smbc_compat_initialized
) {
95 statcont
= smbc_new_context();
99 statcont
->debug
= debug
;
100 statcont
->callbacks
.auth_fn
= fn
;
102 if (!smbc_init_context(statcont
)) {
103 smbc_free_context(statcont
, False
);
107 smbc_compat_initialized
= 1;
115 int smbc_open(const char *furl
, int flags
, mode_t mode
)
120 file
= statcont
->open(statcont
, furl
, flags
, mode
);
126 statcont
->close(statcont
, file
);
131 int smbc_creat(const char *furl
, mode_t mode
)
136 file
= statcont
->creat(statcont
, furl
, mode
);
142 /* Hmm... should we delete the file too ? I guess we could try */
143 statcont
->close(statcont
, file
);
144 statcont
->unlink(statcont
, furl
);
150 ssize_t
smbc_read(int fd
, void *buf
, size_t bufsize
)
152 SMBCFILE
* file
= find_fd(fd
);
153 return statcont
->read(statcont
, file
, buf
, bufsize
);
156 ssize_t
smbc_write(int fd
, void *buf
, size_t bufsize
)
158 SMBCFILE
* file
= find_fd(fd
);
159 return statcont
->write(statcont
, file
, buf
, bufsize
);
162 off_t
smbc_lseek(int fd
, off_t offset
, int whence
)
164 SMBCFILE
* file
= find_fd(fd
);
165 return statcont
->lseek(statcont
, file
, offset
, whence
);
168 int smbc_close(int fd
)
170 SMBCFILE
* file
= find_fd(fd
);
172 return statcont
->close(statcont
, file
);
175 int smbc_unlink(const char *fname
)
177 return statcont
->unlink(statcont
, fname
);
180 int smbc_rename(const char *ourl
, const char *nurl
)
182 return statcont
->rename(statcont
, ourl
, statcont
, nurl
);
185 int smbc_opendir(const char *durl
)
190 file
= statcont
->opendir(statcont
, durl
);
196 statcont
->closedir(statcont
, file
);
201 int smbc_closedir(int dh
)
203 SMBCFILE
* file
= find_fd(dh
);
205 return statcont
->closedir(statcont
, file
);
208 int smbc_getdents(unsigned int dh
, struct smbc_dirent
*dirp
, int count
)
210 SMBCFILE
* file
= find_fd(dh
);
211 return statcont
->getdents(statcont
, file
,dirp
, count
);
214 struct smbc_dirent
* smbc_readdir(unsigned int dh
)
216 SMBCFILE
* file
= find_fd(dh
);
217 return statcont
->readdir(statcont
, file
);
220 off_t
smbc_telldir(int dh
)
222 SMBCFILE
* file
= find_fd(dh
);
223 return statcont
->telldir(statcont
, file
);
226 int smbc_lseekdir(int fd
, off_t offset
)
228 SMBCFILE
* file
= find_fd(fd
);
229 return statcont
->lseekdir(statcont
, file
, offset
);
232 int smbc_mkdir(const char *durl
, mode_t mode
)
234 return statcont
->mkdir(statcont
, durl
, mode
);
237 int smbc_rmdir(const char *durl
)
239 return statcont
->rmdir(statcont
, durl
);
242 int smbc_stat(const char *url
, struct stat
*st
)
244 return statcont
->stat(statcont
, url
, st
);
247 int smbc_fstat(int fd
, struct stat
*st
)
249 SMBCFILE
* file
= find_fd(fd
);
250 return statcont
->fstat(statcont
, file
, st
);
253 int smbc_chmod(const char *url
, mode_t mode
)
255 /* NOT IMPLEMENTED IN LIBSMBCLIENT YET */
259 int smbc_print_file(const char *fname
, const char *printq
)
261 return statcont
->print_file(statcont
, fname
, statcont
, printq
);
264 int smbc_open_print_job(const char *fname
)
266 SMBCFILE
* file
= statcont
->open_print_job(statcont
, fname
);
267 if (!file
) return -1;
271 int smbc_list_print_jobs(const char *purl
, smbc_list_print_job_fn fn
)
273 return statcont
->list_print_jobs(statcont
, purl
, fn
);
276 int smbc_unlink_print_job(const char *purl
, int id
)
278 return statcont
->unlink_print_job(statcont
, purl
, id
);