@@ -110,11 +110,13 @@ int git_set_config(const account_t *account, git_scope_t scope) { |
| 110 | 110 | git_unset_config_value(GIT_CONFIG_CORE_SSHCOMMAND, scope); |
| 111 | 111 | } |
| 112 | 112 | |
| 113 | | - /* Verify configuration was set correctly */ |
| 114 | | - git_current_config_t current_config; |
| 115 | | - if (git_get_current_config(¤t_config) == 0) { |
| 116 | | - if (strcmp(current_config.name, account->name) != 0 || |
| 117 | | - strcmp(current_config.email, account->email) != 0) { |
| 113 | + /* Verify configuration was set correctly - check the same scope we just wrote to */ |
| 114 | + char verify_name[MAX_NAME_LEN]; |
| 115 | + char verify_email[MAX_EMAIL_LEN]; |
| 116 | + if (git_get_config_value(GIT_CONFIG_USER_NAME, verify_name, sizeof(verify_name), scope) == 0 && |
| 117 | + git_get_config_value(GIT_CONFIG_USER_EMAIL, verify_email, sizeof(verify_email), scope) == 0) { |
| 118 | + if (strcmp(verify_name, account->name) != 0 || |
| 119 | + strcmp(verify_email, account->email) != 0) { |
| 118 | 120 | set_error(ERR_GIT_CONFIG_FAILED, "Git configuration verification failed"); |
| 119 | 121 | return -1; |
| 120 | 122 | } |
@@ -262,55 +264,62 @@ git_scope_t git_get_config_scope(const char *config_key) { |
| 262 | 264 | |
| 263 | 265 | /* Test git configuration */ |
| 264 | 266 | int git_test_config(const account_t *account, git_scope_t scope) { |
| 265 | | - git_current_config_t current_config; |
| 266 | | - (void)scope; /* Suppress unused parameter warning */ |
| 267 | | - |
| 267 | + char verify_name[MAX_NAME_LEN]; |
| 268 | + char verify_email[MAX_EMAIL_LEN]; |
| 269 | + |
| 268 | 270 | if (!account) { |
| 269 | 271 | set_error(ERR_INVALID_ARGS, "NULL account to git_test_config"); |
| 270 | 272 | return -1; |
| 271 | 273 | } |
| 272 | | - |
| 274 | + |
| 273 | 275 | log_info("Testing git configuration for account: %s", account->name); |
| 274 | | - |
| 275 | | - /* Get current configuration and verify it matches */ |
| 276 | | - if (git_get_current_config(¤t_config) != 0) { |
| 277 | | - set_error(ERR_GIT_CONFIG_FAILED, "Failed to read current git configuration"); |
| 276 | + |
| 277 | + /* Get configuration from the specified scope and verify it matches */ |
| 278 | + if (git_get_config_value(GIT_CONFIG_USER_NAME, verify_name, sizeof(verify_name), scope) != 0 || |
| 279 | + git_get_config_value(GIT_CONFIG_USER_EMAIL, verify_email, sizeof(verify_email), scope) != 0) { |
| 280 | + set_error(ERR_GIT_CONFIG_FAILED, "Failed to read git configuration from %s scope", |
| 281 | + git_scope_to_flag(scope)); |
| 278 | 282 | return -1; |
| 279 | 283 | } |
| 280 | | - |
| 281 | | - if (strcmp(current_config.name, account->name) != 0) { |
| 284 | + |
| 285 | + if (strcmp(verify_name, account->name) != 0) { |
| 282 | 286 | set_error(ERR_GIT_CONFIG_FAILED, "Git user.name does not match account: expected '%s', got '%s'", |
| 283 | | - account->name, current_config.name); |
| 287 | + account->name, verify_name); |
| 284 | 288 | return -1; |
| 285 | 289 | } |
| 286 | | - |
| 287 | | - if (strcmp(current_config.email, account->email) != 0) { |
| 290 | + |
| 291 | + if (strcmp(verify_email, account->email) != 0) { |
| 288 | 292 | set_error(ERR_GIT_CONFIG_FAILED, "Git user.email does not match account: expected '%s', got '%s'", |
| 289 | | - account->email, current_config.email); |
| 293 | + account->email, verify_email); |
| 290 | 294 | return -1; |
| 291 | 295 | } |
| 292 | 296 | |
| 293 | 297 | /* Test GPG configuration if enabled */ |
| 294 | 298 | if (account->gpg_enabled && strlen(account->gpg_key_id) > 0) { |
| 295 | | - if (strlen(current_config.signing_key) == 0) { |
| 299 | + char signing_key[MAX_KEY_ID_LEN]; |
| 300 | + char gpg_sign[16]; |
| 301 | + |
| 302 | + if (git_get_config_value(GIT_CONFIG_USER_SIGNINGKEY, signing_key, sizeof(signing_key), scope) != 0 || |
| 303 | + strlen(signing_key) == 0) { |
| 296 | 304 | set_error(ERR_GIT_CONFIG_FAILED, "GPG signing key not configured in git"); |
| 297 | 305 | return -1; |
| 298 | 306 | } |
| 299 | | - |
| 300 | | - if (!current_config.gpg_signing_enabled) { |
| 307 | + |
| 308 | + if (git_get_config_value(GIT_CONFIG_COMMIT_GPGSIGN, gpg_sign, sizeof(gpg_sign), scope) != 0 || |
| 309 | + strcmp(gpg_sign, "true") != 0) { |
| 301 | 310 | log_warning("GPG signing is configured but not enabled"); |
| 302 | 311 | } |
| 303 | | - |
| 312 | + |
| 304 | 313 | /* Test GPG key availability */ |
| 305 | 314 | char gpg_test[256]; |
| 306 | | - snprintf(gpg_test, sizeof(gpg_test), "gpg --list-secret-keys '%s' >/dev/null 2>&1", |
| 315 | + snprintf(gpg_test, sizeof(gpg_test), "gpg --list-secret-keys '%s' >/dev/null 2>&1", |
| 307 | 316 | account->gpg_key_id); |
| 308 | 317 | if (system(gpg_test) != 0) { |
| 309 | 318 | set_error(ERR_GPG_KEY_NOT_FOUND, "GPG key not available: %s", account->gpg_key_id); |
| 310 | 319 | return -1; |
| 311 | 320 | } |
| 312 | 321 | } |
| 313 | | - |
| 322 | + |
| 314 | 323 | log_info("Git configuration test passed for %s", account->name); |
| 315 | 324 | return 0; |
| 316 | 325 | } |
@@ -475,7 +484,7 @@ int git_configure_ssh(const account_t *account, git_scope_t scope) { |
| 475 | 484 | |
| 476 | 485 | /* Build SSH command with security options */ |
| 477 | 486 | if ((size_t)snprintf(ssh_command, sizeof(ssh_command), |
| 478 | | - "ssh -i '%s' -o IdentitiesOnly=yes -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no", |
| 487 | + "ssh -i '%s' -o IdentitiesOnly=yes -o StrictHostKeyChecking=accept-new -o LogLevel=ERROR", |
| 479 | 488 | expanded_key_path) >= sizeof(ssh_command)) { |
| 480 | 489 | set_error(ERR_INVALID_ARGS, "SSH command too long"); |
| 481 | 490 | return -1; |