Esempio n. 1
0
static void
cups_read_client_conf(
    cups_file_t         *fp,		/* I - File to read */
    _cups_client_conf_t *cc)		/* I - client.conf values */
{
  int	linenum;			/* Current line number */
  char	line[1024],			/* Line from file */
        *value;				/* Pointer into line */


 /*
  * Read from the file...
  */

  linenum = 0;
  while (cupsFileGetConf(fp, line, sizeof(line), &value, &linenum))
  {
    if (!_cups_strcasecmp(line, "Encryption") && value)
      cups_set_encryption(cc, value);
#ifndef __APPLE__
   /*
    * The ServerName directive is not supported on macOS due to app
    * sandboxing restrictions, i.e. not all apps request network access.
    */
    else if (!_cups_strcasecmp(line, "ServerName") && value)
      cups_set_server_name(cc, value);
#endif /* !__APPLE__ */
    else if (!_cups_strcasecmp(line, "User") && value)
      cups_set_user(cc, value);
    else if (!_cups_strcasecmp(line, "TrustOnFirstUse") && value)
      cc->trust_first = cups_boolean_value(value);
    else if (!_cups_strcasecmp(line, "AllowAnyRoot") && value)
      cc->any_root = cups_boolean_value(value);
    else if (!_cups_strcasecmp(line, "AllowExpiredCerts") &&
             value)
      cc->expired_certs = cups_boolean_value(value);
    else if (!_cups_strcasecmp(line, "ValidateCerts") && value)
      cc->validate_certs = cups_boolean_value(value);
#ifdef HAVE_GSSAPI
    else if (!_cups_strcasecmp(line, "GSSServiceName") && value)
      cups_set_gss_service_name(cc, value);
#endif /* HAVE_GSSAPI */
#ifdef HAVE_SSL
    else if (!_cups_strcasecmp(line, "SSLOptions") && value)
      cups_set_ssl_options(cc, value);
#endif /* HAVE_SSL */
  }
}
Esempio n. 2
0
static void
cups_finalize_client_conf(
    _cups_client_conf_t *cc)		/* I - client.conf values */
{
  const char	*value;			/* Environment variable */


  if ((value = getenv("CUPS_ANYROOT")) != NULL)
    cc->any_root = cups_boolean_value(value);

  if ((value = getenv("CUPS_ENCRYPTION")) != NULL)
    cups_set_encryption(cc, value);

  if ((value = getenv("CUPS_EXPIREDCERTS")) != NULL)
    cc->expired_certs = cups_boolean_value(value);

#ifdef HAVE_GSSAPI
  if ((value = getenv("CUPS_GSSSERVICENAME")) != NULL)
    cups_set_gss_service_name(cc, value);
#endif /* HAVE_GSSAPI */

  if ((value = getenv("CUPS_SERVER")) != NULL)
    cups_set_server_name(cc, value);

  if ((value = getenv("CUPS_USER")) != NULL)
    cups_set_user(cc, value);

  if ((value = getenv("CUPS_VALIDATECERTS")) != NULL)
    cc->validate_certs = cups_boolean_value(value);

 /*
  * Then apply defaults for those values that haven't been set...
  */

  if (cc->any_root < 0)
    cc->any_root = 1;

  if (cc->encryption == (http_encryption_t)-1)
    cc->encryption = HTTP_ENCRYPTION_IF_REQUESTED;

  if (cc->expired_certs < 0)
    cc->expired_certs = 1;

#ifdef HAVE_GSSAPI
  if (!cc->gss_service_name[0])
    cups_set_gss_service_name(cc, CUPS_DEFAULT_GSSSERVICENAME);
#endif /* HAVE_GSSAPI */

  if (!cc->server_name[0])
  {
#ifdef CUPS_DEFAULT_DOMAINSOCKET
   /*
    * If we are compiled with domain socket support, only use the
    * domain socket if it exists and has the right permissions...
    */

    if (!access(CUPS_DEFAULT_DOMAINSOCKET, R_OK))
      cups_set_server_name(cc, CUPS_DEFAULT_DOMAINSOCKET);
    else
#endif /* CUPS_DEFAULT_DOMAINSOCKET */
      cups_set_server_name(cc, "localhost");
  }

  if (!cc->user[0])
  {
#ifdef WIN32
   /*
    * Get the current user name from the OS...
    */

    DWORD	size;			/* Size of string */

    size = sizeof(cc->user);
    if (!GetUserName(cc->user, &size))
#else
   /*
    * Try the USER environment variable as the default username...
    */

    const char *envuser = getenv("USER");
					/* Default username */
    struct passwd *pw = NULL;		/* Account information */

    if (envuser)
    {
     /*
      * Validate USER matches the current UID, otherwise don't allow it to
      * override things...  This makes sure that printing after doing su
      * or sudo records the correct username.
      */

      if ((pw = getpwnam(envuser)) != NULL && pw->pw_uid != getuid())
	pw = NULL;
    }

    if (!pw)
      pw = getpwuid(getuid());

    if (pw)
      strlcpy(cc->user, pw->pw_name, sizeof(cc->user));
    else
#endif /* WIN32 */
    {
     /*
      * Use the default "unknown" user name...
      */

      strlcpy(cc->user, "unknown", sizeof(cc->user));
    }
  }

  if (cc->validate_certs < 0)
    cc->validate_certs = 0;
}