MCPcopy Create free account
hub / github.com/apache/cloudberry / pg_SSPI_startup

Function pg_SSPI_startup

src/interfaces/libpq/fe-auth.c:348–417  ·  view source on GitHub ↗

* 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. */

Source from the content-addressed store, hash-verified

346 * which supports both kerberos and NTLM, but is not compatible with Unix.
347 */
348static int
349pg_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"));

Callers 1

pg_fe_sendauthFunction · 0.85

Calls 4

appendPQExpBufferStrFunction · 0.85
libpq_gettextFunction · 0.85
pg_SSPI_continueFunction · 0.85
pg_SSPI_errorFunction · 0.70

Tested by

no test coverage detected