Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for setting per-connection password callback #2953

Closed
michaelrsweet opened this Issue Sep 25, 2008 · 4 comments

Comments

Projects
None yet
1 participant
@michaelrsweet
Copy link
Collaborator

michaelrsweet commented Sep 25, 2008

Version: 1.4-feature
CUPS.org User: jelmer

Libraries like GTK+ need the ability to set the password callback for a specific http connection, without side-effects that influence whatever application they're loaded into (the application may construct CUPS connections on its own and want to provide a different callback).

The attached patch adds a per-http-connection password callback function that will be used if set. If no per-connection password callback is set, the behaviour is as previously.

@michaelrsweet

This comment has been minimized.

Copy link
Collaborator Author

michaelrsweet commented Sep 25, 2008

CUPS.org User: mike

Assigning to -feature until we decide to add this for a specific build.

@michaelrsweet

This comment has been minimized.

Copy link
Collaborator Author

michaelrsweet commented Apr 29, 2009

CUPS.org User: mike

OK, added the following APIs:

typedef const char _(_cups_password_cb2_t)(const char *prompt, http_t *http, const char *method, const char *resource, void *user_data);

extern const char *cupsGetPassword2(const char *prompt, http_t *http, const char *method, const char *resource);
extern void cupsSetPasswordCB2(cups_password_cb2_t cb, void *user_data);

The callback is still per-thread, but the connection is passed as one of the arguments (along with other necessary information...)

@michaelrsweet

This comment has been minimized.

Copy link
Collaborator Author

michaelrsweet commented Apr 29, 2009

"http-specific-password-callback.diff":

=== modified file 'cups/auth.c'
--- cups/auth.c 2008-07-11 21:46:21 +0000
+++ cups/auth.c 2008-09-25 00:48:17 +0000
@@ -154,8 +154,13 @@
"Digest", 5) != 0;
http->userpass[0] = '\0';

  • if ((password = cupsGetPassword(prompt)) == NULL)
  •  return (-1);
    
  • if (http->password_cb != NULL) {
  •  if ((password = http->password_cb(http, prompt)) == NULL)
    
  •    return (-1);
    
  • } else {
  •  if ((password = cupsGetPassword(prompt)) == NULL)
    
  •    return (-1);
    
  • }

if (!password[0])
return (-1);

=== modified file 'cups/http-private.h'
--- cups/http-private.h 2008-08-19 23:07:25 +0000
+++ cups/http-private.h 2008-09-25 01:03:51 +0000
@@ -130,7 +130,6 @@
size_t _dataLength);

endif /_ HAVE_LIBSSL */

struct http_s /**** HTTP connection structure. ***/
{
int fd; /_ File descriptor for this socket _/
@@ -188,6 +187,8 @@

ifdef HAVE_AUTHORIZATION_H

AuthorizationRef auth_ref; /_ Authorization ref _/

endif /_ HAVE_AUTHORIZATION_H */

  • http_password_cb_t password_cb;
  •                     /\* Connection-specific password callback */
    
    };

=== modified file 'cups/http.c'
--- cups/http.c 2008-08-19 23:07:25 +0000
+++ cups/http.c 2008-09-25 01:02:32 +0000
@@ -3279,6 +3279,11 @@
}
#endif /* HAVE_SSL */

+void
+httpSetPasswordCB(http_t *http, http_password_cb_t cb)
+{

  • http->password_cb = cb;
    +}

/*

  • End of "$Id$".

=== modified file 'cups/http.h'
--- cups/http.h 2007-10-18 23:57:45 +0000
+++ cups/http.h 2008-09-25 01:02:02 +0000
@@ -314,6 +314,8 @@

typedef struct _http_s http_t; /**** HTTP connection type ****/

+/**** Password callback ***_/
+typedef const char *(_http_password_cb_t)(http_t *http, const char *prompt);

/*

  • Prototypes...
    @@ -437,6 +439,8 @@
    extern void httpSetAuthString(http_t *http, const char *scheme,
    const char *data) _CUPS_API_1_3;

+extern void httpSetPasswordCB(http_t http, http_password_cb_t cb);
+
/

  • C++ magic...
    */
@michaelrsweet

This comment has been minimized.

Copy link
Collaborator Author

michaelrsweet commented Apr 29, 2009

"str2953.patch":

Index: cups/auth.c

--- cups/auth.c (revision 8566)
+++ cups/auth.c (working copy)
@@ -83,10 +83,10 @@
*/

int /* O - 0 on success, -1 on error /
-cupsDoAuthentication(http_t *http, /
I - Connection to server or @code CUPS_HTTP_DEFAULT@ */

  •                 const char _method,/_ I - Request method ("GET", "POST", "PUT") */
    
  •        const char *resource)
    
  •               /\* I - Resource path */
    
    +cupsDoAuthentication(
  • http_t http, / I - Connection to server or @code CUPS_HTTP_DEFAULT@ */
  • const char method, / I - Request method ("GET", "POST", "PUT") */
  • const char resource) / I - Resource path /
    {
    const char *password; /
    Password string /
    char prompt[1024], /
    Prompt for user */
    @@ -103,6 +103,12 @@
    DEBUG_printf(("2cupsDoAuthentication: WWW-Authenticate="%s"",
    httpGetField(http, HTTP_FIELD_WWW_AUTHENTICATE)));
  • if (!http)
  • http = _cupsConnect();
  • if (!http || !method || !resource)
  • return (-1);

/*

  • Clear the current authentication string...
    */
    @@ -154,7 +160,7 @@
    "Digest", 5) != 0;
    http->userpass[0] = '\0';
  • if ((password = cupsGetPassword(prompt)) == NULL)
  • if ((password = cupsGetPassword2(prompt, http, method, resource)) == NULL)
    return (-1);

if (!password[0])

Index: cups/usersys.c

--- cups/usersys.c (revision 8566)
+++ cups/usersys.c (working copy)
@@ -23,6 +23,7 @@

  •                         server.
    
  • cupsSetEncryption() - Set the encryption preference.
  • cupsSetPasswordCB() - Set the password callback for CUPS.
  • * cupsSetPasswordCB2() - Set the advanced password callback for CUPS.
    • cupsSetServer() - Set the default server name.
    • cupsSetUser() - Set the default user name.
    • cupsUser() - Return the current user's name.
      @@ -87,11 +88,40 @@
      const char * /* O - Password /
      cupsGetPassword(const char *prompt) /
      I - Prompt string */
      {
  • return ((*_cupsGlobals()->password_cb)(prompt));
  • _cups_globals_t _cg = cupsGlobals(); / Pointer to library globals */
  • return ((cg->password_cb)(prompt, NULL, NULL, NULL, cg->password_data));
    }

/*

  • * 'cupsGetPassword2()' - Get a password from the user using the advanced
  • * callback.
  • * Uses the current password callback function. Returns @code NULL@ if the
  • * user does not provide a password.
  • * @SInCE CUPS 1.4@
  • /
    +
    +const char * /
    O - Password /
    +cupsGetPassword2(const char *prompt, /
    I - Prompt string */
  •    http_t     _http,  /_ I - Connection to server or @code CUPS_HTTP_DEFAULT@ */
    
  •    const char _method,    /_ I - Request method ("GET", "POST", "PUT") */
    
  •    const char _resource)  /_ I - Resource path */
    
    +{
  • _cups_globals_t _cg = cupsGlobals(); / Pointer to library globals */
  • if (!http)
  • http = _cupsConnect();
  • return ((cg->password_cb)(prompt, http, method, resource, cg->password_data));
    +}

+/*

  • 'cupsServer()' - Return the hostname/address of the default server.
    *
  • The returned value can be a fully-qualified hostname, a numeric
    @@ -140,10 +170,37 @@
    _cups_globals_t _cg = cupsGlobals(); / Pointer to library globals */
  • if (cb == (const char ()(const char *))0)
  • cg->password_cb = _cupsGetPassword;
  • if (cb == (cups_password_cb_t)0)
  • cg->password_cb = (cups_password_cb2_t)_cupsGetPassword;
    else
  • cg->password_cb = (cups_password_cb2_t)cb;
  • cg->password_data = NULL;
    +}

+/*

  • * 'cupsSetPasswordCB2()' - Set the advanced password callback for CUPS.
  • * Pass @code NULL@ to restore the default (console) password callback.
  • * @SInCE CUPS 1.4@
  • */
    +
    +void
    +cupsSetPasswordCB2(
  • cups_password_cb2_t cb, /* I - Callback function */
  • void user_data) / I - User data pointer */
    +{
  • _cups_globals_t _cg = cupsGlobals(); / Pointer to library globals */
  • if (cb == (cups_password_cb2_t)0)
  • cg->password_cb = (cups_password_cb2_t)_cupsGetPassword;
  • else
    cg->password_cb = cb;
  • cg->password_data = user_data;
    }

Index: cups/cups.h

--- cups/cups.h (revision 8566)
+++ cups/cups.h (working copy)
@@ -125,6 +125,12 @@
typedef const char _(_cups_password_cb_t)(const char prompt);
/
*** Password callback ****/

+typedef const char _(_cups_password_cb2_t)(const char *prompt, http_t *http,

  •                  const char *method,
    
  •                  const char *resource,
    
  •                  void *user_data);
    
  •               /***\* New password callback @since CUPS 1.4@ ***_/
    

    typedef void (_cups_device_cb_t)(const char *device_class,
    const char *device_id, const char *device_info,
    const char *device_make_and_model,
    @@ -294,6 +300,9 @@
    void *user_data) _CUPS_API_1_4;
    extern cups_dest_t *cupsGetNamedDest(http_t *http, const char *name,
    const char *instance) _CUPS_API_1_4;
    +extern const char *cupsGetPassword2(const char *prompt, http_t *http,

  •                 const char *method,
    
  •                 const char *resource) _CUPS_API_1_4;
    

    extern http_status_t cupsGetPPD3(http_t *http, const char *name,
    time_t *modtime, char *buffer,
    size_t bufsize) _CUPS_API_1_4;
    @@ -309,6 +318,8 @@
    extern http_status_t cupsSendRequest(http_t *http, ipp_t *request,
    const char *resource,
    size_t length) _CUPS_API_1_4;
    +extern void cupsSetPasswordCB2(cups_password_cb2_t cb,

  •                          void *user_data) _CUPS_API_1_4;
    

    extern http_status_t cupsStartDocument(http_t *http, const char *name,
    int job_id, const char *docname,
    const char *format,

    Index: cups/globals.c

    --- cups/globals.c (revision 8566)
    +++ cups/globals.c (working copy)
    @@ -112,7 +112,7 @@
    */

    globals->encryption = (http_encryption_t)-1;

  • globals->password_cb = _cupsGetPassword;

  • globals->password_cb = (cups_password_cb2_t)_cupsGetPassword;

cups_env_init(globals);
}

Index: cups/globals.h

--- cups/globals.h (revision 8566)
+++ cups/globals.h (working copy)
@@ -120,7 +120,8 @@
char user[65], /* User name /
server[256], /
Server address /
servername[256];/
Server hostname */

  • cups_password_cb_t password_cb; /* Password callback */
  • cups_password_cb2_t password_cb; /* Password callback */
  • void password_data; / Password user data */

/* util.c /
http_t *http; /
Current server connection */

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.