* Send initial SSPI authentication token. * If use_negotiate is 0, use kerberos authentication package which is * compatible with Unix. If use_negotiate is 1, use the negotiate package * which supports both kerberos and NTLM, but is not compatible with Unix. */
| 346 | * which supports both kerberos and NTLM, but is not compatible with Unix. |
| 347 | */ |
| 348 | static int |
| 349 | pg_SSPI_startup(PGconn *conn, int use_negotiate, int payloadlen) |
| 350 | { |
| 351 | SECURITY_STATUS r; |
| 352 | TimeStamp expire; |
| 353 | char *host = conn->connhost[conn->whichhost].host; |
| 354 | |
| 355 | if (conn->sspictx) |
| 356 | { |
| 357 | appendPQExpBufferStr(&conn->errorMessage, |
| 358 | libpq_gettext("duplicate SSPI authentication request\n")); |
| 359 | return STATUS_ERROR; |
| 360 | } |
| 361 | |
| 362 | /* |
| 363 | * Retrieve credentials handle |
| 364 | */ |
| 365 | conn->sspicred = malloc(sizeof(CredHandle)); |
| 366 | if (conn->sspicred == NULL) |
| 367 | { |
| 368 | appendPQExpBufferStr(&conn->errorMessage, |
| 369 | libpq_gettext("out of memory\n")); |
| 370 | return STATUS_ERROR; |
| 371 | } |
| 372 | |
| 373 | r = AcquireCredentialsHandle(NULL, |
| 374 | use_negotiate ? "negotiate" : "kerberos", |
| 375 | SECPKG_CRED_OUTBOUND, |
| 376 | NULL, |
| 377 | NULL, |
| 378 | NULL, |
| 379 | NULL, |
| 380 | conn->sspicred, |
| 381 | &expire); |
| 382 | if (r != SEC_E_OK) |
| 383 | { |
| 384 | pg_SSPI_error(conn, libpq_gettext("could not acquire SSPI credentials"), r); |
| 385 | free(conn->sspicred); |
| 386 | conn->sspicred = NULL; |
| 387 | return STATUS_ERROR; |
| 388 | } |
| 389 | |
| 390 | /* |
| 391 | * Compute target principal name. SSPI has a different format from GSSAPI, |
| 392 | * but not more complex. We can skip the @REALM part, because Windows will |
| 393 | * fill that in for us automatically. |
| 394 | */ |
| 395 | if (!(host && host[0] != '\0')) |
| 396 | { |
| 397 | appendPQExpBufferStr(&conn->errorMessage, |
| 398 | libpq_gettext("host name must be specified\n")); |
| 399 | return STATUS_ERROR; |
| 400 | } |
| 401 | conn->sspitarget = malloc(strlen(conn->krbsrvname) + strlen(host) + 2); |
| 402 | if (!conn->sspitarget) |
| 403 | { |
| 404 | appendPQExpBufferStr(&conn->errorMessage, |
| 405 | libpq_gettext("out of memory\n")); |
no test coverage detected