diff options
author | Andrew Bartlett <abartlet@samba.org> | 2003-03-22 13:06:52 +0000 |
---|---|---|
committer | Andrew Bartlett <abartlet@samba.org> | 2003-03-22 13:06:52 +0000 |
commit | a38e5e6850220fc1a0afa5097359c05458e1ae41 (patch) | |
tree | b75cac324259de694c3bc3f7ca18ab664a4fa856 /source3/smbd | |
parent | b508fdfc231b73d671b0c283e54532b9f14d7db6 (diff) | |
download | samba-a38e5e6850220fc1a0afa5097359c05458e1ae41.tar.gz samba-a38e5e6850220fc1a0afa5097359c05458e1ae41.tar.bz2 samba-a38e5e6850220fc1a0afa5097359c05458e1ae41.zip |
Small clenaup patches:
- safe_string.h - don't assume that __FUNCTION__ is available
- process.c - use new workaround from safe_string.h for the same
- util.c - Show how many bytes we smb_panic()ed trying to smb_xmalloc()
- gencache.c - Keep valgrind quiet by always null terminating.
- clistr.c - Add copyright
- srvstr.h - move srvstr_push into a .c file again, as a real function.
- srvstr.c - revive, with 'safe' checked srvstr_push
- loadparm.c - set a default for the display charset.
Andrew Bartlett
(This used to be commit a7eba37aadeb0b04cb1bd89deddb58be8aba825c)
Diffstat (limited to 'source3/smbd')
-rw-r--r-- | source3/smbd/connection.c | 23 | ||||
-rw-r--r-- | source3/smbd/process.c | 8 | ||||
-rw-r--r-- | source3/smbd/srvstr.c | 44 |
3 files changed, 58 insertions, 17 deletions
diff --git a/source3/smbd/connection.c b/source3/smbd/connection.c index a7636e889e..ff6974cade 100644 --- a/source3/smbd/connection.c +++ b/source3/smbd/connection.c @@ -35,15 +35,12 @@ TDB_CONTEXT *conn_tdb_ctx(void) return tdb; } -static void make_conn_key(connection_struct *conn, const char *name, TDB_DATA *pkbuf, struct connections_key *pkey) +static void make_conn_key(connection_struct *conn, const char *name, TDB_DATA *pkbuf, fstring tdb_key) { - ZERO_STRUCTP(pkey); - pkey->pid = sys_getpid(); - pkey->cnum = conn?conn->cnum:-1; - fstrcpy(pkey->name, name); + snprintf(tdb_key, sizeof(fstring), "CONN/%lu/%ld", sys_getpid(), conn?conn->cnum:-1); - pkbuf->dptr = (char *)pkey; - pkbuf->dsize = sizeof(*pkey); + pkbuf->dptr = tdb_key; + pkbuf->dsize = strlen(tdb_key)+1; } /**************************************************************************** @@ -52,7 +49,7 @@ static void make_conn_key(connection_struct *conn, const char *name, TDB_DATA *p BOOL yield_connection(connection_struct *conn, const char *name) { - struct connections_key key; + fstring tdb_key; TDB_DATA kbuf; if (!tdb) @@ -60,7 +57,7 @@ BOOL yield_connection(connection_struct *conn, const char *name) DEBUG(3,("Yielding connection to %s\n",name)); - make_conn_key(conn, name, &kbuf, &key); + make_conn_key(conn, name, &kbuf, tdb_key); if (tdb_delete(tdb, kbuf) != 0) { int dbg_lvl = (!conn && (tdb_error(tdb) == TDB_ERR_NOEXIST)) ? 3 : 0; @@ -171,14 +168,14 @@ BOOL claim_connection(connection_struct *conn, const char *name,int max_connecti if (conn) { crec.uid = conn->uid; crec.gid = conn->gid; - StrnCpy(crec.name, - lp_servicename(SNUM(conn)),sizeof(crec.name)-1); + safe_strcpy(crec.name, + lp_servicename(SNUM(conn)),sizeof(crec.name)-1); } crec.start = time(NULL); crec.bcast_msg_flags = msg_flags; - StrnCpy(crec.machine,get_remote_machine_name(),sizeof(crec.machine)-1); - StrnCpy(crec.addr,conn?conn->client_address:client_addr(),sizeof(crec.addr)-1); + safe_strcpy(crec.machine,get_remote_machine_name(),sizeof(crec.machine)-1); + safe_strcpy(crec.addr,conn?conn->client_address:client_addr(),sizeof(crec.addr)-1); dbuf.dptr = (char *)&crec; dbuf.dsize = sizeof(crec); diff --git a/source3/smbd/process.c b/source3/smbd/process.c index c3fbc22e94..16ef30c46c 100644 --- a/source3/smbd/process.c +++ b/source3/smbd/process.c @@ -1256,8 +1256,8 @@ void smbd_process(void) if ((InBuffer == NULL) || (OutBuffer == NULL)) return; - clobber_region(__FUNCTION__, __LINE__, InBuffer, total_buffer_size); - clobber_region(__FUNCTION__, __LINE__, OutBuffer, total_buffer_size); + clobber_region(SAFE_STRING_FUNCTION_NAME, SAFE_STRING_LINE, InBuffer, total_buffer_size); + clobber_region(SAFE_STRING_FUNCTION_NAME, SAFE_STRING_LINE, OutBuffer, total_buffer_size); max_recv = MIN(lp_maxxmit(),BUFFER_SIZE); @@ -1282,7 +1282,7 @@ void smbd_process(void) num_smbs = 0; /* Reset smb counter. */ } - clobber_region(__FUNCTION__, __LINE__, InBuffer, total_buffer_size); + clobber_region(SAFE_STRING_FUNCTION_NAME, SAFE_STRING_LINE, InBuffer, total_buffer_size); while (!receive_message_or_smb(InBuffer,BUFFER_SIZE+LARGE_WRITEX_HDR_SIZE,select_timeout)) { if(!timeout_processing( deadtime, &select_timeout, &last_timeout_processing_time)) @@ -1301,7 +1301,7 @@ void smbd_process(void) */ num_echos = smb_echo_count; - clobber_region(__FUNCTION__, __LINE__, OutBuffer, total_buffer_size); + clobber_region(SAFE_STRING_FUNCTION_NAME, SAFE_STRING_LINE, OutBuffer, total_buffer_size); process_smb(InBuffer, OutBuffer); diff --git a/source3/smbd/srvstr.c b/source3/smbd/srvstr.c new file mode 100644 index 0000000000..409fd30a67 --- /dev/null +++ b/source3/smbd/srvstr.c @@ -0,0 +1,44 @@ +/* + Unix SMB/CIFS implementation. + server specific string routines + Copyright (C) Andrew Tridgell 2001 + Copyright (C) Andrew Bartlett <abartlet@samba.org> 2003 + + 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 + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +*/ + +#include "includes.h" +extern int max_send; + +/* Make sure we can't write a string past the end of the buffer */ + +size_t srvstr_push_fn(const char *function, unsigned int line, + const char *base_ptr, void *dest, + const char *src, int dest_len, int flags) +{ + size_t buf_used = PTR_DIFF(dest, base_ptr); + if (dest_len == -1) { + if (((ptrdiff_t)dest < (ptrdiff_t)base_ptr) || (buf_used > (size_t)max_send)) { +#if 0 + DEBUG(0, ("Pushing string of 'unlimited' length into non-SMB buffer!\n")); +#endif + return push_string_fn(function, line, base_ptr, dest, src, -1, flags); + } + return push_string_fn(function, line, base_ptr, dest, src, max_send - buf_used, flags); + } + + /* 'normal' push into size-specified buffer */ + return push_string_fn(function, line, base_ptr, dest, src, dest_len, flags); +} |