Skip to content

Commit

Permalink
build: Build with system md5.h on OpenIndiana
Browse files Browse the repository at this point in the history
This changes (again...) our system md5 detection to cope with how
OpenIndiana does md5.  I'm becoming increasingly convinced this isn't
worth our while (we should have just done samba_md5...), but for now
this change seems to work on FreeBSD, OpenIndiana and Linux with
libbsd.

This needs us to rename struct MD5Context -> MD5_CTX, but we provide a
config.h define to rename the type bad if MD5_CTX does not exist (it does
however exist in the md5.h from libbsd).

Andrew Bartlett

Signed-off-by: Andrew Bartlett <[email protected]>
Reviewed-by: Jeremy Allison <[email protected]>

Autobuild-User(master): Jeremy Allison <[email protected]>
Autobuild-Date(master): Wed Jun 19 21:32:36 CEST 2013 on sn-devel-104
  • Loading branch information
abartlet authored and jrasamba committed Jun 19, 2013
1 parent 5c4772e commit fc13489
Show file tree
Hide file tree
Showing 26 changed files with 38 additions and 37 deletions.
2 changes: 1 addition & 1 deletion auth/credentials/credentials_ntlm.c
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ _PUBLIC_ NTSTATUS cli_credentials_get_ntlm_response(struct cli_credentials *cred
/* LM Key is incompatible... */
*flags &= ~CLI_CRED_LANMAN_AUTH;
} else if (*flags & CLI_CRED_NTLM2) {
struct MD5Context md5_session_nonce_ctx;
MD5_CTX md5_session_nonce_ctx;
uint8_t session_nonce[16];
uint8_t session_nonce_hash[16];
uint8_t user_session_key[16];
Expand Down
2 changes: 1 addition & 1 deletion auth/ntlmssp/ntlmssp_server.c
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,7 @@ static NTSTATUS ntlmssp_server_preauth(struct gensec_security *gensec_security,
*/
if (ntlmssp_state->neg_flags & NTLMSSP_NEGOTIATE_NTLM2) {
if (ntlmssp_state->nt_resp.length == 24 && ntlmssp_state->lm_resp.length == 24) {
struct MD5Context md5_session_nonce_ctx;
MD5_CTX md5_session_nonce_ctx;
state->doing_ntlm2 = true;

memcpy(state->session_nonce, ntlmssp_state->internal_chal.data, 8);
Expand Down
2 changes: 1 addition & 1 deletion auth/ntlmssp/ntlmssp_sign.c
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ static void calc_ntlmv2_key(uint8_t subkey[16],
DATA_BLOB session_key,
const char *constant)
{
struct MD5Context ctx3;
MD5_CTX ctx3;
MD5Init(&ctx3);
MD5Update(&ctx3, session_key.data, session_key.length);
MD5Update(&ctx3, (const uint8_t *)constant, strlen(constant)+1);
Expand Down
4 changes: 2 additions & 2 deletions lib/crypto/hmacmd5.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ _PUBLIC_ void hmac_md5_init_rfc2104(const uint8_t *key, int key_len, HMACMD5Cont
/* if key is longer than 64 bytes reset it to key=MD5(key) */
if (key_len > 64)
{
struct MD5Context tctx;
MD5_CTX tctx;

MD5Init(&tctx);
MD5Update(&tctx, key, key_len);
Expand Down Expand Up @@ -91,7 +91,7 @@ _PUBLIC_ void hmac_md5_update(const uint8_t *text, int text_len, HMACMD5Context
***********************************************************************/
_PUBLIC_ void hmac_md5_final(uint8_t *digest, HMACMD5Context *ctx)
{
struct MD5Context ctx_o;
MD5_CTX ctx_o;

MD5Final(digest, &ctx->ctx);

Expand Down
2 changes: 1 addition & 1 deletion lib/crypto/hmacmd5.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@

typedef struct
{
struct MD5Context ctx;
MD5_CTX ctx;
uint8_t k_ipad[65];
uint8_t k_opad[65];

Expand Down
6 changes: 3 additions & 3 deletions lib/crypto/md5.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ static void byteReverse(uint8_t *buf, unsigned int longs)
* Start MD5 accumulation. Set bit count to 0 and buffer to mysterious
* initialization constants.
*/
_PUBLIC_ void MD5Init(struct MD5Context *ctx)
_PUBLIC_ void MD5Init(MD5_CTX *ctx)
{
ctx->buf[0] = 0x67452301;
ctx->buf[1] = 0xefcdab89;
Expand All @@ -58,7 +58,7 @@ _PUBLIC_ void MD5Init(struct MD5Context *ctx)
* Update context to reflect the concatenation of another buffer full
* of bytes.
*/
_PUBLIC_ void MD5Update(struct MD5Context *ctx, const uint8_t *buf, size_t len)
_PUBLIC_ void MD5Update(MD5_CTX *ctx, const uint8_t *buf, size_t len)
{
register uint32_t t;

Expand Down Expand Up @@ -106,7 +106,7 @@ _PUBLIC_ void MD5Update(struct MD5Context *ctx, const uint8_t *buf, size_t len)
* Final wrapup - pad to 64-byte boundary with the bit pattern
* 1 0* (64-bit count of bits processed, MSB-first)
*/
_PUBLIC_ void MD5Final(uint8_t digest[16], struct MD5Context *ctx)
_PUBLIC_ void MD5Final(uint8_t digest[16], MD5_CTX *ctx)
{
unsigned int count;
uint8_t *p;
Expand Down
2 changes: 1 addition & 1 deletion lib/crypto/md5test.c
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ bool torture_local_crypto_md5(struct torture_context *torture)
};

for (i=0; i < ARRAY_SIZE(testarray); i++) {
struct MD5Context ctx;
MD5_CTX ctx;
uint8_t md5[16];
int e;

Expand Down
2 changes: 1 addition & 1 deletion lib/crypto/wscript_build
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ elif bld.CONFIG_SET('HAVE_SYS_MD5_H') and bld.CONFIG_SET('HAVE_LIBMD5'):
extra_deps += ' md5'
elif bld.CONFIG_SET('HAVE_SYS_MD5_H') and bld.CONFIG_SET('HAVE_LIBMD'):
extra_deps += ' md'
elif not bld.CONFIG_SET('HAVE_COMMONCRYPTO_COMMONDIGEST_H'):
elif not bld.CONFIG_SET('HAVE_SYS_MD5_H') and not bld.CONFIG_SET('HAVE_COMMONCRYPTO_COMMONDIGEST_H'):
extra_source += ' md5.c'

bld.SAMBA_SUBSYSTEM('LIBCRYPTO',
Expand Down
1 change: 1 addition & 0 deletions lib/crypto/wscript_configure
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@ if not conf.CHECK_FUNCS_IN('MD5Init', 'bsd', headers='bsd/md5.h',
checklibc=True)
conf.CHECK_FUNCS_IN('MD5Init', 'md', headers='sys/md5.h',
checklibc=True)
conf.CHECK_TYPE('MD5_CTX', 'struct MD5Context', headers='sys/md5.h')
conf.CHECK_FUNCS_IN('CC_MD5_Init', '', headers='CommonCrypto/CommonDigest.h',
checklibc=True)
2 changes: 1 addition & 1 deletion libcli/auth/credentials.c
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ static void netlogon_creds_init_128bit(struct netlogon_creds_CredentialState *cr
{
unsigned char zero[4], tmp[16];
HMACMD5Context ctx;
struct MD5Context md5;
MD5_CTX md5;

ZERO_STRUCT(creds->session_key);

Expand Down
2 changes: 1 addition & 1 deletion libcli/auth/schannel_sign.c
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ static void netsec_do_sign(struct schannel_state *state,
} else {
uint8_t packet_digest[16];
static const uint8_t zeros[4];
struct MD5Context ctx;
MD5_CTX ctx;

MD5Init(&ctx);
MD5Update(&ctx, zeros, 4);
Expand Down
8 changes: 4 additions & 4 deletions libcli/auth/smbencrypt.c
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ bool E_md4hash(const char *passwd, uint8_t p16[16])

void E_md5hash(const uint8_t salt[16], const uint8_t nthash[16], uint8_t hash_out[16])
{
struct MD5Context tctx;
MD5_CTX tctx;
MD5Init(&tctx);
MD5Update(&tctx, salt, 16);
MD5Update(&tctx, nthash, 16);
Expand Down Expand Up @@ -637,7 +637,7 @@ bool decode_pw_buffer(TALLOC_CTX *ctx,

void encode_or_decode_arc4_passwd_buffer(unsigned char pw_buf[532], const DATA_BLOB *psession_key)
{
struct MD5Context tctx;
MD5_CTX tctx;
unsigned char key_out[16];

/* Confounder is last 16 bytes. */
Expand Down Expand Up @@ -717,7 +717,7 @@ void encode_wkssvc_join_password_buffer(TALLOC_CTX *mem_ctx,
struct wkssvc_PasswordBuffer **pwd_buf)
{
uint8_t buffer[516];
struct MD5Context ctx;
MD5_CTX ctx;
struct wkssvc_PasswordBuffer *my_pwd_buf = NULL;
DATA_BLOB confounded_session_key;
int confounder_len = 8;
Expand Down Expand Up @@ -755,7 +755,7 @@ WERROR decode_wkssvc_join_password_buffer(TALLOC_CTX *mem_ctx,
char **pwd)
{
uint8_t buffer[516];
struct MD5Context ctx;
MD5_CTX ctx;
size_t pwd_len;

DATA_BLOB confounded_session_key;
Expand Down
4 changes: 2 additions & 2 deletions libcli/drsuapi/repl_decrypt.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ WERROR drsuapi_decrypt_attribute_value(TALLOC_CTX *mem_ctx,
DATA_BLOB confounder;
DATA_BLOB enc_buffer;

struct MD5Context md5;
MD5_CTX md5;
uint8_t _enc_key[16];
DATA_BLOB enc_key;

Expand Down Expand Up @@ -198,7 +198,7 @@ static WERROR drsuapi_encrypt_attribute_value(TALLOC_CTX *mem_ctx,
DATA_BLOB rid_crypt_out = data_blob(NULL, 0);
DATA_BLOB confounder;

struct MD5Context md5;
MD5_CTX md5;
uint8_t _enc_key[16];
DATA_BLOB enc_key;

Expand Down
2 changes: 1 addition & 1 deletion libcli/smb/smb_signing.c
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ static void smb_signing_md5(const DATA_BLOB *mac_key,
{
const size_t offset_end_of_sig = (HDR_SS_FIELD + 8);
uint8_t sequence_buf[8];
struct MD5Context md5_ctx;
MD5_CTX md5_ctx;

/*
* Firstly put the sequence number into the first 4 bytes.
Expand Down
2 changes: 1 addition & 1 deletion source3/libsmb/ntlmssp.c
Original file line number Diff line number Diff line change
Expand Up @@ -537,7 +537,7 @@ static NTSTATUS ntlmssp3_client_challenge(struct ntlmssp_state *ntlmssp_state,
return NT_STATUS_NO_MEMORY;
}
} else if (ntlmssp_state->neg_flags & NTLMSSP_NEGOTIATE_NTLM2) {
struct MD5Context md5_session_nonce_ctx;
MD5_CTX md5_session_nonce_ctx;
uint8_t session_nonce[16];
uint8_t session_nonce_hash[16];
uint8_t user_session_key[16];
Expand Down
2 changes: 1 addition & 1 deletion source3/modules/vfs_streams_xattr.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ struct stream_io {

static SMB_INO_T stream_inode(const SMB_STRUCT_STAT *sbuf, const char *sname)
{
struct MD5Context ctx;
MD5_CTX ctx;
unsigned char hash[16];
SMB_INO_T result;
char *upper_sname;
Expand Down
2 changes: 1 addition & 1 deletion source3/rpc_client/init_samr.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ void init_samr_CryptPasswordEx(const char *pwd,
/* samr_CryptPasswordEx */

uchar pwbuf[532];
struct MD5Context md5_ctx;
MD5_CTX md5_ctx;
uint8_t confounder[16];
DATA_BLOB confounded_session_key = data_blob(NULL, 16);

Expand Down
2 changes: 1 addition & 1 deletion source4/dsdb/samdb/ldb_modules/password_hash.c
Original file line number Diff line number Diff line change
Expand Up @@ -1368,7 +1368,7 @@ static int setup_primary_wdigest(struct setup_password_fields_io *io,
}

for (i=0; i < ARRAY_SIZE(wdigest); i++) {
struct MD5Context md5;
MD5_CTX md5;
MD5Init(&md5);
if (wdigest[i].nt4dom) {
MD5Update(&md5, wdigest[i].nt4dom->data, wdigest[i].nt4dom->length);
Expand Down
4 changes: 2 additions & 2 deletions source4/libcli/raw/smb_signing.c
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ bool signing_good(struct smb_signing_context *sign_info,
void sign_outgoing_message(struct smb_request_buffer *out, DATA_BLOB *mac_key, unsigned int seq_num)
{
uint8_t calc_md5_mac[16];
struct MD5Context md5_ctx;
MD5_CTX md5_ctx;

/*
* Firstly put the sequence number into the first 4 bytes.
Expand Down Expand Up @@ -116,7 +116,7 @@ bool check_signed_incoming_message(struct smb_request_buffer *in, DATA_BLOB *mac
uint8_t calc_md5_mac[16];
uint8_t *server_sent_mac;
uint8_t sequence_buf[8];
struct MD5Context md5_ctx;
MD5_CTX md5_ctx;
const size_t offset_end_of_sig = (HDR_SS_FIELD + 8);
int i;
const int sign_range = 0;
Expand Down
4 changes: 2 additions & 2 deletions source4/libnet/libnet_passwd.c
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ static NTSTATUS libnet_SetPassword_samr_handle_26(struct libnet_context *ctx, TA
DATA_BLOB session_key;
DATA_BLOB confounded_session_key = data_blob_talloc(mem_ctx, NULL, 16);
uint8_t confounder[16];
struct MD5Context md5;
MD5_CTX md5;

if (r->samr_handle.in.info21) {
return NT_STATUS_INVALID_PARAMETER_MIX;
Expand Down Expand Up @@ -330,7 +330,7 @@ static NTSTATUS libnet_SetPassword_samr_handle_25(struct libnet_context *ctx, TA
DATA_BLOB session_key;
DATA_BLOB confounded_session_key = data_blob_talloc(mem_ctx, NULL, 16);
uint8_t confounder[16];
struct MD5Context md5;
MD5_CTX md5;

if (!r->samr_handle.in.info21) {
return NT_STATUS_INVALID_PARAMETER_MIX;
Expand Down
2 changes: 1 addition & 1 deletion source4/ntp_signd/ntp_signd.c
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ static NTSTATUS ntp_signd_process(struct ntp_signd_connection *ntp_signd_conn,
enum ndr_err_code ndr_err;
struct ldb_result *res;
const char *attrs[] = { "unicodePwd", "userAccountControl", "cn", NULL };
struct MD5Context ctx;
MD5_CTX ctx;
struct samr_Password *nt_hash;
uint32_t user_account_control;
int ret;
Expand Down
2 changes: 1 addition & 1 deletion source4/rpc_server/samr/samr_password.c
Original file line number Diff line number Diff line change
Expand Up @@ -566,7 +566,7 @@ NTSTATUS samr_set_password_ex(struct dcesrv_call_state *dce_call,
DATA_BLOB new_password;
DATA_BLOB co_session_key;
DATA_BLOB session_key = data_blob(NULL, 0);
struct MD5Context ctx;
MD5_CTX ctx;

nt_status = dcesrv_fetch_session_key(dce_call->conn, &session_key);
if (!NT_STATUS_IS_OK(nt_status)) {
Expand Down
2 changes: 1 addition & 1 deletion source4/torture/ntp/ntp_signd.c
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ static bool test_ntp_signd(struct torture_context *tctx,
char *unix_address;
int sys_errno;

struct MD5Context ctx;
MD5_CTX ctx;
uint8_t sig[16];
enum ndr_err_code ndr_err;
bool ok;
Expand Down
2 changes: 1 addition & 1 deletion source4/torture/rpc/samba3rpc.c
Original file line number Diff line number Diff line change
Expand Up @@ -780,7 +780,7 @@ static bool join3(struct torture_context *tctx,
DATA_BLOB session_key;
DATA_BLOB confounded_session_key = data_blob_talloc(
mem_ctx, NULL, 16);
struct MD5Context ctx;
MD5_CTX ctx;
uint8_t confounder[16];

ZERO_STRUCT(u_info);
Expand Down
2 changes: 1 addition & 1 deletion source4/torture/rpc/samlogon.c
Original file line number Diff line number Diff line change
Expand Up @@ -1083,7 +1083,7 @@ static bool test_ntlm2(struct samlogon_state *samlogon_state, char **error_strin
uint8_t session_nonce_hash[16];
uint8_t client_chall[8];

struct MD5Context md5_session_nonce_ctx;
MD5_CTX md5_session_nonce_ctx;
HMACMD5Context hmac_ctx;

ZERO_STRUCT(user_session_key);
Expand Down
8 changes: 4 additions & 4 deletions source4/torture/rpc/samr.c
Original file line number Diff line number Diff line change
Expand Up @@ -781,7 +781,7 @@ static bool test_SetUserPassEx(struct dcerpc_pipe *p, struct torture_context *tc
uint8_t confounder[16];
char *newpass;
struct dcerpc_binding_handle *b = p->binding_handle;
struct MD5Context ctx;
MD5_CTX ctx;
struct samr_GetUserPwInfo pwp;
struct samr_PwInfo info;
int policy_min_pw_len = 0;
Expand Down Expand Up @@ -872,7 +872,7 @@ static bool test_SetUserPass_25(struct dcerpc_pipe *p, struct torture_context *t
bool ret = true;
DATA_BLOB session_key;
DATA_BLOB confounded_session_key = data_blob_talloc(tctx, NULL, 16);
struct MD5Context ctx;
MD5_CTX ctx;
uint8_t confounder[16];
char *newpass;
struct dcerpc_binding_handle *b = p->binding_handle;
Expand Down Expand Up @@ -1162,7 +1162,7 @@ static bool test_SetUserPass_level_ex(struct dcerpc_pipe *p,
bool ret = true;
DATA_BLOB session_key;
DATA_BLOB confounded_session_key = data_blob_talloc(tctx, NULL, 16);
struct MD5Context ctx;
MD5_CTX ctx;
uint8_t confounder[16];
char *newpass;
struct dcerpc_binding_handle *b = p->binding_handle;
Expand Down Expand Up @@ -2563,7 +2563,7 @@ bool test_ChangePasswordRandomBytes(struct dcerpc_pipe *p, struct torture_contex
DATA_BLOB session_key;
DATA_BLOB confounded_session_key = data_blob_talloc(tctx, NULL, 16);
uint8_t confounder[16];
struct MD5Context ctx;
MD5_CTX ctx;

bool ret = true;
struct lsa_String server, account;
Expand Down

0 comments on commit fc13489

Please sign in to comment.