allow setting of default user name from config file #3114

Closed
michaelrsweet opened this Issue Mar 2, 2009 · 4 comments

Comments

Projects
None yet
1 participant
Collaborator

michaelrsweet commented Mar 2, 2009

Version: 1.6-feature
CUPS.org User: baszoetekouw

Currently, cups uses the user's user name to print jobs to remote printers, unless it is overridden by for example the -U switch of the lp tool. Unfortunately, it's very annoying to have to specify this every time, and printer dialogs from graphical program's don't even allow this setting.
So please create the possibility to set the username from a config file. As far as I can see in the code, this possibility doesn't exist at the moment, so I made a qucik hack to allow this (see attachment). It works pretty well.

Collaborator

michaelrsweet commented Jan 13, 2012

CUPS.org User: mike

While we won't adopt the change as-is, I think we can add a "User" directive to the client.conf file to supplement the existing USER environment variable support.

Collaborator

michaelrsweet commented Feb 16, 2012

CUPS.org User: mike

Fixed in Subversion repository.

Collaborator

michaelrsweet commented Feb 16, 2012

"patch":

--- usersys.c.eerst 2009-03-02 10:05:20.092915781 +0100
+++ usersys.c 2009-03-02 10:06:08.378947328 +0100
@@ -401,10 +401,43 @@
{
struct passwd pwd; / User/password entry _/
_cups_globals_t *cg = cupsGlobals(); / Pointer to library globals */

  • char filename[1024];
  • char line[1024];
  • const char * home;
  • FILE * fp;
  • // FOOBAS
    if (!cg->user[0])
    {
  • /*
  • \* check if a default user was specified 
    
  • */
    
  • if ((home = getenv("HOME")) != NULL)
  • {
  •  /*
    
  •   \* Look for ~/.cups/suername
    
  •   */
    
  •  snprintf(filename, sizeof(filename), "%s/.cups/username", home);
    
  •  if ((fp = cupsFileOpen(filename, "r")) != NULL)
    
  •  {
    
  •    cupsFileGets( fp, line, sizeof(line) );
    
  •    cupsFileClose( fp );
    
  •    if (line[0])
    
  •    {
    
  •      strlcpy(cg->user, line, sizeof(cg->user));
    
  •    }
    
  •  }
    
  • }
  • }
  • if (!cg->user[0])
  • {

/*

  • Rewind the password file...
    */
Collaborator

michaelrsweet commented Feb 16, 2012

"str3114.patch":

Index: doc/help/ref-client-conf.html

--- doc/help/ref-client-conf.html (revision 10288)
+++ doc/help/ref-client-conf.html (working copy)
@@ -71,5 +71,20 @@
present, only the last one is used. This directive is not supported on Mac OS X 10.7 or later.

+

CUPS 1.6User


+
+

Examples


+
+

+User joe
+User bob
+

+
+

Description


+
+

The User directive sets the user name to use. The default is the username associated with the current login.


+
+

Index: cups/usersys.c

--- cups/usersys.c (revision 10288)
+++ cups/usersys.c (working copy)
@@ -66,6 +66,7 @@
_cups_globals_t *cg,
const char *cups_encryption,
const char *cups_server,

  •                 const char _cups_user,
    
    #ifdef HAVE_GSSAPI
    const char *cups_gssservicename,
    #endif /_ HAVE_GSSAPI /
    @@ -435,56 +436,12 @@
    const char * /
    O - User name */
    cupsUser(void)
    {
  • const char user; / USER environment variable _/
    _cups_globals_t *cg = cupsGlobals(); / Pointer to library globals */

if (!cg->user[0])

  • {
    -#ifdef WIN32
  • /*
  • * Get the current user name from the OS...
  • */
  • _cupsSetDefaults();

- DWORD size; /* Size of string */

  • size = sizeof(cg->user);
  • if (!GetUserName(cg->user, &size))
    -#else
  • /*
  • * Get the user name corresponding to the current UID...

- */

- struct passwd pwd; / User/password entry */

  • setpwent();
  • if ((pwd = getpwuid(getuid())) != NULL)
  • {
  • /*
    
  •  \* Found a match!
    

- */

  •  strlcpy(cg->user, pwd->pw_name, sizeof(cg->user));
    
  • }
  • else
    -#endif /* WIN32 */
  • if ((user = getenv("USER")) != NULL)
  • {
  • /*
    
  •  \* Use the username from the "USER" environment variable...
    
  •  */
    
  •  strlcpy(cg->user, user, sizeof(cg->user));
    
  • }
  • else
  • {
  • /*
    
  •  \* Use the default "unknown" user name...
    

- */

  •  strcpy(cg->user, "unknown");
    
  • }

- }

return (cg->user);
}

@@ -791,6 +748,7 @@
const char home, / Home directory of user /
*cups_encryption, /
CUPS_ENCRYPTION env var /
*cups_server, /
CUPS_SERVER env var */

  •   *cups_user,     /* CUPS_USER/USER env var */
    

    #ifdef HAVE_GSSAPI
    cups_gssservicename, / CUPS_GSSSERVICENAME env var /
    #endif /
    HAVE_GSSAPI */
    @@ -816,13 +774,16 @@
    cups_expiredroot = getenv("CUPS_EXPIREDROOT");
    cups_expiredcerts = getenv("CUPS_EXPIREDCERTS");

  • if ((cups_user = getenv("CUPS_USER")) == NULL)

  • cups_user = getenv("USER");

/*

  • Then, if needed, read the ~/.cups/client.conf or /etc/cups/client.conf
  • files to get the default values...
    */

if (cg->encryption == (http_encryption_t)-1 || !cg->server[0] ||

  •  !cg->ipp_port)
    
  •  !cg->user[0] || !cg->ipp_port)
    

    {
    if ((home = getenv("HOME")) != NULL)
    {
    @@ -852,7 +813,7 @@

    • functions handle NULL cups_file_t pointers...
      */
  • cups_read_client_conf(fp, cg, cups_encryption, cups_server,

  • cups_read_client_conf(fp, cg, cups_encryption, cups_server, cups_user,
    #ifdef HAVE_GSSAPI
    cups_gssservicename,
    #endif /* HAVE_GSSAPI _/
    @@ -873,6 +834,7 @@
    cups_globals_t *cg, / I - Global data /
    const char *cups_encryption, /
    I - CUPS_ENCRYPTION env var /
    const char *cups_server, /
    I - CUPS_SERVER env var */

  • const char cups_user, / I - CUPS_USER env var /
    #ifdef HAVE_GSSAPI
    const char *cups_gssservicename,
    /
    I - CUPS_GSSSERVICENAME env var /
    @@ -888,6 +850,7 @@
    #ifndef APPLE
    server_name[1024], /
    ServerName value /
    #endif /
    !APPLE */

  • user[256], /* User value /
    any_root[1024], /
    AllowAnyRoot value /
    expired_root[1024], /
    AllowExpiredRoot value /
    expired_certs[1024]; /
    AllowExpiredCerts value /
    @@ -921,6 +884,11 @@
    cups_server = server_name;
    }
    #endif /
    !APPLE */

  • else if (!cups_user && !_cups_strcasecmp(line, "User") && value)

  • {

  •  strlcpy(user, value, sizeof(user));
    
  •  cups_user = user;
    
  • }
    else if (!cups_anyroot && !_cups_strcasecmp(line, "AllowAnyRoot") && value)
    {
    strlcpy(any_root, value, sizeof(any_root));
    @@ -1029,6 +997,49 @@
    cg->ipp_port = CUPS_DEFAULT_IPP_PORT;
    }

  • if (!cg->user[0])

  • {

  • if (cups_user)

  •  strlcpy(cg->user, cups_user, sizeof(cg->user));
    
  • else

  • {
    +#ifdef WIN32

  • /*
    
  •  \* Get the current user name from the OS...
    
  •  */
    
  •  DWORD    size;           /\* Size of string */
    
  •  size = sizeof(cg->user);
    
  •  if (!GetUserName(cg->user, &size))
    

    +#else

  • /*
    
  •  \* Get the user name corresponding to the current UID...
    
  •  */
    
  •  struct passwd    _pwd;       /_ User/password entry */
    
  •  setpwent();
    
  •  if ((pwd = getpwuid(getuid())) != NULL)
    
  •  {
    
  •   /*
    
  • * Found a match!

  • */

  • strlcpy(cg->user, pwd->pw_name, sizeof(cg->user));
  •  }
    
  •  else
    
    +#endif /* WIN32 */
  •  {
    
  •   /*
    
  • * Use the default "unknown" user name...
  • */
  • strcpy(cg->user, "unknown");
  •  }
    
  • }
  • }

#ifdef HAVE_GSSAPI
if (!cups_gssservicename)
cups_gssservicename = CUPS_DEFAULT_GSSSERVICENAME;
Index: man/client.conf.man.in

--- man/client.conf.man.in (revision 10288)
+++ man/client.conf.man.in (working copy)
@@ -3,7 +3,7 @@
."
." client.conf man page for CUPS.
."
-." Copyright 2007-2011 by Apple Inc.
+." Copyright 2007-2012 by Apple Inc.
." Copyright 2006 by Easy Software Products.
."
." These coded instructions, statements, and computer programs are the
@@ -12,7 +12,7 @@
." which should have been included with this file. If this file is
." file is missing or damaged, see the license at "http://www.cups.org/".
."
-.TH client.conf 5 "CUPS" "2 September 2011" "Apple Inc."
+.TH client.conf 5 "CUPS" "15 February 2012" "Apple Inc."
.SH NAME
client.conf - client configuration file for cups
.SH DESCRIPTION
@@ -46,10 +46,14 @@
.br
Specifies the address and optionally the port to use when connecting to the
server. \fBNote: Not supported on Mac OS X 10.7 or later.\fR
+.TP 5
+User name
+.br
+Specifies the default user name to use for requests.
.SH SEE ALSO
http://localhost:631/help
.SH COPYRIGHT
-Copyright 2007-2011 by Apple Inc.
+Copyright 2007-2012 by Apple Inc.
."
." End of "$Id$".
."

michaelrsweet added this to the Stable milestone Mar 17, 2016

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment