From a1f5e0ba1ca4dd7f984f589a36989d188832d8e8 Mon Sep 17 00:00:00 2001 From: Maarten Billemont Date: Sat, 24 Mar 2018 15:14:41 -0400 Subject: [PATCH] Harmonize log methods by removing trailing \n. --- core/c/mpw-algorithm.c | 42 +++--- core/c/mpw-algorithm_v0.c | 62 ++++----- core/c/mpw-algorithm_v1.c | 8 +- core/c/mpw-algorithm_v2.c | 14 +- core/c/mpw-algorithm_v3.c | 14 +- core/c/mpw-marshal-util.c | 4 +- core/c/mpw-marshal.c | 6 +- core/c/mpw-types.c | 16 +-- core/c/mpw-util.h | 58 ++++----- platform-independent/cli-c/cli/mpw-bench.c | 6 +- platform-independent/cli-c/cli/mpw-cli-util.c | 14 +- platform-independent/cli-c/cli/mpw-cli.c | 120 +++++++++--------- .../cli-c/cli/mpw-tests-util.c | 2 +- platform-independent/cli-c/cli/mpw-tests.c | 8 +- 14 files changed, 181 insertions(+), 193 deletions(-) diff --git a/core/c/mpw-algorithm.c b/core/c/mpw-algorithm.c index b089eac8..6a730142 100644 --- a/core/c/mpw-algorithm.c +++ b/core/c/mpw-algorithm.c @@ -29,9 +29,9 @@ MPMasterKey mpw_masterKey(const char *fullName, const char *masterPassword, cons if (masterPassword && !strlen( masterPassword )) masterPassword = NULL; - trc( "-- mpw_masterKey (algorithm: %u)\n", algorithmVersion ); - trc( "fullName: %s\n", fullName ); - trc( "masterPassword.id: %s\n", masterPassword? mpw_id_buf( masterPassword, strlen( masterPassword ) ): NULL ); + trc( "-- mpw_masterKey (algorithm: %u)", algorithmVersion ); + trc( "fullName: %s", fullName ); + trc( "masterPassword.id: %s", masterPassword? mpw_id_buf( masterPassword, strlen( masterPassword ) ): NULL ); if (!fullName || !masterPassword) return NULL; @@ -45,7 +45,7 @@ MPMasterKey mpw_masterKey(const char *fullName, const char *masterPassword, cons case MPAlgorithmVersion3: return mpw_masterKey_v3( fullName, masterPassword ); default: - err( "Unsupported version: %d\n", algorithmVersion ); + err( "Unsupported version: %d", algorithmVersion ); return NULL; } } @@ -57,11 +57,11 @@ MPSiteKey mpw_siteKey( if (keyContext && !strlen( keyContext )) keyContext = NULL; - trc( "-- mpw_siteKey (algorithm: %u)\n", algorithmVersion ); - trc( "siteName: %s\n", siteName ); - trc( "siteCounter: %d\n", siteCounter ); - trc( "keyPurpose: %d (%s)\n", keyPurpose, mpw_nameForPurpose( keyPurpose ) ); - trc( "keyContext: %s\n", keyContext ); + trc( "-- mpw_siteKey (algorithm: %u)", algorithmVersion ); + trc( "siteName: %s", siteName ); + trc( "siteCounter: %d", siteCounter ); + trc( "keyPurpose: %d (%s)", keyPurpose, mpw_nameForPurpose( keyPurpose ) ); + trc( "keyContext: %s", keyContext ); if (!masterKey || !siteName) return NULL; @@ -75,7 +75,7 @@ MPSiteKey mpw_siteKey( case MPAlgorithmVersion3: return mpw_siteKey_v3( masterKey, siteName, siteCounter, keyPurpose, keyContext ); default: - err( "Unsupported version: %d\n", algorithmVersion ); + err( "Unsupported version: %d", algorithmVersion ); return NULL; } } @@ -95,9 +95,9 @@ const char *mpw_siteResult( if (!siteKey) return NULL; - trc( "-- mpw_siteResult (algorithm: %u)\n", algorithmVersion ); - trc( "resultType: %d (%s)\n", resultType, mpw_nameForType( resultType ) ); - trc( "resultParam: %s\n", resultParam ); + trc( "-- mpw_siteResult (algorithm: %u)", algorithmVersion ); + trc( "resultType: %d (%s)", resultType, mpw_nameForType( resultType ) ); + trc( "resultParam: %s", resultParam ); char *sitePassword = NULL; if (resultType & MPResultTypeClassTemplate) { @@ -111,7 +111,7 @@ const char *mpw_siteResult( case MPAlgorithmVersion3: return mpw_sitePasswordFromTemplate_v3( masterKey, siteKey, resultType, resultParam ); default: - err( "Unsupported version: %d\n", algorithmVersion ); + err( "Unsupported version: %d", algorithmVersion ); return NULL; } } @@ -126,7 +126,7 @@ const char *mpw_siteResult( case MPAlgorithmVersion3: return mpw_sitePasswordFromCrypt_v3( masterKey, siteKey, resultType, resultParam ); default: - err( "Unsupported version: %d\n", algorithmVersion ); + err( "Unsupported version: %d", algorithmVersion ); return NULL; } } @@ -141,12 +141,12 @@ const char *mpw_siteResult( case MPAlgorithmVersion3: return mpw_sitePasswordFromDerive_v3( masterKey, siteKey, resultType, resultParam ); default: - err( "Unsupported version: %d\n", algorithmVersion ); + err( "Unsupported version: %d", algorithmVersion ); return NULL; } } else { - err( "Unsupported password type: %d\n", resultType ); + err( "Unsupported password type: %d", resultType ); } return sitePassword; @@ -167,9 +167,9 @@ const char *mpw_siteState( if (!siteKey) return NULL; - trc( "-- mpw_siteState (algorithm: %u)\n", algorithmVersion ); - trc( "resultType: %d (%s)\n", resultType, mpw_nameForType( resultType ) ); - trc( "resultParam: %zu bytes = %s\n", sizeof( resultParam ), resultParam ); + trc( "-- mpw_siteState (algorithm: %u)", algorithmVersion ); + trc( "resultType: %d (%s)", resultType, mpw_nameForType( resultType ) ); + trc( "resultParam: %zu bytes = %s", sizeof( resultParam ), resultParam ); if (!masterKey || !resultParam) return NULL; @@ -183,7 +183,7 @@ const char *mpw_siteState( case MPAlgorithmVersion3: return mpw_siteState_v3( masterKey, siteKey, resultType, resultParam ); default: - err( "Unsupported version: %d\n", algorithmVersion ); + err( "Unsupported version: %d", algorithmVersion ); return NULL; } } diff --git a/core/c/mpw-algorithm_v0.c b/core/c/mpw-algorithm_v0.c index 5a2307e2..b1f237d3 100644 --- a/core/c/mpw-algorithm_v0.c +++ b/core/c/mpw-algorithm_v0.c @@ -52,10 +52,10 @@ static MPMasterKey mpw_masterKey_v0( const char *fullName, const char *masterPassword) { const char *keyScope = mpw_scopeForPurpose( MPKeyPurposeAuthentication ); - trc( "keyScope: %s\n", keyScope ); + trc( "keyScope: %s", keyScope ); // Calculate the master key salt. - trc( "masterKeySalt: keyScope=%s | #fullName=%s | fullName=%s\n", + trc( "masterKeySalt: keyScope=%s | #fullName=%s | fullName=%s", keyScope, mpw_hex_l( (uint32_t)mpw_utf8_strlen( fullName ) ), fullName ); size_t masterKeySaltSize = 0; uint8_t *masterKeySalt = NULL; @@ -63,20 +63,20 @@ static MPMasterKey mpw_masterKey_v0( mpw_push_int( &masterKeySalt, &masterKeySaltSize, (uint32_t)mpw_utf8_strlen( fullName ) ); mpw_push_string( &masterKeySalt, &masterKeySaltSize, fullName ); if (!masterKeySalt) { - err( "Could not allocate master key salt: %s\n", strerror( errno ) ); + err( "Could not allocate master key salt: %s", strerror( errno ) ); return NULL; } - trc( " => masterKeySalt.id: %s\n", mpw_id_buf( masterKeySalt, masterKeySaltSize ) ); + trc( " => masterKeySalt.id: %s", mpw_id_buf( masterKeySalt, masterKeySaltSize ) ); // Calculate the master key. - trc( "masterKey: scrypt( masterPassword, masterKeySalt, N=%lu, r=%u, p=%u )\n", MP_N, MP_r, MP_p ); + trc( "masterKey: scrypt( masterPassword, masterKeySalt, N=%lu, r=%u, p=%u )", MP_N, MP_r, MP_p ); MPMasterKey masterKey = mpw_kdf_scrypt( MPMasterKeySize, masterPassword, masterKeySalt, masterKeySaltSize, MP_N, MP_r, MP_p ); mpw_free( &masterKeySalt, masterKeySaltSize ); if (!masterKey) { - err( "Could not derive master key: %s\n", strerror( errno ) ); + err( "Could not derive master key: %s", strerror( errno ) ); return NULL; } - trc( " => masterKey.id: %s\n", mpw_id_buf( masterKey, MPMasterKeySize ) ); + trc( " => masterKey.id: %s", mpw_id_buf( masterKey, MPMasterKeySize ) ); return masterKey; } @@ -86,14 +86,14 @@ static MPSiteKey mpw_siteKey_v0( MPKeyPurpose keyPurpose, const char *keyContext) { const char *keyScope = mpw_scopeForPurpose( keyPurpose ); - trc( "keyScope: %s\n", keyScope ); + trc( "keyScope: %s", keyScope ); // OTP counter value. if (siteCounter == MPCounterValueTOTP) siteCounter = ((uint32_t)time( NULL ) / MP_otp_window) * MP_otp_window; // Calculate the site seed. - trc( "siteSalt: keyScope=%s | #siteName=%s | siteName=%s | siteCounter=%s | #keyContext=%s | keyContext=%s\n", + trc( "siteSalt: keyScope=%s | #siteName=%s | siteName=%s | siteCounter=%s | #keyContext=%s | keyContext=%s", keyScope, mpw_hex_l( (uint32_t)mpw_utf8_strlen( siteName ) ), siteName, mpw_hex_l( siteCounter ), keyContext? mpw_hex_l( (uint32_t)mpw_utf8_strlen( keyContext ) ): NULL, keyContext ); size_t siteSaltSize = 0; @@ -107,20 +107,20 @@ static MPSiteKey mpw_siteKey_v0( mpw_push_string( &siteSalt, &siteSaltSize, keyContext ); } if (!siteSalt) { - err( "Could not allocate site salt: %s\n", strerror( errno ) ); + err( "Could not allocate site salt: %s", strerror( errno ) ); return NULL; } - trc( " => siteSalt.id: %s\n", mpw_id_buf( siteSalt, siteSaltSize ) ); + trc( " => siteSalt.id: %s", mpw_id_buf( siteSalt, siteSaltSize ) ); - trc( "siteKey: hmac-sha256( masterKey.id=%s, siteSalt )\n", + trc( "siteKey: hmac-sha256( masterKey.id=%s, siteSalt )", mpw_id_buf( masterKey, MPMasterKeySize ) ); MPSiteKey siteKey = mpw_hash_hmac_sha256( masterKey, MPMasterKeySize, siteSalt, siteSaltSize ); mpw_free( &siteSalt, siteSaltSize ); if (!siteKey) { - err( "Could not derive site key: %s\n", strerror( errno ) ); + err( "Could not derive site key: %s", strerror( errno ) ); return NULL; } - trc( " => siteKey.id: %s\n", mpw_id_buf( siteKey, MPSiteKeySize ) ); + trc( " => siteKey.id: %s", mpw_id_buf( siteKey, MPSiteKeySize ) ); return siteKey; } @@ -134,11 +134,11 @@ static const char *mpw_sitePasswordFromTemplate_v0( uint16_t seedByte; mpw_uint16( (uint16_t)_siteKey[0], (uint8_t *)&seedByte ); const char *template = mpw_templateForType_v0( resultType, seedByte ); - trc( "template: %u => %s\n", seedByte, template ); + trc( "template: %u => %s", seedByte, template ); if (!template) return NULL; if (strlen( template ) > MPSiteKeySize) { - err( "Template too long for password seed: %zu\n", strlen( template ) ); + err( "Template too long for password seed: %zu", strlen( template ) ); return NULL; } @@ -147,10 +147,10 @@ static const char *mpw_sitePasswordFromTemplate_v0( for (size_t c = 0; c < strlen( template ); ++c) { mpw_uint16( (uint16_t)_siteKey[c + 1], (uint8_t *)&seedByte ); sitePassword[c] = mpw_characterFromClass_v0( template[c], seedByte ); - trc( " - class: %c, index: %5u (0x%02hX) => character: %c\n", + trc( " - class: %c, index: %5u (0x%02hX) => character: %c", template[c], seedByte, seedByte, sitePassword[c] ); } - trc( " => password: %s\n", sitePassword ); + trc( " => password: %s", sitePassword ); return sitePassword; } @@ -159,7 +159,7 @@ static const char *mpw_sitePasswordFromCrypt_v0( MPMasterKey masterKey, MPSiteKey __unused siteKey, MPResultType __unused resultType, const char *cipherText) { if (!cipherText) { - err( "Missing encrypted state.\n" ); + err( "Missing encrypted state." ); return NULL; } @@ -171,7 +171,7 @@ static const char *mpw_sitePasswordFromCrypt_v0( mpw_free( &cipherBuf, mpw_base64_decode_max( cipherText ) ); return NULL; } - trc( "b64 decoded: %zu bytes = %s\n", bufSize, mpw_hex( cipherBuf, bufSize ) ); + trc( "b64 decoded: %zu bytes = %s", bufSize, mpw_hex( cipherBuf, bufSize ) ); // Decrypt const uint8_t *plainBytes = mpw_aes_decrypt( masterKey, MPMasterKeySize, cipherBuf, &bufSize ); @@ -179,8 +179,8 @@ static const char *mpw_sitePasswordFromCrypt_v0( const char *plainText = mpw_strndup( (char *)plainBytes, bufSize ); mpw_free( &plainBytes, bufSize ); if (!plainText) - err( "AES decryption error: %s\n", strerror( errno ) ); - trc( "decrypted -> plainText: %zu bytes = %s = %s\n", strlen( plainText ), plainText, mpw_hex( plainText, strlen( plainText ) ) ); + err( "AES decryption error: %s", strerror( errno ) ); + trc( "decrypted -> plainText: %zu bytes = %s = %s", strlen( plainText ), plainText, mpw_hex( plainText, strlen( plainText ) ) ); return plainText; } @@ -191,23 +191,23 @@ static const char *mpw_sitePasswordFromDerive_v0( switch (resultType) { case MPResultTypeDeriveKey: { if (!resultParam) { - err( "Missing key size parameter.\n" ); + err( "Missing key size parameter." ); return NULL; } int resultParamInt = atoi( resultParam ); if (!resultParamInt) resultParamInt = 512; if (resultParamInt < 128 || resultParamInt > 512 || resultParamInt % 8 != 0) { - err( "Parameter is not a valid key size (should be 128 - 512): %s\n", resultParam ); + err( "Parameter is not a valid key size (should be 128 - 512): %s", resultParam ); return NULL; } uint16_t keySize = (uint16_t)(resultParamInt / 8); - trc( "keySize: %u\n", keySize ); + trc( "keySize: %u", keySize ); // Derive key const uint8_t *resultKey = mpw_kdf_blake2b( keySize, siteKey, MPSiteKeySize, NULL, 0, 0, NULL ); if (!resultKey) { - err( "Could not derive result key: %s\n", strerror( errno ) ); + err( "Could not derive result key: %s", strerror( errno ) ); return NULL; } @@ -219,13 +219,13 @@ static const char *mpw_sitePasswordFromDerive_v0( mpw_free_string( &b64Key ); } else - trc( "b64 encoded -> key: %s\n", b64Key ); + trc( "b64 encoded -> key: %s", b64Key ); mpw_free( &resultKey, keySize ); return b64Key; } default: - err( "Unsupported derived password type: %d\n", resultType ); + err( "Unsupported derived password type: %d", resultType ); return NULL; } } @@ -237,10 +237,10 @@ static const char *mpw_siteState_v0( size_t bufSize = strlen( plainText ); const uint8_t *cipherBuf = mpw_aes_encrypt( masterKey, MPMasterKeySize, (const uint8_t *)plainText, &bufSize ); if (!cipherBuf) { - err( "AES encryption error: %s\n", strerror( errno ) ); + err( "AES encryption error: %s", strerror( errno ) ); return NULL; } - trc( "cipherBuf: %zu bytes = %s\n", bufSize, mpw_hex( cipherBuf, bufSize ) ); + trc( "cipherBuf: %zu bytes = %s", bufSize, mpw_hex( cipherBuf, bufSize ) ); // Base64-encode size_t b64Max = mpw_base64_encode_max( bufSize ); @@ -250,7 +250,7 @@ static const char *mpw_siteState_v0( mpw_free_string( &cipherText ); } else - trc( "b64 encoded -> cipherText: %s\n", cipherText ); + trc( "b64 encoded -> cipherText: %s", cipherText ); mpw_free( &cipherBuf, bufSize ); return cipherText; diff --git a/core/c/mpw-algorithm_v1.c b/core/c/mpw-algorithm_v1.c index c5ed13be..3a4a4bce 100644 --- a/core/c/mpw-algorithm_v1.c +++ b/core/c/mpw-algorithm_v1.c @@ -58,11 +58,11 @@ static const char *mpw_sitePasswordFromTemplate_v1( // Determine the template. uint8_t seedByte = siteKey[0]; const char *template = mpw_templateForType( resultType, seedByte ); - trc( "template: %u => %s\n", seedByte, template ); + trc( "template: %u => %s", seedByte, template ); if (!template) return NULL; if (strlen( template ) > MPSiteKeySize) { - err( "Template too long for password seed: %zu\n", strlen( template ) ); + err( "Template too long for password seed: %zu", strlen( template ) ); return NULL; } @@ -71,10 +71,10 @@ static const char *mpw_sitePasswordFromTemplate_v1( for (size_t c = 0; c < strlen( template ); ++c) { seedByte = siteKey[c + 1]; sitePassword[c] = mpw_characterFromClass( template[c], seedByte ); - trc( " - class: %c, index: %3u (0x%02hhX) => character: %c\n", + trc( " - class: %c, index: %3u (0x%02hhX) => character: %c", template[c], seedByte, seedByte, sitePassword[c] ); } - trc( " => password: %s\n", sitePassword ); + trc( " => password: %s", sitePassword ); return sitePassword; } diff --git a/core/c/mpw-algorithm_v2.c b/core/c/mpw-algorithm_v2.c index d622884e..a6b3d44f 100644 --- a/core/c/mpw-algorithm_v2.c +++ b/core/c/mpw-algorithm_v2.c @@ -51,14 +51,14 @@ static MPSiteKey mpw_siteKey_v2( MPKeyPurpose keyPurpose, const char *keyContext) { const char *keyScope = mpw_scopeForPurpose( keyPurpose ); - trc( "keyScope: %s\n", keyScope ); + trc( "keyScope: %s", keyScope ); // OTP counter value. if (siteCounter == MPCounterValueTOTP) siteCounter = ((uint32_t)time( NULL ) / MP_otp_window) * MP_otp_window; // Calculate the site seed. - trc( "siteSalt: keyScope=%s | #siteName=%s | siteName=%s | siteCounter=%s | #keyContext=%s | keyContext=%s\n", + trc( "siteSalt: keyScope=%s | #siteName=%s | siteName=%s | siteCounter=%s | #keyContext=%s | keyContext=%s", keyScope, mpw_hex_l( (uint32_t)strlen( siteName ) ), siteName, mpw_hex_l( siteCounter ), keyContext? mpw_hex_l( (uint32_t)strlen( keyContext ) ): NULL, keyContext ); size_t siteSaltSize = 0; @@ -72,20 +72,20 @@ static MPSiteKey mpw_siteKey_v2( mpw_push_string( &siteSalt, &siteSaltSize, keyContext ); } if (!siteSalt) { - err( "Could not allocate site salt: %s\n", strerror( errno ) ); + err( "Could not allocate site salt: %s", strerror( errno ) ); return NULL; } - trc( " => siteSalt.id: %s\n", mpw_id_buf( siteSalt, siteSaltSize ) ); + trc( " => siteSalt.id: %s", mpw_id_buf( siteSalt, siteSaltSize ) ); - trc( "siteKey: hmac-sha256( masterKey.id=%s, siteSalt )\n", + trc( "siteKey: hmac-sha256( masterKey.id=%s, siteSalt )", mpw_id_buf( masterKey, MPMasterKeySize ) ); MPSiteKey siteKey = mpw_hash_hmac_sha256( masterKey, MPMasterKeySize, siteSalt, siteSaltSize ); mpw_free( &siteSalt, siteSaltSize ); if (!siteKey) { - err( "Could not derive site key: %s\n", strerror( errno ) ); + err( "Could not derive site key: %s", strerror( errno ) ); return NULL; } - trc( " => siteKey.id: %s\n", mpw_id_buf( siteKey, MPSiteKeySize ) ); + trc( " => siteKey.id: %s", mpw_id_buf( siteKey, MPSiteKeySize ) ); return siteKey; } diff --git a/core/c/mpw-algorithm_v3.c b/core/c/mpw-algorithm_v3.c index 7b5f0b6c..a3caebde 100644 --- a/core/c/mpw-algorithm_v3.c +++ b/core/c/mpw-algorithm_v3.c @@ -44,10 +44,10 @@ static MPMasterKey mpw_masterKey_v3( const char *fullName, const char *masterPassword) { const char *keyScope = mpw_scopeForPurpose( MPKeyPurposeAuthentication ); - trc( "keyScope: %s\n", keyScope ); + trc( "keyScope: %s", keyScope ); // Calculate the master key salt. - trc( "masterKeySalt: keyScope=%s | #fullName=%s | fullName=%s\n", + trc( "masterKeySalt: keyScope=%s | #fullName=%s | fullName=%s", keyScope, mpw_hex_l( (uint32_t)strlen( fullName ) ), fullName ); size_t masterKeySaltSize = 0; uint8_t *masterKeySalt = NULL; @@ -55,20 +55,20 @@ static MPMasterKey mpw_masterKey_v3( mpw_push_int( &masterKeySalt, &masterKeySaltSize, (uint32_t)strlen( fullName ) ); mpw_push_string( &masterKeySalt, &masterKeySaltSize, fullName ); if (!masterKeySalt) { - err( "Could not allocate master key salt: %s\n", strerror( errno ) ); + err( "Could not allocate master key salt: %s", strerror( errno ) ); return NULL; } - trc( " => masterKeySalt.id: %s\n", mpw_id_buf( masterKeySalt, masterKeySaltSize ) ); + trc( " => masterKeySalt.id: %s", mpw_id_buf( masterKeySalt, masterKeySaltSize ) ); // Calculate the master key. - trc( "masterKey: scrypt( masterPassword, masterKeySalt, N=%lu, r=%u, p=%u )\n", MP_N, MP_r, MP_p ); + trc( "masterKey: scrypt( masterPassword, masterKeySalt, N=%lu, r=%u, p=%u )", MP_N, MP_r, MP_p ); MPMasterKey masterKey = mpw_kdf_scrypt( MPMasterKeySize, masterPassword, masterKeySalt, masterKeySaltSize, MP_N, MP_r, MP_p ); mpw_free( &masterKeySalt, masterKeySaltSize ); if (!masterKey) { - err( "Could not derive master key: %s\n", strerror( errno ) ); + err( "Could not derive master key: %s", strerror( errno ) ); return NULL; } - trc( " => masterKey.id: %s\n", mpw_id_buf( masterKey, MPMasterKeySize ) ); + trc( " => masterKey.id: %s", mpw_id_buf( masterKey, MPMasterKeySize ) ); return masterKey; } diff --git a/core/c/mpw-marshal-util.c b/core/c/mpw-marshal-util.c index 1bd22538..9bd0e66b 100644 --- a/core/c/mpw-marshal-util.c +++ b/core/c/mpw-marshal-util.c @@ -58,7 +58,7 @@ json_object *mpw_get_json_section( char *sectionTokenizer = mpw_strdup( section ), *sectionToken = sectionTokenizer; for (sectionToken = strtok( sectionToken, "." ); sectionToken; sectionToken = strtok( NULL, "." )) if (!json_object_object_get_ex( json_value, sectionToken, &json_value ) || !json_value) { - trc( "While resolving: %s: Missing value for: %s\n", section, sectionToken ); + trc( "While resolving: %s: Missing value for: %s", section, sectionToken ); json_value = NULL; break; } @@ -106,7 +106,7 @@ bool mpw_update_masterKey(MPMasterKey *masterKey, MPAlgorithmVersion *masterKeyA *masterKeyAlgorithm = targetKeyAlgorithm; *masterKey = mpw_masterKey( fullName, masterPassword, *masterKeyAlgorithm ); if (!*masterKey) { - err( "Couldn't derive master key for user %s, algorithm %d.\n", fullName, *masterKeyAlgorithm ); + err( "Couldn't derive master key for user %s, algorithm %d.", fullName, *masterKeyAlgorithm ); return false; } } diff --git a/core/c/mpw-marshal.c b/core/c/mpw-marshal.c index d1a287bf..fd17669e 100644 --- a/core/c/mpw-marshal.c +++ b/core/c/mpw-marshal.c @@ -885,7 +885,7 @@ const MPMarshalFormat mpw_formatWithName( if (strncmp( mpw_nameForFormat( MPMarshalFormatJSON ), stdFormatName, strlen( stdFormatName ) ) == 0) return MPMarshalFormatJSON; - dbg( "Not a format name: %s\n", stdFormatName ); + dbg( "Not a format name: %s", stdFormatName ); return (MPMarshalFormat)ERR; } @@ -900,7 +900,7 @@ const char *mpw_nameForFormat( case MPMarshalFormatJSON: return "json"; default: { - dbg( "Unknown format: %d\n", format ); + dbg( "Unknown format: %d", format ); return NULL; } } @@ -917,7 +917,7 @@ const char *mpw_marshal_format_extension( case MPMarshalFormatJSON: return "mpsites.json"; default: { - dbg( "Unknown format: %d\n", format ); + dbg( "Unknown format: %d", format ); return NULL; } } diff --git a/core/c/mpw-types.c b/core/c/mpw-types.c index fd144bbb..12487813 100644 --- a/core/c/mpw-types.c +++ b/core/c/mpw-types.c @@ -84,7 +84,7 @@ const MPResultType mpw_typeWithName(const char *typeName) { if (strncmp( mpw_nameForType( MPResultTypeDeriveKey ), stdTypeName, strlen( stdTypeName ) ) == 0) return MPResultTypeDeriveKey; - dbg( "Not a generated type name: %s\n", stdTypeName ); + dbg( "Not a generated type name: %s", stdTypeName ); return (MPResultType)ERR; } @@ -114,7 +114,7 @@ const char *mpw_nameForType(MPResultType resultType) { case MPResultTypeDeriveKey: return "key"; default: { - dbg( "Unknown password type: %d\n", resultType ); + dbg( "Unknown password type: %d", resultType ); return NULL; } } @@ -123,7 +123,7 @@ const char *mpw_nameForType(MPResultType resultType) { const char **mpw_templatesForType(MPResultType type, size_t *count) { if (!(type & MPResultTypeClassTemplate)) { - dbg( "Not a generated type: %d\n", type ); + dbg( "Not a generated type: %d", type ); return NULL; } @@ -159,7 +159,7 @@ const char **mpw_templatesForType(MPResultType type, size_t *count) { return mpw_alloc_array( count, const char *, "cvcc cvc cvccvcv cvc", "cvc cvccvcvcv cvcv", "cv cvccv cvc cvcvccv" ); default: { - dbg( "Unknown generated type: %d\n", type ); + dbg( "Unknown generated type: %d", type ); return NULL; } } @@ -191,7 +191,7 @@ const MPKeyPurpose mpw_purposeWithName(const char *purposeName) { if (strncmp( mpw_nameForPurpose( MPKeyPurposeRecovery ), stdPurposeName, strlen( stdPurposeName ) ) == 0) return MPKeyPurposeRecovery; - dbg( "Not a purpose name: %s\n", stdPurposeName ); + dbg( "Not a purpose name: %s", stdPurposeName ); return (MPKeyPurpose)ERR; } @@ -205,7 +205,7 @@ const char *mpw_nameForPurpose(MPKeyPurpose purpose) { case MPKeyPurposeRecovery: return "recovery"; default: { - dbg( "Unknown purpose: %d\n", purpose ); + dbg( "Unknown purpose: %d", purpose ); return NULL; } } @@ -221,7 +221,7 @@ const char *mpw_scopeForPurpose(MPKeyPurpose purpose) { case MPKeyPurposeRecovery: return "com.lyndir.masterpassword.answer"; default: { - dbg( "Unknown purpose: %d\n", purpose ); + dbg( "Unknown purpose: %d", purpose ); return NULL; } } @@ -251,7 +251,7 @@ const char *mpw_charactersInClass(char characterClass) { case ' ': return " "; default: { - dbg( "Unknown character class: %c\n", characterClass ); + dbg( "Unknown character class: %c", characterClass ); return NULL; } } diff --git a/core/c/mpw-util.h b/core/c/mpw-util.h index ee90133a..b757c3ad 100644 --- a/core/c/mpw-util.h +++ b/core/c/mpw-util.h @@ -26,48 +26,36 @@ //// Logging. -#ifndef trc +#ifndef log extern int mpw_verbosity; -#define trc_level 3 +#define log(level, format, ...) ({ \ + if (mpw_verbosity >= level) { \ + fprintf( stderr, format "\n", ##__VA_ARGS__ ); \ + }; }) + /** Logging internal state. */ -#define trc(...) ({ \ - if (mpw_verbosity >= trc_level) \ - fprintf( stderr, __VA_ARGS__ ); }) -#endif -#ifndef dbg -#define dbg_level 2 +#define trc_level 3 +#define trc(...) log( trc_level, ##__VA_ARGS__ ) + /** Logging state and events interesting when investigating issues. */ -#define dbg(...) ({ \ - if (mpw_verbosity >= dbg_level) \ - fprintf( stderr, __VA_ARGS__ ); }) -#endif -#ifndef inf -#define inf_level 1 +#define dbg_level 2 +#define dbg(...) log( dbg_level, ##__VA_ARGS__ ) + /** User messages. */ -#define inf(...) ({ \ - if (mpw_verbosity >= inf_level) \ - fprintf( stderr, __VA_ARGS__ ); }) -#endif -#ifndef wrn -#define wrn_level 0 +#define inf_level 1 +#define inf(...) log( inf_level, ##__VA_ARGS__ ) + /** Recoverable issues and user suggestions. */ -#define wrn(...) ({ \ - if (mpw_verbosity >= wrn_level) \ - fprintf( stderr, __VA_ARGS__ ); }) -#endif -#ifndef err -#define err_level -1 +#define wrn_level 0 +#define wrn(...) log( wrn_level, ##__VA_ARGS__ ) + /** Unrecoverable issues. */ -#define err(...) ({ \ - if (mpw_verbosity >= err_level) \ - fprintf( stderr, __VA_ARGS__ ); }) -#endif -#ifndef ftl -#define ftl_level -2 +#define err_level -1 +#define err(...) log( err_level, ##__VA_ARGS__ ) + /** Issues that lead to abortion. */ -#define ftl(...) ({ \ - if (mpw_verbosity >= ftl_level) \ - fprintf( stderr, __VA_ARGS__ ); }) +#define ftl_level -2 +#define ftl(...) log( ftl_level, ##__VA_ARGS__ ) #endif #ifndef min diff --git a/platform-independent/cli-c/cli/mpw-bench.c b/platform-independent/cli-c/cli/mpw-bench.c index 1b72fe41..0ddf155f 100644 --- a/platform-independent/cli-c/cli/mpw-bench.c +++ b/platform-independent/cli-c/cli/mpw-bench.c @@ -43,7 +43,7 @@ static void mpw_getTime(struct timeval *time) { if (gettimeofday( time, NULL ) != 0) - ftl( "Could not get time: %s\n", strerror( errno ) ); + ftl( "Could not get time: %s", strerror( errno ) ); } static const double mpw_showSpeed(struct timeval startTime, const unsigned int iterations, const char *operation) { @@ -82,7 +82,7 @@ int main(int argc, char *const argv[]) { iterations = 4200000; /* tuned to ~10s on dev machine */ masterKey = mpw_masterKey( fullName, masterPassword, MPAlgorithmVersionCurrent ); if (!masterKey) { - ftl( "Could not allocate master key: %s\n", strerror( errno ) ); + ftl( "Could not allocate master key: %s", strerror( errno ) ); abort(); } mpw_getTime( &startTime ); @@ -127,7 +127,7 @@ int main(int argc, char *const argv[]) { for (int i = 1; i <= iterations; ++i) { masterKey = mpw_masterKey( fullName, masterPassword, MPAlgorithmVersionCurrent ); if (!masterKey) { - ftl( "Could not allocate master key: %s\n", strerror( errno ) ); + ftl( "Could not allocate master key: %s", strerror( errno ) ); break; } diff --git a/platform-independent/cli-c/cli/mpw-cli-util.c b/platform-independent/cli-c/cli/mpw-cli-util.c index e604fc56..2608165d 100644 --- a/platform-independent/cli-c/cli/mpw-cli-util.c +++ b/platform-independent/cli-c/cli/mpw-cli-util.c @@ -51,13 +51,13 @@ char *mpw_askpass(const char *prompt) { int pipes[2]; if (pipe( pipes ) == ERR) { - wrn( "Couldn't pipe: %s\n", strerror( errno ) ); + wrn( "Couldn't pipe: %s", strerror( errno ) ); return NULL; } pid_t pid = fork(); if (pid == ERR) { - wrn( "Couldn't fork for askpass:\n %s: %s\n", askpass, strerror( errno ) ); + wrn( "Couldn't fork for askpass:\n %s: %s", askpass, strerror( errno ) ); return NULL; } @@ -65,10 +65,10 @@ char *mpw_askpass(const char *prompt) { // askpass fork close( pipes[0] ); if (dup2( pipes[1], STDOUT_FILENO ) == ERR) - ftl( "Couldn't connect pipe to process: %s\n", strerror( errno ) ); + ftl( "Couldn't connect pipe to process: %s", strerror( errno ) ); else if (execlp( askpass, askpass, prompt, NULL ) == ERR) - ftl( "Couldn't execute askpass:\n %s: %s\n", askpass, strerror( errno ) ); + ftl( "Couldn't execute askpass:\n %s: %s", askpass, strerror( errno ) ); exit( EX_SOFTWARE ); } @@ -78,7 +78,7 @@ char *mpw_askpass(const char *prompt) { close( pipes[0] ); int status; if (waitpid( pid, &status, 0 ) == ERR) { - wrn( "Couldn't wait for askpass: %s\n", strerror( errno ) ); + wrn( "Couldn't wait for askpass: %s", strerror( errno ) ); mpw_free_string( &answer ); return NULL; } @@ -244,7 +244,7 @@ bool mpw_mkdirs(const char *filePath) { free( path ); if (chdir( cwd ) == ERR) - wrn( "Could not restore cwd:\n %s: %s\n", cwd, strerror( errno ) ); + wrn( "Could not restore cwd:\n %s: %s", cwd, strerror( errno ) ); free( cwd ); return success; @@ -291,7 +291,7 @@ static bool mpw_setupterm() { if (!termsetup) { int errret; if (!(termsetup = (setupterm( NULL, STDERR_FILENO, &errret ) == OK))) { - wrn( "Terminal doesn't support color (setupterm errret %d).\n", errret ); + wrn( "Terminal doesn't support color (setupterm errret %d).", errret ); return false; } } diff --git a/platform-independent/cli-c/cli/mpw-cli.c b/platform-independent/cli-c/cli/mpw-cli.c index 3fe83560..9dbc0961 100644 --- a/platform-independent/cli-c/cli/mpw-cli.c +++ b/platform-independent/cli-c/cli/mpw-cli.c @@ -36,24 +36,24 @@ static void usage() { inf( "" " Master Password v%s\n" "--------------------------------------------------------------------------------\n" - " https://masterpasswordapp.com\n\n", stringify_def( MP_VERSION ) ); + " https://masterpasswordapp.com\n", stringify_def( MP_VERSION ) ); inf( "" "\nUSAGE\n\n" " mpw [-u|-U full-name] [-m fd] [-t pw-type] [-P value] [-c counter]\n" " [-a version] [-p purpose] [-C context] [-f|F format] [-R 0|1]\n" - " [-v|-q] [-h] [site-name]\n\n" ); + " [-v|-q] [-h] [site-name]\n" ); inf( "" " -u full-name Specify the full name of the user.\n" " -u checks the master password against the config,\n" " -U allows updating to a new master password.\n" - " Defaults to %s in env or prompts.\n\n", MP_ENV_fullName ); + " Defaults to %s in env or prompts.\n", MP_ENV_fullName ); dbg( "" " -M master-pw Specify the master password of the user.\n" - " Passing secrets as arguments is unsafe, for use in testing only.\n" ); + " Passing secrets as arguments is unsafe, for use in testing only." ); inf( "" " -m fd Read the master password of the user from a file descriptor.\n" " Tip: don't send extra characters like newlines such as by using\n" - " echo in a pipe. Consider printf instead.\n\n" ); + " echo in a pipe. Consider printf instead.\n" ); inf( "" " -t pw-type Specify the password's template.\n" " Defaults to 'long' (-p a), 'name' (-p i) or 'phrase' (-p r).\n" @@ -66,31 +66,31 @@ static void usage() { " n, name | 9 letter name.\n" " p, phrase | 20 character sentence.\n" " K, key | encryption key (512 bit or -P bits).\n" - " P, personal | saved personal password (save with -P pw).\n\n" ); + " P, personal | saved personal password (save with -P pw).\n" ); inf( "" " -P value The parameter value.\n" " -p i | The login name for the site.\n" " -t K | The bit size of the key to generate (eg. 256).\n" - " -t P | The personal password to encrypt.\n\n" ); + " -t P | The personal password to encrypt.\n" ); inf( "" " -c counter The value of the counter.\n" - " Defaults to 1.\n\n" ); + " Defaults to 1.\n" ); inf( "" " -a version The algorithm version to use, %d - %d.\n" - " Defaults to %s in env or %d.\n\n", + " Defaults to %s in env or %d.\n", MPAlgorithmVersionFirst, MPAlgorithmVersionLast, MP_ENV_algorithm, MPAlgorithmVersionCurrent ); inf( "" " -p purpose The purpose of the generated token.\n" " Defaults to 'auth'.\n" " a, auth | An authentication token such as a password.\n" " i, ident | An identification token such as a username.\n" - " r, rec | A recovery token such as a security answer.\n\n" ); + " r, rec | A recovery token such as a security answer.\n" ); inf( "" " -C context A purpose-specific context.\n" " Defaults to empty.\n" " -p a | -\n" " -p i | -\n" - " -p r | Most significant word in security question.\n\n" ); + " -p r | Most significant word in security question.\n" ); inf( "" " -f|F format The mpsites format to use for reading/writing site parameters.\n" " -F forces the use of the given format,\n" @@ -98,24 +98,24 @@ static void usage() { " Defaults to %s in env or json, falls back to plain.\n" " n, none | No file\n" " f, flat | ~/.mpw.d/Full Name.%s\n" - " j, json | ~/.mpw.d/Full Name.%s\n\n", + " j, json | ~/.mpw.d/Full Name.%s\n", MP_ENV_format, mpw_marshal_format_extension( MPMarshalFormatFlat ), mpw_marshal_format_extension( MPMarshalFormatJSON ) ); inf( "" " -R redacted Whether to save the mpsites in redacted format or not.\n" " Redaction omits or encrypts any secrets, making the file safe\n" " for saving on or transmitting via untrusted media.\n" - " Defaults to 1, redacted.\n\n" ); + " Defaults to 1, redacted.\n" ); inf( "" " -v Increase output verbosity (can be repeated).\n" - " -q Decrease output verbosity (can be repeated).\n\n" ); + " -q Decrease output verbosity (can be repeated).\n" ); inf( "" - " -h Show this help output instead of performing any operation.\n\n" ); + " -h Show this help output instead of performing any operation.\n" ); inf( "" "\nENVIRONMENT\n\n" " %-12s The full name of the user (see -u).\n" " %-12s The default algorithm version (see -a).\n" " %-12s The default mpsites format (see -f).\n" - " %-12s The askpass program to use for prompting the user.\n\n", + " %-12s The askpass program to use for prompting the user.\n", MP_ENV_fullName, MP_ENV_algorithm, MP_ENV_format, MP_ENV_askpass ); exit( EX_OK ); } @@ -225,24 +225,24 @@ int main(const int argc, char *const argv[]) { cli_free( &args, NULL ); // Operation summary. - dbg( "-----------------\n" ); + dbg( "-----------------" ); if (operation.user) { - dbg( "fullName : %s\n", operation.user->fullName ); - trc( "masterPassword : %s\n", operation.user->masterPassword ); - dbg( "identicon : %s\n", operation.identicon ); - dbg( "sitesFormat : %s%s\n", mpw_nameForFormat( operation.sitesFormat ), operation.sitesFormatFixed? " (fixed)": "" ); - dbg( "sitesPath : %s\n", operation.sitesPath ); + dbg( "fullName : %s", operation.user->fullName ); + trc( "masterPassword : %s", operation.user->masterPassword ); + dbg( "identicon : %s", operation.identicon ); + dbg( "sitesFormat : %s%s", mpw_nameForFormat( operation.sitesFormat ), operation.sitesFormatFixed? " (fixed)": "" ); + dbg( "sitesPath : %s", operation.sitesPath ); } if (operation.site) { - dbg( "siteName : %s\n", operation.site->name ); - dbg( "siteCounter : %u\n", operation.siteCounter ); - dbg( "resultType : %s (%u)\n", mpw_nameForType( operation.resultType ), operation.resultType ); - dbg( "resultParam : %s\n", operation.resultParam ); - dbg( "keyPurpose : %s (%u)\n", mpw_nameForPurpose( operation.keyPurpose ), operation.keyPurpose ); - dbg( "keyContext : %s\n", operation.keyContext ); - dbg( "algorithmVersion : %u\n", operation.site->algorithm ); + dbg( "siteName : %s", operation.site->name ); + dbg( "siteCounter : %u", operation.siteCounter ); + dbg( "resultType : %s (%u)", mpw_nameForType( operation.resultType ), operation.resultType ); + dbg( "resultParam : %s", operation.resultParam ); + dbg( "keyPurpose : %s (%u)", mpw_nameForPurpose( operation.keyPurpose ), operation.keyPurpose ); + dbg( "keyContext : %s", operation.keyContext ); + dbg( "algorithmVersion : %u", operation.site->algorithm ); } - dbg( "-----------------\n\n" ); + dbg( "-----------------" ); // Finally ready to perform the actual operation. cli_mpw( &args, &operation ); @@ -333,20 +333,20 @@ void cli_args(Arguments *args, Operation *operation, const int argc, char *const case '?': switch (optopt) { case 'u': - ftl( "Missing full name to option: -%c\n", optopt ); + ftl( "Missing full name to option: -%c", optopt ); exit( EX_USAGE ); case 't': - ftl( "Missing type name to option: -%c\n", optopt ); + ftl( "Missing type name to option: -%c", optopt ); exit( EX_USAGE ); case 'c': - ftl( "Missing counter value to option: -%c\n", optopt ); + ftl( "Missing counter value to option: -%c", optopt ); exit( EX_USAGE ); default: - ftl( "Unknown option: -%c\n", optopt ); + ftl( "Unknown option: -%c", optopt ); exit( EX_USAGE ); } default: - ftl( "Unexpected option: %c\n", opt ); + ftl( "Unexpected option: %c", opt ); exit( EX_USAGE ); } @@ -367,7 +367,7 @@ void cli_fullName(Arguments *args, Operation *operation) { } while (operation->fullName && !strlen( operation->fullName )); if (!operation->fullName || !strlen( operation->fullName )) { - ftl( "Missing full name.\n" ); + ftl( "Missing full name." ); cli_free( args, operation ); exit( EX_DATAERR ); } @@ -380,7 +380,7 @@ void cli_masterPassword(Arguments *args, Operation *operation) { if (args->masterPasswordFD) { operation->masterPassword = mpw_read_fd( atoi( args->masterPasswordFD ) ); if (!operation->masterPassword && errno) - wrn( "Error reading master password from FD %s: %s\n", args->masterPasswordFD, strerror( errno ) ); + wrn( "Error reading master password from FD %s: %s", args->masterPasswordFD, strerror( errno ) ); } if (args->masterPassword && !operation->masterPassword) @@ -392,7 +392,7 @@ void cli_masterPassword(Arguments *args, Operation *operation) { } while (operation->masterPassword && !strlen( operation->masterPassword )); if (!operation->masterPassword || !strlen( operation->masterPassword )) { - ftl( "Missing master password.\n" ); + ftl( "Missing master password." ); cli_free( args, operation ); exit( EX_DATAERR ); } @@ -408,7 +408,7 @@ void cli_siteName(Arguments *args, Operation *operation) { operation->siteName = mpw_getline( "Site name:" ); if (!operation->siteName) { - ftl( "Missing site name.\n" ); + ftl( "Missing site name." ); cli_free( args, operation ); exit( EX_DATAERR ); } @@ -421,7 +421,7 @@ void cli_sitesFormat(Arguments *args, Operation *operation) { operation->sitesFormat = mpw_formatWithName( args->sitesFormat ); if (ERR == (int)operation->sitesFormat) { - ftl( "Invalid sites format: %s\n", args->sitesFormat ); + ftl( "Invalid sites format: %s", args->sitesFormat ); cli_free( args, operation ); exit( EX_DATAERR ); } @@ -434,7 +434,7 @@ void cli_keyPurpose(Arguments *args, Operation *operation) { operation->keyPurpose = mpw_purposeWithName( args->keyPurpose ); if (ERR == (int)operation->keyPurpose) { - ftl( "Invalid purpose: %s\n", args->keyPurpose ); + ftl( "Invalid purpose: %s", args->keyPurpose ); cli_free( args, operation ); exit( EX_DATAERR ); } @@ -455,7 +455,7 @@ void cli_user(Arguments *args, Operation *operation) { mpw_free_string( &operation->sitesPath ); operation->sitesPath = mpw_path( operation->fullName, mpw_marshal_format_extension( operation->sitesFormat ) ); if (!operation->sitesPath || !(sitesFile = fopen( operation->sitesPath, "r" ))) { - dbg( "Couldn't open configuration file:\n %s: %s\n", operation->sitesPath, strerror( errno ) ); + dbg( "Couldn't open configuration file:\n %s: %s", operation->sitesPath, strerror( errno ) ); // Try to fall back to the flat format. if (!operation->sitesFormatFixed) { @@ -464,7 +464,7 @@ void cli_user(Arguments *args, Operation *operation) { if (operation->sitesPath && (sitesFile = fopen( operation->sitesPath, "r" ))) operation->sitesFormat = MPMarshalFormatFlat; else - dbg( "Couldn't open configuration file:\n %s: %s\n", operation->sitesPath, strerror( errno ) ); + dbg( "Couldn't open configuration file:\n %s: %s", operation->sitesPath, strerror( errno ) ); } } @@ -476,7 +476,7 @@ void cli_user(Arguments *args, Operation *operation) { // Read file. char *sitesInputData = mpw_read_file( sitesFile ); if (ferror( sitesFile )) - wrn( "Error while reading configuration file:\n %s: %d\n", operation->sitesPath, ferror( sitesFile ) ); + wrn( "Error while reading configuration file:\n %s: %d", operation->sitesPath, ferror( sitesFile ) ); fclose( sitesFile ); // Parse file. @@ -489,8 +489,8 @@ void cli_user(Arguments *args, Operation *operation) { if (marshalError.type == MPMarshalErrorMasterPassword && operation->allowPasswordUpdate) { // Update master password in mpsites. while (marshalError.type == MPMarshalErrorMasterPassword) { - inf( "Given master password does not match configuration.\n" ); - inf( "To update the configuration with this new master password, first confirm the old master password.\n" ); + inf( "Given master password does not match configuration." ); + inf( "To update the configuration with this new master password, first confirm the old master password." ); const char *importMasterPassword = NULL; while (!importMasterPassword || !strlen( importMasterPassword )) @@ -509,14 +509,14 @@ void cli_user(Arguments *args, Operation *operation) { // Incorrect master password. if (marshalError.type == MPMarshalErrorMasterPassword) { - ftl( "Incorrect master password according to configuration:\n %s: %s\n", operation->sitesPath, marshalError.description ); + ftl( "Incorrect master password according to configuration:\n %s: %s", operation->sitesPath, marshalError.description ); cli_free( args, operation ); exit( EX_DATAERR ); } // Any other parse error. if (!operation->user || marshalError.type != MPMarshalSuccess) { - err( "Couldn't parse configuration file:\n %s: %s\n", operation->sitesPath, marshalError.description ); + err( "Couldn't parse configuration file:\n %s: %s", operation->sitesPath, marshalError.description ); cli_free( args, operation ); exit( EX_DATAERR ); } @@ -611,7 +611,7 @@ void cli_resultType(Arguments *args, Operation *operation) { operation->resultType = mpw_typeWithName( args->resultType ); if (ERR == (int)operation->resultType) { - ftl( "Invalid type: %s\n", args->resultType ); + ftl( "Invalid type: %s", args->resultType ); cli_free( args, operation ); exit( EX_USAGE ); } @@ -640,7 +640,7 @@ void cli_siteCounter(Arguments *args, Operation *operation) { long long int siteCounterInt = atoll( args->siteCounter ); if (siteCounterInt < MPCounterValueFirst || siteCounterInt > MPCounterValueLast) { - ftl( "Invalid site counter: %s\n", args->siteCounter ); + ftl( "Invalid site counter: %s", args->siteCounter ); cli_free( args, operation ); exit( EX_USAGE ); } @@ -674,7 +674,7 @@ void cli_algorithmVersion(Arguments *args, Operation *operation) { int algorithmVersionInt = atoi( args->algorithmVersion ); if (algorithmVersionInt < MPAlgorithmVersionFirst || algorithmVersionInt > MPAlgorithmVersionLast) { - ftl( "Invalid algorithm version: %s\n", args->algorithmVersion ); + ftl( "Invalid algorithm version: %s", args->algorithmVersion ); cli_free( args, operation ); exit( EX_USAGE ); } @@ -687,7 +687,7 @@ void cli_sitesRedacted(Arguments *args, Operation *operation) { operation->user->redacted = strcmp( args->sitesRedacted, "1" ) == 0; else if (!operation->user->redacted) - wrn( "Sites configuration is not redacted. Use -R 1 to change this.\n" ); + wrn( "Sites configuration is not redacted. Use -R 1 to change this." ); } void cli_mpw(Arguments *args, Operation *operation) { @@ -701,7 +701,7 @@ void cli_mpw(Arguments *args, Operation *operation) { MPMasterKey masterKey = mpw_masterKey( operation->user->fullName, operation->user->masterPassword, operation->site->algorithm ); if (!masterKey) { - ftl( "Couldn't derive master key.\n" ); + ftl( "Couldn't derive master key." ); cli_free( args, operation ); exit( EX_SOFTWARE ); } @@ -712,7 +712,7 @@ void cli_mpw(Arguments *args, Operation *operation) { if (!(operation->resultState = mpw_siteState( masterKey, operation->site->name, operation->siteCounter, operation->keyPurpose, operation->keyContext, operation->resultType, operation->resultParam, operation->site->algorithm ))) { - ftl( "Couldn't encrypt site result.\n" ); + ftl( "Couldn't encrypt site result." ); mpw_free( &masterKey, MPMasterKeySize ); cli_free( args, operation ); exit( EX_SOFTWARE ); @@ -751,13 +751,13 @@ void cli_mpw(Arguments *args, Operation *operation) { operation->keyPurpose, operation->keyContext, operation->resultType, operation->resultParam, operation->site->algorithm ); mpw_free( &masterKey, MPMasterKeySize ); if (!result) { - ftl( "Couldn't generate site result.\n" ); + ftl( "Couldn't generate site result." ); cli_free( args, operation ); exit( EX_SOFTWARE ); } fprintf( stdout, "%s\n", result ); if (operation->site->url) - inf( "See: %s\n", operation->site->url ); + inf( "See: %s", operation->site->url ); mpw_free_string( &result ); // Update usage metadata. @@ -775,21 +775,21 @@ void cli_save(Arguments __unused *args, Operation *operation) { mpw_free_string( &operation->sitesPath ); operation->sitesPath = mpw_path( operation->user->fullName, mpw_marshal_format_extension( operation->sitesFormat ) ); - dbg( "Updating: %s (%s)\n", operation->sitesPath, mpw_nameForFormat( operation->sitesFormat ) ); + dbg( "Updating: %s (%s)", operation->sitesPath, mpw_nameForFormat( operation->sitesFormat ) ); FILE *sitesFile = NULL; if (!operation->sitesPath || !mpw_mkdirs( operation->sitesPath ) || !(sitesFile = fopen( operation->sitesPath, "w" ))) { - wrn( "Couldn't create updated configuration file:\n %s: %s\n", operation->sitesPath, strerror( errno ) ); + wrn( "Couldn't create updated configuration file:\n %s: %s", operation->sitesPath, strerror( errno ) ); return; } char *buf = NULL; MPMarshalError marshalError = { .type = MPMarshalSuccess }; if (!mpw_marshal_write( &buf, operation->sitesFormat, operation->user, &marshalError ) || marshalError.type != MPMarshalSuccess) - wrn( "Couldn't encode updated configuration file:\n %s: %s\n", operation->sitesPath, marshalError.description ); + wrn( "Couldn't encode updated configuration file:\n %s: %s", operation->sitesPath, marshalError.description ); else if (fwrite( buf, sizeof( char ), strlen( buf ), sitesFile ) != strlen( buf )) - wrn( "Error while writing updated configuration file:\n %s: %d\n", operation->sitesPath, ferror( sitesFile ) ); + wrn( "Error while writing updated configuration file:\n %s: %d", operation->sitesPath, ferror( sitesFile ) ); mpw_free_string( &buf ); fclose( sitesFile ); diff --git a/platform-independent/cli-c/cli/mpw-tests-util.c b/platform-independent/cli-c/cli/mpw-tests-util.c index d6a99ac4..724e8c2e 100644 --- a/platform-independent/cli-c/cli/mpw-tests-util.c +++ b/platform-independent/cli-c/cli/mpw-tests-util.c @@ -75,7 +75,7 @@ xmlNodePtr mpw_xmlTestCaseNode(xmlNodePtr testCaseNode, const char *nodeName) { } } - err( "Missing parent: %s, for case: %s\n", parentId, mpw_xmlTestCaseString( testCaseNode, "id" ) ); + err( "Missing parent: %s, for case: %s", parentId, mpw_xmlTestCaseString( testCaseNode, "id" ) ); return NULL; } diff --git a/platform-independent/cli-c/cli/mpw-tests.c b/platform-independent/cli-c/cli/mpw-tests.c index 4124fc96..e6e157d6 100644 --- a/platform-independent/cli-c/cli/mpw-tests.c +++ b/platform-independent/cli-c/cli/mpw-tests.c @@ -32,7 +32,7 @@ int main(int argc, char *const argv[]) { xmlNodePtr tests = xmlDocGetRootElement( xmlParseFile( "mpw_tests.xml" ) ); if (!tests) { - ftl( "Couldn't find test case: mpw_tests.xml\n" ); + ftl( "Couldn't find test case: mpw_tests.xml" ); abort(); } @@ -60,7 +60,7 @@ int main(int argc, char *const argv[]) { do { fprintf( stdout, "test case %s... ", id ); if (!xmlStrlen( result )) { - fprintf( stdout, "abstract.\n" ); + fprintf( stdout, "abstract." ); continue; } @@ -68,7 +68,7 @@ int main(int argc, char *const argv[]) { MPMasterKey masterKey = mpw_masterKey( (char *)fullName, (char *)masterPassword, algorithm ); if (!masterKey) { - ftl( "Couldn't derive master key.\n" ); + ftl( "Couldn't derive master key." ); abort(); } @@ -85,7 +85,7 @@ int main(int argc, char *const argv[]) { masterKey, (char *)siteName, siteCounter, keyPurpose, (char *)keyContext, resultType, NULL, algorithm ); mpw_free( &masterKey, MPMasterKeySize ); if (!testResult) { - ftl( "Couldn't derive site password.\n" ); + ftl( "Couldn't derive site password." ); continue; }