| 105 | */ |
| 106 | |
| 107 | int /* O - 0 on success, -1 on error */ |
| 108 | cupsDoAuthentication( |
| 109 | http_t *http, /* I - Connection to server or @code CUPS_HTTP_DEFAULT@ */ |
| 110 | const char *method, /* I - Request method ("GET", "POST", "PUT") */ |
| 111 | const char *resource) /* I - Resource path */ |
| 112 | { |
| 113 | const char *password, /* Password string */ |
| 114 | *www_auth, /* WWW-Authenticate header */ |
| 115 | *schemedata; /* Scheme-specific data */ |
| 116 | char scheme[256], /* Scheme name */ |
| 117 | prompt[1024]; /* Prompt for user */ |
| 118 | int localauth; /* Local authentication result */ |
| 119 | _cups_globals_t *cg = _cupsGlobals(); /* Global data */ |
| 120 | |
| 121 | |
| 122 | DEBUG_printf(("cupsDoAuthentication(http=%p, method=\"%s\", resource=\"%s\")", (void *)http, method, resource)); |
| 123 | |
| 124 | if (!http) |
| 125 | http = _cupsConnect(); |
| 126 | |
| 127 | if (!http || !method || !resource) |
| 128 | return (-1); |
| 129 | |
| 130 | DEBUG_printf(("2cupsDoAuthentication: digest_tries=%d, userpass=\"%s\"", |
| 131 | http->digest_tries, http->userpass)); |
| 132 | DEBUG_printf(("2cupsDoAuthentication: WWW-Authenticate=\"%s\"", |
| 133 | httpGetField(http, HTTP_FIELD_WWW_AUTHENTICATE))); |
| 134 | |
| 135 | /* |
| 136 | * Clear the current authentication string... |
| 137 | */ |
| 138 | |
| 139 | httpSetAuthString(http, NULL, NULL); |
| 140 | |
| 141 | /* |
| 142 | * See if we can do local authentication... |
| 143 | */ |
| 144 | |
| 145 | if (http->digest_tries < 3) |
| 146 | { |
| 147 | if ((localauth = cups_local_auth(http)) == 0) |
| 148 | { |
| 149 | DEBUG_printf(("2cupsDoAuthentication: authstring=\"%s\"", |
| 150 | http->authstring)); |
| 151 | |
| 152 | if (http->status == HTTP_STATUS_UNAUTHORIZED) |
| 153 | http->digest_tries ++; |
| 154 | |
| 155 | return (0); |
| 156 | } |
| 157 | else if (localauth == -1) |
| 158 | { |
| 159 | http->status = HTTP_STATUS_CUPS_AUTHORIZATION_CANCELED; |
| 160 | return (-1); /* Error or canceled */ |
| 161 | } |
| 162 | } |
| 163 | |
| 164 | /* |