clang-format: copy latest and re-format

clang-format-17 has some backwards incompatible changes that require
additional settings for best compatibility and re-running the formatter.
Copy the latest .clang-format from the docs repository and reformat the
repository.

Change-Id: I04b3a42ae6b6e53cad330bcd6b524d78368d2bd1
Signed-off-by: Patrick Williams <patrick@stwcx.xyz>
diff --git a/.clang-format b/.clang-format
index ebdee49..0683c55 100644
--- a/.clang-format
+++ b/.clang-format
@@ -1,10 +1,118 @@
-BasedOnStyle: LLVM
-IndentWidth: 8
-UseTab: Always
-BreakBeforeBraces: Linux
-AllowShortBlocksOnASingleLine: Empty
+# SPDX-License-Identifier: GPL-2.0
+#
+# Originally from Linux v5.6
+---
+AccessModifierOffset: -4
+AlignAfterOpenBracket: Align
+AlignConsecutiveMacros: true
+AlignConsecutiveAssignments: false
+AlignConsecutiveDeclarations: false
+#AlignEscapedNewlines: Left # Unknown to clang-format-4.0
+AlignOperands:  Align
+AlignTrailingComments:
+  Kind: Always
+  OverEmptyLines: 1
+AllowAllParametersOfDeclarationOnNextLine: false
+AllowShortBlocksOnASingleLine: false
 AllowShortCaseLabelsOnASingleLine: false
-AllowShortFunctionsOnASingleLine: Empty
+AllowShortFunctionsOnASingleLine: None
 AllowShortIfStatementsOnASingleLine: false
 AllowShortLoopsOnASingleLine: false
+AlwaysBreakAfterDefinitionReturnType: None
+AlwaysBreakAfterReturnType: None
+AlwaysBreakBeforeMultilineStrings: false
+AlwaysBreakTemplateDeclarations: false
+BinPackArguments: true
+BinPackParameters: true
+BraceWrapping:
+  AfterClass: false
+  AfterControlStatement: false
+  AfterEnum: false
+  AfterFunction: true
+  AfterNamespace: true
+  AfterObjCDeclaration: false
+  AfterStruct: false
+  AfterUnion: false
+  #AfterExternBlock: false # Unknown to clang-format-5.0
+  BeforeCatch: false
+  BeforeElse: false
+  IndentBraces: false
+  #SplitEmptyFunction: true # Unknown to clang-format-4.0
+  #SplitEmptyRecord: true # Unknown to clang-format-4.0
+  #SplitEmptyNamespace: true # Unknown to clang-format-4.0
+BreakAfterAttributes: Never
+BreakBeforeBinaryOperators: None
+BreakBeforeBraces: Custom
+#BreakBeforeInheritanceComma: false # Unknown to clang-format-4.0
+BreakBeforeTernaryOperators: false
+BreakConstructorInitializersBeforeComma: false
+#BreakConstructorInitializers: BeforeComma # Unknown to clang-format-4.0
+BreakAfterJavaFieldAnnotations: false
+BreakStringLiterals: false
+ColumnLimit: 80
+CommentPragmas: '^ IWYU pragma:'
+#CompactNamespaces: false # Unknown to clang-format-4.0
+ConstructorInitializerAllOnOneLineOrOnePerLine: false
+ConstructorInitializerIndentWidth: 8
+ContinuationIndentWidth: 8
+Cpp11BracedListStyle: false
+DeriveLineEnding: false
+DerivePointerAlignment: false
+DisableFormat: false
+ExperimentalAutoDetectBinPacking: false
+#FixNamespaceComments: false # Unknown to clang-format-4.0
+#IncludeBlocks: Preserve # Unknown to clang-format-5.0
+IncludeCategories:
+  - Regex: '.*'
+    Priority: 1
+IncludeIsMainRegex: '(Test)?$'
 IndentCaseLabels: false
+IndentExternBlock: NoIndent
+#IndentPPDirectives: None # Unknown to clang-format-5.0
+IndentWidth: 8
+IndentWrappedFunctionNames: false
+InsertNewlineAtEOF: true
+JavaScriptQuotes: Leave
+JavaScriptWrapImports: true
+KeepEmptyLinesAtTheStartOfBlocks: false
+LineEnding: LF
+MacroBlockBegin: ''
+MacroBlockEnd: ''
+MaxEmptyLinesToKeep: 1
+NamespaceIndentation: Inner
+#ObjCBinPackProtocolList: Auto # Unknown to clang-format-5.0
+ObjCBlockIndentWidth: 8
+ObjCSpaceAfterProperty: true
+ObjCSpaceBeforeProtocolList: true
+
+# Taken from git's rules
+PenaltyBreakAssignment: 10
+PenaltyBreakBeforeFirstCallParameter: 30
+PenaltyBreakComment: 10
+PenaltyBreakFirstLessLess: 0
+PenaltyBreakString: 10
+PenaltyExcessCharacter: 100
+PenaltyReturnTypeOnItsOwnLine: 60
+
+PointerAlignment: Right
+ReflowComments: false
+SortIncludes: false
+#SortUsingDeclarations: false # Unknown to clang-format-4.0
+SpaceAfterCStyleCast: false
+SpaceAfterTemplateKeyword: true
+SpaceBeforeAssignmentOperators: true
+#SpaceBeforeCtorInitializerColon: true # Unknown to clang-format-5.0
+#SpaceBeforeInheritanceColon: true # Unknown to clang-format-5.0
+SpaceBeforeParens: ControlStatements
+#SpaceBeforeRangeBasedForLoopColon: true # Unknown to clang-format-5.0
+SpaceInEmptyParentheses: false
+SpacesBeforeTrailingComments: 1
+SpacesInAngles: false
+SpacesInContainerLiterals: false
+SpacesInCStyleCastParentheses: false
+SpacesInParentheses: false
+SpacesInSquareBrackets: false
+Standard: Cpp03
+TabWidth: 8
+UseTab: Always
+...
diff --git a/src/pam_ipmisave/pam_ipmisave.c b/src/pam_ipmisave/pam_ipmisave.c
index 177663d..9e7d33c 100644
--- a/src/pam_ipmisave/pam_ipmisave.c
+++ b/src/pam_ipmisave/pam_ipmisave.c
@@ -38,9 +38,9 @@
 
 #define MAX_SPEC_GRP_PASS_LENGTH 20
 #define MAX_SPEC_GRP_USER_LENGTH 16
-#define MAX_KEY_SIZE 8
-#define DEFAULT_SPEC_PASS_FILE "/etc/ipmi_pass"
-#define META_PASSWD_SIG "=OPENBMC="
+#define MAX_KEY_SIZE		 8
+#define DEFAULT_SPEC_PASS_FILE	 "/etc/ipmi_pass"
+#define META_PASSWD_SIG		 "=OPENBMC="
 
 /*
  * Meta data struct for storing the encrypted password file
@@ -198,8 +198,8 @@
 	if ((retval = EVP_CipherUpdate(ctx, outbytes + outlen, &outEVPlen,
 				       inbytes, inbyteslen))) {
 		outlen += outEVPlen;
-		if ((retval =
-			 EVP_CipherFinal(ctx, outbytes + outlen, &outEVPlen))) {
+		if ((retval = EVP_CipherFinal(ctx, outbytes + outlen,
+					      &outEVPlen))) {
 			outlen += outEVPlen;
 			*outbyteslen = outlen;
 		} else {
@@ -277,7 +277,7 @@
 	char tempfilename[1024];
 	size_t forwholen = strlen(forwho);
 	size_t towhatlen = strlen(towhat);
-	char keybuff[MAX_KEY_SIZE] = {0};
+	char keybuff[MAX_KEY_SIZE] = { 0 };
 	size_t keybuffsize = sizeof(keybuff);
 
 	const EVP_CIPHER *cipher = EVP_aes_128_cbc();
@@ -295,8 +295,8 @@
 	unsigned int maclen = 0;
 	size_t writtensize = 0;
 	unsigned int keylen = 0;
-	metapassstruct pwmp = {META_PASSWD_SIG, {0, 0}, .0, 0, 0, 0, 0};
-	unsigned char mac[EVP_MAX_MD_SIZE] = {0};
+	metapassstruct pwmp = { META_PASSWD_SIG, { 0, 0 }, .0, 0, 0, 0, 0 };
+	unsigned char mac[EVP_MAX_MD_SIZE] = { 0 };
 	unsigned char key[EVP_MAX_KEY_LENGTH];
 	unsigned char iv[EVP_CIPHER_iv_length(cipher)];
 	unsigned char hash[EVP_MD_block_size(digest)];
@@ -412,18 +412,21 @@
 			if (opwmp->datasize != 0) {
 				// Do the decryption
 				if (encrypt_decrypt_data(
-					pamh, 0, cipher, key, keylen,
-					opwfilebuff + sizeof(*opwmp) +
-					    opwmp->hashsize,
-					opwmp->ivsize,
-					opwfilebuff + sizeof(*opwmp) +
-					    opwmp->hashsize + opwmp->ivsize,
-					opwmp->datasize + opwmp->padsize,
-					opwptext, &opwptextlen,
-					opwfilebuff + sizeof(*opwmp) +
-					    opwmp->hashsize + opwmp->ivsize +
+					    pamh, 0, cipher, key, keylen,
+					    opwfilebuff + sizeof(*opwmp) +
+						    opwmp->hashsize,
+					    opwmp->ivsize,
+					    opwfilebuff + sizeof(*opwmp) +
+						    opwmp->hashsize +
+						    opwmp->ivsize,
 					    opwmp->datasize + opwmp->padsize,
-					&tmpmacsize) != 0) {
+					    opwptext, &opwptextlen,
+					    opwfilebuff + sizeof(*opwmp) +
+						    opwmp->hashsize +
+						    opwmp->ivsize +
+						    opwmp->datasize +
+						    opwmp->padsize,
+					    &tmpmacsize) != 0) {
 					pam_syslog(pamh, LOG_DEBUG,
 						   "Decryption failed");
 					free(pwptext);
@@ -448,15 +451,15 @@
 				if ((!strncmp(linebuff, forwho, forwholen)) &&
 				    (linebuff[forwholen] == ':')) {
 					writtensize += snprintf(
-					    (char *)pwptext + writtensize,
-					    pwptextlen - writtensize, "%s:%s\n",
-					    forwho, towhat);
+						(char *)pwptext + writtensize,
+						pwptextlen - writtensize,
+						"%s:%s\n", forwho, towhat);
 					wroteentry = 1;
 				} else {
 					writtensize += snprintf(
-					    (char *)pwptext + writtensize,
-					    pwptextlen - writtensize, "%s\n",
-					    linebuff);
+						(char *)pwptext + writtensize,
+						pwptextlen - writtensize,
+						"%s\n", linebuff);
 				}
 				linebuff = strtok(NULL, "\n");
 			}
@@ -466,8 +469,8 @@
 		free(opwfilebuff);
 		free(opwptext);
 	} else {
-		pwptextlen =
-		    forwholen + towhatlen + 3 + EVP_CIPHER_block_size(cipher);
+		pwptextlen = forwholen + towhatlen + 3 +
+			     EVP_CIPHER_block_size(cipher);
 		pwptext = malloc(pwptextlen);
 		if (pwptext == NULL) {
 			if (opwfile != NULL) {
@@ -525,9 +528,10 @@
 	}
 
 	// Do the encryption
-	if (encrypt_decrypt_data(
-		pamh, 1, cipher, key, keylen, iv, EVP_CIPHER_iv_length(cipher),
-		pwptext, pwptextlen, pwctext, &pwctextlen, mac, &maclen) != 0) {
+	if (encrypt_decrypt_data(pamh, 1, cipher, key, keylen, iv,
+				 EVP_CIPHER_iv_length(cipher), pwptext,
+				 pwptextlen, pwctext, &pwctextlen, mac,
+				 &maclen) != 0) {
 		pam_syslog(pamh, LOG_DEBUG, "Encryption failed");
 		free(pwctext);
 		free(pwptext);
@@ -571,9 +575,9 @@
 
 	if (fflush(pwfile) || fsync(fileno(pwfile))) {
 		pam_syslog(
-		    pamh, LOG_DEBUG,
-		    "fflush or fsync error writing entries to special file: %s",
-		    tempfilename);
+			pamh, LOG_DEBUG,
+			"fflush or fsync error writing entries to special file: %s",
+			tempfilename);
 		err = 1;
 	}
 
@@ -626,9 +630,9 @@
 	const char *user = NULL;
 	const char *pass_new = NULL, *pass_old = NULL;
 	const char *spec_grp_name =
-	    get_option(pamh, "spec_grp_name", argc, argv);
+		get_option(pamh, "spec_grp_name", argc, argv);
 	const char *spec_pass_file =
-	    get_option(pamh, "spec_pass_file", argc, argv);
+		get_option(pamh, "spec_pass_file", argc, argv);
 	const char *key_file = get_option(pamh, "key_file", argc, argv);
 
 	if (spec_grp_name == NULL || key_file == NULL) {
@@ -687,9 +691,9 @@
 		if (spec_pass_file == NULL) {
 			spec_pass_file = DEFAULT_SPEC_PASS_FILE;
 			pam_syslog(
-			    pamh, LOG_ERR,
-			    "Using default special password file name :%s",
-			    spec_pass_file);
+				pamh, LOG_ERR,
+				"Using default special password file name :%s",
+				spec_pass_file);
 		}
 		if ((retval = lock_pwdf())) {
 			pam_syslog(pamh, LOG_ERR,
@@ -697,7 +701,7 @@
 			return retval;
 		}
 		retval = update_pass_special_file(
-		    pamh, key_file, spec_pass_file, user, pass_new);
+			pamh, key_file, spec_pass_file, user, pass_new);
 		unlock_pwdf();
 		return retval;
 	}