From e5a951325a6cac8567af3a66de6d2df577508ae4 Mon Sep 17 00:00:00 2001 From: "Gerald (Jerry) Carter" Date: Wed, 10 Oct 2007 15:34:30 -0500 Subject: [GLUE] Rsync SAMBA_3_2_0 SVN r25598 in order to create the v3-2-test branch. (This used to be commit 5c6c8e1fe93f340005110a7833946191659d88ab) --- source3/lib/dbwrap_tdb.c | 3 +- source3/lib/dummysmbd.c | 20 --- source3/lib/launchd.c | 241 ------------------------------- source3/lib/replace/system/getaddrinfo.h | 0 source3/lib/substitute.c | 18 +++ source3/lib/tdb/common/tdb_private.h | 4 + source3/lib/util.c | 48 ++---- source3/lib/util_sock.c | 45 +----- source3/lib/util_str.c | 1 - 9 files changed, 40 insertions(+), 340 deletions(-) delete mode 100644 source3/lib/launchd.c create mode 100644 source3/lib/replace/system/getaddrinfo.h (limited to 'source3/lib') diff --git a/source3/lib/dbwrap_tdb.c b/source3/lib/dbwrap_tdb.c index be691dc7ec..24462d6789 100644 --- a/source3/lib/dbwrap_tdb.c +++ b/source3/lib/dbwrap_tdb.c @@ -72,8 +72,7 @@ static struct db_record *db_tdb_fetch_locked(struct db_context *db, result->delete_rec = db_tdb_delete; if (DEBUGLEVEL > 10) { - char *keystr = hex_encode(NULL, (unsigned char *)key.dptr, - key.dsize); + char *keystr = hex_encode(NULL, key.dptr, key.dsize); DEBUG(10, (DEBUGLEVEL > 10 ? "Locking key %s\n" : "Locking key %20s\n", keystr)); diff --git a/source3/lib/dummysmbd.c b/source3/lib/dummysmbd.c index cdda964f66..38bec5270d 100644 --- a/source3/lib/dummysmbd.c +++ b/source3/lib/dummysmbd.c @@ -47,23 +47,3 @@ NTSTATUS can_delete_directory(struct connection_struct *conn, return NT_STATUS_OK; } -NTSTATUS srv_decrypt_buffer(char *buf) -{ - return NT_STATUS_OK; -} - -NTSTATUS srv_encrypt_buffer(char *buffer, char **buf_out) -{ - *buf_out = buffer; - return NT_STATUS_OK; -} - -void srv_free_enc_buffer(char *buf) -{ - ; -} - -BOOL srv_encryption_on(void) -{ - return False; -} diff --git a/source3/lib/launchd.c b/source3/lib/launchd.c deleted file mode 100644 index 97480f9828..0000000000 --- a/source3/lib/launchd.c +++ /dev/null @@ -1,241 +0,0 @@ -/* - Unix SMB/CIFS implementation. - Launchd integration wrapper API - - Copyright (C) 2007 James Peach - - 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 3 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, see . -*/ - -#include "includes.h" -#include "smb_launchd.h" - -/* launchd source code and documentation is available here: - * http://launchd.macosforge.org/ - */ - -#if defined(WITH_LAUNCHD_SUPPORT) - -#include -#include - -typedef void (*launchd_iterator)(launch_data_t, const char*, void*); - -#define LAUNCHD_TRACE_LEVEL 10 - - void smb_launchd_checkout(struct smb_launch_info *linfo) -{ - talloc_free(linfo->socket_list); -} - -static void pull_launch_sockets(launch_data_t key, - const char *name, - struct smb_launch_info *linfo) -{ - launch_data_type_t type; - - type = launch_data_get_type(key); - DEBUG(LAUNCHD_TRACE_LEVEL, - ("Searching item name='%s' type=%d for sockets\n", - name ? name : "", (int)type)); - - switch (type) { - case LAUNCH_DATA_FD: - if (!linfo->socket_list) { - /* We are counting the number of sockets. */ - linfo->num_sockets++; - } else { - /* We are collecting the socket fds. */ - int fd = launch_data_get_fd(key); - - linfo->socket_list[linfo->num_sockets] = fd; - linfo->num_sockets++; - DEBUG(LAUNCHD_TRACE_LEVEL, - ("Added fd=%d to launchd set\n", fd)); - } - return; - case LAUNCH_DATA_ARRAY: - { - int i; - launch_data_t item; - - for (i = 0; i < launch_data_array_get_count(key); ++i) { - item = launch_data_array_get_index(key, i); - pull_launch_sockets(item, name, linfo); - } - return; - } - case LAUNCH_DATA_DICTIONARY: - launch_data_dict_iterate(key, - (launchd_iterator)pull_launch_sockets, linfo); - return; - default: - return; - } -} - - BOOL smb_launchd_checkin_names(struct smb_launch_info *linfo, ...) -{ - launch_data_t msg; - launch_data_t resp; - launch_data_t item; - BOOL is_launchd = False; - - ZERO_STRUCTP(linfo); - - msg = launch_data_new_string(LAUNCH_KEY_CHECKIN); - resp = launch_msg(msg); - if (resp == NULL) { - /* IPC to launchd failed. */ - launch_data_free(msg); - return is_launchd; - } - - if (launch_data_get_type(resp) == LAUNCH_DATA_ERRNO) { - errno = launch_data_get_errno(resp); - goto done; - } - - /* At this point, we know we are running under launchd. */ - linfo->idle_timeout_secs = 600; - is_launchd = True; - - if ((item = launch_data_dict_lookup(resp, LAUNCH_JOBKEY_TIMEOUT))) { - linfo->idle_timeout_secs = launch_data_get_integer(item); - } - - if ((item = launch_data_dict_lookup(resp, LAUNCH_JOBKEY_SOCKETS))) { - int count = 0; - const char * sockname = NULL; - launch_data_t sockdata; - va_list args; - - /* Figure out the maximum number of sockets. */ - va_start(args, linfo); - while ((sockname = va_arg(args, const char *))) { - ++count; - } - va_end(args); - - DEBUG(LAUNCHD_TRACE_LEVEL, ("Found %d launchd sockets\n", - linfo->num_sockets)); - - if (launch_data_dict_get_count(item) < count) { - DEBUG(0, ("%d launchd sockets requested, " - "but only %d are available\n", - count, launch_data_dict_get_count(item))); - } - - linfo->socket_list = TALLOC_ARRAY(NULL, int, count); - if (linfo->socket_list == NULL) { - goto done; - } - - linfo->num_sockets = 0; - va_start(args, linfo); - while ((sockname = va_arg(args, const char *))) { - sockdata = launch_data_dict_lookup(item, sockname); - - pull_launch_sockets(sockdata, sockname, linfo); - DEBUG(LAUNCHD_TRACE_LEVEL, - ("Added launchd socket \"%s\"\n", sockname)); - } - - SMB_ASSERT(count >= linfo->num_sockets); - } - -done: - launch_data_free(msg); - launch_data_free(resp); - return is_launchd; -} - - BOOL smb_launchd_checkin(struct smb_launch_info *linfo) -{ - launch_data_t msg; - launch_data_t resp; - launch_data_t item; - BOOL is_launchd = False; - - ZERO_STRUCTP(linfo); - - msg = launch_data_new_string(LAUNCH_KEY_CHECKIN); - resp = launch_msg(msg); - if (resp == NULL) { - /* IPC to launchd failed. */ - launch_data_free(msg); - return is_launchd; - } - - if (launch_data_get_type(resp) == LAUNCH_DATA_ERRNO) { - errno = launch_data_get_errno(resp); - goto done; - } - - /* At this point, we know we are running under launchd. */ - linfo->idle_timeout_secs = 600; - is_launchd = True; - - if ((item = launch_data_dict_lookup(resp, LAUNCH_JOBKEY_TIMEOUT))) { - linfo->idle_timeout_secs = launch_data_get_integer(item); - } - - if ((item = launch_data_dict_lookup(resp, LAUNCH_JOBKEY_SOCKETS))) { - int count; - - pull_launch_sockets(item, NULL, linfo); - DEBUG(LAUNCHD_TRACE_LEVEL, ("Found %d launchd sockets\n", - linfo->num_sockets)); - - count = linfo->num_sockets; - linfo->socket_list = TALLOC_ARRAY(NULL, int, count); - if (linfo->socket_list == NULL) { - goto done; - } - - linfo->num_sockets = 0; - pull_launch_sockets(item, NULL, linfo); - - DEBUG(LAUNCHD_TRACE_LEVEL, ("Added %d launchd sockets\n", - linfo->num_sockets)); - - SMB_ASSERT(count == linfo->num_sockets); - } - -done: - launch_data_free(msg); - launch_data_free(resp); - return is_launchd; -} - -#else /* defined(WITH_LAUNCHD_SUPPORT) */ - - BOOL smb_launchd_checkin(struct smb_launch_info * UNUSED(linfo)) -{ - ZERO_STRUCTP(linfo); - return False; -} - - BOOL smb_launchd_checkin_names(struct smb_launch_info * UNUSED(linfo), ...) -{ - ZERO_STRUCTP(linfo); - return False; -} - - void smb_launchd_checkout(struct smb_launch_info * UNUSED(linfo)) -{ -} - -#endif /* defined(WITH_LAUNCHD_SUPPORT) */ - diff --git a/source3/lib/replace/system/getaddrinfo.h b/source3/lib/replace/system/getaddrinfo.h new file mode 100644 index 0000000000..e69de29bb2 diff --git a/source3/lib/substitute.c b/source3/lib/substitute.c index 80233c5080..57df02f721 100644 --- a/source3/lib/substitute.c +++ b/source3/lib/substitute.c @@ -767,3 +767,21 @@ void standard_sub_advanced(const char *servicename, const char *user, SAFE_FREE( s ); } } + +/**************************************************************************** + * Do some standard substitutions in a string. + * ****************************************************************************/ + +void standard_sub_conn(connection_struct *conn, char *str, size_t len) +{ + char *s; + + s = alloc_sub_advanced(lp_servicename(SNUM(conn)), conn->user, conn->connectpath, + conn->gid, smb_user_name, "", str); + + if ( s ) { + strncpy( str, s, len ); + SAFE_FREE( s ); + } +} + diff --git a/source3/lib/tdb/common/tdb_private.h b/source3/lib/tdb/common/tdb_private.h index d2f2c23d72..032b0ca638 100644 --- a/source3/lib/tdb/common/tdb_private.h +++ b/source3/lib/tdb/common/tdb_private.h @@ -37,6 +37,10 @@ typedef uint32_t tdb_len_t; typedef uint32_t tdb_off_t; +#ifndef offsetof +#define offsetof(t,f) ((unsigned int)&((t *)0)->f) +#endif + #define TDB_MAGIC_FOOD "TDB file\n" #define TDB_VERSION (0x26011967 + 6) #define TDB_MAGIC (0x26011999U) diff --git a/source3/lib/util.c b/source3/lib/util.c index b98441ea53..adbebb04d4 100644 --- a/source3/lib/util.c +++ b/source3/lib/util.c @@ -514,51 +514,32 @@ void show_msg(char *buf) dump_data(10, (uint8 *)smb_buf(buf), bcc); } -/******************************************************************* - Set the length and marker of an encrypted smb packet. -********************************************************************/ - -void smb_set_enclen(char *buf,int len,uint16 enc_ctx_num) -{ - _smb_setlen(buf,len); - - SCVAL(buf,4,0xFF); - SCVAL(buf,5,'E'); - SSVAL(buf,6,enc_ctx_num); -} - /******************************************************************* Set the length and marker of an smb packet. ********************************************************************/ -void smb_setlen(const char *frombuf, char *buf, int len) +void smb_setlen(char *buf,int len) { _smb_setlen(buf,len); - if (frombuf) { - if (buf != frombuf) { - memcpy(buf+4, frombuf+4, 4); - } - } else { - SCVAL(buf,4,0xFF); - SCVAL(buf,5,'S'); - SCVAL(buf,6,'M'); - SCVAL(buf,7,'B'); - } + SCVAL(buf,4,0xFF); + SCVAL(buf,5,'S'); + SCVAL(buf,6,'M'); + SCVAL(buf,7,'B'); } /******************************************************************* Setup the word count and byte count for a smb message. ********************************************************************/ -int set_message(const char *frombuf, char *buf,int num_words,int num_bytes,BOOL zero) +int set_message(char *buf,int num_words,int num_bytes,BOOL zero) { if (zero && (num_words || num_bytes)) { memset(buf + smb_size,'\0',num_words*2 + num_bytes); } SCVAL(buf,smb_wct,num_words); SSVAL(buf,smb_vwv + num_words*SIZEOFWORD,num_bytes); - smb_setlen(frombuf, buf,smb_size + num_words*2 + num_bytes - 4); + smb_setlen(buf,smb_size + num_words*2 + num_bytes - 4); return (smb_size + num_words*2 + num_bytes); } @@ -566,11 +547,11 @@ int set_message(const char *frombuf, char *buf,int num_words,int num_bytes,BOOL Setup only the byte count for a smb message. ********************************************************************/ -int set_message_bcc(const char *frombuf, char *buf,int num_bytes) +int set_message_bcc(char *buf,int num_bytes) { int num_words = CVAL(buf,smb_wct); SSVAL(buf,smb_vwv + num_words*SIZEOFWORD,num_bytes); - smb_setlen(frombuf, buf,smb_size + num_words*2 + num_bytes - 4); + smb_setlen(buf,smb_size + num_words*2 + num_bytes - 4); return (smb_size + num_words*2 + num_bytes); } @@ -579,11 +560,9 @@ int set_message_bcc(const char *frombuf, char *buf,int num_bytes) message as a marker. ********************************************************************/ -int set_message_end(const char *frombuf, void *outbuf,void *end_ptr) +int set_message_end(void *outbuf,void *end_ptr) { - return set_message_bcc(frombuf, - (char *)outbuf, - PTR_DIFF(end_ptr,smb_buf((char *)outbuf))); + return set_message_bcc((char *)outbuf,PTR_DIFF(end_ptr,smb_buf((char *)outbuf))); } /******************************************************************* @@ -603,7 +582,7 @@ ssize_t message_push_blob(uint8 **outbuf, DATA_BLOB blob) *outbuf = tmp; memcpy(tmp + smb_len(tmp) + 4, blob.data, blob.length); - set_message_bcc(NULL, (char *)tmp, smb_buflen(tmp) + blob.length); + set_message_bcc((char *)tmp, smb_buflen(tmp) + blob.length); return blob.length; } @@ -2296,8 +2275,9 @@ void print_asc(int level, const unsigned char *buf,int len) DEBUG(level,("%c", isprint(buf[i])?buf[i]:'.')); } -void dump_data(int level, const unsigned char *buf,int len) +void dump_data(int level, const unsigned char *buf1,int len) { + const unsigned char *buf = (const unsigned char *)buf1; int i=0; if (len<=0) return; diff --git a/source3/lib/util_sock.c b/source3/lib/util_sock.c index d061d73a81..1508ddfce3 100644 --- a/source3/lib/util_sock.c +++ b/source3/lib/util_sock.c @@ -815,19 +815,6 @@ BOOL receive_smb(int fd, char *buffer, unsigned int timeout) return False; } - if (srv_encryption_on()) { - NTSTATUS status = srv_decrypt_buffer(buffer); - if (!NT_STATUS_IS_OK(status)) { - DEBUG(0, ("receive_smb: SMB decryption failed " - "on incoming packet! Error %s\n", - nt_errstr(status) )); - if (smb_read_error == 0) { - smb_read_error = READ_BAD_DECRYPT; - } - return False; - } - } - /* Check the incoming SMB signature. */ if (!srv_check_sign_mac(buffer, True)) { DEBUG(0, ("receive_smb: SMB Signature verification " @@ -852,19 +839,6 @@ ssize_t receive_smb_talloc(TALLOC_CTX *mem_ctx, int fd, char **buffer, return -1; } - if (srv_encryption_on()) { - NTSTATUS status = srv_decrypt_buffer(*buffer); - if (!NT_STATUS_IS_OK(status)) { - DEBUG(0, ("receive_smb: SMB decryption failed on " - "incoming packet! Error %s\n", - nt_errstr(status) )); - if (smb_read_error == 0) { - smb_read_error = READ_BAD_DECRYPT; - } - return -1; - } - } - /* Check the incoming SMB signature. */ if (!srv_check_sign_mac(*buffer, True)) { DEBUG(0, ("receive_smb: SMB Signature verification failed on " @@ -887,35 +861,22 @@ BOOL send_smb(int fd, char *buffer) size_t len; size_t nwritten=0; ssize_t ret; - char *buf_out = buffer; /* Sign the outgoing packet if required. */ - srv_calculate_sign_mac(buf_out); - - if (srv_encryption_on()) { - NTSTATUS status = srv_encrypt_buffer(buffer, &buf_out); - if (!NT_STATUS_IS_OK(status)) { - DEBUG(0, ("send_smb: SMB encryption failed " - "on outgoing packet! Error %s\n", - nt_errstr(status) )); - return False; - } - } + srv_calculate_sign_mac(buffer); - len = smb_len(buf_out) + 4; + len = smb_len(buffer) + 4; while (nwritten < len) { - ret = write_data(fd,buf_out+nwritten,len - nwritten); + ret = write_data(fd,buffer+nwritten,len - nwritten); if (ret <= 0) { DEBUG(0,("Error writing %d bytes to client. %d. (%s)\n", (int)len,(int)ret, strerror(errno) )); - srv_free_enc_buffer(buf_out); return False; } nwritten += ret; } - srv_free_enc_buffer(buf_out); return True; } diff --git a/source3/lib/util_str.c b/source3/lib/util_str.c index db5775b79f..fbd9c1ca6d 100644 --- a/source3/lib/util_str.c +++ b/source3/lib/util_str.c @@ -447,7 +447,6 @@ BOOL strisnormal(const char *s, int case_default) String replace. NOTE: oldc and newc must be 7 bit characters **/ - void string_replace( char *s, char oldc, char newc ) { char *p; -- cgit