2 * "$Id: conf.c 7952 2008-09-17 00:56:20Z mike $"
4 * Configuration routines for the Common UNIX Printing System (CUPS).
6 * Copyright 2007-2010 by Apple Inc.
7 * Copyright 1997-2007 by Easy Software Products, all rights reserved.
9 * These coded instructions, statements, and computer programs are the
10 * property of Apple Inc. and are protected by Federal copyright
11 * law. Distribution and use rights are outlined in the file "LICENSE.txt"
12 * which should have been included with this file. If this file is
13 * file is missing or damaged, see the license at "http://www.cups.org/".
17 * cupsdAddAlias() - Add a host alias.
18 * cupsdCheckPermissions() - Fix the mode and ownership of a file or
20 * cupsdFreeAliases() - Free all of the alias entries.
21 * cupsdReadConfiguration() - Read the cupsd.conf file.
22 * get_address() - Get an address + port number from a line.
23 * get_addr_and_mask() - Get an IP address and netmask.
24 * parse_aaa() - Parse authentication, authorization, and access
26 * parse_fatal_errors() - Parse FatalErrors values in a string.
27 * parse_groups() - Parse system group names in a string.
28 * parse_protocols() - Parse browse protocols in a string.
29 * read_configuration() - Read a configuration file.
30 * read_location() - Read a <Location path> definition.
31 * read_policy() - Read a <Policy name> definition.
35 * Include necessary headers...
41 #include <sys/utsname.h>
46 #endif /* HAVE_LIBPAPER */
50 * Possibly missing network definitions...
54 # define INADDR_NONE 0xffffffff
55 #endif /* !INADDR_NONE */
59 * Configuration variable structure...
64 CUPSD_VARTYPE_INTEGER
, /* Integer option */
65 CUPSD_VARTYPE_STRING
, /* String option */
66 CUPSD_VARTYPE_BOOLEAN
, /* Boolean option */
67 CUPSD_VARTYPE_PATHNAME
/* File/directory name option */
72 char *name
; /* Name of variable */
73 void *ptr
; /* Pointer to variable */
74 cupsd_vartype_t type
; /* Type (int, string, address) */
82 static const cupsd_var_t variables
[] =
84 { "AccessLog", &AccessLog
, CUPSD_VARTYPE_STRING
},
85 { "AutoPurgeJobs", &JobAutoPurge
, CUPSD_VARTYPE_BOOLEAN
},
86 { "BrowseInterval", &BrowseInterval
, CUPSD_VARTYPE_INTEGER
},
88 { "BrowseLDAPBindDN", &BrowseLDAPBindDN
, CUPSD_VARTYPE_STRING
},
90 { "BrowseLDAPCACertFile", &BrowseLDAPCACertFile
, CUPSD_VARTYPE_PATHNAME
},
91 # endif /* HAVE_LDAP_SSL */
92 { "BrowseLDAPDN", &BrowseLDAPDN
, CUPSD_VARTYPE_STRING
},
93 { "BrowseLDAPPassword", &BrowseLDAPPassword
, CUPSD_VARTYPE_STRING
},
94 { "BrowseLDAPServer", &BrowseLDAPServer
, CUPSD_VARTYPE_STRING
},
95 #endif /* HAVE_LDAP */
96 { "BrowseLocalOptions", &BrowseLocalOptions
, CUPSD_VARTYPE_STRING
},
97 { "BrowsePort", &BrowsePort
, CUPSD_VARTYPE_INTEGER
},
98 { "BrowseRemoteOptions", &BrowseRemoteOptions
, CUPSD_VARTYPE_STRING
},
99 { "BrowseShortNames", &BrowseShortNames
, CUPSD_VARTYPE_BOOLEAN
},
100 { "BrowseTimeout", &BrowseTimeout
, CUPSD_VARTYPE_INTEGER
},
101 { "BrowseWebIF", &BrowseWebIF
, CUPSD_VARTYPE_BOOLEAN
},
102 { "Browsing", &Browsing
, CUPSD_VARTYPE_BOOLEAN
},
103 { "CacheDir", &CacheDir
, CUPSD_VARTYPE_STRING
},
104 { "Classification", &Classification
, CUPSD_VARTYPE_STRING
},
105 { "ClassifyOverride", &ClassifyOverride
, CUPSD_VARTYPE_BOOLEAN
},
106 { "ConfigFilePerm", &ConfigFilePerm
, CUPSD_VARTYPE_INTEGER
},
107 { "DataDir", &DataDir
, CUPSD_VARTYPE_STRING
},
108 { "DefaultLanguage", &DefaultLanguage
, CUPSD_VARTYPE_STRING
},
109 { "DefaultLeaseDuration", &DefaultLeaseDuration
, CUPSD_VARTYPE_INTEGER
},
110 { "DefaultPaperSize", &DefaultPaperSize
, CUPSD_VARTYPE_STRING
},
111 { "DefaultPolicy", &DefaultPolicy
, CUPSD_VARTYPE_STRING
},
112 { "DefaultShared", &DefaultShared
, CUPSD_VARTYPE_BOOLEAN
},
113 { "DirtyCleanInterval", &DirtyCleanInterval
, CUPSD_VARTYPE_INTEGER
},
114 { "DocumentRoot", &DocumentRoot
, CUPSD_VARTYPE_STRING
},
115 { "ErrorLog", &ErrorLog
, CUPSD_VARTYPE_STRING
},
116 { "ErrorPolicy", &ErrorPolicy
, CUPSD_VARTYPE_STRING
},
117 { "FileDevice", &FileDevice
, CUPSD_VARTYPE_BOOLEAN
},
118 { "FilterLimit", &FilterLimit
, CUPSD_VARTYPE_INTEGER
},
119 { "FilterNice", &FilterNice
, CUPSD_VARTYPE_INTEGER
},
120 { "FontPath", &FontPath
, CUPSD_VARTYPE_STRING
},
121 { "HideImplicitMembers", &HideImplicitMembers
, CUPSD_VARTYPE_BOOLEAN
},
122 { "ImplicitClasses", &ImplicitClasses
, CUPSD_VARTYPE_BOOLEAN
},
123 { "ImplicitAnyClasses", &ImplicitAnyClasses
, CUPSD_VARTYPE_BOOLEAN
},
124 { "JobKillDelay", &JobKillDelay
, CUPSD_VARTYPE_INTEGER
},
125 { "JobRetryLimit", &JobRetryLimit
, CUPSD_VARTYPE_INTEGER
},
126 { "JobRetryInterval", &JobRetryInterval
, CUPSD_VARTYPE_INTEGER
},
127 { "KeepAliveTimeout", &KeepAliveTimeout
, CUPSD_VARTYPE_INTEGER
},
128 { "KeepAlive", &KeepAlive
, CUPSD_VARTYPE_BOOLEAN
},
130 { "LaunchdTimeout", &LaunchdTimeout
, CUPSD_VARTYPE_INTEGER
},
131 #endif /* HAVE_LAUNCHD */
132 { "LimitRequestBody", &MaxRequestSize
, CUPSD_VARTYPE_INTEGER
},
133 { "ListenBackLog", &ListenBackLog
, CUPSD_VARTYPE_INTEGER
},
134 { "LogDebugHistory", &LogDebugHistory
, CUPSD_VARTYPE_INTEGER
},
135 { "LogFilePerm", &LogFilePerm
, CUPSD_VARTYPE_INTEGER
},
136 { "LPDConfigFile", &LPDConfigFile
, CUPSD_VARTYPE_STRING
},
137 { "MaxActiveJobs", &MaxActiveJobs
, CUPSD_VARTYPE_INTEGER
},
138 { "MaxClients", &MaxClients
, CUPSD_VARTYPE_INTEGER
},
139 { "MaxClientsPerHost", &MaxClientsPerHost
, CUPSD_VARTYPE_INTEGER
},
140 { "MaxCopies", &MaxCopies
, CUPSD_VARTYPE_INTEGER
},
141 { "MaxEvents", &MaxEvents
, CUPSD_VARTYPE_INTEGER
},
142 { "MaxJobs", &MaxJobs
, CUPSD_VARTYPE_INTEGER
},
143 { "MaxJobsPerPrinter", &MaxJobsPerPrinter
, CUPSD_VARTYPE_INTEGER
},
144 { "MaxJobsPerUser", &MaxJobsPerUser
, CUPSD_VARTYPE_INTEGER
},
145 { "MaxLeaseDuration", &MaxLeaseDuration
, CUPSD_VARTYPE_INTEGER
},
146 { "MaxLogSize", &MaxLogSize
, CUPSD_VARTYPE_INTEGER
},
147 { "MaxPrinterHistory", &MaxPrinterHistory
, CUPSD_VARTYPE_INTEGER
},
148 { "MaxRequestSize", &MaxRequestSize
, CUPSD_VARTYPE_INTEGER
},
149 { "MaxSubscriptions", &MaxSubscriptions
, CUPSD_VARTYPE_INTEGER
},
150 { "MaxSubscriptionsPerJob", &MaxSubscriptionsPerJob
, CUPSD_VARTYPE_INTEGER
},
151 { "MaxSubscriptionsPerPrinter",&MaxSubscriptionsPerPrinter
, CUPSD_VARTYPE_INTEGER
},
152 { "MaxSubscriptionsPerUser", &MaxSubscriptionsPerUser
, CUPSD_VARTYPE_INTEGER
},
153 { "MultipleOperationTimeout", &MultipleOperationTimeout
, CUPSD_VARTYPE_INTEGER
},
154 { "PageLog", &PageLog
, CUPSD_VARTYPE_STRING
},
155 { "PageLogFormat", &PageLogFormat
, CUPSD_VARTYPE_STRING
},
156 { "PreserveJobFiles", &JobFiles
, CUPSD_VARTYPE_BOOLEAN
},
157 { "PreserveJobHistory", &JobHistory
, CUPSD_VARTYPE_BOOLEAN
},
158 { "Printcap", &Printcap
, CUPSD_VARTYPE_STRING
},
159 { "PrintcapGUI", &PrintcapGUI
, CUPSD_VARTYPE_STRING
},
160 { "ReloadTimeout", &ReloadTimeout
, CUPSD_VARTYPE_INTEGER
},
161 { "RemoteRoot", &RemoteRoot
, CUPSD_VARTYPE_STRING
},
162 { "RequestRoot", &RequestRoot
, CUPSD_VARTYPE_STRING
},
163 { "RIPCache", &RIPCache
, CUPSD_VARTYPE_STRING
},
164 { "RootCertDuration", &RootCertDuration
, CUPSD_VARTYPE_INTEGER
},
165 { "ServerAdmin", &ServerAdmin
, CUPSD_VARTYPE_STRING
},
166 { "ServerBin", &ServerBin
, CUPSD_VARTYPE_PATHNAME
},
168 { "ServerCertificate", &ServerCertificate
, CUPSD_VARTYPE_PATHNAME
},
169 # if defined(HAVE_LIBSSL) || defined(HAVE_GNUTLS)
170 { "ServerKey", &ServerKey
, CUPSD_VARTYPE_PATHNAME
},
171 # endif /* HAVE_LIBSSL || HAVE_GNUTLS */
172 #endif /* HAVE_SSL */
173 { "ServerName", &ServerName
, CUPSD_VARTYPE_STRING
},
174 { "ServerRoot", &ServerRoot
, CUPSD_VARTYPE_PATHNAME
},
175 { "SMBConfigFile", &SMBConfigFile
, CUPSD_VARTYPE_STRING
},
176 { "StateDir", &StateDir
, CUPSD_VARTYPE_STRING
},
177 #ifdef HAVE_AUTHORIZATION_H
178 { "SystemGroupAuthKey", &SystemGroupAuthKey
, CUPSD_VARTYPE_STRING
},
179 #endif /* HAVE_AUTHORIZATION_H */
180 { "TempDir", &TempDir
, CUPSD_VARTYPE_PATHNAME
},
181 { "Timeout", &Timeout
, CUPSD_VARTYPE_INTEGER
},
182 { "UseNetworkDefault", &UseNetworkDefault
, CUPSD_VARTYPE_BOOLEAN
}
184 #define NUM_VARS (sizeof(variables) / sizeof(variables[0]))
187 static const unsigned ones
[4] =
189 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff
191 static const unsigned zeros
[4] =
193 0x00000000, 0x00000000, 0x00000000, 0x00000000
201 static http_addrlist_t
*get_address(const char *value
, int defport
);
202 static int get_addr_and_mask(const char *value
, unsigned *ip
,
204 static int parse_aaa(cupsd_location_t
*loc
, char *line
,
205 char *value
, int linenum
);
206 static int parse_fatal_errors(const char *s
);
207 static int parse_groups(const char *s
);
208 static int parse_protocols(const char *s
);
209 static int read_configuration(cups_file_t
*fp
);
210 static int read_location(cups_file_t
*fp
, char *name
, int linenum
);
211 static int read_policy(cups_file_t
*fp
, char *name
, int linenum
);
215 * 'cupsdAddAlias()' - Add a host alias.
219 cupsdAddAlias(cups_array_t
*aliases
, /* I - Array of aliases */
220 const char *name
) /* I - Name to add */
222 cupsd_alias_t
*a
; /* New alias */
223 size_t namelen
; /* Length of name */
226 namelen
= strlen(name
);
228 if ((a
= (cupsd_alias_t
*)malloc(sizeof(cupsd_alias_t
) + namelen
)) == NULL
)
231 a
->namelen
= namelen
;
232 strcpy(a
->name
, name
); /* OK since a->name is allocated */
234 cupsArrayAdd(aliases
, a
);
239 * 'cupsdCheckPermissions()' - Fix the mode and ownership of a file or directory.
242 int /* O - 0 on success, -1 on error, 1 on warning */
243 cupsdCheckPermissions(
244 const char *filename
, /* I - File/directory name */
245 const char *suffix
, /* I - Additional file/directory name */
246 int mode
, /* I - Permissions */
247 int user
, /* I - Owner */
248 int group
, /* I - Group */
249 int is_dir
, /* I - 1 = directory, 0 = file */
250 int create_dir
) /* I - 1 = create directory, -1 = create w/o logging, 0 = not */
252 int dir_created
= 0; /* Did we create a directory? */
253 char pathname
[1024]; /* File name with prefix */
254 struct stat fileinfo
; /* Stat buffer */
255 int is_symlink
; /* Is "filename" a symlink? */
259 * Prepend the given root to the filename before testing it...
264 snprintf(pathname
, sizeof(pathname
), "%s/%s", filename
, suffix
);
269 * See if we can stat the file/directory...
272 if (lstat(filename
, &fileinfo
))
274 if (errno
== ENOENT
&& create_dir
)
277 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Creating missing directory \"%s\"",
280 if (mkdir(filename
, mode
))
283 cupsdLogMessage(CUPSD_LOG_ERROR
,
284 "Unable to create directory \"%s\" - %s", filename
,
287 syslog(LOG_ERR
, "Unable to create directory \"%s\" - %s", filename
,
294 fileinfo
.st_mode
= mode
| S_IFDIR
;
297 return (create_dir
? -1 : 1);
300 if ((is_symlink
= S_ISLNK(fileinfo
.st_mode
)) != 0)
302 if (stat(filename
, &fileinfo
))
304 cupsdLogMessage(CUPSD_LOG_ERROR
, "\"%s\" is a bad symlink - %s",
305 filename
, strerror(errno
));
311 * Make sure it's a regular file or a directory as needed...
314 if (!dir_created
&& !is_dir
&& !S_ISREG(fileinfo
.st_mode
))
316 cupsdLogMessage(CUPSD_LOG_ERROR
, "\"%s\" is not a regular file!", filename
);
320 if (!dir_created
&& is_dir
&& !S_ISDIR(fileinfo
.st_mode
))
323 cupsdLogMessage(CUPSD_LOG_ERROR
, "\"%s\" is not a directory!", filename
);
325 syslog(LOG_ERR
, "\"%s\" is not a directory!", filename
);
331 * If the filename is a symlink, do not change permissions (STR #2937)...
338 * Fix owner, group, and mode as needed...
341 if (dir_created
|| fileinfo
.st_uid
!= user
|| fileinfo
.st_gid
!= group
)
344 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Repairing ownership of \"%s\"",
347 if (chown(filename
, user
, group
) && !getuid())
350 cupsdLogMessage(CUPSD_LOG_ERROR
,
351 "Unable to change ownership of \"%s\" - %s", filename
,
354 syslog(LOG_ERR
, "Unable to change ownership of \"%s\" - %s", filename
,
361 if (dir_created
|| (fileinfo
.st_mode
& 07777) != mode
)
364 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Repairing access permissions of \"%s\"",
367 if (chmod(filename
, mode
))
370 cupsdLogMessage(CUPSD_LOG_ERROR
,
371 "Unable to change permissions of \"%s\" - %s", filename
,
374 syslog(LOG_ERR
, "Unable to change permissions of \"%s\" - %s", filename
,
382 * Everything is OK...
390 * 'cupsdFreeAliases()' - Free all of the alias entries.
394 cupsdFreeAliases(cups_array_t
*aliases
) /* I - Array of aliases */
396 cupsd_alias_t
*a
; /* Current alias */
399 for (a
= (cupsd_alias_t
*)cupsArrayFirst(aliases
);
401 a
= (cupsd_alias_t
*)cupsArrayNext(aliases
))
404 cupsArrayDelete(aliases
);
409 * 'cupsdReadConfiguration()' - Read the cupsd.conf file.
412 int /* O - 1 on success, 0 otherwise */
413 cupsdReadConfiguration(void)
415 int i
; /* Looping var */
416 cups_file_t
*fp
; /* Configuration file */
417 int status
; /* Return status */
418 char temp
[1024], /* Temporary buffer */
419 mimedir
[1024], /* MIME directory */
420 *slash
; /* Directory separator */
421 cups_lang_t
*language
; /* Language */
422 struct passwd
*user
; /* Default user */
423 struct group
*group
; /* Default group */
424 char *old_serverroot
, /* Old ServerRoot */
425 *old_requestroot
; /* Old RequestRoot */
426 int old_remote_port
; /* Old RemotePort */
427 const char *tmpdir
; /* TMPDIR environment variable */
428 struct stat tmpinfo
; /* Temporary directory info */
429 cupsd_policy_t
*p
; /* Policy */
433 * Save the old root paths...
436 old_serverroot
= NULL
;
437 cupsdSetString(&old_serverroot
, ServerRoot
);
438 old_requestroot
= NULL
;
439 cupsdSetString(&old_requestroot
, RequestRoot
);
442 * Reset the server configuration data...
445 cupsdDeleteAllLocations();
464 for (i
= 0; i
< NumRelays
; i
++)
465 if (Relays
[i
].from
.type
== CUPSD_AUTH_NAME
)
466 free(Relays
[i
].from
.mask
.name
.name
);
473 cupsdDeleteAllListeners();
475 old_remote_port
= RemotePort
;
482 cupsdFreeAliases(ServerAlias
);
485 cupsdClearString(&ServerName
);
486 cupsdClearString(&ServerAdmin
);
487 cupsdSetString(&ServerBin
, CUPS_SERVERBIN
);
488 cupsdSetString(&RequestRoot
, CUPS_REQUESTS
);
489 cupsdSetString(&CacheDir
, CUPS_CACHEDIR
);
490 cupsdSetString(&DataDir
, CUPS_DATADIR
);
491 cupsdSetString(&DocumentRoot
, CUPS_DOCROOT
);
492 cupsdSetString(&AccessLog
, CUPS_LOGDIR
"/access_log");
493 cupsdSetString(&ErrorLog
, CUPS_LOGDIR
"/error_log");
494 cupsdSetString(&PageLog
, CUPS_LOGDIR
"/page_log");
495 cupsdSetString(&PageLogFormat
,
496 "%p %j %u %T %P %C %{job-billing} "
497 "%{job-originating-host-name} %{job-name} %{media} %{sides}");
498 cupsdSetString(&Printcap
, CUPS_DEFAULT_PRINTCAP
);
499 cupsdSetString(&PrintcapGUI
, "/usr/bin/glpoptions");
500 cupsdSetString(&FontPath
, CUPS_FONTPATH
);
501 cupsdSetString(&RemoteRoot
, "remroot");
502 cupsdSetString(&ServerHeader
, "CUPS/1.4");
503 cupsdSetString(&StateDir
, CUPS_STATEDIR
);
505 if (!strcmp(CUPS_DEFAULT_PRINTCAP
, "/etc/printers.conf"))
506 PrintcapFormat
= PRINTCAP_SOLARIS
;
507 else if (!strcmp(CUPS_DEFAULT_PRINTCAP
,
508 "/Library/Preferences/org.cups.printers.plist"))
509 PrintcapFormat
= PRINTCAP_PLIST
;
511 PrintcapFormat
= PRINTCAP_BSD
;
513 strlcpy(temp
, ConfigurationFile
, sizeof(temp
));
514 if ((slash
= strrchr(temp
, '/')) != NULL
)
517 cupsdSetString(&ServerRoot
, temp
);
519 cupsdClearString(&Classification
);
520 ClassifyOverride
= 0;
524 cupsdSetString(&ServerCertificate
, "/Library/Keychains/System.keychain");
526 cupsdSetString(&ServerCertificate
, "ssl/server.crt");
527 cupsdSetString(&ServerKey
, "ssl/server.key");
528 # endif /* HAVE_CDSASSL */
529 #endif /* HAVE_SSL */
531 language
= cupsLangDefault();
533 if (!strcmp(language
->language
, "C") || !strcmp(language
->language
, "POSIX"))
534 cupsdSetString(&DefaultLanguage
, "en");
536 cupsdSetString(&DefaultLanguage
, language
->language
);
538 cupsdClearString(&DefaultPaperSize
);
540 cupsdSetString(&RIPCache
, "8m");
542 cupsdSetString(&TempDir
, NULL
);
545 * Find the default user...
548 if ((user
= getpwnam(CUPS_DEFAULT_USER
)) != NULL
)
553 * Use the (historical) NFS nobody user ID (-2 as a 16-bit twos-
554 * complement number...)
563 * Find the default group...
566 group
= getgrnam(CUPS_DEFAULT_GROUP
);
570 Group
= group
->gr_gid
;
574 * Fallback to group "nobody"...
577 group
= getgrnam("nobody");
581 Group
= group
->gr_gid
;
585 * Use the (historical) NFS nobody group ID (-2 as a 16-bit twos-
586 * complement number...)
597 AccessLogLevel
= CUPSD_ACCESSLOG_ACTIONS
;
598 ConfigFilePerm
= CUPS_DEFAULT_CONFIG_FILE_PERM
;
599 FatalErrors
= parse_fatal_errors(CUPS_DEFAULT_FATAL_ERRORS
);
600 DefaultAuthType
= CUPSD_AUTH_BASIC
;
602 DefaultEncryption
= HTTP_ENCRYPT_REQUIRED
;
603 SSLOptions
= CUPSD_SSL_NONE
;
604 #endif /* HAVE_SSL */
605 DirtyCleanInterval
= DEFAULT_KEEPALIVE
;
606 JobKillDelay
= DEFAULT_TIMEOUT
;
608 JobRetryInterval
= 300;
613 HostNameLookups
= FALSE
;
614 ImplicitClasses
= CUPS_DEFAULT_IMPLICIT_CLASSES
;
615 ImplicitAnyClasses
= FALSE
;
616 HideImplicitMembers
= TRUE
;
618 KeepAliveTimeout
= DEFAULT_KEEPALIVE
;
619 ListenBackLog
= SOMAXCONN
;
620 LogDebugHistory
= 200;
621 LogFilePerm
= CUPS_DEFAULT_LOG_FILE_PERM
;
622 LogLevel
= CUPSD_LOG_WARN
;
623 LogTimeFormat
= CUPSD_TIME_STANDARD
;
625 MaxClientsPerHost
= 0;
626 MaxLogSize
= 1024 * 1024;
627 MaxPrinterHistory
= 0;
629 MultipleOperationTimeout
= DEFAULT_TIMEOUT
;
630 ReloadTimeout
= DEFAULT_KEEPALIVE
;
631 RootCertDuration
= 300;
632 Timeout
= DEFAULT_TIMEOUT
;
635 BrowseInterval
= DEFAULT_INTERVAL
;
636 BrowsePort
= ippPort();
637 BrowseLocalProtocols
= parse_protocols(CUPS_DEFAULT_BROWSE_LOCAL_PROTOCOLS
);
638 BrowseRemoteProtocols
= parse_protocols(CUPS_DEFAULT_BROWSE_REMOTE_PROTOCOLS
);
639 BrowseShortNames
= CUPS_DEFAULT_BROWSE_SHORT_NAMES
;
640 BrowseTimeout
= DEFAULT_TIMEOUT
;
642 Browsing
= CUPS_DEFAULT_BROWSING
;
643 DefaultShared
= CUPS_DEFAULT_DEFAULT_SHARED
;
645 cupsdSetString(&LPDConfigFile
, CUPS_DEFAULT_LPD_CONFIG_FILE
);
646 cupsdSetString(&SMBConfigFile
, CUPS_DEFAULT_SMB_CONFIG_FILE
);
648 cupsdClearString(&BrowseLocalOptions
);
649 cupsdClearString(&BrowseRemoteOptions
);
651 cupsdSetString(&ErrorPolicy
, "stop-printer");
654 cupsdClearString(&BrowseLDAPBindDN
);
655 cupsdClearString(&BrowseLDAPDN
);
656 cupsdClearString(&BrowseLDAPPassword
);
657 cupsdClearString(&BrowseLDAPServer
);
658 # ifdef HAVE_LDAP_SSL
659 cupsdClearString(&BrowseLDAPCACertFile
);
660 # endif /* HAVE_LDAP_SSL */
661 #endif /* HAVE_LDAP */
663 JobHistory
= DEFAULT_HISTORY
;
664 JobFiles
= DEFAULT_FILES
;
669 MaxJobsPerPrinter
= 0;
670 MaxCopies
= CUPS_DEFAULT_MAX_COPIES
;
672 cupsdDeleteAllPolicies();
673 cupsdClearString(&DefaultPolicy
);
675 #ifdef HAVE_AUTHORIZATION_H
676 cupsdClearString(&SystemGroupAuthKey
);
677 #endif /* HAVE_AUTHORIZATION_H */
679 MaxSubscriptions
= 100;
680 MaxSubscriptionsPerJob
= 0;
681 MaxSubscriptionsPerPrinter
= 0;
682 MaxSubscriptionsPerUser
= 0;
683 DefaultLeaseDuration
= 86400;
684 MaxLeaseDuration
= 0;
687 LaunchdTimeout
= DEFAULT_TIMEOUT
+ 10;
688 #endif /* HAVE_LAUNCHD */
691 * Read the configuration file...
694 if ((fp
= cupsFileOpen(ConfigurationFile
, "r")) == NULL
)
697 status
= read_configuration(fp
);
706 cupsdLogMessage(CUPSD_LOG_INFO
, "Remote access is %s.",
707 RemotePort
? "enabled" : "disabled");
710 BrowseLocalProtocols
= 0; /* Disable sharing - no remote access */
713 * See if the ServerName is an IP address...
719 ServerAlias
= cupsArrayNew(NULL
, NULL
);
721 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Added auto ServerAlias %s", ServerName
);
725 if (gethostname(temp
, sizeof(temp
)))
727 cupsdLogMessage(CUPSD_LOG_ERROR
, "Unable to get hostname: %s",
729 strlcpy(temp
, "localhost", sizeof(temp
));
732 cupsdSetString(&ServerName
, temp
);
735 ServerAlias
= cupsArrayNew(NULL
, NULL
);
737 cupsdAddAlias(ServerAlias
, temp
);
738 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Added auto ServerAlias %s", temp
);
740 if (HostNameLookups
|| RemotePort
)
742 struct hostent
*host
; /* Host entry to get FQDN */
744 if ((host
= gethostbyname(temp
)) != NULL
)
746 if (strcasecmp(temp
, host
->h_name
))
748 cupsdSetString(&ServerName
, host
->h_name
);
749 cupsdAddAlias(ServerAlias
, host
->h_name
);
750 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Added auto ServerAlias %s",
756 for (i
= 0; host
->h_aliases
[i
]; i
++)
757 if (strcasecmp(temp
, host
->h_aliases
[i
]))
759 cupsdAddAlias(ServerAlias
, host
->h_aliases
[i
]);
760 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Added auto ServerAlias %s",
768 * Make sure we have the base hostname added as an alias, too!
771 if ((slash
= strchr(temp
, '.')) != NULL
)
774 cupsdAddAlias(ServerAlias
, temp
);
775 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Added auto ServerAlias %s", temp
);
779 for (slash
= ServerName
; isdigit(*slash
& 255) || *slash
== '.'; slash
++);
781 ServerNameIsIP
= !*slash
;
784 * Make sure ServerAdmin is initialized...
788 cupsdSetStringf(&ServerAdmin
, "root@%s", ServerName
);
791 * Use the default system group if none was supplied in cupsd.conf...
794 if (NumSystemGroups
== 0)
796 if (!parse_groups(CUPS_DEFAULT_SYSTEM_GROUPS
))
799 * Find the group associated with GID 0...
806 cupsdSetString(&SystemGroups
[0], group
->gr_name
);
808 cupsdSetString(&SystemGroups
[0], "unknown");
810 SystemGroupIDs
[0] = 0;
816 * Get the access control list for browsing...
819 BrowseACL
= cupsdFindLocation("CUPS_INTERNAL_BROWSE_ACL");
822 * Open the system log for cupsd if necessary...
826 if (!strcmp(AccessLog
, "syslog") ||
827 !strcmp(ErrorLog
, "syslog") ||
828 !strcmp(PageLog
, "syslog"))
829 openlog("cupsd", LOG_PID
| LOG_NOWAIT
| LOG_NDELAY
, LOG_LPR
);
830 #endif /* HAVE_VSYSLOG */
833 * Log the configuration file that was used...
836 cupsdLogMessage(CUPSD_LOG_INFO
, "Loaded configuration file \"%s\"",
840 * Validate the Group and SystemGroup settings - they cannot be the same,
841 * otherwise the CGI programs will be able to authenticate as root without
847 for (i
= 0; i
< NumSystemGroups
; i
++)
848 if (Group
== SystemGroupIDs
[i
])
851 if (i
< NumSystemGroups
)
854 * Log the error and reset the group to a safe value...
857 cupsdLogMessage(CUPSD_LOG_NOTICE
,
858 "Group and SystemGroup cannot use the same groups!");
859 cupsdLogMessage(CUPSD_LOG_INFO
, "Resetting Group to \"nobody\"...");
861 group
= getgrnam("nobody");
865 Group
= group
->gr_gid
;
869 * Use the (historical) NFS nobody group ID (-2 as a 16-bit twos-
870 * complement number...)
879 * Check that we have at least one listen/port line; if not, report this
880 * as an error and exit!
883 if (cupsArrayCount(Listeners
) == 0)
889 cupsdLogMessage(CUPSD_LOG_EMERG
,
890 "No valid Listen or Port lines were found in the "
891 "configuration file!");
897 cupsdEndProcess(getpid(), 0);
901 * Set the default locale using the language and charset...
904 cupsdSetStringf(&DefaultLocale
, "%s.UTF-8", DefaultLanguage
);
907 * Update all relative filenames to include the full path from ServerRoot...
910 if (DocumentRoot
[0] != '/')
911 cupsdSetStringf(&DocumentRoot
, "%s/%s", ServerRoot
, DocumentRoot
);
913 if (RequestRoot
[0] != '/')
914 cupsdSetStringf(&RequestRoot
, "%s/%s", ServerRoot
, RequestRoot
);
916 if (ServerBin
[0] != '/')
917 cupsdSetStringf(&ServerBin
, "%s/%s", ServerRoot
, ServerBin
);
919 if (StateDir
[0] != '/')
920 cupsdSetStringf(&StateDir
, "%s/%s", ServerRoot
, StateDir
);
922 if (CacheDir
[0] != '/')
923 cupsdSetStringf(&CacheDir
, "%s/%s", ServerRoot
, CacheDir
);
926 if (ServerCertificate
[0] != '/')
927 cupsdSetStringf(&ServerCertificate
, "%s/%s", ServerRoot
, ServerCertificate
);
929 if (!strncmp(ServerRoot
, ServerCertificate
, strlen(ServerRoot
)) &&
930 cupsdCheckPermissions(ServerCertificate
, NULL
, 0600, RunUser
, Group
,
932 (FatalErrors
& CUPSD_FATAL_PERMISSIONS
))
935 # if defined(HAVE_LIBSSL) || defined(HAVE_GNUTLS)
936 if (ServerKey
[0] != '/')
937 cupsdSetStringf(&ServerKey
, "%s/%s", ServerRoot
, ServerKey
);
939 if (!strncmp(ServerRoot
, ServerKey
, strlen(ServerRoot
)) &&
940 cupsdCheckPermissions(ServerKey
, NULL
, 0600, RunUser
, Group
, 0, 0) < 0 &&
941 (FatalErrors
& CUPSD_FATAL_PERMISSIONS
))
943 # endif /* HAVE_LIBSSL || HAVE_GNUTLS */
944 #endif /* HAVE_SSL */
947 * Make sure that directories and config files are owned and
948 * writable by the user and group in the cupsd.conf file...
951 snprintf(temp
, sizeof(temp
), "%s/rss", CacheDir
);
953 if ((cupsdCheckPermissions(RequestRoot
, NULL
, 0710, RunUser
,
955 cupsdCheckPermissions(CacheDir
, NULL
, 0775, RunUser
,
957 cupsdCheckPermissions(temp
, NULL
, 0775, RunUser
,
959 cupsdCheckPermissions(StateDir
, NULL
, 0755, RunUser
,
961 cupsdCheckPermissions(StateDir
, "certs", RunUser
? 0711 : 0511, User
,
962 SystemGroupIDs
[0], 1, 1) < 0 ||
963 cupsdCheckPermissions(ServerRoot
, NULL
, 0755, RunUser
,
965 cupsdCheckPermissions(ServerRoot
, "ppd", 0755, RunUser
,
967 cupsdCheckPermissions(ServerRoot
, "ssl", 0700, RunUser
,
969 cupsdCheckPermissions(ServerRoot
, "cupsd.conf", ConfigFilePerm
, RunUser
,
971 cupsdCheckPermissions(ServerRoot
, "classes.conf", 0600, RunUser
,
973 cupsdCheckPermissions(ServerRoot
, "printers.conf", 0600, RunUser
,
975 cupsdCheckPermissions(ServerRoot
, "passwd.md5", 0600, User
,
977 (FatalErrors
& CUPSD_FATAL_PERMISSIONS
))
981 * Update TempDir to the default if it hasn't been set already...
986 if ((tmpdir
= getenv("TMPDIR")) != NULL
)
989 * TMPDIR is defined, see if it is OK for us to use...
992 if (stat(tmpdir
, &tmpinfo
))
993 cupsdLogMessage(CUPSD_LOG_ERROR
, "Unable to access TMPDIR (%s): %s",
994 tmpdir
, strerror(errno
));
995 else if (!S_ISDIR(tmpinfo
.st_mode
))
996 cupsdLogMessage(CUPSD_LOG_ERROR
, "TMPDIR (%s) is not a directory!",
998 else if ((tmpinfo
.st_uid
!= User
|| !(tmpinfo
.st_mode
& S_IWUSR
)) &&
999 (tmpinfo
.st_gid
!= Group
|| !(tmpinfo
.st_mode
& S_IWGRP
)) &&
1000 !(tmpinfo
.st_mode
& S_IWOTH
))
1001 cupsdLogMessage(CUPSD_LOG_ERROR
,
1002 "TMPDIR (%s) has the wrong permissions!", tmpdir
);
1004 cupsdSetString(&TempDir
, tmpdir
);
1009 cupsdLogMessage(CUPSD_LOG_INFO
, "Using default TempDir of %s/tmp...",
1011 cupsdSetStringf(&TempDir
, "%s/tmp", RequestRoot
);
1016 * Make sure the temporary directory has the right permissions...
1019 if (!strncmp(TempDir
, RequestRoot
, strlen(RequestRoot
)) ||
1023 * Update ownership and permissions if the CUPS temp directory
1024 * is under the spool directory or does not exist...
1027 if (cupsdCheckPermissions(TempDir
, NULL
, 01770, RunUser
, Group
, 1, 1) < 0 &&
1028 (FatalErrors
& CUPSD_FATAL_PERMISSIONS
))
1033 * Setup environment variables...
1039 * Update default paper size setting as needed...
1042 if (!DefaultPaperSize
)
1044 #ifdef HAVE_LIBPAPER
1045 char *paper_result
; /* Paper size name from libpaper */
1047 if ((paper_result
= systempapername()) != NULL
)
1048 cupsdSetString(&DefaultPaperSize
, paper_result
);
1050 #endif /* HAVE_LIBPAPER */
1051 if (!DefaultLanguage
||
1052 !strcasecmp(DefaultLanguage
, "C") ||
1053 !strcasecmp(DefaultLanguage
, "POSIX") ||
1054 !strcasecmp(DefaultLanguage
, "en") ||
1055 !strncasecmp(DefaultLanguage
, "en.", 3) ||
1056 !strncasecmp(DefaultLanguage
, "en_US", 5) ||
1057 !strncasecmp(DefaultLanguage
, "en_CA", 5) ||
1058 !strncasecmp(DefaultLanguage
, "fr_CA", 5))
1061 * These are the only locales that will default to "letter" size...
1064 cupsdSetString(&DefaultPaperSize
, "Letter");
1067 cupsdSetString(&DefaultPaperSize
, "A4");
1071 * Update classification setting as needed...
1074 if (Classification
&& !strcasecmp(Classification
, "none"))
1075 cupsdClearString(&Classification
);
1078 cupsdLogMessage(CUPSD_LOG_INFO
, "Security set to \"%s\"", Classification
);
1081 * Check the MaxClients setting, and then allocate memory for it...
1084 if (MaxClients
> (MaxFDs
/ 3) || MaxClients
<= 0)
1087 cupsdLogMessage(CUPSD_LOG_INFO
,
1088 "MaxClients limited to 1/3 (%d) of the file descriptor "
1090 MaxFDs
/ 3, MaxFDs
);
1092 MaxClients
= MaxFDs
/ 3;
1095 cupsdLogMessage(CUPSD_LOG_INFO
, "Configured for up to %d clients.",
1099 * Check the MaxActiveJobs setting; limit to 1/3 the available
1100 * file descriptors, since we need a pipe for each job...
1103 if (MaxActiveJobs
> (MaxFDs
/ 3))
1104 MaxActiveJobs
= MaxFDs
/ 3;
1107 * Update the MaxClientsPerHost value, as needed...
1110 if (MaxClientsPerHost
<= 0)
1111 MaxClientsPerHost
= MaxClients
;
1113 if (MaxClientsPerHost
> MaxClients
)
1114 MaxClientsPerHost
= MaxClients
;
1116 cupsdLogMessage(CUPSD_LOG_INFO
,
1117 "Allowing up to %d client connections per host.",
1121 * Make sure that BrowseTimeout is at least twice the interval...
1124 if (BrowseTimeout
< (2 * BrowseInterval
) || BrowseTimeout
<= 0)
1126 cupsdLogMessage(CUPSD_LOG_ALERT
, "Invalid BrowseTimeout value %d!",
1130 BrowseTimeout
= BrowseInterval
* 2;
1132 BrowseTimeout
= DEFAULT_TIMEOUT
;
1134 cupsdLogMessage(CUPSD_LOG_ALERT
, "Reset BrowseTimeout to %d!",
1139 * Update the default policy, as needed...
1143 DefaultPolicyPtr
= cupsdFindPolicy(DefaultPolicy
);
1145 DefaultPolicyPtr
= NULL
;
1147 if (!DefaultPolicyPtr
)
1149 cupsd_location_t
*po
; /* New policy operation */
1153 cupsdLogMessage(CUPSD_LOG_ERROR
, "Default policy \"%s\" not found!",
1156 cupsdSetString(&DefaultPolicy
, "default");
1158 if ((DefaultPolicyPtr
= cupsdFindPolicy("default")) != NULL
)
1159 cupsdLogMessage(CUPSD_LOG_INFO
,
1160 "Using policy \"default\" as the default!");
1163 cupsdLogMessage(CUPSD_LOG_INFO
,
1164 "Creating CUPS default administrative policy:");
1166 DefaultPolicyPtr
= p
= cupsdAddPolicy("default");
1168 cupsdLogMessage(CUPSD_LOG_INFO
, "<Policy default>");
1169 cupsdLogMessage(CUPSD_LOG_INFO
,
1170 "<Limit Create-Job Print-Job Print-URI Validate-Job>");
1171 cupsdLogMessage(CUPSD_LOG_INFO
, "Order Deny,Allow");
1173 po
= cupsdAddPolicyOp(p
, NULL
, IPP_CREATE_JOB
);
1174 po
->order_type
= CUPSD_AUTH_ALLOW
;
1176 cupsdAddPolicyOp(p
, po
, IPP_PRINT_JOB
);
1177 cupsdAddPolicyOp(p
, po
, IPP_PRINT_URI
);
1178 cupsdAddPolicyOp(p
, po
, IPP_VALIDATE_JOB
);
1180 cupsdLogMessage(CUPSD_LOG_INFO
, "</Limit>");
1182 cupsdLogMessage(CUPSD_LOG_INFO
,
1183 "<Limit Send-Document Send-URI Cancel-Job Hold-Job "
1184 "Release-Job Restart-Job Purge-Jobs "
1185 "Set-Job-Attributes Create-Job-Subscription "
1186 "Renew-Subscription Cancel-Subscription "
1187 "Get-Notifications Reprocess-Job Cancel-Current-Job "
1188 "Suspend-Current-Job Resume-Job Cancel-Jobs "
1189 "Cancel-My-Jobs Close-Job CUPS-Move-Job "
1190 "CUPS-Authenticate-Job CUPS-Get-Document>");
1191 cupsdLogMessage(CUPSD_LOG_INFO
, "Order Deny,Allow");
1193 po
= cupsdAddPolicyOp(p
, NULL
, IPP_SEND_DOCUMENT
);
1194 po
->order_type
= CUPSD_AUTH_ALLOW
;
1195 po
->level
= CUPSD_AUTH_USER
;
1197 cupsdAddName(po
, "@OWNER");
1198 cupsdAddName(po
, "@SYSTEM");
1199 cupsdLogMessage(CUPSD_LOG_INFO
, "Require user @OWNER @SYSTEM");
1201 cupsdAddPolicyOp(p
, po
, IPP_SEND_URI
);
1202 cupsdAddPolicyOp(p
, po
, IPP_CANCEL_JOB
);
1203 cupsdAddPolicyOp(p
, po
, IPP_HOLD_JOB
);
1204 cupsdAddPolicyOp(p
, po
, IPP_RELEASE_JOB
);
1205 cupsdAddPolicyOp(p
, po
, IPP_RESTART_JOB
);
1206 cupsdAddPolicyOp(p
, po
, IPP_PURGE_JOBS
);
1207 cupsdAddPolicyOp(p
, po
, IPP_SET_JOB_ATTRIBUTES
);
1208 cupsdAddPolicyOp(p
, po
, IPP_CREATE_JOB_SUBSCRIPTION
);
1209 cupsdAddPolicyOp(p
, po
, IPP_RENEW_SUBSCRIPTION
);
1210 cupsdAddPolicyOp(p
, po
, IPP_CANCEL_SUBSCRIPTION
);
1211 cupsdAddPolicyOp(p
, po
, IPP_GET_NOTIFICATIONS
);
1212 cupsdAddPolicyOp(p
, po
, IPP_REPROCESS_JOB
);
1213 cupsdAddPolicyOp(p
, po
, IPP_CANCEL_CURRENT_JOB
);
1214 cupsdAddPolicyOp(p
, po
, IPP_SUSPEND_CURRENT_JOB
);
1215 cupsdAddPolicyOp(p
, po
, IPP_RESUME_JOB
);
1216 cupsdAddPolicyOp(p
, po
, IPP_CANCEL_JOBS
);
1217 cupsdAddPolicyOp(p
, po
, IPP_CANCEL_MY_JOBS
);
1218 cupsdAddPolicyOp(p
, po
, IPP_CLOSE_JOB
);
1219 cupsdAddPolicyOp(p
, po
, CUPS_MOVE_JOB
);
1220 cupsdAddPolicyOp(p
, po
, CUPS_AUTHENTICATE_JOB
);
1221 cupsdAddPolicyOp(p
, po
, CUPS_GET_DOCUMENT
);
1223 cupsdLogMessage(CUPSD_LOG_INFO
, "</Limit>");
1225 cupsdLogMessage(CUPSD_LOG_INFO
,
1226 "<Limit Pause-Printer Resume-Printer "
1227 "Set-Printer-Attributes Enable-Printer "
1228 "Disable-Printer Pause-Printer-After-Current-Job "
1229 "Hold-New-Jobs Release-Held-New-Jobs "
1230 "Deactivate-Printer Activate-Printer Restart-Printer "
1231 "Shutdown-Printer Startup-Printer Promote-Job "
1232 "Schedule-Job-After CUPS-Add-Printer "
1233 "CUPS-Delete-Printer CUPS-Add-Class CUPS-Delete-Class "
1234 "CUPS-Accept-Jobs CUPS-Reject-Jobs CUPS-Set-Default>");
1235 cupsdLogMessage(CUPSD_LOG_INFO
, "Order Deny,Allow");
1236 cupsdLogMessage(CUPSD_LOG_INFO
, "AuthType Default");
1238 po
= cupsdAddPolicyOp(p
, NULL
, IPP_PAUSE_PRINTER
);
1239 po
->order_type
= CUPSD_AUTH_ALLOW
;
1240 po
->type
= CUPSD_AUTH_DEFAULT
;
1241 po
->level
= CUPSD_AUTH_USER
;
1243 cupsdAddName(po
, "@SYSTEM");
1244 cupsdLogMessage(CUPSD_LOG_INFO
, "Require user @SYSTEM");
1246 cupsdAddPolicyOp(p
, po
, IPP_RESUME_PRINTER
);
1247 cupsdAddPolicyOp(p
, po
, IPP_SET_PRINTER_ATTRIBUTES
);
1248 cupsdAddPolicyOp(p
, po
, IPP_ENABLE_PRINTER
);
1249 cupsdAddPolicyOp(p
, po
, IPP_DISABLE_PRINTER
);
1250 cupsdAddPolicyOp(p
, po
, IPP_PAUSE_PRINTER_AFTER_CURRENT_JOB
);
1251 cupsdAddPolicyOp(p
, po
, IPP_HOLD_NEW_JOBS
);
1252 cupsdAddPolicyOp(p
, po
, IPP_RELEASE_HELD_NEW_JOBS
);
1253 cupsdAddPolicyOp(p
, po
, IPP_DEACTIVATE_PRINTER
);
1254 cupsdAddPolicyOp(p
, po
, IPP_ACTIVATE_PRINTER
);
1255 cupsdAddPolicyOp(p
, po
, IPP_RESTART_PRINTER
);
1256 cupsdAddPolicyOp(p
, po
, IPP_SHUTDOWN_PRINTER
);
1257 cupsdAddPolicyOp(p
, po
, IPP_STARTUP_PRINTER
);
1258 cupsdAddPolicyOp(p
, po
, IPP_PROMOTE_JOB
);
1259 cupsdAddPolicyOp(p
, po
, IPP_SCHEDULE_JOB_AFTER
);
1260 cupsdAddPolicyOp(p
, po
, CUPS_ADD_PRINTER
);
1261 cupsdAddPolicyOp(p
, po
, CUPS_DELETE_PRINTER
);
1262 cupsdAddPolicyOp(p
, po
, CUPS_ADD_CLASS
);
1263 cupsdAddPolicyOp(p
, po
, CUPS_DELETE_CLASS
);
1264 cupsdAddPolicyOp(p
, po
, CUPS_ACCEPT_JOBS
);
1265 cupsdAddPolicyOp(p
, po
, CUPS_REJECT_JOBS
);
1266 cupsdAddPolicyOp(p
, po
, CUPS_SET_DEFAULT
);
1268 cupsdLogMessage(CUPSD_LOG_INFO
, "</Limit>");
1270 cupsdLogMessage(CUPSD_LOG_INFO
, "<Limit All>");
1271 cupsdLogMessage(CUPSD_LOG_INFO
, "Order Deny,Allow");
1273 po
= cupsdAddPolicyOp(p
, NULL
, IPP_ANY_OPERATION
);
1274 po
->order_type
= CUPSD_AUTH_ALLOW
;
1276 cupsdLogMessage(CUPSD_LOG_INFO
, "</Limit>");
1277 cupsdLogMessage(CUPSD_LOG_INFO
, "</Policy>");
1281 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "cupsdReadConfiguration: NumPolicies=%d",
1282 cupsArrayCount(Policies
));
1283 for (i
= 0, p
= (cupsd_policy_t
*)cupsArrayFirst(Policies
);
1285 i
++, p
= (cupsd_policy_t
*)cupsArrayNext(Policies
))
1286 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
1287 "cupsdReadConfiguration: Policies[%d]=\"%s\"", i
, p
->name
);
1290 * If we are doing a full reload or the server root has changed, flush
1291 * the jobs, printers, etc. and start from scratch...
1294 if (NeedReload
== RELOAD_ALL
||
1295 old_remote_port
!= RemotePort
||
1296 !old_serverroot
|| !ServerRoot
|| strcmp(old_serverroot
, ServerRoot
) ||
1297 !old_requestroot
|| !RequestRoot
|| strcmp(old_requestroot
, RequestRoot
))
1299 mime_type_t
*type
; /* Current type */
1300 char mimetype
[MIME_MAX_SUPER
+ MIME_MAX_TYPE
];
1301 /* MIME type name */
1304 cupsdLogMessage(CUPSD_LOG_INFO
, "Full reload is required.");
1307 * Free all memory...
1310 cupsdDeleteAllSubscriptions();
1312 cupsdDeleteAllPrinters();
1314 DefaultPrinter
= NULL
;
1316 if (MimeDatabase
!= NULL
)
1317 mimeDelete(MimeDatabase
);
1321 for (i
= 0; i
< NumMimeTypes
; i
++)
1322 _cupsStrFree(MimeTypes
[i
]);
1328 * Read the MIME type and conversion database...
1331 snprintf(temp
, sizeof(temp
), "%s/filter", ServerBin
);
1332 snprintf(mimedir
, sizeof(mimedir
), "%s/mime", DataDir
);
1334 MimeDatabase
= mimeLoadTypes(NULL
, mimedir
);
1335 MimeDatabase
= mimeLoadTypes(MimeDatabase
, ServerRoot
);
1336 MimeDatabase
= mimeLoadFilters(MimeDatabase
, mimedir
, temp
);
1337 MimeDatabase
= mimeLoadFilters(MimeDatabase
, ServerRoot
, temp
);
1341 cupsdLogMessage(CUPSD_LOG_EMERG
,
1342 "Unable to load MIME database from \"%s\" or \"%s\"!",
1343 mimedir
, ServerRoot
);
1344 if (FatalErrors
& CUPSD_FATAL_CONFIG
)
1348 cupsdLogMessage(CUPSD_LOG_INFO
,
1349 "Loaded MIME database from \"%s\" and \"%s\": %d types, "
1350 "%d filters...", mimedir
, ServerRoot
,
1351 mimeNumTypes(MimeDatabase
), mimeNumFilters(MimeDatabase
));
1354 * Create a list of MIME types for the document-format-supported
1358 NumMimeTypes
= mimeNumTypes(MimeDatabase
);
1359 if (!mimeType(MimeDatabase
, "application", "octet-stream"))
1362 if ((MimeTypes
= calloc(NumMimeTypes
, sizeof(const char *))) == NULL
)
1364 cupsdLogMessage(CUPSD_LOG_ERROR
,
1365 "Unable to allocate memory for %d MIME types!",
1371 for (i
= 0, type
= mimeFirstType(MimeDatabase
);
1373 i
++, type
= mimeNextType(MimeDatabase
))
1375 snprintf(mimetype
, sizeof(mimetype
), "%s/%s", type
->super
, type
->type
);
1377 MimeTypes
[i
] = _cupsStrAlloc(mimetype
);
1380 if (i
< NumMimeTypes
)
1381 MimeTypes
[i
] = _cupsStrAlloc("application/octet-stream");
1384 if (LogLevel
== CUPSD_LOG_DEBUG2
)
1386 mime_filter_t
*filter
; /* Current filter */
1389 for (type
= mimeFirstType(MimeDatabase
);
1391 type
= mimeNextType(MimeDatabase
))
1392 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "cupsdReadConfiguration: type %s/%s",
1393 type
->super
, type
->type
);
1395 for (filter
= mimeFirstFilter(MimeDatabase
);
1397 filter
= mimeNextFilter(MimeDatabase
))
1398 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
1399 "cupsdReadConfiguration: filter %s/%s to %s/%s %d %s",
1400 filter
->src
->super
, filter
->src
->type
,
1401 filter
->dst
->super
, filter
->dst
->type
,
1402 filter
->cost
, filter
->filter
);
1409 snprintf(temp
, sizeof(temp
), "%s/banners", DataDir
);
1410 cupsdLoadBanners(temp
);
1413 * Load printers and classes...
1416 cupsdLoadAllPrinters();
1417 cupsdLoadAllClasses();
1418 cupsdLoadRemoteCache();
1420 cupsdCreateCommonData();
1423 * Update the printcap file as needed...
1426 if (Printcap
&& *Printcap
&& access(Printcap
, 0))
1427 cupsdWritePrintcap();
1430 * Load queued jobs...
1436 * Load subscriptions...
1439 cupsdLoadAllSubscriptions();
1441 cupsdLogMessage(CUPSD_LOG_INFO
, "Full reload complete.");
1446 * Not a full reload, so recreate the common printer attributes...
1449 cupsdCreateCommonData();
1452 * Update all printers as needed...
1455 cupsdUpdatePrinters();
1456 cupsdMarkDirty(CUPSD_DIRTY_PRINTCAP
);
1458 cupsdLogMessage(CUPSD_LOG_INFO
, "Partial reload complete.");
1462 * Reset the reload state...
1465 NeedReload
= RELOAD_NONE
;
1467 cupsdClearString(&old_serverroot
);
1468 cupsdClearString(&old_requestroot
);
1475 * 'get_address()' - Get an address + port number from a line.
1478 static http_addrlist_t
* /* O - Pointer to list if address good, NULL if bad */
1479 get_address(const char *value
, /* I - Value string */
1480 int defport
) /* I - Default port */
1482 char buffer
[1024], /* Hostname + port number buffer */
1483 defpname
[255], /* Default port name */
1484 *hostname
, /* Hostname or IP */
1485 *portname
; /* Port number or name */
1486 http_addrlist_t
*addrlist
; /* Address list */
1490 * Check for an empty value...
1495 cupsdLogMessage(CUPSD_LOG_ERROR
, "Bad (empty) address!");
1500 * Grab a hostname and port number; if there is no colon and the port name
1501 * is only digits, then we have a port number by itself...
1504 strlcpy(buffer
, value
, sizeof(buffer
));
1506 if ((portname
= strrchr(buffer
, ':')) != NULL
&& !strchr(portname
, ']'))
1513 for (portname
= buffer
; isdigit(*portname
& 255); portname
++);
1518 * Use the default port...
1521 sprintf(defpname
, "%d", defport
);
1522 portname
= defpname
;
1528 * The buffer contains just a port number...
1536 if (hostname
&& !strcmp(hostname
, "*"))
1540 * Now lookup the address using httpAddrGetList()...
1543 if ((addrlist
= httpAddrGetList(hostname
, AF_UNSPEC
, portname
)) == NULL
)
1544 cupsdLogMessage(CUPSD_LOG_ERROR
, "Hostname lookup for \"%s\" failed!",
1545 hostname
? hostname
: "(nil)");
1552 * 'get_addr_and_mask()' - Get an IP address and netmask.
1555 static int /* O - 1 on success, 0 on failure */
1556 get_addr_and_mask(const char *value
, /* I - String from config file */
1557 unsigned *ip
, /* O - Address value */
1558 unsigned *mask
) /* O - Mask value */
1560 int i
, j
, /* Looping vars */
1561 family
, /* Address family */
1562 ipcount
; /* Count of fields in address */
1563 unsigned ipval
; /* Value */
1564 const char *maskval
, /* Pointer to start of mask value */
1565 *ptr
, /* Pointer into value */
1570 * Get the address...
1573 ip
[0] = ip
[1] = ip
[2] = ip
[3] = 0x00000000;
1574 mask
[0] = mask
[1] = mask
[2] = mask
[3] = 0xffffffff;
1576 if ((maskval
= strchr(value
, '/')) != NULL
)
1579 maskval
= value
+ strlen(value
);
1583 * Check for an IPv6 address...
1589 * Parse hexadecimal IPv6 address...
1594 for (i
= 0, ptr
= value
+ 1; *ptr
&& i
< 8; i
++)
1598 else if (!strncmp(ptr
, "::", 2))
1600 for (ptr2
= strchr(ptr
+ 2, ':'), j
= 0;
1602 ptr2
= strchr(ptr2
+ 1, ':'), j
++);
1607 else if (isxdigit(*ptr
& 255))
1609 ipval
= strtoul(ptr
, (char **)&ptr
, 16);
1617 ip
[i
/ 2] |= ipval
<< 16;
1631 if (*ptr
&& *ptr
!= '/')
1635 #endif /* AF_INET6 */
1638 * Parse dotted-decimal IPv4 address...
1641 unsigned val
[4]; /* IPv4 address values */
1645 ipcount
= sscanf(value
, "%u.%u.%u.%u", val
+ 0, val
+ 1, val
+ 2, val
+ 3);
1648 * Range check the IP numbers...
1651 for (i
= 0; i
< ipcount
; i
++)
1656 * Make sure the trailing values are zeroed, as some C libraries like
1657 * glibc apparently like to fill the unused arguments with garbage...
1660 for (i
= ipcount
; i
< 4; i
++)
1664 * Merge everything into a 32-bit IPv4 address in ip[3]...
1667 ip
[3] = (((((val
[0] << 8) | val
[1]) << 8) | val
[2]) << 8) | val
[3];
1670 mask
[3] = (0xffffffff << (32 - 8 * ipcount
)) & 0xffffffff;
1676 * Get the netmask value(s)...
1679 memset(mask
, 0, sizeof(unsigned) * 4);
1681 if (strchr(maskval
, '.'))
1684 * Get dotted-decimal mask...
1687 if (family
!= AF_INET
)
1690 if (sscanf(maskval
, "%u.%u.%u.%u", mask
+ 0, mask
+ 1, mask
+ 2, mask
+ 3) != 4)
1693 mask
[3] |= ((((mask
[0] << 8) | mask
[1]) << 8) | mask
[2]) << 8;
1694 mask
[0] = mask
[1] = mask
[2] = 0;
1699 * Get address/bits format...
1705 if (family
== AF_INET6
)
1713 mask
[0] = 0xffffffff;
1715 mask
[0] = (0xffffffff << (i
- 96)) & 0xffffffff;
1718 mask
[1] = 0xffffffff;
1722 mask
[1] = (0xffffffff << (i
- 64)) & 0xffffffff;
1725 mask
[2] = 0xffffffff;
1729 mask
[2] = (0xffffffff << (i
- 32)) & 0xffffffff;
1732 mask
[3] = 0xffffffff;
1736 mask
[3] = (0xffffffff << i
) & 0xffffffff;
1739 #endif /* AF_INET6 */
1744 mask
[0] = 0xffffffff;
1745 mask
[1] = 0xffffffff;
1746 mask
[2] = 0xffffffff;
1749 mask
[3] = (0xffffffff << (32 - i
)) & 0xffffffff;
1751 mask
[3] = 0xffffffff;
1756 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
1757 "get_addr_and_mask(value=\"%s\", "
1758 "ip=[%08x:%08x:%08x:%08x], mask=[%08x:%08x:%08x:%08x])",
1759 value
, ip
[0], ip
[1], ip
[2], ip
[3], mask
[0], mask
[1], mask
[2],
1763 * Check for a valid netmask; no fallback like in CUPS 1.1.x!
1766 if ((ip
[0] & ~mask
[0]) != 0 ||
1767 (ip
[1] & ~mask
[1]) != 0 ||
1768 (ip
[2] & ~mask
[2]) != 0 ||
1769 (ip
[3] & ~mask
[3]) != 0)
1777 * 'parse_aaa()' - Parse authentication, authorization, and access control lines.
1780 static int /* O - 1 on success, 0 on failure */
1781 parse_aaa(cupsd_location_t
*loc
, /* I - Location */
1782 char *line
, /* I - Line from file */
1783 char *value
, /* I - Start of value data */
1784 int linenum
) /* I - Current line number */
1786 char *valptr
; /* Pointer into value */
1787 unsigned ip
[4], /* IP address components */
1788 mask
[4]; /* IP netmask components */
1791 if (!strcasecmp(line
, "Encryption"))
1794 * "Encryption xxx" - set required encryption level...
1797 if (!strcasecmp(value
, "never"))
1798 loc
->encryption
= HTTP_ENCRYPT_NEVER
;
1799 else if (!strcasecmp(value
, "always"))
1801 cupsdLogMessage(CUPSD_LOG_ERROR
,
1802 "Encryption value \"%s\" on line %d is invalid in this "
1803 "context. Using \"required\" instead.", value
, linenum
);
1805 loc
->encryption
= HTTP_ENCRYPT_REQUIRED
;
1807 else if (!strcasecmp(value
, "required"))
1808 loc
->encryption
= HTTP_ENCRYPT_REQUIRED
;
1809 else if (!strcasecmp(value
, "ifrequested"))
1810 loc
->encryption
= HTTP_ENCRYPT_IF_REQUESTED
;
1813 cupsdLogMessage(CUPSD_LOG_ERROR
,
1814 "Unknown Encryption value %s on line %d.", value
, linenum
);
1818 else if (!strcasecmp(line
, "Order"))
1821 * "Order Deny,Allow" or "Order Allow,Deny"...
1824 if (!strncasecmp(value
, "deny", 4))
1825 loc
->order_type
= CUPSD_AUTH_ALLOW
;
1826 else if (!strncasecmp(value
, "allow", 5))
1827 loc
->order_type
= CUPSD_AUTH_DENY
;
1830 cupsdLogMessage(CUPSD_LOG_ERROR
, "Unknown Order value %s on line %d.",
1835 else if (!strcasecmp(line
, "Allow") || !strcasecmp(line
, "Deny"))
1838 * Allow [From] host/ip...
1839 * Deny [From] host/ip...
1844 if (!strncasecmp(value
, "from", 4))
1847 * Strip leading "from"...
1852 while (isspace(*value
& 255))
1860 * Find the end of the value...
1863 for (valptr
= value
; *valptr
&& !isspace(*valptr
& 255); valptr
++);
1865 while (isspace(*valptr
& 255))
1869 * Figure out what form the allow/deny address takes:
1880 * nnn.nnn.nnn.nnn/mm
1881 * nnn.nnn.nnn.nnn/mmm.mmm.mmm.mmm
1884 if (!strcasecmp(value
, "all"))
1890 if (!strcasecmp(line
, "Allow"))
1891 cupsdAllowIP(loc
, zeros
, zeros
);
1893 cupsdDenyIP(loc
, zeros
, zeros
);
1895 else if (!strcasecmp(value
, "none"))
1901 if (!strcasecmp(line
, "Allow"))
1902 cupsdAllowIP(loc
, ones
, zeros
);
1904 cupsdDenyIP(loc
, ones
, zeros
);
1907 else if (value
[0] == '*' || value
[0] == '.' ||
1908 (!isdigit(value
[0] & 255) && value
[0] != '['))
1910 else if (value
[0] == '*' || value
[0] == '.' || !isdigit(value
[0] & 255))
1911 #endif /* AF_INET6 */
1914 * Host or domain name...
1917 if (value
[0] == '*')
1920 if (!strcasecmp(line
, "Allow"))
1921 cupsdAllowHost(loc
, value
);
1923 cupsdDenyHost(loc
, value
);
1928 * One of many IP address forms...
1931 if (!get_addr_and_mask(value
, ip
, mask
))
1933 cupsdLogMessage(CUPSD_LOG_ERROR
, "Bad netmask value %s on line %d.",
1938 if (!strcasecmp(line
, "Allow"))
1939 cupsdAllowIP(loc
, ip
, mask
);
1941 cupsdDenyIP(loc
, ip
, mask
);
1945 * Advance to next value...
1951 else if (!strcasecmp(line
, "AuthType"))
1954 * AuthType {none,basic,digest,basicdigest,negotiate,default}
1957 if (!strcasecmp(value
, "none"))
1959 loc
->type
= CUPSD_AUTH_NONE
;
1960 loc
->level
= CUPSD_AUTH_ANON
;
1962 else if (!strcasecmp(value
, "basic"))
1964 loc
->type
= CUPSD_AUTH_BASIC
;
1966 if (loc
->level
== CUPSD_AUTH_ANON
)
1967 loc
->level
= CUPSD_AUTH_USER
;
1969 else if (!strcasecmp(value
, "digest"))
1971 loc
->type
= CUPSD_AUTH_DIGEST
;
1973 if (loc
->level
== CUPSD_AUTH_ANON
)
1974 loc
->level
= CUPSD_AUTH_USER
;
1976 else if (!strcasecmp(value
, "basicdigest"))
1978 loc
->type
= CUPSD_AUTH_BASICDIGEST
;
1980 if (loc
->level
== CUPSD_AUTH_ANON
)
1981 loc
->level
= CUPSD_AUTH_USER
;
1983 else if (!strcasecmp(value
, "default"))
1985 loc
->type
= CUPSD_AUTH_DEFAULT
;
1987 if (loc
->level
== CUPSD_AUTH_ANON
)
1988 loc
->level
= CUPSD_AUTH_USER
;
1991 else if (!strcasecmp(value
, "negotiate"))
1993 loc
->type
= CUPSD_AUTH_NEGOTIATE
;
1995 if (loc
->level
== CUPSD_AUTH_ANON
)
1996 loc
->level
= CUPSD_AUTH_USER
;
1998 #endif /* HAVE_GSSAPI */
2001 cupsdLogMessage(CUPSD_LOG_WARN
,
2002 "Unknown authorization type %s on line %d.",
2007 else if (!strcasecmp(line
, "AuthClass"))
2010 * AuthClass anonymous, user, system, group
2013 if (!strcasecmp(value
, "anonymous"))
2015 loc
->type
= CUPSD_AUTH_NONE
;
2016 loc
->level
= CUPSD_AUTH_ANON
;
2018 cupsdLogMessage(CUPSD_LOG_WARN
,
2019 "\"AuthClass %s\" is deprecated; consider removing "
2023 else if (!strcasecmp(value
, "user"))
2025 loc
->level
= CUPSD_AUTH_USER
;
2027 cupsdLogMessage(CUPSD_LOG_WARN
,
2028 "\"AuthClass %s\" is deprecated; consider using "
2029 "\"Require valid-user\" on line %d.",
2032 else if (!strcasecmp(value
, "group"))
2034 loc
->level
= CUPSD_AUTH_GROUP
;
2036 cupsdLogMessage(CUPSD_LOG_WARN
,
2037 "\"AuthClass %s\" is deprecated; consider using "
2038 "\"Require user @groupname\" on line %d.",
2041 else if (!strcasecmp(value
, "system"))
2043 loc
->level
= CUPSD_AUTH_GROUP
;
2045 cupsdAddName(loc
, "@SYSTEM");
2047 cupsdLogMessage(CUPSD_LOG_WARN
,
2048 "\"AuthClass %s\" is deprecated; consider using "
2049 "\"Require user @SYSTEM\" on line %d.",
2054 cupsdLogMessage(CUPSD_LOG_WARN
,
2055 "Unknown authorization class %s on line %d.",
2060 else if (!strcasecmp(line
, "AuthGroupName"))
2062 cupsdAddName(loc
, value
);
2064 cupsdLogMessage(CUPSD_LOG_WARN
,
2065 "\"AuthGroupName %s\" directive is deprecated; consider "
2066 "using \"Require user @%s\" on line %d.",
2067 value
, value
, linenum
);
2069 else if (!strcasecmp(line
, "Require"))
2072 * Apache synonym for AuthClass and AuthGroupName...
2076 * Require valid-user
2077 * Require group names
2078 * Require user names
2081 for (valptr
= value
; !isspace(*valptr
& 255) && *valptr
; valptr
++);
2086 if (!strcasecmp(value
, "valid-user") ||
2087 !strcasecmp(value
, "user"))
2088 loc
->level
= CUPSD_AUTH_USER
;
2089 else if (!strcasecmp(value
, "group"))
2090 loc
->level
= CUPSD_AUTH_GROUP
;
2093 cupsdLogMessage(CUPSD_LOG_WARN
, "Unknown Require type %s on line %d.",
2099 * Get the list of names from the line...
2102 for (value
= valptr
; *value
;)
2104 while (isspace(*value
& 255))
2107 #ifdef HAVE_AUTHORIZATION_H
2108 if (!strncmp(value
, "@AUTHKEY(", 9))
2111 * Grab "@AUTHKEY(name)" value...
2114 for (valptr
= value
+ 9; *valptr
!= ')' && *valptr
; valptr
++);
2120 #endif /* HAVE_AUTHORIZATION_H */
2121 if (*value
== '\"' || *value
== '\'')
2124 * Grab quoted name...
2127 for (valptr
= value
+ 1; *valptr
!= *value
&& *valptr
; valptr
++);
2134 * Grab literal name.
2137 for (valptr
= value
; !isspace(*valptr
& 255) && *valptr
; valptr
++);
2143 cupsdAddName(loc
, value
);
2145 for (value
= valptr
; isspace(*value
& 255); value
++);
2148 else if (!strcasecmp(line
, "Satisfy"))
2150 if (!strcasecmp(value
, "all"))
2151 loc
->satisfy
= CUPSD_AUTH_SATISFY_ALL
;
2152 else if (!strcasecmp(value
, "any"))
2153 loc
->satisfy
= CUPSD_AUTH_SATISFY_ANY
;
2156 cupsdLogMessage(CUPSD_LOG_WARN
, "Unknown Satisfy value %s on line %d.",
2169 * 'parse_fatal_errors()' - Parse FatalErrors values in a string.
2172 static int /* O - FatalErrors bits */
2173 parse_fatal_errors(const char *s
) /* I - FatalErrors string */
2175 int fatal
; /* FatalErrors bits */
2176 char value
[1024], /* Value string */
2177 *valstart
, /* Pointer into value */
2178 *valend
; /* End of value */
2182 * Empty FatalErrors line yields NULL pointer...
2186 return (CUPSD_FATAL_NONE
);
2189 * Loop through the value string,...
2192 strlcpy(value
, s
, sizeof(value
));
2194 fatal
= CUPSD_FATAL_NONE
;
2196 for (valstart
= value
; *valstart
;)
2199 * Get the current space/comma-delimited kind name...
2202 for (valend
= valstart
; *valend
; valend
++)
2203 if (isspace(*valend
& 255) || *valend
== ',')
2210 * Add the error to the bitmask...
2213 if (!strcasecmp(valstart
, "all"))
2214 fatal
= CUPSD_FATAL_ALL
;
2215 else if (!strcasecmp(valstart
, "browse"))
2216 fatal
|= CUPSD_FATAL_BROWSE
;
2217 else if (!strcasecmp(valstart
, "-browse"))
2218 fatal
&= ~CUPSD_FATAL_BROWSE
;
2219 else if (!strcasecmp(valstart
, "config"))
2220 fatal
|= CUPSD_FATAL_CONFIG
;
2221 else if (!strcasecmp(valstart
, "-config"))
2222 fatal
&= ~CUPSD_FATAL_CONFIG
;
2223 else if (!strcasecmp(valstart
, "listen"))
2224 fatal
|= CUPSD_FATAL_LISTEN
;
2225 else if (!strcasecmp(valstart
, "-listen"))
2226 fatal
&= ~CUPSD_FATAL_LISTEN
;
2227 else if (!strcasecmp(valstart
, "log"))
2228 fatal
|= CUPSD_FATAL_LOG
;
2229 else if (!strcasecmp(valstart
, "-log"))
2230 fatal
&= ~CUPSD_FATAL_LOG
;
2231 else if (!strcasecmp(valstart
, "permissions"))
2232 fatal
|= CUPSD_FATAL_PERMISSIONS
;
2233 else if (!strcasecmp(valstart
, "-permissions"))
2234 fatal
&= ~CUPSD_FATAL_PERMISSIONS
;
2235 else if (strcasecmp(valstart
, "none"))
2236 cupsdLogMessage(CUPSD_LOG_ERROR
,
2237 "Unknown FatalErrors kind \"%s\" ignored!", valstart
);
2239 for (valstart
= valend
; *valstart
; valstart
++)
2240 if (!isspace(*valstart
& 255) || *valstart
!= ',')
2249 * 'parse_groups()' - Parse system group names in a string.
2252 static int /* O - 1 on success, 0 on failure */
2253 parse_groups(const char *s
) /* I - Space-delimited groups */
2255 int status
; /* Return status */
2256 char value
[1024], /* Value string */
2257 *valstart
, /* Pointer into value */
2258 *valend
, /* End of value */
2259 quote
; /* Quote character */
2260 struct group
*group
; /* Group */
2264 * Make a copy of the string and parse out the groups...
2267 strlcpy(value
, s
, sizeof(value
));
2272 while (*valstart
&& NumSystemGroups
< MAX_SYSTEM_GROUPS
)
2274 if (*valstart
== '\'' || *valstart
== '\"')
2277 * Scan quoted name...
2280 quote
= *valstart
++;
2282 for (valend
= valstart
; *valend
; valend
++)
2283 if (*valend
== quote
)
2289 * Scan space or comma-delimited name...
2292 for (valend
= valstart
; *valend
; valend
++)
2293 if (isspace(*valend
) || *valend
== ',')
2300 group
= getgrnam(valstart
);
2303 cupsdSetString(SystemGroups
+ NumSystemGroups
, valstart
);
2304 SystemGroupIDs
[NumSystemGroups
] = group
->gr_gid
;
2315 while (*valstart
== ',' || isspace(*valstart
))
2324 * 'parse_protocols()' - Parse browse protocols in a string.
2327 static int /* O - Browse protocol bits */
2328 parse_protocols(const char *s
) /* I - Space-delimited protocols */
2330 int protocols
; /* Browse protocol bits */
2331 char value
[1024], /* Value string */
2332 *valstart
, /* Pointer into value */
2333 *valend
; /* End of value */
2337 * Empty protocol line yields NULL pointer...
2344 * Loop through the value string,...
2347 strlcpy(value
, s
, sizeof(value
));
2351 for (valstart
= value
; *valstart
;)
2354 * Get the current space/comma-delimited protocol name...
2357 for (valend
= valstart
; *valend
; valend
++)
2358 if (isspace(*valend
& 255) || *valend
== ',')
2365 * Add the protocol to the bitmask...
2368 if (!strcasecmp(valstart
, "cups"))
2369 protocols
|= BROWSE_CUPS
;
2370 else if (!strcasecmp(valstart
, "slp"))
2371 protocols
|= BROWSE_SLP
;
2372 else if (!strcasecmp(valstart
, "ldap"))
2373 protocols
|= BROWSE_LDAP
;
2374 else if (!strcasecmp(valstart
, "dnssd") ||
2375 !strcasecmp(valstart
, "dns-sd") ||
2376 !strcasecmp(valstart
, "bonjour"))
2377 protocols
|= BROWSE_DNSSD
;
2378 else if (!strcasecmp(valstart
, "lpd"))
2379 protocols
|= BROWSE_LPD
;
2380 else if (!strcasecmp(valstart
, "smb"))
2381 protocols
|= BROWSE_SMB
;
2382 else if (!strcasecmp(valstart
, "all"))
2383 protocols
|= BROWSE_ALL
;
2384 else if (strcasecmp(valstart
, "none"))
2385 cupsdLogMessage(CUPSD_LOG_ERROR
,
2386 "Unknown browse protocol \"%s\" ignored!", valstart
);
2388 for (valstart
= valend
; *valstart
; valstart
++)
2389 if (!isspace(*valstart
& 255) || *valstart
!= ',')
2398 * 'read_configuration()' - Read a configuration file.
2401 static int /* O - 1 on success, 0 on failure */
2402 read_configuration(cups_file_t
*fp
) /* I - File to read from */
2404 int i
; /* Looping var */
2405 int linenum
; /* Current line number */
2406 char line
[HTTP_MAX_BUFFER
],
2407 /* Line from file */
2408 temp
[HTTP_MAX_BUFFER
],
2409 /* Temporary buffer for value */
2410 temp2
[HTTP_MAX_BUFFER
],
2411 /* Temporary buffer 2 for value */
2412 *ptr
, /* Pointer into line/temp */
2413 *value
, /* Pointer to value */
2414 *valueptr
; /* Pointer into value */
2415 int valuelen
; /* Length of value */
2416 cupsd_var_t
const *var
; /* Current variable */
2417 http_addrlist_t
*addrlist
, /* Address list */
2418 *addr
; /* Current address */
2419 unsigned ip
[4], /* Address value */
2420 mask
[4]; /* Netmask value */
2421 cupsd_dirsvc_relay_t
*relay
; /* Relay data */
2422 cupsd_dirsvc_poll_t
*pollp
; /* Polling data */
2423 cupsd_location_t
*location
; /* Browse location */
2424 cups_file_t
*incfile
; /* Include file */
2425 char incname
[1024]; /* Include filename */
2426 struct group
*group
; /* Group */
2430 * Loop through each line in the file...
2435 while (cupsFileGetConf(fp
, line
, sizeof(line
), &value
, &linenum
))
2438 * Decode the directive...
2441 if (!strcasecmp(line
, "Include") && value
)
2447 if (value
[0] == '/')
2448 strlcpy(incname
, value
, sizeof(incname
));
2450 snprintf(incname
, sizeof(incname
), "%s/%s", ServerRoot
, value
);
2452 if ((incfile
= cupsFileOpen(incname
, "rb")) == NULL
)
2453 cupsdLogMessage(CUPSD_LOG_ERROR
,
2454 "Unable to include config file \"%s\" - %s",
2455 incname
, strerror(errno
));
2458 read_configuration(incfile
);
2459 cupsFileClose(incfile
);
2462 else if (!strcasecmp(line
, "<Location") && value
)
2468 linenum
= read_location(fp
, value
, linenum
);
2472 else if (!strcasecmp(line
, "<Policy") && value
)
2478 linenum
= read_policy(fp
, value
, linenum
);
2482 else if (!strcasecmp(line
, "FatalErrors"))
2483 FatalErrors
= parse_fatal_errors(value
);
2484 else if (!strcasecmp(line
, "FaxRetryInterval") && value
)
2486 JobRetryInterval
= atoi(value
);
2487 cupsdLogMessage(CUPSD_LOG_WARN
,
2488 "FaxRetryInterval is deprecated; use "
2489 "JobRetryInterval on line %d.", linenum
);
2491 else if (!strcasecmp(line
, "FaxRetryLimit") && value
)
2493 JobRetryLimit
= atoi(value
);
2494 cupsdLogMessage(CUPSD_LOG_WARN
,
2495 "FaxRetryLimit is deprecated; use "
2496 "JobRetryLimit on line %d.", linenum
);
2498 else if (!strcasecmp(line
, "Port") || !strcasecmp(line
, "Listen")
2500 || !strcasecmp(line
, "SSLPort") || !strcasecmp(line
, "SSLListen")
2501 #endif /* HAVE_SSL */
2505 * Add listening address(es) to the list...
2508 cupsd_listener_t
*lis
; /* New listeners array */
2512 * Get the address list...
2515 addrlist
= get_address(value
, IPP_PORT
);
2519 cupsdLogMessage(CUPSD_LOG_ERROR
, "Bad %s address %s at line %d.", line
,
2525 * Add each address...
2528 for (addr
= addrlist
; addr
; addr
= addr
->next
)
2531 * See if this address is already present...
2534 for (lis
= (cupsd_listener_t
*)cupsArrayFirst(Listeners
);
2536 lis
= (cupsd_listener_t
*)cupsArrayNext(Listeners
))
2537 if (httpAddrEqual(&(addr
->addr
), &(lis
->address
)) &&
2538 _httpAddrPort(&(addr
->addr
)) == _httpAddrPort(&(lis
->address
)))
2543 httpAddrString(&lis
->address
, temp
, sizeof(temp
));
2544 cupsdLogMessage(CUPSD_LOG_WARN
,
2545 "Duplicate listen address \"%s\" ignored!", temp
);
2550 * Allocate another listener...
2554 Listeners
= cupsArrayNew(NULL
, NULL
);
2558 cupsdLogMessage(CUPSD_LOG_ERROR
,
2559 "Unable to allocate %s at line %d - %s.",
2560 line
, linenum
, strerror(errno
));
2564 if ((lis
= calloc(1, sizeof(cupsd_listener_t
))) == NULL
)
2566 cupsdLogMessage(CUPSD_LOG_ERROR
,
2567 "Unable to allocate %s at line %d - %s.",
2568 line
, linenum
, strerror(errno
));
2572 cupsArrayAdd(Listeners
, lis
);
2575 * Copy the current address and log it...
2578 memcpy(&(lis
->address
), &(addr
->addr
), sizeof(lis
->address
));
2582 if (!strcasecmp(line
, "SSLPort") || !strcasecmp(line
, "SSLListen"))
2583 lis
->encryption
= HTTP_ENCRYPT_ALWAYS
;
2584 #endif /* HAVE_SSL */
2586 httpAddrString(&lis
->address
, temp
, sizeof(temp
));
2589 if (lis
->address
.addr
.sa_family
== AF_INET6
)
2590 cupsdLogMessage(CUPSD_LOG_INFO
, "Listening to %s:%d (IPv6)", temp
,
2591 ntohs(lis
->address
.ipv6
.sin6_port
));
2593 #endif /* AF_INET6 */
2595 if (lis
->address
.addr
.sa_family
== AF_LOCAL
)
2596 cupsdLogMessage(CUPSD_LOG_INFO
, "Listening to %s (Domain)", temp
);
2598 #endif /* AF_LOCAL */
2599 cupsdLogMessage(CUPSD_LOG_INFO
, "Listening to %s:%d (IPv4)", temp
,
2600 ntohs(lis
->address
.ipv4
.sin_port
));
2602 if (!httpAddrLocalhost(&(lis
->address
)))
2605 if (lis
->address
.addr
.sa_family
== AF_INET6
)
2606 RemotePort
= ntohs(lis
->address
.ipv6
.sin6_port
);
2608 #endif /* AF_INET6 */
2609 RemotePort
= ntohs(lis
->address
.ipv4
.sin_port
);
2617 httpAddrFreeList(addrlist
);
2619 else if (!strcasecmp(line
, "BrowseAddress") && value
)
2622 * Add a browse address to the list...
2625 cupsd_dirsvc_addr_t
*dira
; /* New browse address array */
2628 if (NumBrowsers
== 0)
2629 dira
= malloc(sizeof(cupsd_dirsvc_addr_t
));
2631 dira
= realloc(Browsers
, (NumBrowsers
+ 1) * sizeof(cupsd_dirsvc_addr_t
));
2635 cupsdLogMessage(CUPSD_LOG_ERROR
,
2636 "Unable to allocate BrowseAddress at line %d - %s.",
2637 linenum
, strerror(errno
));
2642 dira
+= NumBrowsers
;
2644 memset(dira
, 0, sizeof(cupsd_dirsvc_addr_t
));
2646 if (!strcasecmp(value
, "@LOCAL"))
2649 * Send browse data to all local interfaces...
2652 strcpy(dira
->iface
, "*");
2655 else if (!strncasecmp(value
, "@IF(", 4))
2658 * Send browse data to the named interface...
2661 strlcpy(dira
->iface
, value
+ 4, sizeof(Browsers
[0].iface
));
2663 ptr
= dira
->iface
+ strlen(dira
->iface
) - 1;
2669 else if ((addrlist
= get_address(value
, BrowsePort
)) != NULL
)
2672 * Only IPv4 addresses are supported...
2675 for (addr
= addrlist
; addr
; addr
= addr
->next
)
2676 if (addr
->addr
.addr
.sa_family
== AF_INET
)
2681 memcpy(&(dira
->to
), &(addrlist
->addr
), sizeof(dira
->to
));
2682 httpAddrString(&(dira
->to
), temp
, sizeof(temp
));
2684 cupsdLogMessage(CUPSD_LOG_INFO
,
2685 "Sending browsing info to %s:%d (IPv4)",
2686 temp
, ntohs(dira
->to
.ipv4
.sin_port
));
2691 cupsdLogMessage(CUPSD_LOG_ERROR
, "Bad BrowseAddress %s at line %d.",
2694 httpAddrFreeList(addrlist
);
2697 cupsdLogMessage(CUPSD_LOG_ERROR
, "Bad BrowseAddress %s at line %d.",
2700 else if (!strcasecmp(line
, "BrowseOrder") && value
)
2703 * "BrowseOrder Deny,Allow" or "BrowseOrder Allow,Deny"...
2706 if ((location
= cupsdFindLocation("CUPS_INTERNAL_BROWSE_ACL")) == NULL
)
2707 location
= cupsdAddLocation("CUPS_INTERNAL_BROWSE_ACL");
2709 if (location
== NULL
)
2710 cupsdLogMessage(CUPSD_LOG_ERROR
,
2711 "Unable to initialize browse access control list!");
2712 else if (!strncasecmp(value
, "deny", 4))
2713 location
->order_type
= CUPSD_AUTH_ALLOW
;
2714 else if (!strncasecmp(value
, "allow", 5))
2715 location
->order_type
= CUPSD_AUTH_DENY
;
2717 cupsdLogMessage(CUPSD_LOG_ERROR
,
2718 "Unknown BrowseOrder value %s on line %d.",
2721 else if (!strcasecmp(line
, "BrowseProtocols") ||
2722 !strcasecmp(line
, "BrowseLocalProtocols") ||
2723 !strcasecmp(line
, "BrowseRemoteProtocols"))
2726 * "BrowseProtocols name [... name]"
2727 * "BrowseLocalProtocols name [... name]"
2728 * "BrowseRemoteProtocols name [... name]"
2731 int protocols
= parse_protocols(value
);
2735 cupsdLogMessage(CUPSD_LOG_ERROR
,
2736 "Unknown browse protocol \"%s\" on line %d.",
2741 if (strcasecmp(line
, "BrowseLocalProtocols"))
2742 BrowseRemoteProtocols
= protocols
;
2743 if (strcasecmp(line
, "BrowseRemoteProtocols"))
2744 BrowseLocalProtocols
= protocols
;
2746 else if ((!strcasecmp(line
, "BrowseAllow") ||
2747 !strcasecmp(line
, "BrowseDeny")) && value
)
2750 * BrowseAllow [From] host/ip...
2751 * BrowseDeny [From] host/ip...
2754 if ((location
= cupsdFindLocation("CUPS_INTERNAL_BROWSE_ACL")) == NULL
)
2755 location
= cupsdAddLocation("CUPS_INTERNAL_BROWSE_ACL");
2757 if (location
== NULL
)
2758 cupsdLogMessage(CUPSD_LOG_ERROR
,
2759 "Unable to initialize browse access control list!");
2764 if (!strncasecmp(value
, "from", 4))
2767 * Strip leading "from"...
2772 while (isspace(*value
& 255))
2780 * Find the end of the value...
2783 for (valueptr
= value
; *valueptr
&& !isspace(*valueptr
& 255); valueptr
++);
2785 while (isspace(*valueptr
& 255))
2789 * Figure out what form the allow/deny address takes:
2800 * nnn.nnn.nnn.nnn/mm
2801 * nnn.nnn.nnn.nnn/mmm.mmm.mmm.mmm
2804 if (!strcasecmp(value
, "all"))
2810 if (!strcasecmp(line
, "BrowseAllow"))
2811 cupsdAllowIP(location
, zeros
, zeros
);
2813 cupsdDenyIP(location
, zeros
, zeros
);
2815 else if (!strcasecmp(value
, "none"))
2821 if (!strcasecmp(line
, "BrowseAllow"))
2822 cupsdAllowIP(location
, ones
, zeros
);
2824 cupsdDenyIP(location
, ones
, zeros
);
2827 else if (value
[0] == '*' || value
[0] == '.' ||
2828 (!isdigit(value
[0] & 255) && value
[0] != '['))
2830 else if (value
[0] == '*' || value
[0] == '.' || !isdigit(value
[0] & 255))
2831 #endif /* AF_INET6 */
2834 * Host or domain name...
2837 if (value
[0] == '*')
2840 if (!strcasecmp(line
, "BrowseAllow"))
2841 cupsdAllowHost(location
, value
);
2843 cupsdDenyHost(location
, value
);
2848 * One of many IP address forms...
2851 if (!get_addr_and_mask(value
, ip
, mask
))
2853 cupsdLogMessage(CUPSD_LOG_ERROR
, "Bad netmask value %s on line %d.",
2858 if (!strcasecmp(line
, "BrowseAllow"))
2859 cupsdAllowIP(location
, ip
, mask
);
2861 cupsdDenyIP(location
, ip
, mask
);
2865 * Advance to next value...
2872 else if (!strcasecmp(line
, "BrowseRelay") && value
)
2875 * BrowseRelay [from] source [to] destination
2879 relay
= malloc(sizeof(cupsd_dirsvc_relay_t
));
2881 relay
= realloc(Relays
, (NumRelays
+ 1) * sizeof(cupsd_dirsvc_relay_t
));
2885 cupsdLogMessage(CUPSD_LOG_ERROR
,
2886 "Unable to allocate BrowseRelay at line %d - %s.",
2887 linenum
, strerror(errno
));
2894 memset(relay
, 0, sizeof(cupsd_dirsvc_relay_t
));
2896 if (!strncasecmp(value
, "from ", 5))
2899 * Strip leading "from"...
2904 while (isspace(*value
))
2909 * Figure out what form the from address takes:
2918 * nnn.nnn.nnn.nnn/mm
2919 * nnn.nnn.nnn.nnn/mmm.mmm.mmm.mmm
2923 if (value
[0] == '*' || value
[0] == '.' ||
2924 (!isdigit(value
[0] & 255) && value
[0] != '['))
2926 if (value
[0] == '*' || value
[0] == '.' || !isdigit(value
[0] & 255))
2927 #endif /* AF_INET6 */
2930 * Host or domain name...
2933 if (value
[0] == '*')
2936 strlcpy(temp
, value
, sizeof(temp
));
2937 if ((ptr
= strchr(temp
, ' ')) != NULL
)
2940 relay
->from
.type
= CUPSD_AUTH_NAME
;
2942 if ((relay
->from
.mask
.name
.name
= strdup(temp
)) == NULL
)
2944 cupsdLogMessage(CUPSD_LOG_ERROR
,
2945 "Unable to allocate BrowseRelay name at line %d - %s.",
2946 linenum
, strerror(errno
));
2950 relay
->from
.mask
.name
.length
= strlen(temp
);
2955 * One of many IP address forms...
2958 if (!get_addr_and_mask(value
, ip
, mask
))
2960 cupsdLogMessage(CUPSD_LOG_ERROR
, "Bad netmask value %s on line %d.",
2965 relay
->from
.type
= CUPSD_AUTH_IP
;
2966 memcpy(relay
->from
.mask
.ip
.address
, ip
,
2967 sizeof(relay
->from
.mask
.ip
.address
));
2968 memcpy(relay
->from
.mask
.ip
.netmask
, mask
,
2969 sizeof(relay
->from
.mask
.ip
.netmask
));
2973 * Skip value and trailing whitespace...
2976 for (; *value
; value
++)
2977 if (isspace(*value
))
2980 while (isspace(*value
))
2983 if (!strncasecmp(value
, "to ", 3))
2986 * Strip leading "to"...
2991 while (isspace(*value
))
2996 * Get "to" address and port...
2999 if ((addrlist
= get_address(value
, BrowsePort
)) != NULL
)
3002 * Only IPv4 addresses are supported...
3005 for (addr
= addrlist
; addr
; addr
= addr
->next
)
3006 if (addr
->addr
.addr
.sa_family
== AF_INET
)
3011 memcpy(&(relay
->to
), &(addrlist
->addr
), sizeof(relay
->to
));
3013 httpAddrString(&(relay
->to
), temp
, sizeof(temp
));
3015 if (relay
->from
.type
== CUPSD_AUTH_IP
)
3016 snprintf(temp2
, sizeof(temp2
), "%u.%u.%u.%u/%u.%u.%u.%u",
3017 relay
->from
.mask
.ip
.address
[0] >> 24,
3018 (relay
->from
.mask
.ip
.address
[0] >> 16) & 255,
3019 (relay
->from
.mask
.ip
.address
[0] >> 8) & 255,
3020 relay
->from
.mask
.ip
.address
[0] & 255,
3021 relay
->from
.mask
.ip
.netmask
[0] >> 24,
3022 (relay
->from
.mask
.ip
.netmask
[0] >> 16) & 255,
3023 (relay
->from
.mask
.ip
.netmask
[0] >> 8) & 255,
3024 relay
->from
.mask
.ip
.netmask
[0] & 255);
3026 strlcpy(temp2
, relay
->from
.mask
.name
.name
, sizeof(temp2
));
3028 cupsdLogMessage(CUPSD_LOG_INFO
, "Relaying from %s to %s:%d (IPv4)",
3029 temp2
, temp
, ntohs(relay
->to
.ipv4
.sin_port
));
3034 cupsdLogMessage(CUPSD_LOG_ERROR
, "Bad relay address %s at line %d.",
3037 httpAddrFreeList(addrlist
);
3041 if (relay
->from
.type
== CUPSD_AUTH_NAME
)
3042 free(relay
->from
.mask
.name
.name
);
3044 cupsdLogMessage(CUPSD_LOG_ERROR
, "Bad relay address %s at line %d.",
3048 else if (!strcasecmp(line
, "BrowsePoll") && value
)
3051 * BrowsePoll address[:port]
3054 char *portname
; /* Port name */
3055 int portnum
; /* Port number */
3056 struct servent
*service
; /* Service */
3060 * Extract the port name from the address...
3063 if ((portname
= strrchr(value
, ':')) != NULL
&& !strchr(portname
, ']'))
3067 if (isdigit(*portname
& 255))
3068 portnum
= atoi(portname
);
3069 else if ((service
= getservbyname(portname
, NULL
)) != NULL
)
3070 portnum
= ntohs(service
->s_port
);
3073 cupsdLogMessage(CUPSD_LOG_ERROR
, "Lookup of service \"%s\" failed!",
3079 portnum
= ippPort();
3082 * Add the poll entry...
3086 pollp
= malloc(sizeof(cupsd_dirsvc_poll_t
));
3088 pollp
= realloc(Polled
, (NumPolled
+ 1) * sizeof(cupsd_dirsvc_poll_t
));
3092 cupsdLogMessage(CUPSD_LOG_ERROR
,
3093 "Unable to allocate BrowsePoll at line %d - %s.",
3094 linenum
, strerror(errno
));
3102 memset(pollp
, 0, sizeof(cupsd_dirsvc_poll_t
));
3104 strlcpy(pollp
->hostname
, value
, sizeof(pollp
->hostname
));
3105 pollp
->port
= portnum
;
3107 cupsdLogMessage(CUPSD_LOG_INFO
, "Polling %s:%d", pollp
->hostname
,
3110 else if (!strcasecmp(line
, "DefaultAuthType") && value
)
3113 * DefaultAuthType {basic,digest,basicdigest,negotiate}
3116 if (!strcasecmp(value
, "none"))
3117 DefaultAuthType
= CUPSD_AUTH_NONE
;
3118 else if (!strcasecmp(value
, "basic"))
3119 DefaultAuthType
= CUPSD_AUTH_BASIC
;
3120 else if (!strcasecmp(value
, "digest"))
3121 DefaultAuthType
= CUPSD_AUTH_DIGEST
;
3122 else if (!strcasecmp(value
, "basicdigest"))
3123 DefaultAuthType
= CUPSD_AUTH_BASICDIGEST
;
3125 else if (!strcasecmp(value
, "negotiate"))
3126 DefaultAuthType
= CUPSD_AUTH_NEGOTIATE
;
3127 #endif /* HAVE_GSSAPI */
3130 cupsdLogMessage(CUPSD_LOG_WARN
,
3131 "Unknown default authorization type %s on line %d.",
3133 if (FatalErrors
& CUPSD_FATAL_CONFIG
)
3138 else if (!strcasecmp(line
, "DefaultEncryption"))
3141 * DefaultEncryption {Never,IfRequested,Required}
3144 if (!value
|| !strcasecmp(value
, "never"))
3145 DefaultEncryption
= HTTP_ENCRYPT_NEVER
;
3146 else if (!strcasecmp(value
, "required"))
3147 DefaultEncryption
= HTTP_ENCRYPT_REQUIRED
;
3148 else if (!strcasecmp(value
, "ifrequested"))
3149 DefaultEncryption
= HTTP_ENCRYPT_IF_REQUESTED
;
3152 cupsdLogMessage(CUPSD_LOG_WARN
,
3153 "Unknown default encryption %s on line %d.",
3155 if (FatalErrors
& CUPSD_FATAL_CONFIG
)
3159 #endif /* HAVE_SSL */
3160 else if (!strcasecmp(line
, "User") && value
)
3163 * User ID to run as...
3166 if (isdigit(value
[0] & 255))
3168 int uid
= atoi(value
);
3171 cupsdLogMessage(CUPSD_LOG_ERROR
,
3172 "Will not use User 0 as specified on line %d "
3173 "for security reasons. You must use a non-"
3174 "privileged account instead.",
3181 struct passwd
*p
; /* Password information */
3184 p
= getpwnam(value
);
3189 cupsdLogMessage(CUPSD_LOG_ERROR
,
3190 "Will not use User %s (UID=0) as specified on line "
3191 "%d for security reasons. You must use a non-"
3192 "privileged account instead.",
3198 cupsdLogMessage(CUPSD_LOG_ERROR
,
3199 "Unknown User \"%s\" on line %d, ignoring!",
3203 else if (!strcasecmp(line
, "Group") && value
)
3206 * Group ID to run as...
3209 if (isdigit(value
[0]))
3210 Group
= atoi(value
);
3214 group
= getgrnam(value
);
3217 Group
= group
->gr_gid
;
3219 cupsdLogMessage(CUPSD_LOG_ERROR
,
3220 "Unknown Group \"%s\" on line %d, ignoring!",
3224 else if (!strcasecmp(line
, "SystemGroup") && value
)
3227 * SystemGroup (admin) group(s)...
3230 if (!parse_groups(value
))
3231 cupsdLogMessage(CUPSD_LOG_ERROR
,
3232 "Unknown SystemGroup \"%s\" on line %d, ignoring!",
3235 else if (!strcasecmp(line
, "HostNameLookups") && value
)
3238 * Do hostname lookups?
3241 if (!strcasecmp(value
, "off") || !strcasecmp(value
, "no") ||
3242 !strcasecmp(value
, "false"))
3243 HostNameLookups
= 0;
3244 else if (!strcasecmp(value
, "on") || !strcasecmp(value
, "yes") ||
3245 !strcasecmp(value
, "true"))
3246 HostNameLookups
= 1;
3247 else if (!strcasecmp(value
, "double"))
3248 HostNameLookups
= 2;
3250 cupsdLogMessage(CUPSD_LOG_WARN
, "Unknown HostNameLookups %s on line %d.",
3253 else if (!strcasecmp(line
, "AccessLogLevel") && value
)
3256 * Amount of logging to do to access log...
3259 if (!strcasecmp(value
, "all"))
3260 AccessLogLevel
= CUPSD_ACCESSLOG_ALL
;
3261 else if (!strcasecmp(value
, "actions"))
3262 AccessLogLevel
= CUPSD_ACCESSLOG_ACTIONS
;
3263 else if (!strcasecmp(value
, "config"))
3264 AccessLogLevel
= CUPSD_ACCESSLOG_CONFIG
;
3266 cupsdLogMessage(CUPSD_LOG_WARN
, "Unknown AccessLogLevel %s on line %d.",
3269 else if (!strcasecmp(line
, "LogLevel") && value
)
3272 * Amount of logging to do to error log...
3275 if (!strcasecmp(value
, "debug2"))
3276 LogLevel
= CUPSD_LOG_DEBUG2
;
3277 else if (!strcasecmp(value
, "debug"))
3278 LogLevel
= CUPSD_LOG_DEBUG
;
3279 else if (!strcasecmp(value
, "info"))
3280 LogLevel
= CUPSD_LOG_INFO
;
3281 else if (!strcasecmp(value
, "notice"))
3282 LogLevel
= CUPSD_LOG_NOTICE
;
3283 else if (!strcasecmp(value
, "warn"))
3284 LogLevel
= CUPSD_LOG_WARN
;
3285 else if (!strcasecmp(value
, "error"))
3286 LogLevel
= CUPSD_LOG_ERROR
;
3287 else if (!strcasecmp(value
, "crit"))
3288 LogLevel
= CUPSD_LOG_CRIT
;
3289 else if (!strcasecmp(value
, "alert"))
3290 LogLevel
= CUPSD_LOG_ALERT
;
3291 else if (!strcasecmp(value
, "emerg"))
3292 LogLevel
= CUPSD_LOG_EMERG
;
3293 else if (!strcasecmp(value
, "none"))
3294 LogLevel
= CUPSD_LOG_NONE
;
3296 cupsdLogMessage(CUPSD_LOG_WARN
, "Unknown LogLevel %s on line %d.",
3299 else if (!strcasecmp(line
, "LogTimeFormat") && value
)
3302 * Amount of logging to do to error log...
3305 if (!strcasecmp(value
, "standard"))
3306 LogTimeFormat
= CUPSD_TIME_STANDARD
;
3307 else if (!strcasecmp(value
, "usecs"))
3308 LogTimeFormat
= CUPSD_TIME_USECS
;
3310 cupsdLogMessage(CUPSD_LOG_WARN
, "Unknown LogTimeFormat %s on line %d.",
3313 else if (!strcasecmp(line
, "PrintcapFormat") && value
)
3316 * Format of printcap file?
3319 if (!strcasecmp(value
, "bsd"))
3320 PrintcapFormat
= PRINTCAP_BSD
;
3321 else if (!strcasecmp(value
, "plist"))
3322 PrintcapFormat
= PRINTCAP_PLIST
;
3323 else if (!strcasecmp(value
, "solaris"))
3324 PrintcapFormat
= PRINTCAP_SOLARIS
;
3326 cupsdLogMessage(CUPSD_LOG_WARN
, "Unknown PrintcapFormat %s on line %d.",
3329 else if (!strcasecmp(line
, "ServerTokens") && value
)
3332 * Set the string used for the Server header...
3335 struct utsname plat
; /* Platform info */
3340 if (!strcasecmp(value
, "ProductOnly"))
3341 cupsdSetString(&ServerHeader
, "CUPS");
3342 else if (!strcasecmp(value
, "Major"))
3343 cupsdSetString(&ServerHeader
, "CUPS/1");
3344 else if (!strcasecmp(value
, "Minor"))
3345 cupsdSetString(&ServerHeader
, "CUPS/1.4");
3346 else if (!strcasecmp(value
, "Minimal"))
3347 cupsdSetString(&ServerHeader
, CUPS_MINIMAL
);
3348 else if (!strcasecmp(value
, "OS"))
3349 cupsdSetStringf(&ServerHeader
, CUPS_MINIMAL
" (%s)", plat
.sysname
);
3350 else if (!strcasecmp(value
, "Full"))
3351 cupsdSetStringf(&ServerHeader
, CUPS_MINIMAL
" (%s) IPP/1.1",
3353 else if (!strcasecmp(value
, "None"))
3354 cupsdClearString(&ServerHeader
);
3356 cupsdLogMessage(CUPSD_LOG_WARN
, "Unknown ServerTokens %s on line %d.",
3359 else if (!strcasecmp(line
, "PassEnv") && value
)
3362 * PassEnv variable [... variable]
3367 for (valuelen
= 0; value
[valuelen
]; valuelen
++)
3368 if (isspace(value
[valuelen
]) || value
[valuelen
] == ',')
3371 if (value
[valuelen
])
3373 value
[valuelen
] = '\0';
3377 cupsdSetEnv(value
, NULL
);
3379 for (value
+= valuelen
; *value
; value
++)
3380 if (!isspace(*value
) || *value
!= ',')
3384 else if (!strcasecmp(line
, "ServerAlias") && value
)
3387 ServerAlias
= cupsArrayNew(NULL
, NULL
);
3389 cupsdAddAlias(ServerAlias
, value
);
3391 else if (!strcasecmp(line
, "SetEnv") && value
)
3394 * SetEnv variable value
3397 for (valueptr
= value
; *valueptr
&& !isspace(*valueptr
& 255); valueptr
++);
3405 while (isspace(*valueptr
& 255))
3408 cupsdSetEnv(value
, valueptr
);
3411 cupsdLogMessage(CUPSD_LOG_ERROR
,
3412 "Missing value for SetEnv directive on line %d.",
3416 else if (!strcasecmp(line
, "SSLOptions"))
3419 * SSLOptions options
3422 if (!value
|| !strcasecmp(value
, "none"))
3423 SSLOptions
= CUPSD_SSL_NONE
;
3424 else if (!strcasecmp(value
, "noemptyfragments"))
3425 SSLOptions
= CUPSD_SSL_NOEMPTY
;
3427 cupsdLogMessage(CUPSD_LOG_ERROR
,
3428 "Unknown value \"%s\" for SSLOptions directive on "
3429 "line %d.", value
, linenum
);
3431 #endif /* HAVE_SSL */
3435 * Find a simple variable in the list...
3438 for (i
= NUM_VARS
, var
= variables
; i
> 0; i
--, var
++)
3439 if (!strcasecmp(line
, var
->name
))
3445 * Unknown directive! Output an error message and continue...
3449 cupsdLogMessage(CUPSD_LOG_ERROR
, "Missing value for %s on line %d.",
3452 cupsdLogMessage(CUPSD_LOG_ERROR
, "Unknown directive %s on line %d.",
3459 case CUPSD_VARTYPE_INTEGER
:
3461 cupsdLogMessage(CUPSD_LOG_ERROR
,
3462 "Missing integer value for %s on line %d!",
3467 char *units
; /* Units */
3470 n
= strtol(value
, &units
, 0);
3472 if (units
&& *units
)
3474 if (tolower(units
[0] & 255) == 'g')
3475 n
*= 1024 * 1024 * 1024;
3476 else if (tolower(units
[0] & 255) == 'm')
3478 else if (tolower(units
[0] & 255) == 'k')
3480 else if (tolower(units
[0] & 255) == 't')
3485 cupsdLogMessage(CUPSD_LOG_ERROR
,
3486 "Bad negative integer value for %s on line %d!",
3489 *((int *)var
->ptr
) = n
;
3493 case CUPSD_VARTYPE_BOOLEAN
:
3495 cupsdLogMessage(CUPSD_LOG_ERROR
,
3496 "Missing boolean value for %s on line %d!",
3498 else if (!strcasecmp(value
, "true") ||
3499 !strcasecmp(value
, "on") ||
3500 !strcasecmp(value
, "enabled") ||
3501 !strcasecmp(value
, "yes") ||
3503 *((int *)var
->ptr
) = TRUE
;
3504 else if (!strcasecmp(value
, "false") ||
3505 !strcasecmp(value
, "off") ||
3506 !strcasecmp(value
, "disabled") ||
3507 !strcasecmp(value
, "no") ||
3508 !strcasecmp(value
, "0"))
3509 *((int *)var
->ptr
) = FALSE
;
3511 cupsdLogMessage(CUPSD_LOG_ERROR
,
3512 "Unknown boolean value %s on line %d.",
3516 case CUPSD_VARTYPE_PATHNAME
:
3519 cupsdLogMessage(CUPSD_LOG_ERROR
,
3520 "Missing pathname value for %s on line %d!",
3525 if (value
[0] == '/')
3526 strlcpy(temp
, value
, sizeof(temp
));
3528 snprintf(temp
, sizeof(temp
), "%s/%s", ServerRoot
, value
);
3530 if (access(temp
, 0))
3532 cupsdLogMessage(CUPSD_LOG_ERROR
,
3533 "File or directory for \"%s %s\" on line %d "
3534 "does not exist!", line
, value
, linenum
);
3538 case CUPSD_VARTYPE_STRING
:
3539 cupsdSetString((char **)var
->ptr
, value
);
3550 * 'read_location()' - Read a <Location path> definition.
3553 static int /* O - New line number or 0 on error */
3554 read_location(cups_file_t
*fp
, /* I - Configuration file */
3555 char *location
, /* I - Location name/path */
3556 int linenum
) /* I - Current line number */
3558 cupsd_location_t
*loc
, /* New location */
3559 *parent
; /* Parent location */
3560 char line
[HTTP_MAX_BUFFER
],
3562 *value
, /* Value for directive */
3563 *valptr
; /* Pointer into value */
3566 if ((parent
= cupsdAddLocation(location
)) == NULL
)
3569 parent
->limit
= CUPSD_AUTH_LIMIT_ALL
;
3572 while (cupsFileGetConf(fp
, line
, sizeof(line
), &value
, &linenum
))
3575 * Decode the directive...
3578 if (!strcasecmp(line
, "</Location>"))
3580 else if (!strcasecmp(line
, "<Limit") ||
3581 !strcasecmp(line
, "<LimitExcept"))
3585 cupsdLogMessage(CUPSD_LOG_ERROR
, "Syntax error on line %d.", linenum
);
3586 if (FatalErrors
& CUPSD_FATAL_CONFIG
)
3592 if ((loc
= cupsdCopyLocation(&parent
)) == NULL
)
3598 for (valptr
= value
; !isspace(*valptr
& 255) && *valptr
; valptr
++);
3603 if (!strcmp(value
, "ALL"))
3604 loc
->limit
= CUPSD_AUTH_LIMIT_ALL
;
3605 else if (!strcmp(value
, "GET"))
3606 loc
->limit
|= CUPSD_AUTH_LIMIT_GET
;
3607 else if (!strcmp(value
, "HEAD"))
3608 loc
->limit
|= CUPSD_AUTH_LIMIT_HEAD
;
3609 else if (!strcmp(value
, "OPTIONS"))
3610 loc
->limit
|= CUPSD_AUTH_LIMIT_OPTIONS
;
3611 else if (!strcmp(value
, "POST"))
3612 loc
->limit
|= CUPSD_AUTH_LIMIT_POST
;
3613 else if (!strcmp(value
, "PUT"))
3614 loc
->limit
|= CUPSD_AUTH_LIMIT_PUT
;
3615 else if (!strcmp(value
, "TRACE"))
3616 loc
->limit
|= CUPSD_AUTH_LIMIT_TRACE
;
3618 cupsdLogMessage(CUPSD_LOG_WARN
, "Unknown request type %s on line %d!",
3621 for (value
= valptr
; isspace(*value
& 255); value
++);
3624 if (!strcasecmp(line
, "<LimitExcept"))
3625 loc
->limit
= CUPSD_AUTH_LIMIT_ALL
^ loc
->limit
;
3627 parent
->limit
&= ~loc
->limit
;
3629 else if (!strcasecmp(line
, "</Limit>") ||
3630 !strcasecmp(line
, "</LimitExcept>"))
3632 else if (!parse_aaa(loc
, line
, value
, linenum
))
3634 cupsdLogMessage(CUPSD_LOG_ERROR
,
3635 "Unknown Location directive %s on line %d.",
3637 if (FatalErrors
& CUPSD_FATAL_CONFIG
)
3642 cupsdLogMessage(CUPSD_LOG_ERROR
,
3643 "Unexpected end-of-file at line %d while reading location!",
3646 return ((FatalErrors
& CUPSD_FATAL_CONFIG
) ? 0 : linenum
);
3651 * 'read_policy()' - Read a <Policy name> definition.
3654 static int /* O - New line number or 0 on error */
3655 read_policy(cups_file_t
*fp
, /* I - Configuration file */
3656 char *policy
, /* I - Location name/path */
3657 int linenum
) /* I - Current line number */
3659 int i
; /* Looping var */
3660 cupsd_policy_t
*pol
; /* Policy */
3661 cupsd_location_t
*op
; /* Policy operation */
3662 int num_ops
; /* Number of IPP operations */
3663 ipp_op_t ops
[100]; /* Operations */
3664 char line
[HTTP_MAX_BUFFER
],
3666 *value
, /* Value for directive */
3667 *valptr
; /* Pointer into value */
3671 * Create the policy...
3674 if ((pol
= cupsdAddPolicy(policy
)) == NULL
)
3678 * Read from the file...
3684 while (cupsFileGetConf(fp
, line
, sizeof(line
), &value
, &linenum
))
3687 * Decode the directive...
3690 if (!strcasecmp(line
, "</Policy>"))
3693 cupsdLogMessage(CUPSD_LOG_WARN
,
3694 "Missing </Limit> before </Policy> on line %d!",
3698 * Verify that we have an explicit policy for Validate-Job, Cancel-Jobs,
3699 * Cancel-My-Jobs, Close-Job, and CUPS-Get-Document, which ensures that
3700 * upgrades do not introduce new security issues...
3703 if ((op
= cupsdFindPolicyOp(pol
, IPP_VALIDATE_JOB
)) == NULL
||
3704 op
->op
== IPP_ANY_OPERATION
)
3706 if ((op
= cupsdFindPolicyOp(pol
, IPP_PRINT_JOB
)) != NULL
&&
3707 op
->op
!= IPP_ANY_OPERATION
)
3710 * Add a new limit for Validate-Job using the Print-Job limit as a
3714 cupsdLogMessage(CUPSD_LOG_WARN
,
3715 "No limit for Validate-Job defined in policy %s "
3716 "- using Print-Job's policy", pol
->name
);
3718 cupsdAddPolicyOp(pol
, op
, IPP_VALIDATE_JOB
);
3722 if ((op
= cupsdFindPolicyOp(pol
, IPP_CANCEL_JOBS
)) == NULL
||
3723 op
->op
== IPP_ANY_OPERATION
)
3725 if ((op
= cupsdFindPolicyOp(pol
, IPP_CANCEL_JOB
)) != NULL
&&
3726 op
->op
!= IPP_ANY_OPERATION
)
3729 * Add a new limit for Cancel-Jobs using the Cancel-Job limit as a
3733 cupsdLogMessage(CUPSD_LOG_WARN
,
3734 "No limit for Cancel-Jobs defined in policy %s "
3735 "- using Cancel-Job's policy", pol
->name
);
3737 cupsdAddPolicyOp(pol
, op
, IPP_CANCEL_JOBS
);
3741 if ((op
= cupsdFindPolicyOp(pol
, IPP_CANCEL_MY_JOBS
)) == NULL
||
3742 op
->op
== IPP_ANY_OPERATION
)
3744 if ((op
= cupsdFindPolicyOp(pol
, IPP_SEND_DOCUMENT
)) != NULL
&&
3745 op
->op
!= IPP_ANY_OPERATION
)
3748 * Add a new limit for Cancel-My-Jobs using the Send-Document limit as
3752 cupsdLogMessage(CUPSD_LOG_WARN
,
3753 "No limit for Cancel-My-Jobs defined in policy %s "
3754 "- using Send-Document's policy", pol
->name
);
3756 cupsdAddPolicyOp(pol
, op
, IPP_CANCEL_MY_JOBS
);
3760 if ((op
= cupsdFindPolicyOp(pol
, IPP_CLOSE_JOB
)) == NULL
||
3761 op
->op
== IPP_ANY_OPERATION
)
3763 if ((op
= cupsdFindPolicyOp(pol
, IPP_SEND_DOCUMENT
)) != NULL
&&
3764 op
->op
!= IPP_ANY_OPERATION
)
3767 * Add a new limit for Close-Job using the Send-Document limit as a
3771 cupsdLogMessage(CUPSD_LOG_WARN
,
3772 "No limit for Close-Job defined in policy %s "
3773 "- using Send-Document's policy", pol
->name
);
3775 cupsdAddPolicyOp(pol
, op
, IPP_CLOSE_JOB
);
3779 if ((op
= cupsdFindPolicyOp(pol
, CUPS_GET_DOCUMENT
)) == NULL
||
3780 op
->op
== IPP_ANY_OPERATION
)
3782 if ((op
= cupsdFindPolicyOp(pol
, IPP_SEND_DOCUMENT
)) != NULL
&&
3783 op
->op
!= IPP_ANY_OPERATION
)
3786 * Add a new limit for CUPS-Get-Document using the Send-Document
3787 * limit as a template...
3790 cupsdLogMessage(CUPSD_LOG_WARN
,
3791 "No limit for CUPS-Get-Document defined in policy %s "
3792 "- using Send-Document's policy", pol
->name
);
3794 cupsdAddPolicyOp(pol
, op
, CUPS_GET_DOCUMENT
);
3800 else if (!strcasecmp(line
, "<Limit") && !op
)
3804 cupsdLogMessage(CUPSD_LOG_ERROR
, "Syntax error on line %d.", linenum
);
3805 if (FatalErrors
& CUPSD_FATAL_CONFIG
)
3812 * Scan for IPP operation names...
3819 for (valptr
= value
; !isspace(*valptr
& 255) && *valptr
; valptr
++);
3824 if (num_ops
< (int)(sizeof(ops
) / sizeof(ops
[0])))
3826 if (!strcasecmp(value
, "All"))
3827 ops
[num_ops
] = IPP_ANY_OPERATION
;
3828 else if ((ops
[num_ops
] = ippOpValue(value
)) == IPP_BAD_OPERATION
)
3829 cupsdLogMessage(CUPSD_LOG_ERROR
,
3830 "Bad IPP operation name \"%s\" on line %d!",
3836 cupsdLogMessage(CUPSD_LOG_ERROR
,
3837 "Too many operations listed on line %d!",
3840 for (value
= valptr
; isspace(*value
& 255); value
++);
3844 * If none are specified, apply the policy to all operations...
3849 ops
[0] = IPP_ANY_OPERATION
;
3854 * Add a new policy for the first operation...
3857 op
= cupsdAddPolicyOp(pol
, NULL
, ops
[0]);
3859 else if (!strcasecmp(line
, "</Limit>") && op
)
3862 * Finish the current operation limit...
3868 * Copy the policy to the other operations...
3871 for (i
= 1; i
< num_ops
; i
++)
3872 cupsdAddPolicyOp(pol
, op
, ops
[i
]);
3879 cupsdLogMessage(CUPSD_LOG_ERROR
,
3880 "Missing <Limit ops> directive before %s on line %d.",
3882 if (FatalErrors
& CUPSD_FATAL_CONFIG
)
3885 else if (!parse_aaa(op
, line
, value
, linenum
))
3888 cupsdLogMessage(CUPSD_LOG_ERROR
,
3889 "Unknown Policy Limit directive %s on line %d.",
3892 cupsdLogMessage(CUPSD_LOG_ERROR
,
3893 "Unknown Policy directive %s on line %d.",
3896 if (FatalErrors
& CUPSD_FATAL_CONFIG
)
3901 cupsdLogMessage(CUPSD_LOG_ERROR
,
3902 "Unexpected end-of-file at line %d while reading policy \"%s\"!",
3905 return ((FatalErrors
& CUPSD_FATAL_CONFIG
) ? 0 : linenum
);
3910 * End of "$Id: conf.c 7952 2008-09-17 00:56:20Z mike $".