Skip to content

Commit

Permalink
lib/util: remove extra safe_string.h file
Browse files Browse the repository at this point in the history
lib/util/safe_string.h is similar to source3/include/safe_string.h, but
the former has fewer checks. It is missing bcopy, strcasecmp, and
strncasecmp.

Add the missing elements to lib/util/safe_string.h remove the other
safe_string.h which is in the source3-specific path. To accomodate
existing uses of str(n?)casecmp, add #undef lines to source files where
they are used.

Signed-off-by: Matthew DeVore <[email protected]>
Reviewed-by: David Mulder <[email protected]>
Reviewed-by: Jeremy Allison <[email protected]>

Autobuild-User(master): Jeremy Allison <[email protected]>
Autobuild-Date(master): Fri Aug 28 02:18:40 UTC 2020 on sn-devel-184
  • Loading branch information
matvore authored and jrasamba committed Aug 28, 2020
1 parent c2ac923 commit 232054c
Show file tree
Hide file tree
Showing 90 changed files with 195 additions and 67 deletions.
2 changes: 2 additions & 0 deletions auth/credentials/credentials_krb5.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@
#undef DBGC_CLASS
#define DBGC_CLASS DBGC_AUTH

#undef strncasecmp

static void cli_credentials_invalidate_client_gss_creds(
struct cli_credentials *cred,
enum credentials_obtained obtained);
Expand Down
2 changes: 2 additions & 0 deletions auth/gensec/gensec_start.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@
#undef DBGC_CLASS
#define DBGC_CLASS DBGC_AUTH

#undef strcasecmp

/* the list of currently registered GENSEC backends */
static const struct gensec_security_ops **generic_security_ops;
static int gensec_num_backends;
Expand Down
2 changes: 2 additions & 0 deletions dfs_server/dfs_server_ad.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@

#define MAX_DFS_RESPONSE 56*1024 /* 56 Kb */

#undef strcasecmp

/* A DC set is a group of DC, they might have been grouped together
because they belong to the same site, or to site with same cost ...
*/
Expand Down
1 change: 1 addition & 0 deletions lib/ldb/include/ldb.h
Original file line number Diff line number Diff line change
Expand Up @@ -1944,6 +1944,7 @@ int ldb_dn_update_components(struct ldb_dn *dn, const struct ldb_dn *ref_dn);
strcasecmp and toupper here is ok.
return 0 for match
*/
#undef strcasecmp
#define ldb_attr_cmp(a, b) strcasecmp(a, b)
char *ldb_attr_casefold(TALLOC_CTX *mem_ctx, const char *s);
int ldb_attr_dn(const char *attr);
Expand Down
3 changes: 3 additions & 0 deletions lib/util/charset/tests/charset.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@
#include "includes.h"
#include "torture/torture.h"

#undef strcasecmp
#undef strncasecmp

struct torture_suite *torture_local_charset(TALLOC_CTX *mem_ctx);

static bool test_toupper_m(struct torture_context *tctx)
Expand Down
4 changes: 4 additions & 0 deletions lib/util/charset/util_str.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@
#ifdef strcasecmp
#undef strcasecmp
#endif
#ifdef strncasecmp
#undef strncasecmp
#endif


/**
Case insensitive string compararison, handle specified for testing
Expand Down
22 changes: 21 additions & 1 deletion lib/util/safe_string.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
Unix SMB/CIFS implementation.
Safe string handling routines.
Copyright (C) Andrew Tridgell 1994-1998
Copyright (C) Andrew Bartlett <[email protected]> 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
Expand All @@ -19,11 +20,16 @@

#ifndef _SAFE_STRING_H
#define _SAFE_STRING_H

#ifndef _SPLINT_ /* http://www.splint.org */

/* Some macros to ensure people don't use buffer overflow vulnerable string
functions. */

#ifdef bcopy
#undef bcopy
#endif /* bcopy */
#define bcopy(src,dest,size) __ERROR__XX__NEVER_USE_BCOPY___;

#ifdef strcpy
#undef strcpy
#endif /* strcpy */
Expand All @@ -39,6 +45,20 @@
#endif /* sprintf */
#define sprintf __ERROR__XX__NEVER_USE_SPRINTF__;

/*
* strcasecmp/strncasecmp aren't an error, but it means you're not thinking about
* multibyte. Don't use them. JRA.
*/
#ifdef strcasecmp
#undef strcasecmp
#endif
#define strcasecmp __ERROR__XX__NEVER_USE_STRCASECMP__;

#ifdef strncasecmp
#undef strncasecmp
#endif
#define strncasecmp __ERROR__XX__NEVER_USE_STRNCASECMP__;

#endif /* !_SPLINT_ */

#endif
2 changes: 2 additions & 0 deletions lib/util/util_net.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@
#include "system/locale.h"
#include "system/filesys.h"
#include "lib/util/util_net.h"

#undef strcasecmp
#undef strncasecmp

/*******************************************************************
Set an address to INADDR_ANY.
Expand Down
2 changes: 2 additions & 0 deletions libcli/http/gensec/generic.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
#include "auth/gensec/gensec_internal.h"
#include "lib/util/base64.h"

#undef strncasecmp

_PUBLIC_ NTSTATUS gensec_http_generic_init(TALLOC_CTX *);

struct gensec_http_generic_state {
Expand Down
1 change: 1 addition & 0 deletions libcli/http/http.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#include "util/tevent_werror.h"
#include "lib/util/dlinklist.h"

#undef strcasecmp

/**
* Determines if a response should have a body.
Expand Down
3 changes: 3 additions & 0 deletions libcli/http/http_auth.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@
#include "auth/credentials/credentials.h"
#include "lib/util/data_blob.h"

#undef strcasecmp
#undef strncasecmp

/**
* Copy the request headers from src to dst
*/
Expand Down
3 changes: 3 additions & 0 deletions libcli/security/util_sid.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@
#include "../librpc/gen_ndr/netlogon.h"
#include "../libcli/security/security.h"

#undef strcasecmp
#undef strncasecmp

/*
* Some useful sids, more well known sids can be found at
* http://support.microsoft.com/kb/243330/EN-US/
Expand Down
2 changes: 2 additions & 0 deletions librpc/rpc/dcerpc_util.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@
#include "lib/crypto/gnutls_helpers.h"
#include <gnutls/crypto.h>

#undef strncasecmp

/* we need to be able to get/set the fragment length without doing a full
decode */
void dcerpc_set_frag_length(DATA_BLOB *blob, uint16_t v)
Expand Down
2 changes: 2 additions & 0 deletions librpc/rpc/dcesrv_core.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@
#undef DBGC_CLASS
#define DBGC_CLASS DBGC_RPC_SRV

#undef strcasecmp

static NTSTATUS dcesrv_negotiate_contexts(struct dcesrv_call_state *call,
const struct dcerpc_bind *b,
struct dcerpc_ack_ctx *ack_ctx_list);
Expand Down
2 changes: 1 addition & 1 deletion source3/include/includes.h
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ typedef char fstring[FSTRING_LEN];
/* String routines */

#include "srvstr.h"
#include "safe_string.h"
#include "lib/util/safe_string.h"

#ifndef SIGCLD
#define SIGCLD SIGCHLD
Expand Down
65 changes: 0 additions & 65 deletions source3/include/safe_string.h

This file was deleted.

2 changes: 2 additions & 0 deletions source3/modules/vfs_vxfs.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include "system/filesys.h"
#include "vfs_vxfs.h"

#undef strcasecmp

#undef DBGC_CLASS
#define DBGC_CLASS DBGC_VFS

Expand Down
2 changes: 2 additions & 0 deletions source4/auth/ntlm/auth_developer.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
#undef DBGC_CLASS
#define DBGC_CLASS DBGC_AUTH

#undef strncasecmp

_PUBLIC_ NTSTATUS auth4_developer_init(TALLOC_CTX *);

static NTSTATUS name_to_ntstatus_want_check(struct auth_method_context *ctx,
Expand Down
2 changes: 2 additions & 0 deletions source4/client/client.c
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@
#define DEFAULT_PAGER "more"
#endif

#undef strncasecmp

struct smbclient_context {
char *remote_cur_dir;
struct smbcli_state *cli;
Expand Down
2 changes: 2 additions & 0 deletions source4/dns_server/dlz_bind9.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@
#include "dnsserver_common.h"
#include "lib/util/smb_strtox.h"

#undef strcasecmp

struct b9_options {
const char *url;
const char *debug;
Expand Down
2 changes: 2 additions & 0 deletions source4/dns_server/dnsserver_common.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@
#undef DBGC_CLASS
#define DBGC_CLASS DBGC_DNS

#undef strncasecmp

uint8_t werr_to_dns_err(WERROR werr)
{
if (W_ERROR_EQUAL(WERR_OK, werr)) {
Expand Down
2 changes: 2 additions & 0 deletions source4/dsdb/common/util.c
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@
#include "libcli/util/ntstatus.h"
#include "lib/util/smb_strtox.h"

#undef strncasecmp

/*
* This included to allow us to handle DSDB_FLAG_REPLICATED_UPDATE in
* dsdb_request_add_controls()
Expand Down
2 changes: 2 additions & 0 deletions source4/dsdb/common/util_trusts.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@
#include "lib/crypto/md4.h"
#include "libcli/ldap/ldap_ndr.h"

#undef strcasecmp

NTSTATUS dsdb_trust_forest_info_from_lsa(TALLOC_CTX *mem_ctx,
const struct lsa_ForestTrustInformation *lfti,
struct ForestTrustInfo **_fti)
Expand Down
2 changes: 2 additions & 0 deletions source4/dsdb/repl/drepl_partitions.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@
#undef DBGC_CLASS
#define DBGC_CLASS DBGC_DRS_REPL

#undef strcasecmp

/*
load the partitions list based on replicated NC attributes in our
NTDSDSA object
Expand Down
2 changes: 2 additions & 0 deletions source4/dsdb/samdb/cracknames.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@
#include "dsdb/common/util.h"
#include "param/param.h"

#undef strcasecmp

static WERROR DsCrackNameOneFilter(struct ldb_context *sam_ctx, TALLOC_CTX *mem_ctx,
struct smb_krb5_context *smb_krb5_context,
uint32_t format_flags, enum drsuapi_DsNameFormat format_offered,
Expand Down
3 changes: 3 additions & 0 deletions source4/dsdb/samdb/ldb_modules/acl.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@
#include "system/kerberos.h"
#include "auth/kerberos/kerberos.h"

#undef strcasecmp
#undef strncasecmp

struct extended_access_check_attribute {
const char *oa_name;
const uint32_t requires_rights;
Expand Down
2 changes: 2 additions & 0 deletions source4/dsdb/samdb/ldb_modules/count_attrs.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@
#define NULL_REQ_PSEUDO_N -2LL;
#define STAR_REQ_PSEUDO_N -4LL;

#undef strcasecmp

struct count_attrs_private {
struct tdb_wrap *requested;
struct tdb_wrap *duplicates;
Expand Down
1 change: 1 addition & 0 deletions source4/dsdb/samdb/ldb_modules/encrypted_secrets.c
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ static const size_t num_secret_attributes = ARRAY_SIZE(secret_attributes);
#define NUMBER_OF_KEYS 1
#define SECRETS_KEY_FILE "encrypted_secrets.key"

#undef strcasecmp

struct es_data {
/*
Expand Down
2 changes: 2 additions & 0 deletions source4/dsdb/samdb/ldb_modules/extended_dn_in.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@
#include "dsdb/samdb/ldb_modules/util.h"
#include "lib/ldb-samba/ldb_matching_rules.h"

#undef strncasecmp

/*
TODO: if relax is not set then we need to reject the fancy RMD_* and
DELETED extended DN codes
Expand Down
3 changes: 3 additions & 0 deletions source4/dsdb/samdb/ldb_modules/extended_dn_out.c
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@
#include "dsdb/samdb/samdb.h"
#include "dsdb/samdb/ldb_modules/util.h"

#undef strcasecmp
#undef strncasecmp

struct extended_dn_out_private {
bool dereference;
bool normalise;
Expand Down
1 change: 1 addition & 0 deletions source4/dsdb/samdb/ldb_modules/linked_attributes.c
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
#include "librpc/gen_ndr/ndr_misc.h"
#include "dsdb/samdb/ldb_modules/util.h"

#undef strcasecmp

struct la_private_transaction {
struct la_context *la_list;
Expand Down
2 changes: 2 additions & 0 deletions source4/dsdb/samdb/ldb_modules/netlogon.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@
#include "libds/common/flag_mapping.h"
#include "lib/util/util_net.h"

#undef strcasecmp

/*
fill in the cldap netlogon union for a given version
*/
Expand Down
2 changes: 2 additions & 0 deletions source4/dsdb/samdb/ldb_modules/password_hash.c
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@
#define MINIMUM_GPGME_VERSION "1.2.0"
#endif

#undef strncasecmp

/* If we have decided there is a reason to work on this request, then
* setup all the password hash types correctly.
*
Expand Down
Loading

0 comments on commit 232054c

Please sign in to comment.