MCPcopy Create free account
hub / github.com/OpenPrinting/cups / authenticate_request

Function authenticate_request

tools/ippeveprinter.c:753–845  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

751 */
752
753static http_status_t /* O - HTTP_STATUS_CONTINUE to keep going, otherwise status to return */
754authenticate_request(
755 ippeve_client_t *client) /* I - Client */
756{
757#if HAVE_LIBPAM
758 /*
759 * If PAM isn't enabled, return 'continue' now...
760 */
761
762 const char *authorization; /* Pointer into Authorization string */
763 int userlen; /* Username:password length */
764 pam_handle_t *pamh; /* PAM authentication handle */
765 int pamerr; /* PAM error code */
766 struct pam_conv pamdata; /* PAM conversation data */
767 ippeve_authdata_t data; /* Authentication data */
768
769
770 if (!PAMService)
771 return (HTTP_STATUS_CONTINUE);
772
773 /*
774 * Try authenticating using PAM...
775 */
776
777 authorization = httpGetField(client->http, HTTP_FIELD_AUTHORIZATION);
778
779 if (!*authorization)
780 return (HTTP_STATUS_UNAUTHORIZED);
781
782 if (strncmp(authorization, "Basic ", 6))
783 {
784 fputs("Unsupported scheme in Authorization header.\n", stderr);
785 return (HTTP_STATUS_BAD_REQUEST);
786 }
787
788 authorization += 5;
789 while (isspace(*authorization & 255))
790 authorization ++;
791
792 userlen = sizeof(data.username);
793 httpDecode64_2(data.username, &userlen, authorization);
794
795 if ((data.password = strchr(data.username, ':')) == NULL)
796 {
797 fputs("No password in Authorization header.\n", stderr);
798 return (HTTP_STATUS_BAD_REQUEST);
799 }
800
801 *(data.password)++ = '\0';
802
803 if (!data.username[0])
804 {
805 fputs("No username in Authorization header.\n", stderr);
806 return (HTTP_STATUS_BAD_REQUEST);
807 }
808
809 pamdata.conv = pam_func;
810 pamdata.appdata_ptr = &data;

Callers 2

process_httpFunction · 0.85
process_ippFunction · 0.85

Calls 2

httpGetFieldFunction · 0.85
httpDecode64_2Function · 0.85

Tested by

no test coverage detected