1
0
mirror of https://github.com/samba-team/samba.git synced 2025-01-11 05:18:09 +03:00

s3: Fix some nonempty blank lines

This commit is contained in:
Volker Lendecke 2009-11-21 22:52:12 +01:00
parent 384f303c2c
commit e28545e854
9 changed files with 468 additions and 568 deletions

View File

@ -5,17 +5,17 @@
Copyright (C) Richard Sharpe 2000 Copyright (C) Richard Sharpe 2000
Copyright (C) John Terpstra 2000 Copyright (C) John Terpstra 2000
Copyright (C) Tom Jansen (Ninja ISD) 2002 Copyright (C) Tom Jansen (Ninja ISD) 2002
This program is free software; you can redistribute it and/or modify This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or the Free Software Foundation; either version 3 of the License, or
(at your option) any later version. (at your option) any later version.
This program is distributed in the hope that it will be useful, This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details. GNU General Public License for more details.
You should have received a copy of the GNU General Public License You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
@ -34,7 +34,7 @@ struct smbc_server_cache {
char *workgroup; char *workgroup;
char *username; char *username;
SMBCSRV *server; SMBCSRV *server;
struct smbc_server_cache *next, *prev; struct smbc_server_cache *next, *prev;
}; };
@ -53,51 +53,51 @@ SMBC_add_cached_server(SMBCCTX * context,
const char * username) const char * username)
{ {
struct smbc_server_cache * srvcache = NULL; struct smbc_server_cache * srvcache = NULL;
if (!(srvcache = SMB_MALLOC_P(struct smbc_server_cache))) { if (!(srvcache = SMB_MALLOC_P(struct smbc_server_cache))) {
errno = ENOMEM; errno = ENOMEM;
DEBUG(3, ("Not enough space for server cache allocation\n")); DEBUG(3, ("Not enough space for server cache allocation\n"));
return 1; return 1;
} }
ZERO_STRUCTP(srvcache); ZERO_STRUCTP(srvcache);
srvcache->server = newsrv; srvcache->server = newsrv;
srvcache->server_name = SMB_STRDUP(server); srvcache->server_name = SMB_STRDUP(server);
if (!srvcache->server_name) { if (!srvcache->server_name) {
errno = ENOMEM; errno = ENOMEM;
goto failed; goto failed;
} }
srvcache->share_name = SMB_STRDUP(share); srvcache->share_name = SMB_STRDUP(share);
if (!srvcache->share_name) { if (!srvcache->share_name) {
errno = ENOMEM; errno = ENOMEM;
goto failed; goto failed;
} }
srvcache->workgroup = SMB_STRDUP(workgroup); srvcache->workgroup = SMB_STRDUP(workgroup);
if (!srvcache->workgroup) { if (!srvcache->workgroup) {
errno = ENOMEM; errno = ENOMEM;
goto failed; goto failed;
} }
srvcache->username = SMB_STRDUP(username); srvcache->username = SMB_STRDUP(username);
if (!srvcache->username) { if (!srvcache->username) {
errno = ENOMEM; errno = ENOMEM;
goto failed; goto failed;
} }
DLIST_ADD(context->internal->server_cache, srvcache); DLIST_ADD(context->internal->server_cache, srvcache);
return 0; return 0;
failed: failed:
SAFE_FREE(srvcache->server_name); SAFE_FREE(srvcache->server_name);
SAFE_FREE(srvcache->share_name); SAFE_FREE(srvcache->share_name);
SAFE_FREE(srvcache->workgroup); SAFE_FREE(srvcache->workgroup);
SAFE_FREE(srvcache->username); SAFE_FREE(srvcache->username);
SAFE_FREE(srvcache); SAFE_FREE(srvcache);
return 1; return 1;
} }
@ -116,19 +116,19 @@ SMBC_get_cached_server(SMBCCTX * context,
const char * user) const char * user)
{ {
struct smbc_server_cache * srv = NULL; struct smbc_server_cache * srv = NULL;
/* Search the cache lines */ /* Search the cache lines */
for (srv = context->internal->server_cache; srv; srv = srv->next) { for (srv = context->internal->server_cache; srv; srv = srv->next) {
if (strcmp(server,srv->server_name) == 0 && if (strcmp(server,srv->server_name) == 0 &&
strcmp(workgroup,srv->workgroup) == 0 && strcmp(workgroup,srv->workgroup) == 0 &&
strcmp(user, srv->username) == 0) { strcmp(user, srv->username) == 0) {
/* If the share name matches, we're cool */ /* If the share name matches, we're cool */
if (strcmp(share, srv->share_name) == 0) { if (strcmp(share, srv->share_name) == 0) {
return srv->server; return srv->server;
} }
/* /*
* We only return an empty share name or the attribute * We only return an empty share name or the attribute
* server on an exact match (which would have been * server on an exact match (which would have been
@ -136,7 +136,7 @@ SMBC_get_cached_server(SMBCCTX * context,
*/ */
if (*share == '\0' || strcmp(share, "*IPC$") == 0) if (*share == '\0' || strcmp(share, "*IPC$") == 0)
continue; continue;
/* /*
* Never return an empty share name or the attribute * Never return an empty share name or the attribute
* server if it wasn't what was requested. * server if it wasn't what was requested.
@ -144,7 +144,7 @@ SMBC_get_cached_server(SMBCCTX * context,
if (*srv->share_name == '\0' || if (*srv->share_name == '\0' ||
strcmp(srv->share_name, "*IPC$") == 0) strcmp(srv->share_name, "*IPC$") == 0)
continue; continue;
/* /*
* If we're only allowing one share per server, then * If we're only allowing one share per server, then
* a connection to the server (other than the * a connection to the server (other than the
@ -163,7 +163,7 @@ SMBC_get_cached_server(SMBCCTX * context,
smbc_getFunctionRemoveCachedServer(context)(context, srv->server); smbc_getFunctionRemoveCachedServer(context)(context, srv->server);
continue; continue;
} }
/* /*
* Save the new share name. We've * Save the new share name. We've
* disconnected from the old share, and are * disconnected from the old share, and are
@ -178,13 +178,12 @@ SMBC_get_cached_server(SMBCCTX * context,
smbc_getFunctionRemoveCachedServer(context)(context, srv->server); smbc_getFunctionRemoveCachedServer(context)(context, srv->server);
continue; continue;
} }
return srv->server; return srv->server;
} }
} }
} }
return NULL; return NULL;
} }
@ -199,10 +198,10 @@ SMBC_remove_cached_server(SMBCCTX * context,
SMBCSRV * server) SMBCSRV * server)
{ {
struct smbc_server_cache * srv = NULL; struct smbc_server_cache * srv = NULL;
for (srv = context->internal->server_cache; srv; srv = srv->next) { for (srv = context->internal->server_cache; srv; srv = srv->next) {
if (server == srv->server) { if (server == srv->server) {
/* remove this sucker */ /* remove this sucker */
DLIST_REMOVE(context->internal->server_cache, srv); DLIST_REMOVE(context->internal->server_cache, srv);
SAFE_FREE(srv->server_name); SAFE_FREE(srv->server_name);
@ -228,13 +227,13 @@ SMBC_purge_cached_servers(SMBCCTX * context)
struct smbc_server_cache * srv; struct smbc_server_cache * srv;
struct smbc_server_cache * next; struct smbc_server_cache * next;
int could_not_purge_all = 0; int could_not_purge_all = 0;
for (srv = context->internal->server_cache, for (srv = context->internal->server_cache,
next = (srv ? srv->next :NULL); next = (srv ? srv->next :NULL);
srv; srv;
srv = next, srv = next,
next = (srv ? srv->next : NULL)) { next = (srv ? srv->next : NULL)) {
if (SMBC_remove_unused_server(context, srv->server)) { if (SMBC_remove_unused_server(context, srv->server)) {
/* could not be removed */ /* could not be removed */
could_not_purge_all = 1; could_not_purge_all = 1;

View File

@ -6,17 +6,17 @@
Copyright (C) John Terpstra 2000 Copyright (C) John Terpstra 2000
Copyright (C) Tom Jansen (Ninja ISD) 2002 Copyright (C) Tom Jansen (Ninja ISD) 2002
Copyright (C) Derrell Lipman 2003, 2008 Copyright (C) Derrell Lipman 2003, 2008
This program is free software; you can redistribute it and/or modify This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or the Free Software Foundation; either version 3 of the License, or
(at your option) any later version. (at your option) any later version.
This program is distributed in the hope that it will be useful, This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details. GNU General Public License for more details.
You should have received a copy of the GNU General Public License You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
@ -55,11 +55,10 @@ static int
add_fd(SMBCFILE * file) add_fd(SMBCFILE * file)
{ {
struct smbc_compat_fdlist * f = smbc_compat_fd_avail; struct smbc_compat_fdlist * f = smbc_compat_fd_avail;
if (f) { if (f) {
/* We found one that's available */ /* We found one that's available */
DLIST_REMOVE(smbc_compat_fd_avail, f); DLIST_REMOVE(smbc_compat_fd_avail, f);
} else { } else {
/* /*
* None were available, so allocate one. Keep the number of * None were available, so allocate one. Keep the number of
@ -72,19 +71,19 @@ add_fd(SMBCFILE * file)
errno = EMFILE; errno = EMFILE;
return -1; return -1;
} }
f = SMB_MALLOC_P(struct smbc_compat_fdlist); f = SMB_MALLOC_P(struct smbc_compat_fdlist);
if (!f) { if (!f) {
errno = ENOMEM; errno = ENOMEM;
return -1; return -1;
} }
f->fd = SMBC_BASE_FD + smbc_compat_nextfd++; f->fd = SMBC_BASE_FD + smbc_compat_nextfd++;
} }
f->file = file; f->file = file;
DLIST_ADD(smbc_compat_fd_in_use, f); DLIST_ADD(smbc_compat_fd_in_use, f);
return f->fd; return f->fd;
} }
@ -95,13 +94,13 @@ static int
del_fd(int fd) del_fd(int fd)
{ {
struct smbc_compat_fdlist * f = smbc_compat_fd_in_use; struct smbc_compat_fdlist * f = smbc_compat_fd_in_use;
while (f) { while (f) {
if (f->fd == fd) if (f->fd == fd)
break; break;
f = f->next; f = f->next;
} }
if (f) { if (f) {
/* found */ /* found */
DLIST_REMOVE(smbc_compat_fd_in_use, f); DLIST_REMOVE(smbc_compat_fd_in_use, f);
@ -122,17 +121,17 @@ smbc_init(smbc_get_auth_data_fn fn,
statcont = smbc_new_context(); statcont = smbc_new_context();
if (!statcont) if (!statcont)
return -1; return -1;
smbc_setDebug(statcont, debug); smbc_setDebug(statcont, debug);
smbc_setFunctionAuthData(statcont, fn); smbc_setFunctionAuthData(statcont, fn);
if (!smbc_init_context(statcont)) { if (!smbc_init_context(statcont)) {
smbc_free_context(statcont, False); smbc_free_context(statcont, False);
return -1; return -1;
} }
smbc_compat_initialized = 1; smbc_compat_initialized = 1;
return 0; return 0;
} }
return 0; return 0;
@ -143,15 +142,15 @@ SMBCCTX *
smbc_set_context(SMBCCTX * context) smbc_set_context(SMBCCTX * context)
{ {
SMBCCTX *old_context = statcont; SMBCCTX *old_context = statcont;
if (context) { if (context) {
/* Save provided context. It must have been initialized! */ /* Save provided context. It must have been initialized! */
statcont = context; statcont = context;
/* You'd better know what you're doing. We won't help you. */ /* You'd better know what you're doing. We won't help you. */
smbc_compat_initialized = 1; smbc_compat_initialized = 1;
} }
return old_context; return old_context;
} }
@ -163,11 +162,11 @@ smbc_open(const char *furl,
{ {
SMBCFILE * file; SMBCFILE * file;
int fd; int fd;
file = smbc_getFunctionOpen(statcont)(statcont, furl, flags, mode); file = smbc_getFunctionOpen(statcont)(statcont, furl, flags, mode);
if (!file) if (!file)
return -1; return -1;
fd = add_fd(file); fd = add_fd(file);
if (fd == -1) if (fd == -1)
smbc_getFunctionClose(statcont)(statcont, file); smbc_getFunctionClose(statcont)(statcont, file);
@ -181,11 +180,11 @@ smbc_creat(const char *furl,
{ {
SMBCFILE * file; SMBCFILE * file;
int fd; int fd;
file = smbc_getFunctionCreat(statcont)(statcont, furl, mode); file = smbc_getFunctionCreat(statcont)(statcont, furl, mode);
if (!file) if (!file)
return -1; return -1;
fd = add_fd(file); fd = add_fd(file);
if (fd == -1) { if (fd == -1) {
/* Hmm... should we delete the file too ? I guess we could try */ /* Hmm... should we delete the file too ? I guess we could try */
@ -250,15 +249,15 @@ smbc_opendir(const char *durl)
{ {
SMBCFILE * file; SMBCFILE * file;
int fd; int fd;
file = smbc_getFunctionOpendir(statcont)(statcont, durl); file = smbc_getFunctionOpendir(statcont)(statcont, durl);
if (!file) if (!file)
return -1; return -1;
fd = add_fd(file); fd = add_fd(file);
if (fd == -1) if (fd == -1)
smbc_getFunctionClosedir(statcont)(statcont, file); smbc_getFunctionClosedir(statcont)(statcont, file);
return fd; return fd;
} }
@ -372,14 +371,14 @@ smbc_utime(const char *fname,
struct utimbuf *utbuf) struct utimbuf *utbuf)
{ {
struct timeval tv[2]; struct timeval tv[2];
if (utbuf == NULL) if (utbuf == NULL)
return smbc_getFunctionUtimes(statcont)(statcont, fname, NULL); return smbc_getFunctionUtimes(statcont)(statcont, fname, NULL);
tv[0].tv_sec = utbuf->actime; tv[0].tv_sec = utbuf->actime;
tv[1].tv_sec = utbuf->modtime; tv[1].tv_sec = utbuf->modtime;
tv[0].tv_usec = tv[1].tv_usec = 0; tv[0].tv_usec = tv[1].tv_usec = 0;
return smbc_getFunctionUtimes(statcont)(statcont, fname, tv); return smbc_getFunctionUtimes(statcont)(statcont, fname, tv);
} }
#endif #endif
@ -534,7 +533,7 @@ int
smbc_open_print_job(const char *fname) smbc_open_print_job(const char *fname)
{ {
SMBCFILE * file; SMBCFILE * file;
file = smbc_getFunctionOpenPrintJob(statcont)(statcont, fname); file = smbc_getFunctionOpenPrintJob(statcont)(statcont, fname);
if (!file) return -1; if (!file) return -1;
return file->cli_fd; return file->cli_fd;

View File

@ -7,17 +7,17 @@
Copyright (C) Tom Jansen (Ninja ISD) 2002 Copyright (C) Tom Jansen (Ninja ISD) 2002
Copyright (C) Derrell Lipman 2003-2008 Copyright (C) Derrell Lipman 2003-2008
Copyright (C) Jeremy Allison 2007, 2008 Copyright (C) Jeremy Allison 2007, 2008
This program is free software; you can redistribute it and/or modify This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or the Free Software Foundation; either version 3 of the License, or
(at your option) any later version. (at your option) any later version.
This program is distributed in the hope that it will be useful, This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details. GNU General Public License for more details.
You should have received a copy of the GNU General Public License You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
@ -50,23 +50,19 @@ SMBC_open_ctx(SMBCCTX *context,
uint16_t fd; uint16_t fd;
NTSTATUS status = NT_STATUS_OBJECT_PATH_INVALID; NTSTATUS status = NT_STATUS_OBJECT_PATH_INVALID;
TALLOC_CTX *frame = talloc_stackframe(); TALLOC_CTX *frame = talloc_stackframe();
if (!context || !context->internal->initialized) { if (!context || !context->internal->initialized) {
errno = EINVAL; /* Best I can think of ... */ errno = EINVAL; /* Best I can think of ... */
TALLOC_FREE(frame); TALLOC_FREE(frame);
return NULL; return NULL;
} }
if (!fname) { if (!fname) {
errno = EINVAL; errno = EINVAL;
TALLOC_FREE(frame); TALLOC_FREE(frame);
return NULL; return NULL;
} }
if (SMBC_parse_path(frame, if (SMBC_parse_path(frame,
context, context,
fname, fname,
@ -81,7 +77,7 @@ SMBC_open_ctx(SMBCCTX *context,
TALLOC_FREE(frame); TALLOC_FREE(frame);
return NULL; return NULL;
} }
if (!user || user[0] == (char)0) { if (!user || user[0] == (char)0) {
user = talloc_strdup(frame, smbc_getUser(context)); user = talloc_strdup(frame, smbc_getUser(context));
if (!user) { if (!user) {
@ -90,31 +86,29 @@ SMBC_open_ctx(SMBCCTX *context,
return NULL; return NULL;
} }
} }
srv = SMBC_server(frame, context, True, srv = SMBC_server(frame, context, True,
server, share, &workgroup, &user, &password); server, share, &workgroup, &user, &password);
if (!srv) { if (!srv) {
if (errno == EPERM) errno = EACCES; if (errno == EPERM) errno = EACCES;
TALLOC_FREE(frame); TALLOC_FREE(frame);
return NULL; /* SMBC_server sets errno */ return NULL; /* SMBC_server sets errno */
} }
/* Hmmm, the test for a directory is suspect here ... FIXME */ /* Hmmm, the test for a directory is suspect here ... FIXME */
if (strlen(path) > 0 && path[strlen(path) - 1] == '\\') { if (strlen(path) > 0 && path[strlen(path) - 1] == '\\') {
status = NT_STATUS_OBJECT_PATH_INVALID; status = NT_STATUS_OBJECT_PATH_INVALID;
} else { } else {
file = SMB_MALLOC_P(SMBCFILE); file = SMB_MALLOC_P(SMBCFILE);
if (!file) { if (!file) {
errno = ENOMEM; errno = ENOMEM;
TALLOC_FREE(frame); TALLOC_FREE(frame);
return NULL; return NULL;
} }
ZERO_STRUCTP(file); ZERO_STRUCTP(file);
/*d_printf(">>>open: resolving %s\n", path);*/ /*d_printf(">>>open: resolving %s\n", path);*/
if (!cli_resolve_path(frame, "", context->internal->auth_info, if (!cli_resolve_path(frame, "", context->internal->auth_info,
srv->cli, path, srv->cli, path,
@ -126,30 +120,29 @@ SMBC_open_ctx(SMBCCTX *context,
return NULL; return NULL;
} }
/*d_printf(">>>open: resolved %s as %s\n", path, targetpath);*/ /*d_printf(">>>open: resolved %s as %s\n", path, targetpath);*/
status = cli_open(targetcli, targetpath, flags, status = cli_open(targetcli, targetpath, flags,
context->internal->share_mode, &fd); context->internal->share_mode, &fd);
if (!NT_STATUS_IS_OK(status)) { if (!NT_STATUS_IS_OK(status)) {
/* Handle the error ... */ /* Handle the error ... */
SAFE_FREE(file); SAFE_FREE(file);
errno = SMBC_errno(context, targetcli); errno = SMBC_errno(context, targetcli);
TALLOC_FREE(frame); TALLOC_FREE(frame);
return NULL; return NULL;
} }
/* Fill in file struct */ /* Fill in file struct */
file->cli_fd = fd; file->cli_fd = fd;
file->fname = SMB_STRDUP(fname); file->fname = SMB_STRDUP(fname);
file->srv = srv; file->srv = srv;
file->offset = 0; file->offset = 0;
file->file = True; file->file = True;
DLIST_ADD(context->internal->files, file); DLIST_ADD(context->internal->files, file);
/* /*
* If the file was opened in O_APPEND mode, all write * If the file was opened in O_APPEND mode, all write
* operations should be appended to the file. To do that, * operations should be appended to the file. To do that,
@ -180,29 +173,26 @@ SMBC_open_ctx(SMBCCTX *context,
return NULL; return NULL;
} }
} }
TALLOC_FREE(frame); TALLOC_FREE(frame);
return file; return file;
} }
/* Check if opendir needed ... */ /* Check if opendir needed ... */
if (!NT_STATUS_IS_OK(status)) { if (!NT_STATUS_IS_OK(status)) {
int eno = 0; int eno = 0;
eno = SMBC_errno(context, srv->cli); eno = SMBC_errno(context, srv->cli);
file = smbc_getFunctionOpendir(context)(context, fname); file = smbc_getFunctionOpendir(context)(context, fname);
if (!file) errno = eno; if (!file) errno = eno;
TALLOC_FREE(frame); TALLOC_FREE(frame);
return file; return file;
} }
errno = EINVAL; /* FIXME, correct errno ? */ errno = EINVAL; /* FIXME, correct errno ? */
TALLOC_FREE(frame); TALLOC_FREE(frame);
return NULL; return NULL;
} }
/* /*
@ -214,14 +204,11 @@ SMBC_creat_ctx(SMBCCTX *context,
const char *path, const char *path,
mode_t mode) mode_t mode)
{ {
if (!context || !context->internal->initialized) { if (!context || !context->internal->initialized) {
errno = EINVAL; errno = EINVAL;
return NULL; return NULL;
} }
return SMBC_open_ctx(context, path, return SMBC_open_ctx(context, path,
O_WRONLY | O_CREAT | O_TRUNC, mode); O_WRONLY | O_CREAT | O_TRUNC, mode);
} }
@ -242,7 +229,7 @@ SMBC_read_ctx(SMBCCTX *context,
char *targetpath = NULL; char *targetpath = NULL;
struct cli_state *targetcli = NULL; struct cli_state *targetcli = NULL;
TALLOC_CTX *frame = talloc_stackframe(); TALLOC_CTX *frame = talloc_stackframe();
/* /*
* offset: * offset:
* *
@ -253,35 +240,31 @@ SMBC_read_ctx(SMBCCTX *context,
* retrieving data at an offset greater than 4GB. * retrieving data at an offset greater than 4GB.
*/ */
off_t offset; off_t offset;
if (!context || !context->internal->initialized) { if (!context || !context->internal->initialized) {
errno = EINVAL; errno = EINVAL;
TALLOC_FREE(frame); TALLOC_FREE(frame);
return -1; return -1;
} }
DEBUG(4, ("smbc_read(%p, %d)\n", file, (int)count)); DEBUG(4, ("smbc_read(%p, %d)\n", file, (int)count));
if (!file || !SMBC_dlist_contains(context->internal->files, file)) { if (!file || !SMBC_dlist_contains(context->internal->files, file)) {
errno = EBADF; errno = EBADF;
TALLOC_FREE(frame); TALLOC_FREE(frame);
return -1; return -1;
} }
offset = file->offset; offset = file->offset;
/* Check that the buffer exists ... */ /* Check that the buffer exists ... */
if (buf == NULL) { if (buf == NULL) {
errno = EINVAL; errno = EINVAL;
TALLOC_FREE(frame); TALLOC_FREE(frame);
return -1; return -1;
} }
/*d_printf(">>>read: parsing %s\n", file->fname);*/ /*d_printf(">>>read: parsing %s\n", file->fname);*/
if (SMBC_parse_path(frame, if (SMBC_parse_path(frame,
context, context,
@ -297,7 +280,7 @@ SMBC_read_ctx(SMBCCTX *context,
TALLOC_FREE(frame); TALLOC_FREE(frame);
return -1; return -1;
} }
/*d_printf(">>>read: resolving %s\n", path);*/ /*d_printf(">>>read: resolving %s\n", path);*/
if (!cli_resolve_path(frame, "", context->internal->auth_info, if (!cli_resolve_path(frame, "", context->internal->auth_info,
file->srv->cli, path, file->srv->cli, path,
@ -308,24 +291,21 @@ SMBC_read_ctx(SMBCCTX *context,
return -1; return -1;
} }
/*d_printf(">>>fstat: resolved path as %s\n", targetpath);*/ /*d_printf(">>>fstat: resolved path as %s\n", targetpath);*/
ret = cli_read(targetcli, file->cli_fd, (char *)buf, offset, count); ret = cli_read(targetcli, file->cli_fd, (char *)buf, offset, count);
if (ret < 0) { if (ret < 0) {
errno = SMBC_errno(context, targetcli); errno = SMBC_errno(context, targetcli);
TALLOC_FREE(frame); TALLOC_FREE(frame);
return -1; return -1;
} }
file->offset += ret; file->offset += ret;
DEBUG(4, (" --> %d\n", ret)); DEBUG(4, (" --> %d\n", ret));
TALLOC_FREE(frame); TALLOC_FREE(frame);
return ret; /* Success, ret bytes of data ... */ return ret; /* Success, ret bytes of data ... */
} }
/* /*
@ -345,34 +325,31 @@ SMBC_write_ctx(SMBCCTX *context,
char *targetpath = NULL; char *targetpath = NULL;
struct cli_state *targetcli = NULL; struct cli_state *targetcli = NULL;
TALLOC_CTX *frame = talloc_stackframe(); TALLOC_CTX *frame = talloc_stackframe();
/* First check all pointers before dereferencing them */ /* First check all pointers before dereferencing them */
if (!context || !context->internal->initialized) { if (!context || !context->internal->initialized) {
errno = EINVAL; errno = EINVAL;
TALLOC_FREE(frame); TALLOC_FREE(frame);
return -1; return -1;
} }
if (!file || !SMBC_dlist_contains(context->internal->files, file)) { if (!file || !SMBC_dlist_contains(context->internal->files, file)) {
errno = EBADF; errno = EBADF;
TALLOC_FREE(frame); TALLOC_FREE(frame);
return -1; return -1;
} }
/* Check that the buffer exists ... */ /* Check that the buffer exists ... */
if (buf == NULL) { if (buf == NULL) {
errno = EINVAL; errno = EINVAL;
TALLOC_FREE(frame); TALLOC_FREE(frame);
return -1; return -1;
} }
offset = file->offset; /* See "offset" comment in SMBC_read_ctx() */ offset = file->offset; /* See "offset" comment in SMBC_read_ctx() */
/*d_printf(">>>write: parsing %s\n", file->fname);*/ /*d_printf(">>>write: parsing %s\n", file->fname);*/
if (SMBC_parse_path(frame, if (SMBC_parse_path(frame,
context, context,
@ -399,19 +376,17 @@ SMBC_write_ctx(SMBCCTX *context,
return -1; return -1;
} }
/*d_printf(">>>write: resolved path as %s\n", targetpath);*/ /*d_printf(">>>write: resolved path as %s\n", targetpath);*/
ret = cli_write(targetcli, file->cli_fd, ret = cli_write(targetcli, file->cli_fd,
0, (char *)buf, offset, count); 0, (char *)buf, offset, count);
if (ret <= 0) { if (ret <= 0) {
errno = SMBC_errno(context, targetcli); errno = SMBC_errno(context, targetcli);
TALLOC_FREE(frame); TALLOC_FREE(frame);
return -1; return -1;
} }
file->offset += ret; file->offset += ret;
TALLOC_FREE(frame); TALLOC_FREE(frame);
return ret; /* Success, 0 bytes of data ... */ return ret; /* Success, 0 bytes of data ... */
} }
@ -430,26 +405,25 @@ SMBC_close_ctx(SMBCCTX *context,
char *targetpath = NULL; char *targetpath = NULL;
struct cli_state *targetcli = NULL; struct cli_state *targetcli = NULL;
TALLOC_CTX *frame = talloc_stackframe(); TALLOC_CTX *frame = talloc_stackframe();
if (!context || !context->internal->initialized) { if (!context || !context->internal->initialized) {
errno = EINVAL; errno = EINVAL;
TALLOC_FREE(frame); TALLOC_FREE(frame);
return -1; return -1;
} }
if (!file || !SMBC_dlist_contains(context->internal->files, file)) { if (!file || !SMBC_dlist_contains(context->internal->files, file)) {
errno = EBADF; errno = EBADF;
TALLOC_FREE(frame); TALLOC_FREE(frame);
return -1; return -1;
} }
/* IS a dir ... */ /* IS a dir ... */
if (!file->file) { if (!file->file) {
TALLOC_FREE(frame); TALLOC_FREE(frame);
return smbc_getFunctionClosedir(context)(context, file); return smbc_getFunctionClosedir(context)(context, file);
} }
/*d_printf(">>>close: parsing %s\n", file->fname);*/ /*d_printf(">>>close: parsing %s\n", file->fname);*/
if (SMBC_parse_path(frame, if (SMBC_parse_path(frame,
context, context,
@ -465,7 +439,7 @@ SMBC_close_ctx(SMBCCTX *context,
TALLOC_FREE(frame); TALLOC_FREE(frame);
return -1; return -1;
} }
/*d_printf(">>>close: resolving %s\n", path);*/ /*d_printf(">>>close: resolving %s\n", path);*/
if (!cli_resolve_path(frame, "", context->internal->auth_info, if (!cli_resolve_path(frame, "", context->internal->auth_info,
file->srv->cli, path, file->srv->cli, path,
@ -476,9 +450,8 @@ SMBC_close_ctx(SMBCCTX *context,
return -1; return -1;
} }
/*d_printf(">>>close: resolved path as %s\n", targetpath);*/ /*d_printf(">>>close: resolved path as %s\n", targetpath);*/
if (!NT_STATUS_IS_OK(cli_close(targetcli, file->cli_fd))) { if (!NT_STATUS_IS_OK(cli_close(targetcli, file->cli_fd))) {
DEBUG(3, ("cli_close failed on %s. purging server.\n", DEBUG(3, ("cli_close failed on %s. purging server.\n",
file->fname)); file->fname));
/* Deallocate slot and remove the server /* Deallocate slot and remove the server
@ -491,14 +464,12 @@ SMBC_close_ctx(SMBCCTX *context,
smbc_getFunctionRemoveUnusedServer(context)(context, srv); smbc_getFunctionRemoveUnusedServer(context)(context, srv);
TALLOC_FREE(frame); TALLOC_FREE(frame);
return -1; return -1;
} }
DLIST_REMOVE(context->internal->files, file); DLIST_REMOVE(context->internal->files, file);
SAFE_FREE(file->fname); SAFE_FREE(file->fname);
SAFE_FREE(file); SAFE_FREE(file);
TALLOC_FREE(frame); TALLOC_FREE(frame);
return 0; return 0;
} }
@ -523,14 +494,13 @@ SMBC_getatr(SMBCCTX * context,
struct cli_state *targetcli = NULL; struct cli_state *targetcli = NULL;
time_t write_time; time_t write_time;
TALLOC_CTX *frame = talloc_stackframe(); TALLOC_CTX *frame = talloc_stackframe();
if (!context || !context->internal->initialized) { if (!context || !context->internal->initialized) {
errno = EINVAL; errno = EINVAL;
TALLOC_FREE(frame); TALLOC_FREE(frame);
return False; return False;
} }
/* path fixup for . and .. */ /* path fixup for . and .. */
if (strequal(path, ".") || strequal(path, "..")) { if (strequal(path, ".") || strequal(path, "..")) {
fixedpath = talloc_strdup(frame, "\\"); fixedpath = talloc_strdup(frame, "\\");
@ -550,7 +520,7 @@ SMBC_getatr(SMBCCTX * context,
trim_string(fixedpath, NULL, "\\."); trim_string(fixedpath, NULL, "\\.");
} }
DEBUG(4,("SMBC_getatr: sending qpathinfo\n")); DEBUG(4,("SMBC_getatr: sending qpathinfo\n"));
if (!cli_resolve_path(frame, "", context->internal->auth_info, if (!cli_resolve_path(frame, "", context->internal->auth_info,
srv->cli, fixedpath, srv->cli, fixedpath,
&targetcli, &targetpath)) { &targetcli, &targetpath)) {
@ -559,7 +529,7 @@ SMBC_getatr(SMBCCTX * context,
TALLOC_FREE(frame); TALLOC_FREE(frame);
return False; return False;
} }
if (!srv->no_pathinfo2 && if (!srv->no_pathinfo2 &&
cli_qpathinfo2(targetcli, targetpath, cli_qpathinfo2(targetcli, targetpath,
create_time_ts, create_time_ts,
@ -570,45 +540,38 @@ SMBC_getatr(SMBCCTX * context,
TALLOC_FREE(frame); TALLOC_FREE(frame);
return True; return True;
} }
/* if this is NT then don't bother with the getatr */ /* if this is NT then don't bother with the getatr */
if (targetcli->capabilities & CAP_NT_SMBS) { if (targetcli->capabilities & CAP_NT_SMBS) {
errno = EPERM; errno = EPERM;
TALLOC_FREE(frame); TALLOC_FREE(frame);
return False; return False;
} }
if (NT_STATUS_IS_OK(cli_getatr(targetcli, targetpath, mode, size, &write_time))) { if (NT_STATUS_IS_OK(cli_getatr(targetcli, targetpath, mode, size, &write_time))) {
struct timespec w_time_ts; struct timespec w_time_ts;
w_time_ts = convert_time_t_to_timespec(write_time); w_time_ts = convert_time_t_to_timespec(write_time);
if (write_time_ts != NULL) { if (write_time_ts != NULL) {
*write_time_ts = w_time_ts; *write_time_ts = w_time_ts;
} }
if (create_time_ts != NULL) { if (create_time_ts != NULL) {
*create_time_ts = w_time_ts; *create_time_ts = w_time_ts;
} }
if (access_time_ts != NULL) { if (access_time_ts != NULL) {
*access_time_ts = w_time_ts; *access_time_ts = w_time_ts;
} }
if (change_time_ts != NULL) { if (change_time_ts != NULL) {
*change_time_ts = w_time_ts; *change_time_ts = w_time_ts;
} }
srv->no_pathinfo2 = True; srv->no_pathinfo2 = True;
TALLOC_FREE(frame); TALLOC_FREE(frame);
return True; return True;
} }
errno = EPERM; errno = EPERM;
TALLOC_FREE(frame); TALLOC_FREE(frame);
return False; return False;
} }
/* /*
@ -632,7 +595,7 @@ SMBC_setatr(SMBCCTX * context, SMBCSRV *srv, char *path,
uint16_t fd; uint16_t fd;
int ret; int ret;
TALLOC_CTX *frame = talloc_stackframe(); TALLOC_CTX *frame = talloc_stackframe();
/* /*
* First, try setpathinfo (if qpathinfo succeeded), for it is the * First, try setpathinfo (if qpathinfo succeeded), for it is the
* modern function for "new code" to be using, and it works given a * modern function for "new code" to be using, and it works given a
@ -646,7 +609,7 @@ SMBC_setatr(SMBCCTX * context, SMBCSRV *srv, char *path,
write_time, write_time,
change_time, change_time,
mode)) { mode)) {
/* /*
* setpathinfo is not supported; go to plan B. * setpathinfo is not supported; go to plan B.
* *
@ -656,27 +619,26 @@ SMBC_setatr(SMBCCTX * context, SMBCSRV *srv, char *path,
* cli_setattrE() which should work on all OS versions, and * cli_setattrE() which should work on all OS versions, and
* supports both times. * supports both times.
*/ */
/* Don't try {q,set}pathinfo() again, with this server */ /* Don't try {q,set}pathinfo() again, with this server */
srv->no_pathinfo = True; srv->no_pathinfo = True;
/* Open the file */ /* Open the file */
if (!NT_STATUS_IS_OK(cli_open(srv->cli, path, O_RDWR, DENY_NONE, &fd))) { if (!NT_STATUS_IS_OK(cli_open(srv->cli, path, O_RDWR, DENY_NONE, &fd))) {
errno = SMBC_errno(context, srv->cli); errno = SMBC_errno(context, srv->cli);
TALLOC_FREE(frame); TALLOC_FREE(frame);
return -1; return -1;
} }
/* Set the new attributes */ /* Set the new attributes */
ret = NT_STATUS_IS_OK(cli_setattrE(srv->cli, fd, ret = NT_STATUS_IS_OK(cli_setattrE(srv->cli, fd,
change_time, change_time,
access_time, access_time,
write_time)); write_time));
/* Close the file */ /* Close the file */
cli_close(srv->cli, fd); cli_close(srv->cli, fd);
/* /*
* Unfortunately, setattrE() doesn't have a provision for * Unfortunately, setattrE() doesn't have a provision for
* setting the access mode (attributes). We'll have to try * setting the access mode (attributes). We'll have to try
@ -686,14 +648,14 @@ SMBC_setatr(SMBCCTX * context, SMBCSRV *srv, char *path,
if (ret && mode != (uint16) -1) { if (ret && mode != (uint16) -1) {
ret = NT_STATUS_IS_OK(cli_setatr(srv->cli, path, mode, 0)); ret = NT_STATUS_IS_OK(cli_setatr(srv->cli, path, mode, 0));
} }
if (! ret) { if (! ret) {
errno = SMBC_errno(context, srv->cli); errno = SMBC_errno(context, srv->cli);
TALLOC_FREE(frame); TALLOC_FREE(frame);
return False; return False;
} }
} }
TALLOC_FREE(frame); TALLOC_FREE(frame);
return True; return True;
} }
@ -714,39 +676,32 @@ SMBC_lseek_ctx(SMBCCTX *context,
char *targetpath = NULL; char *targetpath = NULL;
struct cli_state *targetcli = NULL; struct cli_state *targetcli = NULL;
TALLOC_CTX *frame = talloc_stackframe(); TALLOC_CTX *frame = talloc_stackframe();
if (!context || !context->internal->initialized) { if (!context || !context->internal->initialized) {
errno = EINVAL; errno = EINVAL;
TALLOC_FREE(frame); TALLOC_FREE(frame);
return -1; return -1;
} }
if (!file || !SMBC_dlist_contains(context->internal->files, file)) { if (!file || !SMBC_dlist_contains(context->internal->files, file)) {
errno = EBADF; errno = EBADF;
TALLOC_FREE(frame); TALLOC_FREE(frame);
return -1; return -1;
} }
if (!file->file) { if (!file->file) {
errno = EINVAL; errno = EINVAL;
TALLOC_FREE(frame); TALLOC_FREE(frame);
return -1; /* Can't lseek a dir ... */ return -1; /* Can't lseek a dir ... */
} }
switch (whence) { switch (whence) {
case SEEK_SET: case SEEK_SET:
file->offset = offset; file->offset = offset;
break; break;
case SEEK_CUR: case SEEK_CUR:
file->offset += offset; file->offset += offset;
break; break;
case SEEK_END: case SEEK_END:
/*d_printf(">>>lseek: parsing %s\n", file->fname);*/ /*d_printf(">>>lseek: parsing %s\n", file->fname);*/
if (SMBC_parse_path(frame, if (SMBC_parse_path(frame,
@ -763,7 +718,7 @@ SMBC_lseek_ctx(SMBCCTX *context,
TALLOC_FREE(frame); TALLOC_FREE(frame);
return -1; return -1;
} }
/*d_printf(">>>lseek: resolving %s\n", path);*/ /*d_printf(">>>lseek: resolving %s\n", path);*/
if (!cli_resolve_path(frame, "", context->internal->auth_info, if (!cli_resolve_path(frame, "", context->internal->auth_info,
file->srv->cli, path, file->srv->cli, path,
@ -773,8 +728,8 @@ SMBC_lseek_ctx(SMBCCTX *context,
TALLOC_FREE(frame); TALLOC_FREE(frame);
return -1; return -1;
} }
/*d_printf(">>>lseek: resolved path as %s\n", targetpath);*/ /*d_printf(">>>lseek: resolved path as %s\n", targetpath);*/
if (!cli_qfileinfo(targetcli, file->cli_fd, NULL, if (!cli_qfileinfo(targetcli, file->cli_fd, NULL,
&size, NULL, NULL, NULL, NULL, NULL)) &size, NULL, NULL, NULL, NULL, NULL))
{ {
@ -789,16 +744,13 @@ SMBC_lseek_ctx(SMBCCTX *context,
} }
file->offset = size + offset; file->offset = size + offset;
break; break;
default: default:
errno = EINVAL; errno = EINVAL;
break; break;
} }
TALLOC_FREE(frame); TALLOC_FREE(frame);
return file->offset; return file->offset;
} }
@ -820,26 +772,25 @@ SMBC_ftruncate_ctx(SMBCCTX *context,
char *targetpath = NULL; char *targetpath = NULL;
struct cli_state *targetcli = NULL; struct cli_state *targetcli = NULL;
TALLOC_CTX *frame = talloc_stackframe(); TALLOC_CTX *frame = talloc_stackframe();
if (!context || !context->internal->initialized) { if (!context || !context->internal->initialized) {
errno = EINVAL; errno = EINVAL;
TALLOC_FREE(frame); TALLOC_FREE(frame);
return -1; return -1;
} }
if (!file || !SMBC_dlist_contains(context->internal->files, file)) { if (!file || !SMBC_dlist_contains(context->internal->files, file)) {
errno = EBADF; errno = EBADF;
TALLOC_FREE(frame); TALLOC_FREE(frame);
return -1; return -1;
} }
if (!file->file) { if (!file->file) {
errno = EINVAL; errno = EINVAL;
TALLOC_FREE(frame); TALLOC_FREE(frame);
return -1; return -1;
} }
/*d_printf(">>>fstat: parsing %s\n", file->fname);*/ /*d_printf(">>>fstat: parsing %s\n", file->fname);*/
if (SMBC_parse_path(frame, if (SMBC_parse_path(frame,
context, context,
@ -855,7 +806,7 @@ SMBC_ftruncate_ctx(SMBCCTX *context,
TALLOC_FREE(frame); TALLOC_FREE(frame);
return -1; return -1;
} }
/*d_printf(">>>fstat: resolving %s\n", path);*/ /*d_printf(">>>fstat: resolving %s\n", path);*/
if (!cli_resolve_path(frame, "", context->internal->auth_info, if (!cli_resolve_path(frame, "", context->internal->auth_info,
file->srv->cli, path, file->srv->cli, path,
@ -866,14 +817,13 @@ SMBC_ftruncate_ctx(SMBCCTX *context,
return -1; return -1;
} }
/*d_printf(">>>fstat: resolved path as %s\n", targetpath);*/ /*d_printf(">>>fstat: resolved path as %s\n", targetpath);*/
if (!NT_STATUS_IS_OK(cli_ftruncate(targetcli, file->cli_fd, (uint64_t)size))) { if (!NT_STATUS_IS_OK(cli_ftruncate(targetcli, file->cli_fd, (uint64_t)size))) {
errno = EINVAL; errno = EINVAL;
TALLOC_FREE(frame); TALLOC_FREE(frame);
return -1; return -1;
} }
TALLOC_FREE(frame); TALLOC_FREE(frame);
return 0; return 0;
} }

View File

@ -7,17 +7,17 @@
Copyright (C) Tom Jansen (Ninja ISD) 2002 Copyright (C) Tom Jansen (Ninja ISD) 2002
Copyright (C) Derrell Lipman 2003-2008 Copyright (C) Derrell Lipman 2003-2008
Copyright (C) Jeremy Allison 2007, 2008 Copyright (C) Jeremy Allison 2007, 2008
This program is free software; you can redistribute it and/or modify This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or the Free Software Foundation; either version 3 of the License, or
(at your option) any later version. (at your option) any later version.
This program is distributed in the hope that it will be useful, This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details. GNU General Public License for more details.
You should have received a copy of the GNU General Public License You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
@ -50,24 +50,24 @@ SMBC_errno(SMBCCTX *context,
struct cli_state *c) struct cli_state *c)
{ {
int ret = cli_errno(c); int ret = cli_errno(c);
if (cli_is_dos_error(c)) { if (cli_is_dos_error(c)) {
uint8 eclass; uint8 eclass;
uint32 ecode; uint32 ecode;
cli_dos_error(c, &eclass, &ecode); cli_dos_error(c, &eclass, &ecode);
DEBUG(3,("smbc_error %d %d (0x%x) -> %d\n", DEBUG(3,("smbc_error %d %d (0x%x) -> %d\n",
(int)eclass, (int)ecode, (int)ecode, ret)); (int)eclass, (int)ecode, (int)ecode, ret));
} else { } else {
NTSTATUS status; NTSTATUS status;
status = cli_nt_error(c); status = cli_nt_error(c);
DEBUG(3,("smbc errno %s -> %d\n", DEBUG(3,("smbc errno %s -> %d\n",
nt_errstr(status), ret)); nt_errstr(status), ret));
} }
return ret; return ret;
} }

View File

@ -7,17 +7,17 @@
Copyright (C) Tom Jansen (Ninja ISD) 2002 Copyright (C) Tom Jansen (Ninja ISD) 2002
Copyright (C) Derrell Lipman 2003-2008 Copyright (C) Derrell Lipman 2003-2008
Copyright (C) Jeremy Allison 2007, 2008 Copyright (C) Jeremy Allison 2007, 2008
This program is free software; you can redistribute it and/or modify This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or the Free Software Foundation; either version 3 of the License, or
(at your option) any later version. (at your option) any later version.
This program is distributed in the hope that it will be useful, This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details. GNU General Public License for more details.
You should have received a copy of the GNU General Public License You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
@ -60,19 +60,19 @@ urldecode_talloc(TALLOC_CTX *ctx, char **pp_dest, const char *src)
int err_count = 0; int err_count = 0;
size_t newlen = 1; size_t newlen = 1;
char *p, *dest; char *p, *dest;
if (old_length == 0) { if (old_length == 0) {
return 0; return 0;
} }
*pp_dest = NULL; *pp_dest = NULL;
for (i = 0; i < old_length; ) { for (i = 0; i < old_length; ) {
unsigned char character = src[i++]; unsigned char character = src[i++];
if (character == '%') { if (character == '%') {
int a = i+1 < old_length ? hex2int(src[i]) : -1; int a = i+1 < old_length ? hex2int(src[i]) : -1;
int b = i+1 < old_length ? hex2int(src[i+1]) : -1; int b = i+1 < old_length ? hex2int(src[i+1]) : -1;
/* Replace valid sequence */ /* Replace valid sequence */
if (a != -1 && b != -1) { if (a != -1 && b != -1) {
/* Replace valid %xx sequence with %dd */ /* Replace valid %xx sequence with %dd */
@ -87,20 +87,20 @@ urldecode_talloc(TALLOC_CTX *ctx, char **pp_dest, const char *src)
} }
newlen++; newlen++;
} }
dest = TALLOC_ARRAY(ctx, char, newlen); dest = TALLOC_ARRAY(ctx, char, newlen);
if (!dest) { if (!dest) {
return err_count; return err_count;
} }
err_count = 0; err_count = 0;
for (p = dest, i = 0; i < old_length; ) { for (p = dest, i = 0; i < old_length; ) {
unsigned char character = src[i++]; unsigned char character = src[i++];
if (character == '%') { if (character == '%') {
int a = i+1 < old_length ? hex2int(src[i]) : -1; int a = i+1 < old_length ? hex2int(src[i]) : -1;
int b = i+1 < old_length ? hex2int(src[i+1]) : -1; int b = i+1 < old_length ? hex2int(src[i+1]) : -1;
/* Replace valid sequence */ /* Replace valid sequence */
if (a != -1 && b != -1) { if (a != -1 && b != -1) {
/* Replace valid %xx sequence with %dd */ /* Replace valid %xx sequence with %dd */
@ -115,7 +115,7 @@ urldecode_talloc(TALLOC_CTX *ctx, char **pp_dest, const char *src)
} }
*p++ = character; *p++ = character;
} }
*p = '\0'; *p = '\0';
*pp_dest = dest; *pp_dest = dest;
return err_count; return err_count;
@ -129,7 +129,7 @@ smbc_urldecode(char *dest,
TALLOC_CTX *frame = talloc_stackframe(); TALLOC_CTX *frame = talloc_stackframe();
char *pdest; char *pdest;
int ret = urldecode_talloc(frame, &pdest, src); int ret = urldecode_talloc(frame, &pdest, src);
if (pdest) { if (pdest) {
strlcpy(dest, pdest, max_dest_len); strlcpy(dest, pdest, max_dest_len);
} }
@ -151,9 +151,9 @@ smbc_urlencode(char *dest,
int max_dest_len) int max_dest_len)
{ {
char hex[] = "0123456789ABCDEF"; char hex[] = "0123456789ABCDEF";
for (; *src != '\0' && max_dest_len >= 3; src++) { for (; *src != '\0' && max_dest_len >= 3; src++) {
if ((*src < '0' && if ((*src < '0' &&
*src != '-' && *src != '-' &&
*src != '.') || *src != '.') ||
@ -172,10 +172,10 @@ smbc_urlencode(char *dest,
max_dest_len--; max_dest_len--;
} }
} }
*dest++ = '\0'; *dest++ = '\0';
max_dest_len--; max_dest_len--;
return max_dest_len; return max_dest_len;
} }
@ -235,19 +235,19 @@ SMBC_parse_path(TALLOC_CTX *ctx,
char *q, *r; char *q, *r;
char *workgroup = NULL; char *workgroup = NULL;
int len; int len;
/* Ensure these returns are at least valid pointers. */ /* Ensure these returns are at least valid pointers. */
*pp_server = talloc_strdup(ctx, ""); *pp_server = talloc_strdup(ctx, "");
*pp_share = talloc_strdup(ctx, ""); *pp_share = talloc_strdup(ctx, "");
*pp_path = talloc_strdup(ctx, ""); *pp_path = talloc_strdup(ctx, "");
*pp_user = talloc_strdup(ctx, ""); *pp_user = talloc_strdup(ctx, "");
*pp_password = talloc_strdup(ctx, ""); *pp_password = talloc_strdup(ctx, "");
if (!*pp_server || !*pp_share || !*pp_path || if (!*pp_server || !*pp_share || !*pp_path ||
!*pp_user || !*pp_password) { !*pp_user || !*pp_password) {
return -1; return -1;
} }
/* /*
* Assume we wont find an authentication domain to parse, so default * Assume we wont find an authentication domain to parse, so default
* to the workgroup in the provided context. * to the workgroup in the provided context.
@ -256,54 +256,54 @@ SMBC_parse_path(TALLOC_CTX *ctx,
*pp_workgroup = *pp_workgroup =
talloc_strdup(ctx, smbc_getWorkgroup(context)); talloc_strdup(ctx, smbc_getWorkgroup(context));
} }
if (pp_options) { if (pp_options) {
*pp_options = talloc_strdup(ctx, ""); *pp_options = talloc_strdup(ctx, "");
} }
s = talloc_strdup(ctx, fname); s = talloc_strdup(ctx, fname);
/* see if it has the right prefix */ /* see if it has the right prefix */
len = strlen(SMBC_PREFIX); len = strlen(SMBC_PREFIX);
if (strncmp(s,SMBC_PREFIX,len) || (s[len] != '/' && s[len] != 0)) { if (strncmp(s,SMBC_PREFIX,len) || (s[len] != '/' && s[len] != 0)) {
return -1; /* What about no smb: ? */ return -1; /* What about no smb: ? */
} }
p = s + len; p = s + len;
/* Watch the test below, we are testing to see if we should exit */ /* Watch the test below, we are testing to see if we should exit */
if (strncmp(p, "//", 2) && strncmp(p, "\\\\", 2)) { if (strncmp(p, "//", 2) && strncmp(p, "\\\\", 2)) {
DEBUG(1, ("Invalid path (does not begin with smb://")); DEBUG(1, ("Invalid path (does not begin with smb://"));
return -1; return -1;
} }
p += 2; /* Skip the double slash */ p += 2; /* Skip the double slash */
/* See if any options were specified */ /* See if any options were specified */
if ((q = strrchr(p, '?')) != NULL ) { if ((q = strrchr(p, '?')) != NULL ) {
/* There are options. Null terminate here and point to them */ /* There are options. Null terminate here and point to them */
*q++ = '\0'; *q++ = '\0';
DEBUG(4, ("Found options '%s'", q)); DEBUG(4, ("Found options '%s'", q));
/* Copy the options */ /* Copy the options */
if (pp_options && *pp_options != NULL) { if (pp_options && *pp_options != NULL) {
TALLOC_FREE(*pp_options); TALLOC_FREE(*pp_options);
*pp_options = talloc_strdup(ctx, q); *pp_options = talloc_strdup(ctx, q);
} }
} }
if (*p == '\0') { if (*p == '\0') {
goto decoding; goto decoding;
} }
if (*p == '/') { if (*p == '/') {
int wl = strlen(smbc_getWorkgroup(context)); int wl = strlen(smbc_getWorkgroup(context));
if (wl > 16) { if (wl > 16) {
wl = 16; wl = 16;
} }
*pp_server = talloc_strdup(ctx, smbc_getWorkgroup(context)); *pp_server = talloc_strdup(ctx, smbc_getWorkgroup(context));
if (!*pp_server) { if (!*pp_server) {
return -1; return -1;
@ -311,27 +311,27 @@ SMBC_parse_path(TALLOC_CTX *ctx,
*pp_server[wl] = '\0'; *pp_server[wl] = '\0';
return 0; return 0;
} }
/* /*
* ok, its for us. Now parse out the server, share etc. * ok, its for us. Now parse out the server, share etc.
* *
* However, we want to parse out [[domain;]user[:password]@] if it * However, we want to parse out [[domain;]user[:password]@] if it
* exists ... * exists ...
*/ */
/* check that '@' occurs before '/', if '/' exists at all */ /* check that '@' occurs before '/', if '/' exists at all */
q = strchr_m(p, '@'); q = strchr_m(p, '@');
r = strchr_m(p, '/'); r = strchr_m(p, '/');
if (q && (!r || q < r)) { if (q && (!r || q < r)) {
char *userinfo = NULL; char *userinfo = NULL;
const char *u; const char *u;
next_token_no_ltrim_talloc(ctx, &p, &userinfo, "@"); next_token_no_ltrim_talloc(ctx, &p, &userinfo, "@");
if (!userinfo) { if (!userinfo) {
return -1; return -1;
} }
u = userinfo; u = userinfo;
if (strchr_m(u, ';')) { if (strchr_m(u, ';')) {
next_token_no_ltrim_talloc(ctx, &u, &workgroup, ";"); next_token_no_ltrim_talloc(ctx, &u, &workgroup, ";");
if (!workgroup) { if (!workgroup) {
@ -341,7 +341,7 @@ SMBC_parse_path(TALLOC_CTX *ctx,
*pp_workgroup = workgroup; *pp_workgroup = workgroup;
} }
} }
if (strchr_m(u, ':')) { if (strchr_m(u, ':')) {
next_token_no_ltrim_talloc(ctx, &u, pp_user, ":"); next_token_no_ltrim_talloc(ctx, &u, pp_user, ":");
if (!*pp_user) { if (!*pp_user) {
@ -358,19 +358,19 @@ SMBC_parse_path(TALLOC_CTX *ctx,
} }
} }
} }
if (!next_token_talloc(ctx, &p, pp_server, "/")) { if (!next_token_talloc(ctx, &p, pp_server, "/")) {
return -1; return -1;
} }
if (*p == (char)0) { if (*p == (char)0) {
goto decoding; /* That's it ... */ goto decoding; /* That's it ... */
} }
if (!next_token_talloc(ctx, &p, pp_share, "/")) { if (!next_token_talloc(ctx, &p, pp_share, "/")) {
return -1; return -1;
} }
/* /*
* Prepend a leading slash if there's a file path, as required by * Prepend a leading slash if there's a file path, as required by
* NetApp filers. * NetApp filers.
@ -386,9 +386,8 @@ SMBC_parse_path(TALLOC_CTX *ctx,
return -1; return -1;
} }
string_replace(*pp_path, '/', '\\'); string_replace(*pp_path, '/', '\\');
decoding: decoding:
(void) urldecode_talloc(ctx, pp_path, *pp_path); (void) urldecode_talloc(ctx, pp_path, *pp_path);
(void) urldecode_talloc(ctx, pp_server, *pp_server); (void) urldecode_talloc(ctx, pp_server, *pp_server);
(void) urldecode_talloc(ctx, pp_share, *pp_share); (void) urldecode_talloc(ctx, pp_share, *pp_share);
@ -407,7 +406,6 @@ decoding:
workgroup, workgroup,
*pp_user, *pp_user,
*pp_password); *pp_password);
return 0; return 0;
} }

View File

@ -7,17 +7,17 @@
Copyright (C) Tom Jansen (Ninja ISD) 2002 Copyright (C) Tom Jansen (Ninja ISD) 2002
Copyright (C) Derrell Lipman 2003-2008 Copyright (C) Derrell Lipman 2003-2008
Copyright (C) Jeremy Allison 2007, 2008 Copyright (C) Jeremy Allison 2007, 2008
This program is free software; you can redistribute it and/or modify This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or the Free Software Foundation; either version 3 of the License, or
(at your option) any later version. (at your option) any later version.
This program is distributed in the hope that it will be useful, This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details. GNU General Public License for more details.
You should have received a copy of the GNU General Public License You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
@ -41,22 +41,21 @@ SMBC_open_print_job_ctx(SMBCCTX *context,
char *password = NULL; char *password = NULL;
char *path = NULL; char *path = NULL;
TALLOC_CTX *frame = talloc_stackframe(); TALLOC_CTX *frame = talloc_stackframe();
if (!context || !context->internal->initialized) { if (!context || !context->internal->initialized) {
errno = EINVAL; errno = EINVAL;
TALLOC_FREE(frame); TALLOC_FREE(frame);
return NULL; return NULL;
} }
if (!fname) { if (!fname) {
errno = EINVAL; errno = EINVAL;
TALLOC_FREE(frame); TALLOC_FREE(frame);
return NULL; return NULL;
} }
DEBUG(4, ("SMBC_open_print_job_ctx(%s)\n", fname)); DEBUG(4, ("SMBC_open_print_job_ctx(%s)\n", fname));
if (SMBC_parse_path(frame, if (SMBC_parse_path(frame,
context, context,
fname, fname,
@ -71,9 +70,9 @@ SMBC_open_print_job_ctx(SMBCCTX *context,
TALLOC_FREE(frame); TALLOC_FREE(frame);
return NULL; return NULL;
} }
/* What if the path is empty, or the file exists? */ /* What if the path is empty, or the file exists? */
TALLOC_FREE(frame); TALLOC_FREE(frame);
return smbc_getFunctionOpen(context)(context, fname, O_WRONLY, 666); return smbc_getFunctionOpen(context)(context, fname, O_WRONLY, 666);
} }
@ -98,79 +97,66 @@ SMBC_print_file_ctx(SMBCCTX *c_file,
int tot_bytes = 0; int tot_bytes = 0;
char buf[4096]; char buf[4096];
TALLOC_CTX *frame = talloc_stackframe(); TALLOC_CTX *frame = talloc_stackframe();
if (!c_file || !c_file->internal->initialized || if (!c_file || !c_file->internal->initialized ||
!c_print || !c_print->internal->initialized) { !c_print || !c_print->internal->initialized) {
errno = EINVAL; errno = EINVAL;
TALLOC_FREE(frame); TALLOC_FREE(frame);
return -1; return -1;
} }
if (!fname && !printq) { if (!fname && !printq) {
errno = EINVAL; errno = EINVAL;
TALLOC_FREE(frame); TALLOC_FREE(frame);
return -1; return -1;
} }
/* Try to open the file for reading ... */ /* Try to open the file for reading ... */
if ((long)(fid1 = smbc_getFunctionOpen(c_file)(c_file, fname, if ((long)(fid1 = smbc_getFunctionOpen(c_file)(c_file, fname,
O_RDONLY, 0666)) < 0) { O_RDONLY, 0666)) < 0) {
DEBUG(3, ("Error, fname=%s, errno=%i\n", fname, errno)); DEBUG(3, ("Error, fname=%s, errno=%i\n", fname, errno));
TALLOC_FREE(frame); TALLOC_FREE(frame);
return -1; /* smbc_open sets errno */ return -1; /* smbc_open sets errno */
} }
/* Now, try to open the printer file for writing */ /* Now, try to open the printer file for writing */
if ((long)(fid2 = smbc_getFunctionOpenPrintJob(c_print)(c_print, if ((long)(fid2 = smbc_getFunctionOpenPrintJob(c_print)(c_print,
printq)) < 0) { printq)) < 0) {
saverr = errno; /* Save errno */ saverr = errno; /* Save errno */
smbc_getFunctionClose(c_file)(c_file, fid1); smbc_getFunctionClose(c_file)(c_file, fid1);
errno = saverr; errno = saverr;
TALLOC_FREE(frame); TALLOC_FREE(frame);
return -1; return -1;
} }
while ((bytes = smbc_getFunctionRead(c_file)(c_file, fid1, while ((bytes = smbc_getFunctionRead(c_file)(c_file, fid1,
buf, sizeof(buf))) > 0) { buf, sizeof(buf))) > 0) {
tot_bytes += bytes; tot_bytes += bytes;
if ((smbc_getFunctionWrite(c_print)(c_print, fid2, if ((smbc_getFunctionWrite(c_print)(c_print, fid2,
buf, bytes)) < 0) { buf, bytes)) < 0) {
saverr = errno; saverr = errno;
smbc_getFunctionClose(c_file)(c_file, fid1); smbc_getFunctionClose(c_file)(c_file, fid1);
smbc_getFunctionClose(c_print)(c_print, fid2); smbc_getFunctionClose(c_print)(c_print, fid2);
errno = saverr; errno = saverr;
} }
} }
saverr = errno; saverr = errno;
smbc_getFunctionClose(c_file)(c_file, fid1); smbc_getFunctionClose(c_file)(c_file, fid1);
smbc_getFunctionClose(c_print)(c_print, fid2); smbc_getFunctionClose(c_print)(c_print, fid2);
if (bytes < 0) { if (bytes < 0) {
errno = saverr; errno = saverr;
TALLOC_FREE(frame); TALLOC_FREE(frame);
return -1; return -1;
} }
TALLOC_FREE(frame); TALLOC_FREE(frame);
return tot_bytes; return tot_bytes;
} }
/* /*
@ -190,22 +176,21 @@ SMBC_list_print_jobs_ctx(SMBCCTX *context,
char *workgroup = NULL; char *workgroup = NULL;
char *path = NULL; char *path = NULL;
TALLOC_CTX *frame = talloc_stackframe(); TALLOC_CTX *frame = talloc_stackframe();
if (!context || !context->internal->initialized) { if (!context || !context->internal->initialized) {
errno = EINVAL; errno = EINVAL;
TALLOC_FREE(frame); TALLOC_FREE(frame);
return -1; return -1;
} }
if (!fname) { if (!fname) {
errno = EINVAL; errno = EINVAL;
TALLOC_FREE(frame); TALLOC_FREE(frame);
return -1; return -1;
} }
DEBUG(4, ("smbc_list_print_jobs(%s)\n", fname)); DEBUG(4, ("smbc_list_print_jobs(%s)\n", fname));
if (SMBC_parse_path(frame, if (SMBC_parse_path(frame,
context, context,
fname, fname,
@ -220,7 +205,7 @@ SMBC_list_print_jobs_ctx(SMBCCTX *context,
TALLOC_FREE(frame); TALLOC_FREE(frame);
return -1; return -1;
} }
if (!user || user[0] == (char)0) { if (!user || user[0] == (char)0) {
user = talloc_strdup(frame, smbc_getUser(context)); user = talloc_strdup(frame, smbc_getUser(context));
if (!user) { if (!user) {
@ -229,25 +214,24 @@ SMBC_list_print_jobs_ctx(SMBCCTX *context,
return -1; return -1;
} }
} }
srv = SMBC_server(frame, context, True, srv = SMBC_server(frame, context, True,
server, share, &workgroup, &user, &password); server, share, &workgroup, &user, &password);
if (!srv) { if (!srv) {
TALLOC_FREE(frame); TALLOC_FREE(frame);
return -1; /* errno set by SMBC_server */ return -1; /* errno set by SMBC_server */
} }
if (cli_print_queue(srv->cli, if (cli_print_queue(srv->cli,
(void (*)(struct print_job_info *))fn) < 0) { (void (*)(struct print_job_info *))fn) < 0) {
errno = SMBC_errno(context, srv->cli); errno = SMBC_errno(context, srv->cli);
TALLOC_FREE(frame); TALLOC_FREE(frame);
return -1; return -1;
} }
TALLOC_FREE(frame); TALLOC_FREE(frame);
return 0; return 0;
} }
/* /*
@ -268,22 +252,21 @@ SMBC_unlink_print_job_ctx(SMBCCTX *context,
char *path = NULL; char *path = NULL;
int err; int err;
TALLOC_CTX *frame = talloc_stackframe(); TALLOC_CTX *frame = talloc_stackframe();
if (!context || !context->internal->initialized) { if (!context || !context->internal->initialized) {
errno = EINVAL; errno = EINVAL;
TALLOC_FREE(frame); TALLOC_FREE(frame);
return -1; return -1;
} }
if (!fname) { if (!fname) {
errno = EINVAL; errno = EINVAL;
TALLOC_FREE(frame); TALLOC_FREE(frame);
return -1; return -1;
} }
DEBUG(4, ("smbc_unlink_print_job(%s)\n", fname)); DEBUG(4, ("smbc_unlink_print_job(%s)\n", fname));
if (SMBC_parse_path(frame, if (SMBC_parse_path(frame,
context, context,
fname, fname,
@ -298,7 +281,7 @@ SMBC_unlink_print_job_ctx(SMBCCTX *context,
TALLOC_FREE(frame); TALLOC_FREE(frame);
return -1; return -1;
} }
if (!user || user[0] == (char)0) { if (!user || user[0] == (char)0) {
user = talloc_strdup(frame, smbc_getUser(context)); user = talloc_strdup(frame, smbc_getUser(context));
if (!user) { if (!user) {
@ -307,30 +290,25 @@ SMBC_unlink_print_job_ctx(SMBCCTX *context,
return -1; return -1;
} }
} }
srv = SMBC_server(frame, context, True, srv = SMBC_server(frame, context, True,
server, share, &workgroup, &user, &password); server, share, &workgroup, &user, &password);
if (!srv) { if (!srv) {
TALLOC_FREE(frame); TALLOC_FREE(frame);
return -1; /* errno set by SMBC_server */ return -1; /* errno set by SMBC_server */
} }
if ((err = cli_printjob_del(srv->cli, id)) != 0) { if ((err = cli_printjob_del(srv->cli, id)) != 0) {
if (err < 0) if (err < 0)
errno = SMBC_errno(context, srv->cli); errno = SMBC_errno(context, srv->cli);
else if (err == ERRnosuchprintjob) else if (err == ERRnosuchprintjob)
errno = EINVAL; errno = EINVAL;
TALLOC_FREE(frame); TALLOC_FREE(frame);
return -1; return -1;
} }
TALLOC_FREE(frame); TALLOC_FREE(frame);
return 0; return 0;
} }

View File

@ -7,17 +7,17 @@
Copyright (C) Tom Jansen (Ninja ISD) 2002 Copyright (C) Tom Jansen (Ninja ISD) 2002
Copyright (C) Derrell Lipman 2003-2008 Copyright (C) Derrell Lipman 2003-2008
Copyright (C) Jeremy Allison 2007, 2008 Copyright (C) Jeremy Allison 2007, 2008
This program is free software; you can redistribute it and/or modify This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or the Free Software Foundation; either version 3 of the License, or
(at your option) any later version. (at your option) any later version.
This program is distributed in the hope that it will be useful, This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details. GNU General Public License for more details.
You should have received a copy of the GNU General Public License You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */

View File

@ -7,17 +7,17 @@
Copyright (C) Tom Jansen (Ninja ISD) 2002 Copyright (C) Tom Jansen (Ninja ISD) 2002
Copyright (C) Derrell Lipman 2003-2008 Copyright (C) Derrell Lipman 2003-2008
Copyright (C) Jeremy Allison 2007, 2008 Copyright (C) Jeremy Allison 2007, 2008
This program is free software; you can redistribute it and/or modify This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or the Free Software Foundation; either version 3 of the License, or
(at your option) any later version. (at your option) any later version.
This program is distributed in the hope that it will be useful, This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details. GNU General Public License for more details.
You should have received a copy of the GNU General Public License You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
@ -36,15 +36,12 @@ generate_inode(SMBCCTX *context,
const char *name) const char *name)
{ {
if (!context || !context->internal->initialized) { if (!context || !context->internal->initialized) {
errno = EINVAL; errno = EINVAL;
return -1; return -1;
} }
if (!*name) return 2; /* FIXME, why 2 ??? */ if (!*name) return 2; /* FIXME, why 2 ??? */
return (ino_t)str_checksum(name); return (ino_t)str_checksum(name);
} }
/* /*
@ -60,20 +57,20 @@ setup_stat(SMBCCTX *context,
int mode) int mode)
{ {
TALLOC_CTX *frame = talloc_stackframe(); TALLOC_CTX *frame = talloc_stackframe();
st->st_mode = 0; st->st_mode = 0;
if (IS_DOS_DIR(mode)) { if (IS_DOS_DIR(mode)) {
st->st_mode = SMBC_DIR_MODE; st->st_mode = SMBC_DIR_MODE;
} else { } else {
st->st_mode = SMBC_FILE_MODE; st->st_mode = SMBC_FILE_MODE;
} }
if (IS_DOS_ARCHIVE(mode)) st->st_mode |= S_IXUSR; if (IS_DOS_ARCHIVE(mode)) st->st_mode |= S_IXUSR;
if (IS_DOS_SYSTEM(mode)) st->st_mode |= S_IXGRP; if (IS_DOS_SYSTEM(mode)) st->st_mode |= S_IXGRP;
if (IS_DOS_HIDDEN(mode)) st->st_mode |= S_IXOTH; if (IS_DOS_HIDDEN(mode)) st->st_mode |= S_IXOTH;
if (!IS_DOS_READONLY(mode)) st->st_mode |= S_IWUSR; if (!IS_DOS_READONLY(mode)) st->st_mode |= S_IWUSR;
st->st_size = size; st->st_size = size;
#ifdef HAVE_STAT_ST_BLKSIZE #ifdef HAVE_STAT_ST_BLKSIZE
st->st_blksize = 512; st->st_blksize = 512;
@ -86,20 +83,19 @@ setup_stat(SMBCCTX *context,
#endif #endif
st->st_uid = getuid(); st->st_uid = getuid();
st->st_gid = getgid(); st->st_gid = getgid();
if (IS_DOS_DIR(mode)) { if (IS_DOS_DIR(mode)) {
st->st_nlink = 2; st->st_nlink = 2;
} else { } else {
st->st_nlink = 1; st->st_nlink = 1;
} }
if (st->st_ino == 0) { if (st->st_ino == 0) {
st->st_ino = generate_inode(context, fname); st->st_ino = generate_inode(context, fname);
} }
TALLOC_FREE(frame); TALLOC_FREE(frame);
return True; /* FIXME: Is this needed ? */ return True; /* FIXME: Is this needed ? */
} }
/* /*
@ -125,22 +121,21 @@ SMBC_stat_ctx(SMBCCTX *context,
uint16 mode = 0; uint16 mode = 0;
SMB_INO_T ino = 0; SMB_INO_T ino = 0;
TALLOC_CTX *frame = talloc_stackframe(); TALLOC_CTX *frame = talloc_stackframe();
if (!context || !context->internal->initialized) { if (!context || !context->internal->initialized) {
errno = EINVAL; /* Best I can think of ... */ errno = EINVAL; /* Best I can think of ... */
TALLOC_FREE(frame); TALLOC_FREE(frame);
return -1; return -1;
} }
if (!fname) { if (!fname) {
errno = EINVAL; errno = EINVAL;
TALLOC_FREE(frame); TALLOC_FREE(frame);
return -1; return -1;
} }
DEBUG(4, ("smbc_stat(%s)\n", fname)); DEBUG(4, ("smbc_stat(%s)\n", fname));
if (SMBC_parse_path(frame, if (SMBC_parse_path(frame,
context, context,
fname, fname,
@ -164,15 +159,14 @@ SMBC_stat_ctx(SMBCCTX *context,
return -1; return -1;
} }
} }
srv = SMBC_server(frame, context, True, srv = SMBC_server(frame, context, True,
server, share, &workgroup, &user, &password); server, share, &workgroup, &user, &password);
if (!srv) { if (!srv) {
TALLOC_FREE(frame); TALLOC_FREE(frame);
return -1; /* errno set by SMBC_server */ return -1; /* errno set by SMBC_server */
} }
if (!SMBC_getatr(context, srv, path, &mode, &size, if (!SMBC_getatr(context, srv, path, &mode, &size,
NULL, NULL,
&access_time_ts, &access_time_ts,
@ -183,19 +177,18 @@ SMBC_stat_ctx(SMBCCTX *context,
TALLOC_FREE(frame); TALLOC_FREE(frame);
return -1; return -1;
} }
st->st_ino = ino; st->st_ino = ino;
setup_stat(context, st, (char *) fname, size, mode); setup_stat(context, st, (char *) fname, size, mode);
st->st_atime = convert_timespec_to_time_t(access_time_ts); st->st_atime = convert_timespec_to_time_t(access_time_ts);
st->st_ctime = convert_timespec_to_time_t(change_time_ts); st->st_ctime = convert_timespec_to_time_t(change_time_ts);
st->st_mtime = convert_timespec_to_time_t(write_time_ts); st->st_mtime = convert_timespec_to_time_t(write_time_ts);
st->st_dev = srv->dev; st->st_dev = srv->dev;
TALLOC_FREE(frame); TALLOC_FREE(frame);
return 0; return 0;
} }
/* /*
@ -221,25 +214,24 @@ SMBC_fstat_ctx(SMBCCTX *context,
struct cli_state *targetcli = NULL; struct cli_state *targetcli = NULL;
SMB_INO_T ino = 0; SMB_INO_T ino = 0;
TALLOC_CTX *frame = talloc_stackframe(); TALLOC_CTX *frame = talloc_stackframe();
if (!context || !context->internal->initialized) { if (!context || !context->internal->initialized) {
errno = EINVAL; errno = EINVAL;
TALLOC_FREE(frame); TALLOC_FREE(frame);
return -1; return -1;
} }
if (!file || !SMBC_dlist_contains(context->internal->files, file)) { if (!file || !SMBC_dlist_contains(context->internal->files, file)) {
errno = EBADF; errno = EBADF;
TALLOC_FREE(frame); TALLOC_FREE(frame);
return -1; return -1;
} }
if (!file->file) { if (!file->file) {
TALLOC_FREE(frame); TALLOC_FREE(frame);
return smbc_getFunctionFstatdir(context)(context, file, st); return smbc_getFunctionFstatdir(context)(context, file, st);
} }
/*d_printf(">>>fstat: parsing %s\n", file->fname);*/ /*d_printf(">>>fstat: parsing %s\n", file->fname);*/
if (SMBC_parse_path(frame, if (SMBC_parse_path(frame,
context, context,
@ -255,7 +247,7 @@ SMBC_fstat_ctx(SMBCCTX *context,
TALLOC_FREE(frame); TALLOC_FREE(frame);
return -1; return -1;
} }
/*d_printf(">>>fstat: resolving %s\n", path);*/ /*d_printf(">>>fstat: resolving %s\n", path);*/
if (!cli_resolve_path(frame, "", context->internal->auth_info, if (!cli_resolve_path(frame, "", context->internal->auth_info,
file->srv->cli, path, file->srv->cli, path,
@ -266,41 +258,37 @@ SMBC_fstat_ctx(SMBCCTX *context,
return -1; return -1;
} }
/*d_printf(">>>fstat: resolved path as %s\n", targetpath);*/ /*d_printf(">>>fstat: resolved path as %s\n", targetpath);*/
if (!cli_qfileinfo(targetcli, file->cli_fd, &mode, &size, if (!cli_qfileinfo(targetcli, file->cli_fd, &mode, &size,
NULL, NULL,
&access_time_ts, &access_time_ts,
&write_time_ts, &write_time_ts,
&change_time_ts, &change_time_ts,
&ino)) { &ino)) {
time_t change_time, access_time, write_time; time_t change_time, access_time, write_time;
if (!NT_STATUS_IS_OK(cli_getattrE(targetcli, file->cli_fd, &mode, &size, if (!NT_STATUS_IS_OK(cli_getattrE(targetcli, file->cli_fd, &mode, &size,
&change_time, &access_time, &write_time))) { &change_time, &access_time, &write_time))) {
errno = EINVAL; errno = EINVAL;
TALLOC_FREE(frame); TALLOC_FREE(frame);
return -1; return -1;
} }
change_time_ts = convert_time_t_to_timespec(change_time); change_time_ts = convert_time_t_to_timespec(change_time);
access_time_ts = convert_time_t_to_timespec(access_time); access_time_ts = convert_time_t_to_timespec(access_time);
write_time_ts = convert_time_t_to_timespec(write_time); write_time_ts = convert_time_t_to_timespec(write_time);
} }
st->st_ino = ino; st->st_ino = ino;
setup_stat(context, st, file->fname, size, mode); setup_stat(context, st, file->fname, size, mode);
st->st_atime = convert_timespec_to_time_t(access_time_ts); st->st_atime = convert_timespec_to_time_t(access_time_ts);
st->st_ctime = convert_timespec_to_time_t(change_time_ts); st->st_ctime = convert_timespec_to_time_t(change_time_ts);
st->st_mtime = convert_timespec_to_time_t(write_time_ts); st->st_mtime = convert_timespec_to_time_t(write_time_ts);
st->st_dev = file->srv->dev; st->st_dev = file->srv->dev;
TALLOC_FREE(frame); TALLOC_FREE(frame);
return 0; return 0;
} }
@ -368,7 +356,6 @@ SMBC_fstatvfs_ctx(SMBCCTX *context,
unsigned long flags = 0; unsigned long flags = 0;
uint32 fs_attrs = 0; uint32 fs_attrs = 0;
struct cli_state *cli = file->srv->cli; struct cli_state *cli = file->srv->cli;
/* Initialize all fields (at least until we actually use them) */ /* Initialize all fields (at least until we actually use them) */
memset(st, 0, sizeof(*st)); memset(st, 0, sizeof(*st));
@ -389,7 +376,7 @@ SMBC_fstatvfs_ctx(SMBCCTX *context,
uint64_t actual_allocation_units; uint64_t actual_allocation_units;
uint64_t sectors_per_allocation_unit; uint64_t sectors_per_allocation_unit;
uint64_t bytes_per_sector; uint64_t bytes_per_sector;
/* Nope. If size data is available... */ /* Nope. If size data is available... */
if (cli_get_fs_full_size_info(cli, if (cli_get_fs_full_size_info(cli,
&total_allocation_units, &total_allocation_units,

File diff suppressed because it is too large Load Diff