The branch, master has been updated via 92e490a lib/util make string_wrappers.h a public header via 56a5b7d s4-param Rename secrets_init() -> randseed_init() via 2c32534 lib/util Use lib/util/util_str.c in common, including strequal() via 86a62ab lib/util Use compiler-checked safe string macros in top level code. via d01f318 s4: fix arguments to safe_strcpy() via b96389d s4-socket: rename allow_access() to socket_allow_access() via 80f1d49 lib/util/charset Use push_string and talloc_strupper/strlower from common code via 7c083ca s3-lib make push_ucs2() static via 2742ec0 Remove strlower_m() and strupper_m() from source4 and common code. via 39081a2 s4-param: use new roles.h via 1d165c0 s3-include: use new roles.h via b105576 libds: added roles.h for server roles via 39ded87 libcli/raw: use a different ifdef than s3 smb.h via cdd802a s4-messaging Rename messaging -> imessaging via 7261a9b s4-libcli Remove resolve_name() as it conflicts with Samba3. via 6293136 s4-torture Remove unused and uncompleated test via eea783e lib/util Move set_socket_options() into common code. via 4d0268d s4-lib/socket Merge updated set_socket_options from Samba3 -> Samba4 via fbea52f lib/util Move more network utility functions from source3 into lib/util via 85fa87e s3-ctdb Rename packet file and files to ctdb_packet via 4c8de5a s4-cluster Rename server_id.node -> vnn to match Samba3 via b0578d8 s4:Remove outdated doc on Samba4 upgrade via 1a5955d selftest: Update README via 17ce9e7 Remove reference to Samba4 LDAP backends via f13b7ec s4-cluster: Remove const from cluster_id_string() via 85eb437 s4:cluster Rename .id to .pid in server_id from 8da8c36 s3: Tune broadcast namequeries for unique names
http://gitweb.samba.org/?p=samba.git;a=shortlog;h=master - Log ----------------------------------------------------------------- commit 92e490ac098ce54ff0db9f9234d4a4057435fe3a Author: Andrew Bartlett <abart...@samba.org> Date: Tue May 3 15:35:18 2011 +1000 lib/util make string_wrappers.h a public header This isn't a very good public header, but util.h includes it, so we don't have much choice in the short term. Andrew Bartlett Autobuild-User: Andrew Bartlett <abart...@samba.org> Autobuild-Date: Tue May 3 08:37:22 CEST 2011 on sn-devel-104 commit 56a5b7d09e0eed66690d87241ee71bca5048e2f8 Author: Andrew Bartlett <abart...@samba.org> Date: Tue May 3 13:24:10 2011 +1000 s4-param Rename secrets_init() -> randseed_init() This only sets up the random number generator callback these days, so use a different database for that. (All secrets data in Samba4 is in secrets.ldb) Andrew Bartlett commit 2c32534d5ba5d009c48f377aa5aea8e77b4fa316 Author: Andrew Bartlett <abart...@samba.org> Date: Tue May 3 12:59:36 2011 +1000 lib/util Use lib/util/util_str.c in common, including strequal() strequal() is now implemented in terms of strcasecmp_m() which is tested in smbtorture and which does not talloc() for ASCII or non-ASCII comparions, and has an ASCII fast-path. Andrew Bartlett commit 86a62ab4345b8567a346587d2ddf575523d0b5f8 Author: Andrew Bartlett <abart...@samba.org> Date: Tue May 3 15:23:19 2011 +1000 lib/util Use compiler-checked safe string macros in top level code. This brings the 'safe' macros to the top level code, and removes duplication of the safe_strcpy() and safe_strcat() functions. Andrew Bartlett commit d01f318179f9c2a0e6730642d21465b6dd69ea9f Author: Andrew Bartlett <abart...@samba.org> Date: Tue May 3 15:33:31 2011 +1000 s4: fix arguments to safe_strcpy() Found by the s3-derivied safe_strcpy() macro. Andrew Bartlett commit b96389d3e17013fd22a64b6ce54478bd912d06b3 Author: Andrew Tridgell <tri...@samba.org> Date: Tue May 3 09:34:06 2011 +1000 s4-socket: rename allow_access() to socket_allow_access() this prevents a symbol collision with s3 Pair-Programmed-With: Andrew Bartlett <abart...@samba.org> commit 80f1d49b61560f326fb55f2df09cc4f30e7a85ea Author: Andrew Bartlett <abart...@samba.org> Date: Tue May 3 12:29:12 2011 +1000 lib/util/charset Use push_string and talloc_strupper/strlower from common code The only caller of push_string() (not to be confused with push_string_check()) in the common code was encode_pw_buffer(), and it didn't use the alignment or STR_UPPER flags. The talloc_strupper() and talloc_strlower() functions are tested in smbtorture, and are next_codepoint() based. Andrew Bartlett commit 7c083caf741d4f12cdf630026e02d9f07a64d0fb Author: Andrew Bartlett <abart...@samba.org> Date: Tue May 3 12:25:29 2011 +1000 s3-lib make push_ucs2() static commit 2742ec0e34c06ded2885aa2607f1c1729a57b034 Author: Andrew Bartlett <abart...@samba.org> Date: Tue May 3 12:16:16 2011 +1000 Remove strlower_m() and strupper_m() from source4 and common code. This function is problematic because a string may expand in size when changed into upper or lower case. This will then push characters off the end of the string in the s3 implementation, or panic in the former s4 implementation. Andrew Bartlett commit 39081a20c5b570430e28866e34ae965c60ee2039 Author: Andrew Tridgell <tri...@samba.org> Date: Mon May 2 12:05:13 2011 +1000 s4-param: use new roles.h Pair-Programmed-With: Andrew Bartlett <abart...@samba.org> commit 1d165c080300c7ecef63164c323b1ec0a37bc012 Author: Andrew Tridgell <tri...@samba.org> Date: Mon May 2 12:05:02 2011 +1000 s3-include: use new roles.h Pair-Programmed-With: Andrew Bartlett <abart...@samba.org> commit b1055763d8b046b42580054e4bc15dc8cb414977 Author: Andrew Tridgell <tri...@samba.org> Date: Mon May 2 12:04:32 2011 +1000 libds: added roles.h for server roles this will allow us to move the server roles in common, which will make it much easier to mix s3/s4 calls in the one C file Pair-Programmed-With: Andrew Bartlett <abart...@samba.org> commit 39ded87b45851894f157d2cc800feb402e650420 Author: Andrew Tridgell <tri...@samba.org> Date: Mon May 2 11:34:57 2011 +1000 libcli/raw: use a different ifdef than s3 smb.h this allows both headers to be included in 1 C file Pair-Programmed-With: Andrew Bartlett <abart...@samba.org> commit cdd802af8319e0b0744d8e727cef75526269ece2 Author: Andrew Bartlett <abart...@samba.org> Date: Tue May 3 10:40:33 2011 +1000 s4-messaging Rename messaging -> imessaging This avoid symbol and structure conflicts between Samba3 and Samba4, and chooses a less generic name. Andrew Bartlett commit 7261a9b9f76d19e6a2179a48e903e2fee4ee64a1 Author: Andrew Bartlett <abart...@samba.org> Date: Mon May 2 16:36:48 2011 +1000 s4-libcli Remove resolve_name() as it conflicts with Samba3. This was just a wrapper around resolve_name_ex(), so just call that instead. Andrew Bartlett commit 62931369ee5ca2dfcab3d59afac56c55a70d49e7 Author: Andrew Bartlett <abart...@samba.org> Date: Mon May 2 16:36:21 2011 +1000 s4-torture Remove unused and uncompleated test commit eea783e04cca45b1d3d9e5bb10556a2c8dc79b86 Author: Andrew Bartlett <abart...@samba.org> Date: Mon May 2 16:23:40 2011 +1000 lib/util Move set_socket_options() into common code. commit 4d0268dce4eb5210ee73efdb6c82aa899b27008f Author: Andrew Bartlett <abart...@samba.org> Date: Mon May 2 16:15:50 2011 +1000 s4-lib/socket Merge updated set_socket_options from Samba3 -> Samba4 commit fbea52f74a80268446f45936a0cf40400aba8565 Author: Andrew Bartlett <abart...@samba.org> Date: Mon May 2 15:23:08 2011 +1000 lib/util Move more network utility functions from source3 into lib/util This will help with the merge of the interfaces layer. Andrew Bartlett commit 85fa87ea82a1dcbd4d0145e417d615ffca116751 Author: Andrew Bartlett <abart...@samba.org> Date: Mon May 2 11:38:41 2011 +1000 s3-ctdb Rename packet file and files to ctdb_packet This avoids a conflicts with the Samba4 packet.c, as these is only used in CTDB Andrew Bartlett commit 4c8de5ab135d7d8462e264f616225122945c7682 Author: Andrew Bartlett <abart...@samba.org> Date: Mon May 2 10:53:18 2011 +1000 s4-cluster Rename server_id.node -> vnn to match Samba3 commit b0578d8a180d76bc7884b116a0081973a73b78cf Author: Andrew Bartlett <abart...@samba.org> Date: Sun May 1 20:53:21 2011 +1000 s4:Remove outdated doc on Samba4 upgrade commit 1a5955deb079c426e47fc1296d4dadba9f7f54c0 Author: Andrew Bartlett <abart...@samba.org> Date: Sun May 1 20:14:03 2011 +1000 selftest: Update README commit 17ce9e7154c8480f5fe77d88866b648f48491b44 Author: Andrew Bartlett <abart...@samba.org> Date: Sun May 1 19:54:59 2011 +1000 Remove reference to Samba4 LDAP backends commit f13b7ec0791dc4f805a66300a540238aa57d3337 Author: Andrew Bartlett <abart...@samba.org> Date: Mon May 2 10:06:56 2011 +1000 s4-cluster: Remove const from cluster_id_string() This allows the caller to talloc_free() this result. Andrew Bartlett commit 85eb4377dbc9e2d25e0ee2e358e785347b09f0a7 Author: Andrew Bartlett <abart...@samba.org> Date: Mon May 2 10:05:46 2011 +1000 s4:cluster Rename .id to .pid in server_id This also changes some DEBUG messages to use cluster_id_string() rather than .id, to isolate them from this and other changes. Andrew Bartlett ----------------------------------------------------------------------- Summary of changes: WHATSNEW4.txt | 7 - lib/util/charset/charset.h | 7 - lib/util/charset/util_unistr.c | 89 +------ lib/util/charset/wscript_build | 17 +- lib/util/system.c | 72 +++++ lib/util/tests/str.c | 10 +- lib/util/util.h | 20 +- lib/util/util_net.c | 316 ++++++++++++++++++++ lib/util/util_net.h | 37 +++ lib/util/util_str.c | 58 ++-- lib/util/wscript_build | 6 +- libcli/echo/tests/echo.c | 6 +- source4/libnet/groupinfo.h => libds/common/roles.h | 58 ++--- libds/common/wscript_build | 1 + nsswitch/wbinfo.c | 1 - selftest/README | 11 +- source3/Makefile.in | 4 +- source3/auth/auth_ntlmssp.c | 2 +- source3/include/{packet.h => ctdb_packet.h} | 36 ++-- source3/include/proto.h | 15 - source3/include/smb.h | 9 +- source3/lib/charcnv.c | 124 +-------- source3/lib/{packet.c => ctdb_packet.c} | 47 ++-- source3/lib/ctdbd_conn.c | 58 ++-- source3/lib/system.c | 71 ----- source3/lib/util_sock.c | 316 -------------------- source3/lib/util_str.c | 147 ++++------ source3/wscript_build | 5 +- source4/auth/auth.h | 10 +- source4/auth/ntlm/auth.c | 4 +- source4/auth/ntlm/auth_simple.c | 2 +- source4/auth/ntlmssp/ntlmssp_server.c | 28 +- source4/auth/pyauth.c | 14 +- source4/auth/samba_server_gensec.c | 2 +- source4/client/client.c | 14 +- source4/cluster/cluster.c | 4 +- source4/cluster/cluster.h | 14 +- source4/cluster/cluster_private.h | 6 +- source4/cluster/local.c | 10 +- source4/dsdb/common/util.c | 2 +- source4/dsdb/repl/drepl_ridalloc.c | 2 +- source4/dsdb/repl/drepl_service.c | 2 +- source4/dsdb/samdb/ldb_modules/ridalloc.c | 6 +- source4/dsdb/samdb/ldb_modules/rootdse.c | 9 +- source4/lib/messaging/irpc.h | 14 +- source4/lib/messaging/messaging.c | 166 ++++++----- source4/lib/messaging/messaging.h | 20 +- source4/lib/messaging/pymessaging.c | 112 ++++---- source4/lib/messaging/tests/irpc.c | 10 +- source4/lib/messaging/tests/messaging.c | 34 +- source4/lib/socket/access.c | 8 +- source4/lib/socket/socket.c | 104 ------- source4/lib/socket/socket.h | 6 +- source4/libcli/finddcs_nbt.c | 6 +- source4/libcli/raw/clisocket.c | 2 +- source4/libcli/raw/smb.h | 6 +- source4/libcli/resolve/resolve.c | 12 - source4/libcli/wbclient/wbclient.c | 2 +- source4/libcli/wbclient/wbclient.h | 2 +- source4/libnet/libnet_site.c | 4 +- source4/librpc/idl/server_id4.idl | 5 +- source4/librpc/rpc/pyrpc_util.c | 4 +- source4/ntvfs/cifs_posix_cli/svfs_util.c | 15 +- source4/ntvfs/common/brlock.c | 6 +- source4/ntvfs/common/brlock.h | 2 +- source4/ntvfs/common/brlock_tdb.c | 10 +- source4/ntvfs/common/notify.c | 18 +- source4/ntvfs/common/opendb.c | 2 +- source4/ntvfs/common/opendb_tdb.c | 12 +- source4/ntvfs/ntvfs.h | 4 +- source4/ntvfs/ntvfs_base.c | 2 +- source4/ntvfs/posix/pvfs_oplock.c | 10 +- source4/ntvfs/posix/pvfs_wait.c | 10 +- source4/ntvfs/simple/svfs_util.c | 15 +- source4/ntvfs/sysdep/sys_lease.c | 2 +- source4/ntvfs/sysdep/sys_lease.h | 8 +- source4/param/loadparm.c | 55 +++-- source4/param/param.h | 8 +- source4/param/secrets.c | 10 +- source4/param/secrets.h | 3 +- source4/param/util.c | 2 +- source4/partition-upgrade.txt | 21 -- source4/rpc_server/dcerpc_server.c | 2 +- source4/rpc_server/dcerpc_server.h | 6 +- source4/smb_server/smb/negprot.c | 7 +- source4/smb_server/smb/receive.c | 9 +- source4/smbd/server.c | 13 +- source4/smbd/service_stream.c | 8 +- source4/smbd/service_stream.h | 2 +- source4/smbd/service_task.c | 6 +- source4/smbd/service_task.h | 2 +- source4/torture/drs/rpc/dssync.c | 5 +- source4/torture/ldap/cldapbench.c | 3 +- source4/torture/libnet/libnet_BecomeDC.c | 5 +- source4/torture/masktest.c | 10 +- source4/torture/nbt/browse.c | 54 ---- source4/torture/nbt/dgram.c | 11 +- source4/torture/nbt/nbt.c | 4 +- source4/torture/winbind/struct_based.c | 1 - source4/utils/ntlm_auth.c | 4 +- source4/wrepl_server/wrepl_scavenging.c | 2 +- 101 files changed, 1082 insertions(+), 1483 deletions(-) copy source4/libnet/groupinfo.h => libds/common/roles.h (50%) rename source3/include/{packet.h => ctdb_packet.h} (58%) rename source3/lib/{packet.c => ctdb_packet.c} (78%) delete mode 100644 source4/partition-upgrade.txt delete mode 100644 source4/torture/nbt/browse.c Changeset truncated at 500 lines: diff --git a/WHATSNEW4.txt b/WHATSNEW4.txt index 6758715..6862caa 100644 --- a/WHATSNEW4.txt +++ b/WHATSNEW4.txt @@ -55,13 +55,6 @@ VFS is backed with an extensive automated test suite. A new scripting interface has been added to Samba 4, allowing Python programs to interface to Samba's internals. -The Samba 4 architecture is based around an LDAP-like database that -can use a range of modular backends. One of the backends supports -standards compliant LDAP servers (including OpenLDAP), and we are -working on modules to map between AD-like behaviours and this backend. -We are aiming for Samba 4 to be powerful frontend to large -directories. - CHANGES SINCE alpha13 ===================== diff --git a/lib/util/charset/charset.h b/lib/util/charset/charset.h index d027daa..e5fd596 100644 --- a/lib/util/charset/charset.h +++ b/lib/util/charset/charset.h @@ -105,11 +105,6 @@ typedef struct smb_iconv_s { struct loadparm_context; struct smb_iconv_handle; -/* replace some string functions with multi-byte - versions */ -#define strlower(s) strlower_m(s) -#define strupper(s) strupper_m(s) - char *strchr_m(const char *s, char c); /** * Calculate the number of units (8 or 16-bit, depending on the @@ -137,8 +132,6 @@ int strcasecmp_m_handle(struct smb_iconv_handle *iconv_handle, const char *s1, const char *s2); int strcasecmp_m(const char *s1, const char *s2); size_t count_chars_m(const char *s, char c); -void strupper_m(char *s); -void strlower_m(char *s); char *strupper_talloc(TALLOC_CTX *ctx, const char *src); char *talloc_strdup_upper(TALLOC_CTX *ctx, const char *src); char *strupper_talloc_n_handle(struct smb_iconv_handle *iconv_handle, diff --git a/lib/util/charset/util_unistr.c b/lib/util/charset/util_unistr.c index a585022..e4ae650 100644 --- a/lib/util/charset/util_unistr.c +++ b/lib/util/charset/util_unistr.c @@ -161,85 +161,6 @@ _PUBLIC_ char *talloc_strdup_upper(TALLOC_CTX *ctx, const char *src) } /** - Convert a string to lower case. -**/ -_PUBLIC_ void strlower_m(char *s) -{ - char *d; - struct smb_iconv_handle *iconv_handle; - - /* this is quite a common operation, so we want it to be - fast. We optimise for the ascii case, knowing that all our - supported multi-byte character sets are ascii-compatible - (ie. they match for the first 128 chars) */ - while (*s && !(((uint8_t)*s) & 0x80)) { - *s = tolower((uint8_t)*s); - s++; - } - - if (!*s) - return; - - iconv_handle = get_iconv_handle(); - - d = s; - - while (*s) { - size_t c_size, c_size2; - codepoint_t c = next_codepoint_handle(iconv_handle, s, &c_size); - c_size2 = push_codepoint_handle(iconv_handle, d, tolower_m(c)); - if (c_size2 > c_size) { - DEBUG(0,("FATAL: codepoint 0x%x (0x%x) expanded from %d to %d bytes in strlower_m\n", - c, tolower_m(c), (int)c_size, (int)c_size2)); - smb_panic("codepoint expansion in strlower_m\n"); - } - s += c_size; - d += c_size2; - } - *d = 0; -} - -/** - Convert a string to UPPER case. -**/ -_PUBLIC_ void strupper_m(char *s) -{ - char *d; - struct smb_iconv_handle *iconv_handle; - - /* this is quite a common operation, so we want it to be - fast. We optimise for the ascii case, knowing that all our - supported multi-byte character sets are ascii-compatible - (ie. they match for the first 128 chars) */ - while (*s && !(((uint8_t)*s) & 0x80)) { - *s = toupper((uint8_t)*s); - s++; - } - - if (!*s) - return; - - iconv_handle = get_iconv_handle(); - - d = s; - - while (*s) { - size_t c_size, c_size2; - codepoint_t c = next_codepoint_handle(iconv_handle, s, &c_size); - c_size2 = push_codepoint_handle(iconv_handle, d, toupper_m(c)); - if (c_size2 > c_size) { - DEBUG(0,("FATAL: codepoint 0x%x (0x%x) expanded from %d to %d bytes in strupper_m\n", - c, toupper_m(c), (int)c_size, (int)c_size2)); - smb_panic("codepoint expansion in strupper_m\n"); - } - s += c_size; - d += c_size2; - } - *d = 0; -} - - -/** Find the number of 'c' chars in a string **/ _PUBLIC_ size_t count_chars_m(const char *s, char c) @@ -273,7 +194,7 @@ _PUBLIC_ size_t count_chars_m(const char *s, char c) * @param dest_len the maximum length in bytes allowed in the * destination. If @p dest_len is -1 then no maximum is used. **/ -static bool push_ascii(void *dest, const char *src, size_t dest_len, int flags, size_t *converted_size) +static bool push_ascii_string(void *dest, const char *src, size_t dest_len, int flags, size_t *converted_size) { size_t src_len; bool ret; @@ -283,7 +204,7 @@ static bool push_ascii(void *dest, const char *src, size_t dest_len, int flags, if (tmpbuf == NULL) { return false; } - ret = push_ascii(dest, tmpbuf, dest_len, flags & ~STR_UPPER, converted_size); + ret = push_ascii_string(dest, tmpbuf, dest_len, flags & ~STR_UPPER, converted_size); talloc_free(tmpbuf); return ret; } @@ -311,7 +232,7 @@ static bool push_ascii(void *dest, const char *src, size_t dest_len, int flags, * @param src_len is the length of the source area in bytes. * @returns the number of bytes occupied by the string in @p src. **/ -static ssize_t pull_ascii(char *dest, const void *src, size_t dest_len, size_t src_len, int flags) +static ssize_t pull_ascii_string(char *dest, const void *src, size_t dest_len, size_t src_len, int flags) { size_t size = 0; @@ -452,7 +373,7 @@ _PUBLIC_ ssize_t push_string(void *dest, const char *src, size_t dest_len, int f { if (flags & STR_ASCII) { size_t size = 0; - if (push_ascii(dest, src, dest_len, flags, &size)) { + if (push_ascii_string(dest, src, dest_len, flags, &size)) { return (ssize_t)size; } else { return (ssize_t)-1; @@ -483,7 +404,7 @@ _PUBLIC_ ssize_t push_string(void *dest, const char *src, size_t dest_len, int f _PUBLIC_ ssize_t pull_string(char *dest, const void *src, size_t dest_len, size_t src_len, int flags) { if (flags & STR_ASCII) { - return pull_ascii(dest, src, dest_len, src_len, flags); + return pull_ascii_string(dest, src, dest_len, src_len, flags); } else if (flags & STR_UNICODE) { return pull_ucs2(dest, src, dest_len, src_len, flags); } else { diff --git a/lib/util/charset/wscript_build b/lib/util/charset/wscript_build index 771ff5d..7623131 100644 --- a/lib/util/charset/wscript_build +++ b/lib/util/charset/wscript_build @@ -1,18 +1,11 @@ #!/usr/bin/env python - -if bld.env._SAMBA_BUILD_ == 4: - bld.SAMBA_SUBSYSTEM('CHARSET', - source='util_unistr.c', - public_deps='CODEPOINTS', - public_headers='charset.h', - ) - bld.SAMBA_SUBSYSTEM('ICONV_WRAPPER', source='iconv.c', public_deps='iconv replace talloc') -bld.SAMBA_SUBSYSTEM('CODEPOINTS', - source='codepoints.c convert_string.c util_str.c util_unistr_w.c charcnv.c pull_push.c', - deps='DYNCONFIG ICONV_WRAPPER' - ) +bld.SAMBA_SUBSYSTEM('CHARSET', + public_headers='charset.h', + source='codepoints.c convert_string.c util_str.c util_unistr_w.c charcnv.c pull_push.c util_unistr.c', + deps='DYNCONFIG ICONV_WRAPPER' + ) diff --git a/lib/util/system.c b/lib/util/system.c index 9bf5de1..17c0553 100644 --- a/lib/util/system.c +++ b/lib/util/system.c @@ -117,3 +117,75 @@ _PUBLIC_ pid_t sys_getpid(void) return mypid; } + + +_PUBLIC_ int sys_getpeereid( int s, uid_t *uid) +{ +#if defined(HAVE_PEERCRED) + struct ucred cred; + socklen_t cred_len = sizeof(struct ucred); + int ret; + + ret = getsockopt(s, SOL_SOCKET, SO_PEERCRED, (void *)&cred, &cred_len); + if (ret != 0) { + return -1; + } + + if (cred_len != sizeof(struct ucred)) { + errno = EINVAL; + return -1; + } + + *uid = cred.uid; + return 0; +#else +#if defined(HAVE_GETPEEREID) + gid_t gid; + return getpeereid(s, uid, &gid); +#endif + errno = ENOSYS; + return -1; +#endif +} + +_PUBLIC_ int sys_getnameinfo(const struct sockaddr *psa, + int salen, + char *host, + size_t hostlen, + char *service, + size_t servlen, + int flags) +{ + /* + * For Solaris we must make sure salen is the + * correct length for the incoming sa_family. + */ + + if (salen == sizeof(struct sockaddr_storage)) { + salen = sizeof(struct sockaddr_in); +#if defined(HAVE_IPV6) + if (psa->sa_family == AF_INET6) { + salen = sizeof(struct sockaddr_in6); + } +#endif + } + return getnameinfo(psa, salen, host, hostlen, service, servlen, flags); +} + +_PUBLIC_ int sys_connect(int fd, const struct sockaddr * addr) +{ + socklen_t salen = (socklen_t)-1; + + if (addr->sa_family == AF_INET) { + salen = sizeof(struct sockaddr_in); + } else if (addr->sa_family == AF_UNIX) { + salen = sizeof(struct sockaddr_un); + } +#if defined(HAVE_IPV6) + else if (addr->sa_family == AF_INET6) { + salen = sizeof(struct sockaddr_in6); + } +#endif + + return connect(fd, addr, salen); +} diff --git a/lib/util/tests/str.c b/lib/util/tests/str.c index 6b38fea..b4c45e3 100644 --- a/lib/util/tests/str.c +++ b/lib/util/tests/str.c @@ -25,7 +25,7 @@ static bool test_string_sub_simple(struct torture_context *tctx) { char tmp[100]; - safe_strcpy(tmp, "foobar", sizeof(tmp)); + safe_strcpy(tmp, "foobar", sizeof(tmp)-1); string_sub(tmp, "foo", "bar", sizeof(tmp)); torture_assert_str_equal(tctx, tmp, "barbar", "invalid sub"); return true; @@ -34,7 +34,7 @@ static bool test_string_sub_simple(struct torture_context *tctx) static bool test_string_sub_multiple(struct torture_context *tctx) { char tmp[100]; - safe_strcpy(tmp, "fooblafoo", sizeof(tmp)); + safe_strcpy(tmp, "fooblafoo", sizeof(tmp)-1); string_sub(tmp, "foo", "bar", sizeof(tmp)); torture_assert_str_equal(tctx, tmp, "barblabar", "invalid sub"); return true; @@ -43,7 +43,7 @@ static bool test_string_sub_multiple(struct torture_context *tctx) static bool test_string_sub_longer(struct torture_context *tctx) { char tmp[100]; - safe_strcpy(tmp, "foobla", sizeof(tmp)); + safe_strcpy(tmp, "foobla", sizeof(tmp)-1); string_sub(tmp, "foo", "blie", sizeof(tmp)); torture_assert_str_equal(tctx, tmp, "bliebla", "invalid sub"); return true; @@ -52,7 +52,7 @@ static bool test_string_sub_longer(struct torture_context *tctx) static bool test_string_sub_shorter(struct torture_context *tctx) { char tmp[100]; - safe_strcpy(tmp, "foobla", sizeof(tmp)); + safe_strcpy(tmp, "foobla", sizeof(tmp)-1); string_sub(tmp, "foo", "bl", sizeof(tmp)); torture_assert_str_equal(tctx, tmp, "blbla", "invalid sub"); return true; @@ -61,7 +61,7 @@ static bool test_string_sub_shorter(struct torture_context *tctx) static bool test_string_sub_special_char(struct torture_context *tctx) { char tmp[100]; - safe_strcpy(tmp, "foobla", sizeof(tmp)); + safe_strcpy(tmp, "foobla", sizeof(tmp)-1); string_sub(tmp, "foo", "%b;l", sizeof(tmp)); torture_assert_str_equal(tctx, tmp, "_b_lbla", "invalid sub"); return true; diff --git a/lib/util/util.h b/lib/util/util.h index 8dffece..45f1b9c 100644 --- a/lib/util/util.h +++ b/lib/util/util.h @@ -62,6 +62,8 @@ extern const char *panic_action; #include "lib/util/memory.h" +#include "lib/util/string_wrappers.h" + /** * Write backtrace to debug log */ @@ -131,8 +133,20 @@ _PUBLIC_ pid_t sys_fork(void); **/ _PUBLIC_ pid_t sys_getpid(void); -/* The following definitions come from lib/util/genrand.c */ +_PUBLIC_ int sys_getpeereid( int s, uid_t *uid); + +struct sockaddr; +_PUBLIC_ int sys_getnameinfo(const struct sockaddr *psa, + int salen, + char *host, + size_t hostlen, + char *service, + size_t servlen, + int flags); +_PUBLIC_ int sys_connect(int fd, const struct sockaddr * addr); + +/* The following definitions come from lib/util/genrand.c */ /** Copy any user given reseed data. **/ @@ -236,13 +250,13 @@ _PUBLIC_ _PURE_ size_t count_chars(const char *s, char c); Safe string copy into a known length string. maxlength does not include the terminating zero. **/ -_PUBLIC_ char *safe_strcpy(char *dest,const char *src, size_t maxlength); +_PUBLIC_ char *safe_strcpy_fn(char *dest,const char *src, size_t maxlength); /** Safe string cat into a string. maxlength does not include the terminating zero. **/ -_PUBLIC_ char *safe_strcat(char *dest, const char *src, size_t maxlength); +_PUBLIC_ char *safe_strcat_fn(char *dest, const char *src, size_t maxlength); /** Routine to get hex characters and turn them into a 16 byte array. diff --git a/lib/util/util_net.c b/lib/util/util_net.c index 9c8f5c6..a8a05da 100644 --- a/lib/util/util_net.c +++ b/lib/util/util_net.c @@ -540,3 +540,319 @@ void set_sockaddr_port(struct sockaddr *psa, uint16_t port) } +/**************************************************************************** + Get a port number in host byte order from a sockaddr_storage. +****************************************************************************/ + +uint16_t get_sockaddr_port(const struct sockaddr_storage *pss) +{ + uint16_t port = 0; + + if (pss->ss_family != AF_INET) { +#if defined(HAVE_IPV6) + /* IPv6 */ + const struct sockaddr_in6 *sa6 = + (const struct sockaddr_in6 *)pss; + port = ntohs(sa6->sin6_port); +#endif + } else { + const struct sockaddr_in *sa = + (const struct sockaddr_in *)pss; + port = ntohs(sa->sin_port); + } + return port; +} + +/**************************************************************************** + Print out an IPv4 or IPv6 address from a struct sockaddr_storage. +****************************************************************************/ + +char *print_sockaddr_len(char *dest, + size_t destlen, + const struct sockaddr *psa, + socklen_t psalen) +{ + if (destlen > 0) { + dest[0] = '\0'; + } + (void)sys_getnameinfo(psa, + psalen, + dest, destlen, + NULL, 0, + NI_NUMERICHOST); + return dest; +} + +/**************************************************************************** + Print out an IPv4 or IPv6 address from a struct sockaddr_storage. +****************************************************************************/ + +char *print_sockaddr(char *dest, + size_t destlen, + const struct sockaddr_storage *psa) +{ + return print_sockaddr_len(dest, destlen, (struct sockaddr *)psa, + sizeof(struct sockaddr_storage)); +} + +/**************************************************************************** + Print out a canonical IPv4 or IPv6 address from a struct sockaddr_storage. +****************************************************************************/ + +char *print_canonical_sockaddr(TALLOC_CTX *ctx, + const struct sockaddr_storage *pss) +{ + char addr[INET6_ADDRSTRLEN]; + char *dest = NULL; + int ret; + + /* Linux getnameinfo() man pages says port is unitialized if + service name is NULL. */ + + ret = sys_getnameinfo((const struct sockaddr *)pss, + sizeof(struct sockaddr_storage), + addr, sizeof(addr), + NULL, 0, + NI_NUMERICHOST); + if (ret != 0) { + return NULL; + } + + if (pss->ss_family != AF_INET) { +#if defined(HAVE_IPV6) + dest = talloc_asprintf(ctx, "[%s]", addr); +#else + return NULL; +#endif + } else { + dest = talloc_asprintf(ctx, "%s", addr); + } + + return dest; +} + +/**************************************************************************** + Return the port number we've bound to on a socket. +****************************************************************************/ + +int get_socket_port(int fd) +{ + struct sockaddr_storage sa; + socklen_t length = sizeof(sa); + + if (fd == -1) { + return -1; + } + + if (getsockname(fd, (struct sockaddr *)&sa, &length) < 0) { + int level = (errno == ENOTCONN) ? 2 : 0; -- Samba Shared Repository