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
},
86 { "AppleQuotas", &AppleQuotas
, CUPSD_VARTYPE_BOOLEAN
},
87 #endif /* __APPLE__ */
88 { "AutoPurgeJobs", &JobAutoPurge
, CUPSD_VARTYPE_BOOLEAN
},
89 { "BrowseInterval", &BrowseInterval
, CUPSD_VARTYPE_INTEGER
},
91 { "BrowseLDAPBindDN", &BrowseLDAPBindDN
, CUPSD_VARTYPE_STRING
},
93 { "BrowseLDAPCACertFile", &BrowseLDAPCACertFile
, CUPSD_VARTYPE_PATHNAME
},
94 # endif /* HAVE_LDAP_SSL */
95 { "BrowseLDAPDN", &BrowseLDAPDN
, CUPSD_VARTYPE_STRING
},
96 { "BrowseLDAPPassword", &BrowseLDAPPassword
, CUPSD_VARTYPE_STRING
},
97 { "BrowseLDAPServer", &BrowseLDAPServer
, CUPSD_VARTYPE_STRING
},
98 #endif /* HAVE_LDAP */
99 { "BrowseLocalOptions", &BrowseLocalOptions
, CUPSD_VARTYPE_STRING
},
100 { "BrowsePort", &BrowsePort
, CUPSD_VARTYPE_INTEGER
},
101 { "BrowseRemoteOptions", &BrowseRemoteOptions
, CUPSD_VARTYPE_STRING
},
102 { "BrowseShortNames", &BrowseShortNames
, CUPSD_VARTYPE_BOOLEAN
},
103 { "BrowseTimeout", &BrowseTimeout
, CUPSD_VARTYPE_INTEGER
},
104 { "BrowseWebIF", &BrowseWebIF
, CUPSD_VARTYPE_BOOLEAN
},
105 { "Browsing", &Browsing
, CUPSD_VARTYPE_BOOLEAN
},
106 { "CacheDir", &CacheDir
, CUPSD_VARTYPE_STRING
},
107 { "Classification", &Classification
, CUPSD_VARTYPE_STRING
},
108 { "ClassifyOverride", &ClassifyOverride
, CUPSD_VARTYPE_BOOLEAN
},
109 { "ConfigFilePerm", &ConfigFilePerm
, CUPSD_VARTYPE_INTEGER
},
110 { "DataDir", &DataDir
, CUPSD_VARTYPE_STRING
},
111 { "DefaultLanguage", &DefaultLanguage
, CUPSD_VARTYPE_STRING
},
112 { "DefaultLeaseDuration", &DefaultLeaseDuration
, CUPSD_VARTYPE_INTEGER
},
113 { "DefaultPaperSize", &DefaultPaperSize
, CUPSD_VARTYPE_STRING
},
114 { "DefaultPolicy", &DefaultPolicy
, CUPSD_VARTYPE_STRING
},
115 { "DefaultShared", &DefaultShared
, CUPSD_VARTYPE_BOOLEAN
},
116 { "DirtyCleanInterval", &DirtyCleanInterval
, CUPSD_VARTYPE_INTEGER
},
117 { "DocumentRoot", &DocumentRoot
, CUPSD_VARTYPE_STRING
},
118 { "ErrorLog", &ErrorLog
, CUPSD_VARTYPE_STRING
},
119 { "ErrorPolicy", &ErrorPolicy
, CUPSD_VARTYPE_STRING
},
120 { "FileDevice", &FileDevice
, CUPSD_VARTYPE_BOOLEAN
},
121 { "FilterLimit", &FilterLimit
, CUPSD_VARTYPE_INTEGER
},
122 { "FilterNice", &FilterNice
, CUPSD_VARTYPE_INTEGER
},
123 { "FontPath", &FontPath
, CUPSD_VARTYPE_STRING
},
124 { "HideImplicitMembers", &HideImplicitMembers
, CUPSD_VARTYPE_BOOLEAN
},
125 { "ImplicitClasses", &ImplicitClasses
, CUPSD_VARTYPE_BOOLEAN
},
126 { "ImplicitAnyClasses", &ImplicitAnyClasses
, CUPSD_VARTYPE_BOOLEAN
},
127 { "JobKillDelay", &JobKillDelay
, CUPSD_VARTYPE_INTEGER
},
128 { "JobRetryLimit", &JobRetryLimit
, CUPSD_VARTYPE_INTEGER
},
129 { "JobRetryInterval", &JobRetryInterval
, CUPSD_VARTYPE_INTEGER
},
130 { "KeepAliveTimeout", &KeepAliveTimeout
, CUPSD_VARTYPE_INTEGER
},
131 { "KeepAlive", &KeepAlive
, CUPSD_VARTYPE_BOOLEAN
},
133 { "LaunchdTimeout", &LaunchdTimeout
, CUPSD_VARTYPE_INTEGER
},
134 #endif /* HAVE_LAUNCHD */
135 { "LimitRequestBody", &MaxRequestSize
, CUPSD_VARTYPE_INTEGER
},
136 { "ListenBackLog", &ListenBackLog
, CUPSD_VARTYPE_INTEGER
},
137 { "LogDebugHistory", &LogDebugHistory
, CUPSD_VARTYPE_INTEGER
},
138 { "LogFilePerm", &LogFilePerm
, CUPSD_VARTYPE_INTEGER
},
139 { "LPDConfigFile", &LPDConfigFile
, CUPSD_VARTYPE_STRING
},
140 { "MaxActiveJobs", &MaxActiveJobs
, CUPSD_VARTYPE_INTEGER
},
141 { "MaxClients", &MaxClients
, CUPSD_VARTYPE_INTEGER
},
142 { "MaxClientsPerHost", &MaxClientsPerHost
, CUPSD_VARTYPE_INTEGER
},
143 { "MaxCopies", &MaxCopies
, CUPSD_VARTYPE_INTEGER
},
144 { "MaxEvents", &MaxEvents
, CUPSD_VARTYPE_INTEGER
},
145 { "MaxJobs", &MaxJobs
, CUPSD_VARTYPE_INTEGER
},
146 { "MaxJobsPerPrinter", &MaxJobsPerPrinter
, CUPSD_VARTYPE_INTEGER
},
147 { "MaxJobsPerUser", &MaxJobsPerUser
, CUPSD_VARTYPE_INTEGER
},
148 { "MaxLeaseDuration", &MaxLeaseDuration
, CUPSD_VARTYPE_INTEGER
},
149 { "MaxLogSize", &MaxLogSize
, CUPSD_VARTYPE_INTEGER
},
150 { "MaxPrinterHistory", &MaxPrinterHistory
, CUPSD_VARTYPE_INTEGER
},
151 { "MaxRequestSize", &MaxRequestSize
, CUPSD_VARTYPE_INTEGER
},
152 { "MaxSubscriptions", &MaxSubscriptions
, CUPSD_VARTYPE_INTEGER
},
153 { "MaxSubscriptionsPerJob", &MaxSubscriptionsPerJob
, CUPSD_VARTYPE_INTEGER
},
154 { "MaxSubscriptionsPerPrinter",&MaxSubscriptionsPerPrinter
, CUPSD_VARTYPE_INTEGER
},
155 { "MaxSubscriptionsPerUser", &MaxSubscriptionsPerUser
, CUPSD_VARTYPE_INTEGER
},
156 { "MultipleOperationTimeout", &MultipleOperationTimeout
, CUPSD_VARTYPE_INTEGER
},
157 { "PageLog", &PageLog
, CUPSD_VARTYPE_STRING
},
158 { "PageLogFormat", &PageLogFormat
, CUPSD_VARTYPE_STRING
},
159 { "PreserveJobFiles", &JobFiles
, CUPSD_VARTYPE_BOOLEAN
},
160 { "PreserveJobHistory", &JobHistory
, CUPSD_VARTYPE_BOOLEAN
},
161 { "Printcap", &Printcap
, CUPSD_VARTYPE_STRING
},
162 { "PrintcapGUI", &PrintcapGUI
, CUPSD_VARTYPE_STRING
},
163 { "ReloadTimeout", &ReloadTimeout
, CUPSD_VARTYPE_INTEGER
},
164 { "RemoteRoot", &RemoteRoot
, CUPSD_VARTYPE_STRING
},
165 { "RequestRoot", &RequestRoot
, CUPSD_VARTYPE_STRING
},
166 { "RIPCache", &RIPCache
, CUPSD_VARTYPE_STRING
},
167 { "RootCertDuration", &RootCertDuration
, CUPSD_VARTYPE_INTEGER
},
168 { "ServerAdmin", &ServerAdmin
, CUPSD_VARTYPE_STRING
},
169 { "ServerBin", &ServerBin
, CUPSD_VARTYPE_PATHNAME
},
171 { "ServerCertificate", &ServerCertificate
, CUPSD_VARTYPE_PATHNAME
},
172 # if defined(HAVE_LIBSSL) || defined(HAVE_GNUTLS)
173 { "ServerKey", &ServerKey
, CUPSD_VARTYPE_PATHNAME
},
174 # endif /* HAVE_LIBSSL || HAVE_GNUTLS */
175 #endif /* HAVE_SSL */
176 { "ServerName", &ServerName
, CUPSD_VARTYPE_STRING
},
177 { "ServerRoot", &ServerRoot
, CUPSD_VARTYPE_PATHNAME
},
178 { "SMBConfigFile", &SMBConfigFile
, CUPSD_VARTYPE_STRING
},
179 { "StateDir", &StateDir
, CUPSD_VARTYPE_STRING
},
180 #ifdef HAVE_AUTHORIZATION_H
181 { "SystemGroupAuthKey", &SystemGroupAuthKey
, CUPSD_VARTYPE_STRING
},
182 #endif /* HAVE_AUTHORIZATION_H */
183 { "TempDir", &TempDir
, CUPSD_VARTYPE_PATHNAME
},
184 { "Timeout", &Timeout
, CUPSD_VARTYPE_INTEGER
},
185 { "UseNetworkDefault", &UseNetworkDefault
, CUPSD_VARTYPE_BOOLEAN
}
187 #define NUM_VARS (sizeof(variables) / sizeof(variables[0]))
190 static const unsigned ones
[4] =
192 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff
194 static const unsigned zeros
[4] =
196 0x00000000, 0x00000000, 0x00000000, 0x00000000
204 static http_addrlist_t
*get_address(const char *value
, int defport
);
205 static int get_addr_and_mask(const char *value
, unsigned *ip
,
207 static int parse_aaa(cupsd_location_t
*loc
, char *line
,
208 char *value
, int linenum
);
209 static int parse_fatal_errors(const char *s
);
210 static int parse_groups(const char *s
);
211 static int parse_protocols(const char *s
);
212 static int read_configuration(cups_file_t
*fp
);
213 static int read_location(cups_file_t
*fp
, char *name
, int linenum
);
214 static int read_policy(cups_file_t
*fp
, char *name
, int linenum
);
218 * 'cupsdAddAlias()' - Add a host alias.
222 cupsdAddAlias(cups_array_t
*aliases
, /* I - Array of aliases */
223 const char *name
) /* I - Name to add */
225 cupsd_alias_t
*a
; /* New alias */
226 size_t namelen
; /* Length of name */
229 namelen
= strlen(name
);
231 if ((a
= (cupsd_alias_t
*)malloc(sizeof(cupsd_alias_t
) + namelen
)) == NULL
)
234 a
->namelen
= namelen
;
235 strcpy(a
->name
, name
); /* OK since a->name is allocated */
237 cupsArrayAdd(aliases
, a
);
242 * 'cupsdCheckPermissions()' - Fix the mode and ownership of a file or directory.
245 int /* O - 0 on success, -1 on error, 1 on warning */
246 cupsdCheckPermissions(
247 const char *filename
, /* I - File/directory name */
248 const char *suffix
, /* I - Additional file/directory name */
249 int mode
, /* I - Permissions */
250 int user
, /* I - Owner */
251 int group
, /* I - Group */
252 int is_dir
, /* I - 1 = directory, 0 = file */
253 int create_dir
) /* I - 1 = create directory, -1 = create w/o logging, 0 = not */
255 int dir_created
= 0; /* Did we create a directory? */
256 char pathname
[1024]; /* File name with prefix */
257 struct stat fileinfo
; /* Stat buffer */
258 int is_symlink
; /* Is "filename" a symlink? */
262 * Prepend the given root to the filename before testing it...
267 snprintf(pathname
, sizeof(pathname
), "%s/%s", filename
, suffix
);
272 * See if we can stat the file/directory...
275 if (lstat(filename
, &fileinfo
))
277 if (errno
== ENOENT
&& create_dir
)
280 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Creating missing directory \"%s\"",
283 if (mkdir(filename
, mode
))
286 cupsdLogMessage(CUPSD_LOG_ERROR
,
287 "Unable to create directory \"%s\" - %s", filename
,
290 syslog(LOG_ERR
, "Unable to create directory \"%s\" - %s", filename
,
297 fileinfo
.st_mode
= mode
| S_IFDIR
;
300 return (create_dir
? -1 : 1);
303 if ((is_symlink
= S_ISLNK(fileinfo
.st_mode
)) != 0)
305 if (stat(filename
, &fileinfo
))
307 cupsdLogMessage(CUPSD_LOG_ERROR
, "\"%s\" is a bad symlink - %s",
308 filename
, strerror(errno
));
314 * Make sure it's a regular file or a directory as needed...
317 if (!dir_created
&& !is_dir
&& !S_ISREG(fileinfo
.st_mode
))
319 cupsdLogMessage(CUPSD_LOG_ERROR
, "\"%s\" is not a regular file!", filename
);
323 if (!dir_created
&& is_dir
&& !S_ISDIR(fileinfo
.st_mode
))
326 cupsdLogMessage(CUPSD_LOG_ERROR
, "\"%s\" is not a directory!", filename
);
328 syslog(LOG_ERR
, "\"%s\" is not a directory!", filename
);
334 * If the filename is a symlink, do not change permissions (STR #2937)...
341 * Fix owner, group, and mode as needed...
344 if (dir_created
|| fileinfo
.st_uid
!= user
|| fileinfo
.st_gid
!= group
)
347 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Repairing ownership of \"%s\"",
350 if (chown(filename
, user
, group
) && !getuid())
353 cupsdLogMessage(CUPSD_LOG_ERROR
,
354 "Unable to change ownership of \"%s\" - %s", filename
,
357 syslog(LOG_ERR
, "Unable to change ownership of \"%s\" - %s", filename
,
364 if (dir_created
|| (fileinfo
.st_mode
& 07777) != mode
)
367 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Repairing access permissions of \"%s\"",
370 if (chmod(filename
, mode
))
373 cupsdLogMessage(CUPSD_LOG_ERROR
,
374 "Unable to change permissions of \"%s\" - %s", filename
,
377 syslog(LOG_ERR
, "Unable to change permissions of \"%s\" - %s", filename
,
385 * Everything is OK...
393 * 'cupsdFreeAliases()' - Free all of the alias entries.
397 cupsdFreeAliases(cups_array_t
*aliases
) /* I - Array of aliases */
399 cupsd_alias_t
*a
; /* Current alias */
402 for (a
= (cupsd_alias_t
*)cupsArrayFirst(aliases
);
404 a
= (cupsd_alias_t
*)cupsArrayNext(aliases
))
407 cupsArrayDelete(aliases
);
412 * 'cupsdReadConfiguration()' - Read the cupsd.conf file.
415 int /* O - 1 on success, 0 otherwise */
416 cupsdReadConfiguration(void)
418 int i
; /* Looping var */
419 cups_file_t
*fp
; /* Configuration file */
420 int status
; /* Return status */
421 char temp
[1024], /* Temporary buffer */
422 mimedir
[1024], /* MIME directory */
423 *slash
; /* Directory separator */
424 cups_lang_t
*language
; /* Language */
425 struct passwd
*user
; /* Default user */
426 struct group
*group
; /* Default group */
427 char *old_serverroot
, /* Old ServerRoot */
428 *old_requestroot
; /* Old RequestRoot */
429 int old_remote_port
; /* Old RemotePort */
430 const char *tmpdir
; /* TMPDIR environment variable */
431 struct stat tmpinfo
; /* Temporary directory info */
432 cupsd_policy_t
*p
; /* Policy */
436 * Save the old root paths...
439 old_serverroot
= NULL
;
440 cupsdSetString(&old_serverroot
, ServerRoot
);
441 old_requestroot
= NULL
;
442 cupsdSetString(&old_requestroot
, RequestRoot
);
445 * Reset the server configuration data...
448 cupsdDeleteAllLocations();
467 for (i
= 0; i
< NumRelays
; i
++)
468 if (Relays
[i
].from
.type
== CUPSD_AUTH_NAME
)
469 free(Relays
[i
].from
.mask
.name
.name
);
476 cupsdDeleteAllListeners();
478 old_remote_port
= RemotePort
;
485 cupsdFreeAliases(ServerAlias
);
488 cupsdClearString(&ServerName
);
489 cupsdClearString(&ServerAdmin
);
490 cupsdSetString(&ServerBin
, CUPS_SERVERBIN
);
491 cupsdSetString(&RequestRoot
, CUPS_REQUESTS
);
492 cupsdSetString(&CacheDir
, CUPS_CACHEDIR
);
493 cupsdSetString(&DataDir
, CUPS_DATADIR
);
494 cupsdSetString(&DocumentRoot
, CUPS_DOCROOT
);
495 cupsdSetString(&AccessLog
, CUPS_LOGDIR
"/access_log");
496 cupsdSetString(&ErrorLog
, CUPS_LOGDIR
"/error_log");
497 cupsdSetString(&PageLog
, CUPS_LOGDIR
"/page_log");
498 cupsdSetString(&PageLogFormat
,
499 "%p %j %u %T %P %C %{job-billing} "
500 "%{job-originating-host-name} %{job-name} %{media} %{sides}");
501 cupsdSetString(&Printcap
, CUPS_DEFAULT_PRINTCAP
);
502 cupsdSetString(&PrintcapGUI
, "/usr/bin/glpoptions");
503 cupsdSetString(&FontPath
, CUPS_FONTPATH
);
504 cupsdSetString(&RemoteRoot
, "remroot");
505 cupsdSetString(&ServerHeader
, "CUPS/1.4");
506 cupsdSetString(&StateDir
, CUPS_STATEDIR
);
508 if (!strcmp(CUPS_DEFAULT_PRINTCAP
, "/etc/printers.conf"))
509 PrintcapFormat
= PRINTCAP_SOLARIS
;
510 else if (!strcmp(CUPS_DEFAULT_PRINTCAP
,
511 "/Library/Preferences/org.cups.printers.plist"))
512 PrintcapFormat
= PRINTCAP_PLIST
;
514 PrintcapFormat
= PRINTCAP_BSD
;
516 strlcpy(temp
, ConfigurationFile
, sizeof(temp
));
517 if ((slash
= strrchr(temp
, '/')) != NULL
)
520 cupsdSetString(&ServerRoot
, temp
);
522 cupsdClearString(&Classification
);
523 ClassifyOverride
= 0;
527 cupsdSetString(&ServerCertificate
, "/Library/Keychains/System.keychain");
529 cupsdSetString(&ServerCertificate
, "ssl/server.crt");
530 cupsdSetString(&ServerKey
, "ssl/server.key");
531 # endif /* HAVE_CDSASSL */
532 #endif /* HAVE_SSL */
534 language
= cupsLangDefault();
536 if (!strcmp(language
->language
, "C") || !strcmp(language
->language
, "POSIX"))
537 cupsdSetString(&DefaultLanguage
, "en");
539 cupsdSetString(&DefaultLanguage
, language
->language
);
541 cupsdClearString(&DefaultPaperSize
);
543 cupsdSetString(&RIPCache
, "8m");
545 cupsdSetString(&TempDir
, NULL
);
548 * Find the default user...
551 if ((user
= getpwnam(CUPS_DEFAULT_USER
)) != NULL
)
556 * Use the (historical) NFS nobody user ID (-2 as a 16-bit twos-
557 * complement number...)
566 * Find the default group...
569 group
= getgrnam(CUPS_DEFAULT_GROUP
);
573 Group
= group
->gr_gid
;
577 * Fallback to group "nobody"...
580 group
= getgrnam("nobody");
584 Group
= group
->gr_gid
;
588 * Use the (historical) NFS nobody group ID (-2 as a 16-bit twos-
589 * complement number...)
600 AccessLogLevel
= CUPSD_ACCESSLOG_ACTIONS
;
601 ConfigFilePerm
= CUPS_DEFAULT_CONFIG_FILE_PERM
;
602 FatalErrors
= parse_fatal_errors(CUPS_DEFAULT_FATAL_ERRORS
);
603 DefaultAuthType
= CUPSD_AUTH_BASIC
;
605 DefaultEncryption
= HTTP_ENCRYPT_REQUIRED
;
606 SSLOptions
= CUPSD_SSL_NONE
;
607 #endif /* HAVE_SSL */
608 DirtyCleanInterval
= DEFAULT_KEEPALIVE
;
609 JobKillDelay
= DEFAULT_TIMEOUT
;
611 JobRetryInterval
= 300;
616 HostNameLookups
= FALSE
;
617 ImplicitClasses
= CUPS_DEFAULT_IMPLICIT_CLASSES
;
618 ImplicitAnyClasses
= FALSE
;
619 HideImplicitMembers
= TRUE
;
621 KeepAliveTimeout
= DEFAULT_KEEPALIVE
;
622 ListenBackLog
= SOMAXCONN
;
623 LogDebugHistory
= 200;
624 LogFilePerm
= CUPS_DEFAULT_LOG_FILE_PERM
;
625 LogLevel
= CUPSD_LOG_WARN
;
626 LogTimeFormat
= CUPSD_TIME_STANDARD
;
628 MaxClientsPerHost
= 0;
629 MaxLogSize
= 1024 * 1024;
630 MaxPrinterHistory
= 0;
632 MultipleOperationTimeout
= DEFAULT_TIMEOUT
;
633 ReloadTimeout
= DEFAULT_KEEPALIVE
;
634 RootCertDuration
= 300;
635 Timeout
= DEFAULT_TIMEOUT
;
638 BrowseInterval
= DEFAULT_INTERVAL
;
639 BrowsePort
= ippPort();
640 BrowseLocalProtocols
= parse_protocols(CUPS_DEFAULT_BROWSE_LOCAL_PROTOCOLS
);
641 BrowseRemoteProtocols
= parse_protocols(CUPS_DEFAULT_BROWSE_REMOTE_PROTOCOLS
);
642 BrowseShortNames
= CUPS_DEFAULT_BROWSE_SHORT_NAMES
;
643 BrowseTimeout
= DEFAULT_TIMEOUT
;
645 Browsing
= CUPS_DEFAULT_BROWSING
;
646 DefaultShared
= CUPS_DEFAULT_DEFAULT_SHARED
;
648 cupsdSetString(&LPDConfigFile
, CUPS_DEFAULT_LPD_CONFIG_FILE
);
649 cupsdSetString(&SMBConfigFile
, CUPS_DEFAULT_SMB_CONFIG_FILE
);
651 cupsdClearString(&BrowseLocalOptions
);
652 cupsdClearString(&BrowseRemoteOptions
);
654 cupsdSetString(&ErrorPolicy
, "stop-printer");
657 cupsdClearString(&BrowseLDAPBindDN
);
658 cupsdClearString(&BrowseLDAPDN
);
659 cupsdClearString(&BrowseLDAPPassword
);
660 cupsdClearString(&BrowseLDAPServer
);
661 # ifdef HAVE_LDAP_SSL
662 cupsdClearString(&BrowseLDAPCACertFile
);
663 # endif /* HAVE_LDAP_SSL */
664 #endif /* HAVE_LDAP */
666 JobHistory
= DEFAULT_HISTORY
;
667 JobFiles
= DEFAULT_FILES
;
672 MaxJobsPerPrinter
= 0;
673 MaxCopies
= CUPS_DEFAULT_MAX_COPIES
;
675 cupsdDeleteAllPolicies();
676 cupsdClearString(&DefaultPolicy
);
678 #ifdef HAVE_AUTHORIZATION_H
679 cupsdClearString(&SystemGroupAuthKey
);
680 #endif /* HAVE_AUTHORIZATION_H */
682 MaxSubscriptions
= 100;
683 MaxSubscriptionsPerJob
= 0;
684 MaxSubscriptionsPerPrinter
= 0;
685 MaxSubscriptionsPerUser
= 0;
686 DefaultLeaseDuration
= 86400;
687 MaxLeaseDuration
= 0;
690 LaunchdTimeout
= DEFAULT_TIMEOUT
+ 10;
691 #endif /* HAVE_LAUNCHD */
695 #endif /* __APPLE__ */
698 * Read the configuration file...
701 if ((fp
= cupsFileOpen(ConfigurationFile
, "r")) == NULL
)
704 status
= read_configuration(fp
);
713 cupsdLogMessage(CUPSD_LOG_INFO
, "Remote access is %s.",
714 RemotePort
? "enabled" : "disabled");
717 BrowseLocalProtocols
= 0; /* Disable sharing - no remote access */
720 * See if the ServerName is an IP address...
726 ServerAlias
= cupsArrayNew(NULL
, NULL
);
728 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Added auto ServerAlias %s", ServerName
);
732 if (gethostname(temp
, sizeof(temp
)))
734 cupsdLogMessage(CUPSD_LOG_ERROR
, "Unable to get hostname: %s",
736 strlcpy(temp
, "localhost", sizeof(temp
));
739 cupsdSetString(&ServerName
, temp
);
742 ServerAlias
= cupsArrayNew(NULL
, NULL
);
744 cupsdAddAlias(ServerAlias
, temp
);
745 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Added auto ServerAlias %s", temp
);
747 if (HostNameLookups
|| RemotePort
)
749 struct hostent
*host
; /* Host entry to get FQDN */
751 if ((host
= gethostbyname(temp
)) != NULL
)
753 if (strcasecmp(temp
, host
->h_name
))
755 cupsdSetString(&ServerName
, host
->h_name
);
756 cupsdAddAlias(ServerAlias
, host
->h_name
);
757 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Added auto ServerAlias %s",
763 for (i
= 0; host
->h_aliases
[i
]; i
++)
764 if (strcasecmp(temp
, host
->h_aliases
[i
]))
766 cupsdAddAlias(ServerAlias
, host
->h_aliases
[i
]);
767 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Added auto ServerAlias %s",
775 * Make sure we have the base hostname added as an alias, too!
778 if ((slash
= strchr(temp
, '.')) != NULL
)
781 cupsdAddAlias(ServerAlias
, temp
);
782 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Added auto ServerAlias %s", temp
);
786 for (slash
= ServerName
; isdigit(*slash
& 255) || *slash
== '.'; slash
++);
788 ServerNameIsIP
= !*slash
;
791 * Make sure ServerAdmin is initialized...
795 cupsdSetStringf(&ServerAdmin
, "root@%s", ServerName
);
798 * Use the default system group if none was supplied in cupsd.conf...
801 if (NumSystemGroups
== 0)
803 if (!parse_groups(CUPS_DEFAULT_SYSTEM_GROUPS
))
806 * Find the group associated with GID 0...
813 cupsdSetString(&SystemGroups
[0], group
->gr_name
);
815 cupsdSetString(&SystemGroups
[0], "unknown");
817 SystemGroupIDs
[0] = 0;
823 * Get the access control list for browsing...
826 BrowseACL
= cupsdFindLocation("CUPS_INTERNAL_BROWSE_ACL");
829 * Open the system log for cupsd if necessary...
833 if (!strcmp(AccessLog
, "syslog") ||
834 !strcmp(ErrorLog
, "syslog") ||
835 !strcmp(PageLog
, "syslog"))
836 openlog("cupsd", LOG_PID
| LOG_NOWAIT
| LOG_NDELAY
, LOG_LPR
);
837 #endif /* HAVE_VSYSLOG */
840 * Log the configuration file that was used...
843 cupsdLogMessage(CUPSD_LOG_INFO
, "Loaded configuration file \"%s\"",
847 * Validate the Group and SystemGroup settings - they cannot be the same,
848 * otherwise the CGI programs will be able to authenticate as root without
854 for (i
= 0; i
< NumSystemGroups
; i
++)
855 if (Group
== SystemGroupIDs
[i
])
858 if (i
< NumSystemGroups
)
861 * Log the error and reset the group to a safe value...
864 cupsdLogMessage(CUPSD_LOG_NOTICE
,
865 "Group and SystemGroup cannot use the same groups!");
866 cupsdLogMessage(CUPSD_LOG_INFO
, "Resetting Group to \"nobody\"...");
868 group
= getgrnam("nobody");
872 Group
= group
->gr_gid
;
876 * Use the (historical) NFS nobody group ID (-2 as a 16-bit twos-
877 * complement number...)
886 * Check that we have at least one listen/port line; if not, report this
887 * as an error and exit!
890 if (cupsArrayCount(Listeners
) == 0)
896 cupsdLogMessage(CUPSD_LOG_EMERG
,
897 "No valid Listen or Port lines were found in the "
898 "configuration file!");
904 cupsdEndProcess(getpid(), 0);
908 * Set the default locale using the language and charset...
911 cupsdSetStringf(&DefaultLocale
, "%s.UTF-8", DefaultLanguage
);
914 * Update all relative filenames to include the full path from ServerRoot...
917 if (DocumentRoot
[0] != '/')
918 cupsdSetStringf(&DocumentRoot
, "%s/%s", ServerRoot
, DocumentRoot
);
920 if (RequestRoot
[0] != '/')
921 cupsdSetStringf(&RequestRoot
, "%s/%s", ServerRoot
, RequestRoot
);
923 if (ServerBin
[0] != '/')
924 cupsdSetStringf(&ServerBin
, "%s/%s", ServerRoot
, ServerBin
);
926 if (StateDir
[0] != '/')
927 cupsdSetStringf(&StateDir
, "%s/%s", ServerRoot
, StateDir
);
929 if (CacheDir
[0] != '/')
930 cupsdSetStringf(&CacheDir
, "%s/%s", ServerRoot
, CacheDir
);
933 if (ServerCertificate
[0] != '/')
934 cupsdSetStringf(&ServerCertificate
, "%s/%s", ServerRoot
, ServerCertificate
);
936 if (!strncmp(ServerRoot
, ServerCertificate
, strlen(ServerRoot
)) &&
937 cupsdCheckPermissions(ServerCertificate
, NULL
, 0600, RunUser
, Group
,
939 (FatalErrors
& CUPSD_FATAL_PERMISSIONS
))
942 # if defined(HAVE_LIBSSL) || defined(HAVE_GNUTLS)
943 if (ServerKey
[0] != '/')
944 cupsdSetStringf(&ServerKey
, "%s/%s", ServerRoot
, ServerKey
);
946 if (!strncmp(ServerRoot
, ServerKey
, strlen(ServerRoot
)) &&
947 cupsdCheckPermissions(ServerKey
, NULL
, 0600, RunUser
, Group
, 0, 0) < 0 &&
948 (FatalErrors
& CUPSD_FATAL_PERMISSIONS
))
950 # endif /* HAVE_LIBSSL || HAVE_GNUTLS */
951 #endif /* HAVE_SSL */
954 * Make sure that directories and config files are owned and
955 * writable by the user and group in the cupsd.conf file...
958 snprintf(temp
, sizeof(temp
), "%s/rss", CacheDir
);
960 if ((cupsdCheckPermissions(RequestRoot
, NULL
, 0710, RunUser
,
962 cupsdCheckPermissions(CacheDir
, NULL
, 0775, RunUser
,
964 cupsdCheckPermissions(temp
, NULL
, 0775, RunUser
,
966 cupsdCheckPermissions(StateDir
, NULL
, 0755, RunUser
,
968 cupsdCheckPermissions(StateDir
, "certs", RunUser
? 0711 : 0511, User
,
969 SystemGroupIDs
[0], 1, 1) < 0 ||
970 cupsdCheckPermissions(ServerRoot
, NULL
, 0755, RunUser
,
972 cupsdCheckPermissions(ServerRoot
, "ppd", 0755, RunUser
,
974 cupsdCheckPermissions(ServerRoot
, "ssl", 0700, RunUser
,
976 cupsdCheckPermissions(ServerRoot
, "cupsd.conf", ConfigFilePerm
, RunUser
,
978 cupsdCheckPermissions(ServerRoot
, "classes.conf", 0600, RunUser
,
980 cupsdCheckPermissions(ServerRoot
, "printers.conf", 0600, RunUser
,
982 cupsdCheckPermissions(ServerRoot
, "passwd.md5", 0600, User
,
984 (FatalErrors
& CUPSD_FATAL_PERMISSIONS
))
988 * Update TempDir to the default if it hasn't been set already...
993 if ((tmpdir
= getenv("TMPDIR")) != NULL
)
996 * TMPDIR is defined, see if it is OK for us to use...
999 if (stat(tmpdir
, &tmpinfo
))
1000 cupsdLogMessage(CUPSD_LOG_ERROR
, "Unable to access TMPDIR (%s): %s",
1001 tmpdir
, strerror(errno
));
1002 else if (!S_ISDIR(tmpinfo
.st_mode
))
1003 cupsdLogMessage(CUPSD_LOG_ERROR
, "TMPDIR (%s) is not a directory!",
1005 else if ((tmpinfo
.st_uid
!= User
|| !(tmpinfo
.st_mode
& S_IWUSR
)) &&
1006 (tmpinfo
.st_gid
!= Group
|| !(tmpinfo
.st_mode
& S_IWGRP
)) &&
1007 !(tmpinfo
.st_mode
& S_IWOTH
))
1008 cupsdLogMessage(CUPSD_LOG_ERROR
,
1009 "TMPDIR (%s) has the wrong permissions!", tmpdir
);
1011 cupsdSetString(&TempDir
, tmpdir
);
1016 cupsdLogMessage(CUPSD_LOG_INFO
, "Using default TempDir of %s/tmp...",
1018 cupsdSetStringf(&TempDir
, "%s/tmp", RequestRoot
);
1023 * Make sure the temporary directory has the right permissions...
1026 if (!strncmp(TempDir
, RequestRoot
, strlen(RequestRoot
)) ||
1030 * Update ownership and permissions if the CUPS temp directory
1031 * is under the spool directory or does not exist...
1034 if (cupsdCheckPermissions(TempDir
, NULL
, 01770, RunUser
, Group
, 1, 1) < 0 &&
1035 (FatalErrors
& CUPSD_FATAL_PERMISSIONS
))
1040 * Setup environment variables...
1046 * Update default paper size setting as needed...
1049 if (!DefaultPaperSize
)
1051 #ifdef HAVE_LIBPAPER
1052 char *paper_result
; /* Paper size name from libpaper */
1054 if ((paper_result
= systempapername()) != NULL
)
1055 cupsdSetString(&DefaultPaperSize
, paper_result
);
1057 #endif /* HAVE_LIBPAPER */
1058 if (!DefaultLanguage
||
1059 !strcasecmp(DefaultLanguage
, "C") ||
1060 !strcasecmp(DefaultLanguage
, "POSIX") ||
1061 !strcasecmp(DefaultLanguage
, "en") ||
1062 !strncasecmp(DefaultLanguage
, "en.", 3) ||
1063 !strncasecmp(DefaultLanguage
, "en_US", 5) ||
1064 !strncasecmp(DefaultLanguage
, "en_CA", 5) ||
1065 !strncasecmp(DefaultLanguage
, "fr_CA", 5))
1068 * These are the only locales that will default to "letter" size...
1071 cupsdSetString(&DefaultPaperSize
, "Letter");
1074 cupsdSetString(&DefaultPaperSize
, "A4");
1078 * Update classification setting as needed...
1081 if (Classification
&& !strcasecmp(Classification
, "none"))
1082 cupsdClearString(&Classification
);
1085 cupsdLogMessage(CUPSD_LOG_INFO
, "Security set to \"%s\"", Classification
);
1088 * Check the MaxClients setting, and then allocate memory for it...
1091 if (MaxClients
> (MaxFDs
/ 3) || MaxClients
<= 0)
1094 cupsdLogMessage(CUPSD_LOG_INFO
,
1095 "MaxClients limited to 1/3 (%d) of the file descriptor "
1097 MaxFDs
/ 3, MaxFDs
);
1099 MaxClients
= MaxFDs
/ 3;
1102 cupsdLogMessage(CUPSD_LOG_INFO
, "Configured for up to %d clients.",
1106 * Check the MaxActiveJobs setting; limit to 1/3 the available
1107 * file descriptors, since we need a pipe for each job...
1110 if (MaxActiveJobs
> (MaxFDs
/ 3))
1111 MaxActiveJobs
= MaxFDs
/ 3;
1114 * Update the MaxClientsPerHost value, as needed...
1117 if (MaxClientsPerHost
<= 0)
1118 MaxClientsPerHost
= MaxClients
;
1120 if (MaxClientsPerHost
> MaxClients
)
1121 MaxClientsPerHost
= MaxClients
;
1123 cupsdLogMessage(CUPSD_LOG_INFO
,
1124 "Allowing up to %d client connections per host.",
1128 * Make sure that BrowseTimeout is at least twice the interval...
1131 if (BrowseTimeout
< (2 * BrowseInterval
) || BrowseTimeout
<= 0)
1133 cupsdLogMessage(CUPSD_LOG_ALERT
, "Invalid BrowseTimeout value %d!",
1137 BrowseTimeout
= BrowseInterval
* 2;
1139 BrowseTimeout
= DEFAULT_TIMEOUT
;
1141 cupsdLogMessage(CUPSD_LOG_ALERT
, "Reset BrowseTimeout to %d!",
1146 * Update the default policy, as needed...
1150 DefaultPolicyPtr
= cupsdFindPolicy(DefaultPolicy
);
1152 DefaultPolicyPtr
= NULL
;
1154 if (!DefaultPolicyPtr
)
1156 cupsd_location_t
*po
; /* New policy operation */
1160 cupsdLogMessage(CUPSD_LOG_ERROR
, "Default policy \"%s\" not found!",
1163 cupsdSetString(&DefaultPolicy
, "default");
1165 if ((DefaultPolicyPtr
= cupsdFindPolicy("default")) != NULL
)
1166 cupsdLogMessage(CUPSD_LOG_INFO
,
1167 "Using policy \"default\" as the default!");
1170 cupsdLogMessage(CUPSD_LOG_INFO
,
1171 "Creating CUPS default administrative policy:");
1173 DefaultPolicyPtr
= p
= cupsdAddPolicy("default");
1175 cupsdLogMessage(CUPSD_LOG_INFO
, "<Policy default>");
1176 cupsdLogMessage(CUPSD_LOG_INFO
,
1177 "<Limit Send-Document Send-URI Cancel-Job Hold-Job "
1178 "Release-Job Restart-Job Purge-Jobs "
1179 "Set-Job-Attributes Create-Job-Subscription "
1180 "Renew-Subscription Cancel-Subscription "
1181 "Get-Notifications Reprocess-Job Cancel-Current-Job "
1182 "Suspend-Current-Job Resume-Job CUPS-Move-Job "
1183 "CUPS-Authenticate-Job CUPS-Get-Document>");
1184 cupsdLogMessage(CUPSD_LOG_INFO
, "Order Deny,Allow");
1186 po
= cupsdAddPolicyOp(p
, NULL
, IPP_SEND_DOCUMENT
);
1187 po
->order_type
= CUPSD_AUTH_ALLOW
;
1188 po
->level
= CUPSD_AUTH_USER
;
1190 cupsdAddName(po
, "@OWNER");
1191 cupsdAddName(po
, "@SYSTEM");
1192 cupsdLogMessage(CUPSD_LOG_INFO
, "Require user @OWNER @SYSTEM");
1194 cupsdAddPolicyOp(p
, po
, IPP_SEND_URI
);
1195 cupsdAddPolicyOp(p
, po
, IPP_CANCEL_JOB
);
1196 cupsdAddPolicyOp(p
, po
, IPP_HOLD_JOB
);
1197 cupsdAddPolicyOp(p
, po
, IPP_RELEASE_JOB
);
1198 cupsdAddPolicyOp(p
, po
, IPP_RESTART_JOB
);
1199 cupsdAddPolicyOp(p
, po
, IPP_PURGE_JOBS
);
1200 cupsdAddPolicyOp(p
, po
, IPP_SET_JOB_ATTRIBUTES
);
1201 cupsdAddPolicyOp(p
, po
, IPP_CREATE_JOB_SUBSCRIPTION
);
1202 cupsdAddPolicyOp(p
, po
, IPP_RENEW_SUBSCRIPTION
);
1203 cupsdAddPolicyOp(p
, po
, IPP_CANCEL_SUBSCRIPTION
);
1204 cupsdAddPolicyOp(p
, po
, IPP_GET_NOTIFICATIONS
);
1205 cupsdAddPolicyOp(p
, po
, IPP_REPROCESS_JOB
);
1206 cupsdAddPolicyOp(p
, po
, IPP_CANCEL_CURRENT_JOB
);
1207 cupsdAddPolicyOp(p
, po
, IPP_SUSPEND_CURRENT_JOB
);
1208 cupsdAddPolicyOp(p
, po
, IPP_RESUME_JOB
);
1209 cupsdAddPolicyOp(p
, po
, CUPS_MOVE_JOB
);
1210 cupsdAddPolicyOp(p
, po
, CUPS_AUTHENTICATE_JOB
);
1211 cupsdAddPolicyOp(p
, po
, CUPS_GET_DOCUMENT
);
1213 cupsdLogMessage(CUPSD_LOG_INFO
, "</Limit>");
1215 cupsdLogMessage(CUPSD_LOG_INFO
,
1216 "<Limit Pause-Printer Resume-Printer "
1217 "Set-Printer-Attributes Enable-Printer "
1218 "Disable-Printer Pause-Printer-After-Current-Job "
1219 "Hold-New-Jobs Release-Held-New-Jobs "
1220 "Deactivate-Printer Activate-Printer Restart-Printer "
1221 "Shutdown-Printer Startup-Printer Promote-Job "
1222 "Schedule-Job-After CUPS-Add-Printer "
1223 "CUPS-Delete-Printer CUPS-Add-Class CUPS-Delete-Class "
1224 "CUPS-Accept-Jobs CUPS-Reject-Jobs CUPS-Set-Default>");
1225 cupsdLogMessage(CUPSD_LOG_INFO
, "Order Deny,Allow");
1226 cupsdLogMessage(CUPSD_LOG_INFO
, "AuthType Default");
1228 po
= cupsdAddPolicyOp(p
, NULL
, IPP_PAUSE_PRINTER
);
1229 po
->order_type
= CUPSD_AUTH_ALLOW
;
1230 po
->type
= CUPSD_AUTH_DEFAULT
;
1231 po
->level
= CUPSD_AUTH_USER
;
1233 cupsdAddName(po
, "@SYSTEM");
1234 cupsdLogMessage(CUPSD_LOG_INFO
, "Require user @SYSTEM");
1236 cupsdAddPolicyOp(p
, po
, IPP_RESUME_PRINTER
);
1237 cupsdAddPolicyOp(p
, po
, IPP_SET_PRINTER_ATTRIBUTES
);
1238 cupsdAddPolicyOp(p
, po
, IPP_ENABLE_PRINTER
);
1239 cupsdAddPolicyOp(p
, po
, IPP_DISABLE_PRINTER
);
1240 cupsdAddPolicyOp(p
, po
, IPP_PAUSE_PRINTER_AFTER_CURRENT_JOB
);
1241 cupsdAddPolicyOp(p
, po
, IPP_HOLD_NEW_JOBS
);
1242 cupsdAddPolicyOp(p
, po
, IPP_RELEASE_HELD_NEW_JOBS
);
1243 cupsdAddPolicyOp(p
, po
, IPP_DEACTIVATE_PRINTER
);
1244 cupsdAddPolicyOp(p
, po
, IPP_ACTIVATE_PRINTER
);
1245 cupsdAddPolicyOp(p
, po
, IPP_RESTART_PRINTER
);
1246 cupsdAddPolicyOp(p
, po
, IPP_SHUTDOWN_PRINTER
);
1247 cupsdAddPolicyOp(p
, po
, IPP_STARTUP_PRINTER
);
1248 cupsdAddPolicyOp(p
, po
, IPP_PROMOTE_JOB
);
1249 cupsdAddPolicyOp(p
, po
, IPP_SCHEDULE_JOB_AFTER
);
1250 cupsdAddPolicyOp(p
, po
, CUPS_ADD_PRINTER
);
1251 cupsdAddPolicyOp(p
, po
, CUPS_DELETE_PRINTER
);
1252 cupsdAddPolicyOp(p
, po
, CUPS_ADD_CLASS
);
1253 cupsdAddPolicyOp(p
, po
, CUPS_DELETE_CLASS
);
1254 cupsdAddPolicyOp(p
, po
, CUPS_ACCEPT_JOBS
);
1255 cupsdAddPolicyOp(p
, po
, CUPS_REJECT_JOBS
);
1256 cupsdAddPolicyOp(p
, po
, CUPS_SET_DEFAULT
);
1258 cupsdLogMessage(CUPSD_LOG_INFO
, "</Limit>");
1260 cupsdLogMessage(CUPSD_LOG_INFO
, "<Limit All>");
1261 cupsdLogMessage(CUPSD_LOG_INFO
, "Order Deny,Allow");
1263 po
= cupsdAddPolicyOp(p
, NULL
, IPP_ANY_OPERATION
);
1264 po
->order_type
= CUPSD_AUTH_ALLOW
;
1266 cupsdLogMessage(CUPSD_LOG_INFO
, "</Limit>");
1267 cupsdLogMessage(CUPSD_LOG_INFO
, "</Policy>");
1271 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "cupsdReadConfiguration: NumPolicies=%d",
1272 cupsArrayCount(Policies
));
1273 for (i
= 0, p
= (cupsd_policy_t
*)cupsArrayFirst(Policies
);
1275 i
++, p
= (cupsd_policy_t
*)cupsArrayNext(Policies
))
1276 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
1277 "cupsdReadConfiguration: Policies[%d]=\"%s\"", i
, p
->name
);
1280 * If we are doing a full reload or the server root has changed, flush
1281 * the jobs, printers, etc. and start from scratch...
1284 if (NeedReload
== RELOAD_ALL
||
1285 old_remote_port
!= RemotePort
||
1286 !old_serverroot
|| !ServerRoot
|| strcmp(old_serverroot
, ServerRoot
) ||
1287 !old_requestroot
|| !RequestRoot
|| strcmp(old_requestroot
, RequestRoot
))
1289 mime_type_t
*type
; /* Current type */
1290 char mimetype
[MIME_MAX_SUPER
+ MIME_MAX_TYPE
];
1291 /* MIME type name */
1294 cupsdLogMessage(CUPSD_LOG_INFO
, "Full reload is required.");
1297 * Free all memory...
1300 cupsdDeleteAllSubscriptions();
1302 cupsdDeleteAllPrinters();
1304 DefaultPrinter
= NULL
;
1306 if (MimeDatabase
!= NULL
)
1307 mimeDelete(MimeDatabase
);
1311 for (i
= 0; i
< NumMimeTypes
; i
++)
1312 _cupsStrFree(MimeTypes
[i
]);
1318 * Read the MIME type and conversion database...
1321 snprintf(temp
, sizeof(temp
), "%s/filter", ServerBin
);
1322 snprintf(mimedir
, sizeof(mimedir
), "%s/mime", DataDir
);
1324 MimeDatabase
= mimeLoadTypes(NULL
, mimedir
);
1325 MimeDatabase
= mimeLoadTypes(MimeDatabase
, ServerRoot
);
1326 MimeDatabase
= mimeLoadFilters(MimeDatabase
, mimedir
, temp
);
1327 MimeDatabase
= mimeLoadFilters(MimeDatabase
, ServerRoot
, temp
);
1331 cupsdLogMessage(CUPSD_LOG_EMERG
,
1332 "Unable to load MIME database from \"%s\" or \"%s\"!",
1333 mimedir
, ServerRoot
);
1334 if (FatalErrors
& CUPSD_FATAL_CONFIG
)
1338 cupsdLogMessage(CUPSD_LOG_INFO
,
1339 "Loaded MIME database from \"%s\" and \"%s\": %d types, "
1340 "%d filters...", mimedir
, ServerRoot
,
1341 mimeNumTypes(MimeDatabase
), mimeNumFilters(MimeDatabase
));
1344 * Create a list of MIME types for the document-format-supported
1348 NumMimeTypes
= mimeNumTypes(MimeDatabase
);
1349 if (!mimeType(MimeDatabase
, "application", "octet-stream"))
1352 if ((MimeTypes
= calloc(NumMimeTypes
, sizeof(const char *))) == NULL
)
1354 cupsdLogMessage(CUPSD_LOG_ERROR
,
1355 "Unable to allocate memory for %d MIME types!",
1361 for (i
= 0, type
= mimeFirstType(MimeDatabase
);
1363 i
++, type
= mimeNextType(MimeDatabase
))
1365 snprintf(mimetype
, sizeof(mimetype
), "%s/%s", type
->super
, type
->type
);
1367 MimeTypes
[i
] = _cupsStrAlloc(mimetype
);
1370 if (i
< NumMimeTypes
)
1371 MimeTypes
[i
] = _cupsStrAlloc("application/octet-stream");
1374 if (LogLevel
== CUPSD_LOG_DEBUG2
)
1376 mime_filter_t
*filter
; /* Current filter */
1379 for (type
= mimeFirstType(MimeDatabase
);
1381 type
= mimeNextType(MimeDatabase
))
1382 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "cupsdReadConfiguration: type %s/%s",
1383 type
->super
, type
->type
);
1385 for (filter
= mimeFirstFilter(MimeDatabase
);
1387 filter
= mimeNextFilter(MimeDatabase
))
1388 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
1389 "cupsdReadConfiguration: filter %s/%s to %s/%s %d %s",
1390 filter
->src
->super
, filter
->src
->type
,
1391 filter
->dst
->super
, filter
->dst
->type
,
1392 filter
->cost
, filter
->filter
);
1399 snprintf(temp
, sizeof(temp
), "%s/banners", DataDir
);
1400 cupsdLoadBanners(temp
);
1403 * Load printers and classes...
1406 cupsdLoadAllPrinters();
1407 cupsdLoadAllClasses();
1408 cupsdLoadRemoteCache();
1410 cupsdCreateCommonData();
1413 * Update the printcap file as needed...
1416 if (Printcap
&& *Printcap
&& access(Printcap
, 0))
1417 cupsdWritePrintcap();
1420 * Load queued jobs...
1426 * Load subscriptions...
1429 cupsdLoadAllSubscriptions();
1431 cupsdLogMessage(CUPSD_LOG_INFO
, "Full reload complete.");
1436 * Not a full reload, so recreate the common printer attributes...
1439 cupsdCreateCommonData();
1442 * Update all printers as needed...
1445 cupsdUpdatePrinters();
1446 cupsdMarkDirty(CUPSD_DIRTY_PRINTCAP
);
1448 cupsdLogMessage(CUPSD_LOG_INFO
, "Partial reload complete.");
1452 * Reset the reload state...
1455 NeedReload
= RELOAD_NONE
;
1457 cupsdClearString(&old_serverroot
);
1458 cupsdClearString(&old_requestroot
);
1465 * 'get_address()' - Get an address + port number from a line.
1468 static http_addrlist_t
* /* O - Pointer to list if address good, NULL if bad */
1469 get_address(const char *value
, /* I - Value string */
1470 int defport
) /* I - Default port */
1472 char buffer
[1024], /* Hostname + port number buffer */
1473 defpname
[255], /* Default port name */
1474 *hostname
, /* Hostname or IP */
1475 *portname
; /* Port number or name */
1476 http_addrlist_t
*addrlist
; /* Address list */
1480 * Check for an empty value...
1485 cupsdLogMessage(CUPSD_LOG_ERROR
, "Bad (empty) address!");
1490 * Grab a hostname and port number; if there is no colon and the port name
1491 * is only digits, then we have a port number by itself...
1494 strlcpy(buffer
, value
, sizeof(buffer
));
1496 if ((portname
= strrchr(buffer
, ':')) != NULL
&& !strchr(portname
, ']'))
1503 for (portname
= buffer
; isdigit(*portname
& 255); portname
++);
1508 * Use the default port...
1511 sprintf(defpname
, "%d", defport
);
1512 portname
= defpname
;
1518 * The buffer contains just a port number...
1526 if (hostname
&& !strcmp(hostname
, "*"))
1530 * Now lookup the address using httpAddrGetList()...
1533 if ((addrlist
= httpAddrGetList(hostname
, AF_UNSPEC
, portname
)) == NULL
)
1534 cupsdLogMessage(CUPSD_LOG_ERROR
, "Hostname lookup for \"%s\" failed!",
1535 hostname
? hostname
: "(nil)");
1542 * 'get_addr_and_mask()' - Get an IP address and netmask.
1545 static int /* O - 1 on success, 0 on failure */
1546 get_addr_and_mask(const char *value
, /* I - String from config file */
1547 unsigned *ip
, /* O - Address value */
1548 unsigned *mask
) /* O - Mask value */
1550 int i
, j
, /* Looping vars */
1551 family
, /* Address family */
1552 ipcount
; /* Count of fields in address */
1553 unsigned ipval
; /* Value */
1554 const char *maskval
, /* Pointer to start of mask value */
1555 *ptr
, /* Pointer into value */
1560 * Get the address...
1563 ip
[0] = ip
[1] = ip
[2] = ip
[3] = 0x00000000;
1564 mask
[0] = mask
[1] = mask
[2] = mask
[3] = 0xffffffff;
1566 if ((maskval
= strchr(value
, '/')) != NULL
)
1569 maskval
= value
+ strlen(value
);
1573 * Check for an IPv6 address...
1579 * Parse hexadecimal IPv6 address...
1584 for (i
= 0, ptr
= value
+ 1; *ptr
&& i
< 8; i
++)
1588 else if (!strncmp(ptr
, "::", 2))
1590 for (ptr2
= strchr(ptr
+ 2, ':'), j
= 0;
1592 ptr2
= strchr(ptr2
+ 1, ':'), j
++);
1597 else if (isxdigit(*ptr
& 255))
1599 ipval
= strtoul(ptr
, (char **)&ptr
, 16);
1607 ip
[i
/ 2] |= ipval
<< 16;
1621 if (*ptr
&& *ptr
!= '/')
1625 #endif /* AF_INET6 */
1628 * Parse dotted-decimal IPv4 address...
1631 unsigned val
[4]; /* IPv4 address values */
1635 ipcount
= sscanf(value
, "%u.%u.%u.%u", val
+ 0, val
+ 1, val
+ 2, val
+ 3);
1638 * Range check the IP numbers...
1641 for (i
= 0; i
< ipcount
; i
++)
1646 * Make sure the trailing values are zeroed, as some C libraries like
1647 * glibc apparently like to fill the unused arguments with garbage...
1650 for (i
= ipcount
; i
< 4; i
++)
1654 * Merge everything into a 32-bit IPv4 address in ip[3]...
1657 ip
[3] = (((((val
[0] << 8) | val
[1]) << 8) | val
[2]) << 8) | val
[3];
1660 mask
[3] = (0xffffffff << (32 - 8 * ipcount
)) & 0xffffffff;
1666 * Get the netmask value(s)...
1669 memset(mask
, 0, sizeof(unsigned) * 4);
1671 if (strchr(maskval
, '.'))
1674 * Get dotted-decimal mask...
1677 if (family
!= AF_INET
)
1680 if (sscanf(maskval
, "%u.%u.%u.%u", mask
+ 0, mask
+ 1, mask
+ 2, mask
+ 3) != 4)
1683 mask
[3] |= ((((mask
[0] << 8) | mask
[1]) << 8) | mask
[2]) << 8;
1684 mask
[0] = mask
[1] = mask
[2] = 0;
1689 * Get address/bits format...
1695 if (family
== AF_INET6
)
1703 mask
[0] = 0xffffffff;
1705 mask
[0] = (0xffffffff << (i
- 96)) & 0xffffffff;
1708 mask
[1] = 0xffffffff;
1712 mask
[1] = (0xffffffff << (i
- 64)) & 0xffffffff;
1715 mask
[2] = 0xffffffff;
1719 mask
[2] = (0xffffffff << (i
- 32)) & 0xffffffff;
1722 mask
[3] = 0xffffffff;
1726 mask
[3] = (0xffffffff << i
) & 0xffffffff;
1729 #endif /* AF_INET6 */
1734 mask
[0] = 0xffffffff;
1735 mask
[1] = 0xffffffff;
1736 mask
[2] = 0xffffffff;
1739 mask
[3] = (0xffffffff << (32 - i
)) & 0xffffffff;
1741 mask
[3] = 0xffffffff;
1746 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
1747 "get_addr_and_mask(value=\"%s\", "
1748 "ip=[%08x:%08x:%08x:%08x], mask=[%08x:%08x:%08x:%08x])",
1749 value
, ip
[0], ip
[1], ip
[2], ip
[3], mask
[0], mask
[1], mask
[2],
1753 * Check for a valid netmask; no fallback like in CUPS 1.1.x!
1756 if ((ip
[0] & ~mask
[0]) != 0 ||
1757 (ip
[1] & ~mask
[1]) != 0 ||
1758 (ip
[2] & ~mask
[2]) != 0 ||
1759 (ip
[3] & ~mask
[3]) != 0)
1767 * 'parse_aaa()' - Parse authentication, authorization, and access control lines.
1770 static int /* O - 1 on success, 0 on failure */
1771 parse_aaa(cupsd_location_t
*loc
, /* I - Location */
1772 char *line
, /* I - Line from file */
1773 char *value
, /* I - Start of value data */
1774 int linenum
) /* I - Current line number */
1776 char *valptr
; /* Pointer into value */
1777 unsigned ip
[4], /* IP address components */
1778 mask
[4]; /* IP netmask components */
1781 if (!strcasecmp(line
, "Encryption"))
1784 * "Encryption xxx" - set required encryption level...
1787 if (!strcasecmp(value
, "never"))
1788 loc
->encryption
= HTTP_ENCRYPT_NEVER
;
1789 else if (!strcasecmp(value
, "always"))
1791 cupsdLogMessage(CUPSD_LOG_ERROR
,
1792 "Encryption value \"%s\" on line %d is invalid in this "
1793 "context. Using \"required\" instead.", value
, linenum
);
1795 loc
->encryption
= HTTP_ENCRYPT_REQUIRED
;
1797 else if (!strcasecmp(value
, "required"))
1798 loc
->encryption
= HTTP_ENCRYPT_REQUIRED
;
1799 else if (!strcasecmp(value
, "ifrequested"))
1800 loc
->encryption
= HTTP_ENCRYPT_IF_REQUESTED
;
1803 cupsdLogMessage(CUPSD_LOG_ERROR
,
1804 "Unknown Encryption value %s on line %d.", value
, linenum
);
1808 else if (!strcasecmp(line
, "Order"))
1811 * "Order Deny,Allow" or "Order Allow,Deny"...
1814 if (!strncasecmp(value
, "deny", 4))
1815 loc
->order_type
= CUPSD_AUTH_ALLOW
;
1816 else if (!strncasecmp(value
, "allow", 5))
1817 loc
->order_type
= CUPSD_AUTH_DENY
;
1820 cupsdLogMessage(CUPSD_LOG_ERROR
, "Unknown Order value %s on line %d.",
1825 else if (!strcasecmp(line
, "Allow") || !strcasecmp(line
, "Deny"))
1828 * Allow [From] host/ip...
1829 * Deny [From] host/ip...
1834 if (!strncasecmp(value
, "from", 4))
1837 * Strip leading "from"...
1842 while (isspace(*value
& 255))
1850 * Find the end of the value...
1853 for (valptr
= value
; *valptr
&& !isspace(*valptr
& 255); valptr
++);
1855 while (isspace(*valptr
& 255))
1859 * Figure out what form the allow/deny address takes:
1870 * nnn.nnn.nnn.nnn/mm
1871 * nnn.nnn.nnn.nnn/mmm.mmm.mmm.mmm
1874 if (!strcasecmp(value
, "all"))
1880 if (!strcasecmp(line
, "Allow"))
1881 cupsdAllowIP(loc
, zeros
, zeros
);
1883 cupsdDenyIP(loc
, zeros
, zeros
);
1885 else if (!strcasecmp(value
, "none"))
1891 if (!strcasecmp(line
, "Allow"))
1892 cupsdAllowIP(loc
, ones
, zeros
);
1894 cupsdDenyIP(loc
, ones
, zeros
);
1897 else if (value
[0] == '*' || value
[0] == '.' ||
1898 (!isdigit(value
[0] & 255) && value
[0] != '['))
1900 else if (value
[0] == '*' || value
[0] == '.' || !isdigit(value
[0] & 255))
1901 #endif /* AF_INET6 */
1904 * Host or domain name...
1907 if (value
[0] == '*')
1910 if (!strcasecmp(line
, "Allow"))
1911 cupsdAllowHost(loc
, value
);
1913 cupsdDenyHost(loc
, value
);
1918 * One of many IP address forms...
1921 if (!get_addr_and_mask(value
, ip
, mask
))
1923 cupsdLogMessage(CUPSD_LOG_ERROR
, "Bad netmask value %s on line %d.",
1928 if (!strcasecmp(line
, "Allow"))
1929 cupsdAllowIP(loc
, ip
, mask
);
1931 cupsdDenyIP(loc
, ip
, mask
);
1935 * Advance to next value...
1941 else if (!strcasecmp(line
, "AuthType"))
1944 * AuthType {none,basic,digest,basicdigest,negotiate,default}
1947 if (!strcasecmp(value
, "none"))
1949 loc
->type
= CUPSD_AUTH_NONE
;
1950 loc
->level
= CUPSD_AUTH_ANON
;
1952 else if (!strcasecmp(value
, "basic"))
1954 loc
->type
= CUPSD_AUTH_BASIC
;
1956 if (loc
->level
== CUPSD_AUTH_ANON
)
1957 loc
->level
= CUPSD_AUTH_USER
;
1959 else if (!strcasecmp(value
, "digest"))
1961 loc
->type
= CUPSD_AUTH_DIGEST
;
1963 if (loc
->level
== CUPSD_AUTH_ANON
)
1964 loc
->level
= CUPSD_AUTH_USER
;
1966 else if (!strcasecmp(value
, "basicdigest"))
1968 loc
->type
= CUPSD_AUTH_BASICDIGEST
;
1970 if (loc
->level
== CUPSD_AUTH_ANON
)
1971 loc
->level
= CUPSD_AUTH_USER
;
1973 else if (!strcasecmp(value
, "default"))
1975 loc
->type
= CUPSD_AUTH_DEFAULT
;
1977 if (loc
->level
== CUPSD_AUTH_ANON
)
1978 loc
->level
= CUPSD_AUTH_USER
;
1981 else if (!strcasecmp(value
, "negotiate"))
1983 loc
->type
= CUPSD_AUTH_NEGOTIATE
;
1985 if (loc
->level
== CUPSD_AUTH_ANON
)
1986 loc
->level
= CUPSD_AUTH_USER
;
1988 #endif /* HAVE_GSSAPI */
1991 cupsdLogMessage(CUPSD_LOG_WARN
,
1992 "Unknown authorization type %s on line %d.",
1997 else if (!strcasecmp(line
, "AuthClass"))
2000 * AuthClass anonymous, user, system, group
2003 if (!strcasecmp(value
, "anonymous"))
2005 loc
->type
= CUPSD_AUTH_NONE
;
2006 loc
->level
= CUPSD_AUTH_ANON
;
2008 cupsdLogMessage(CUPSD_LOG_WARN
,
2009 "\"AuthClass %s\" is deprecated; consider removing "
2013 else if (!strcasecmp(value
, "user"))
2015 loc
->level
= CUPSD_AUTH_USER
;
2017 cupsdLogMessage(CUPSD_LOG_WARN
,
2018 "\"AuthClass %s\" is deprecated; consider using "
2019 "\"Require valid-user\" on line %d.",
2022 else if (!strcasecmp(value
, "group"))
2024 loc
->level
= CUPSD_AUTH_GROUP
;
2026 cupsdLogMessage(CUPSD_LOG_WARN
,
2027 "\"AuthClass %s\" is deprecated; consider using "
2028 "\"Require user @groupname\" on line %d.",
2031 else if (!strcasecmp(value
, "system"))
2033 loc
->level
= CUPSD_AUTH_GROUP
;
2035 cupsdAddName(loc
, "@SYSTEM");
2037 cupsdLogMessage(CUPSD_LOG_WARN
,
2038 "\"AuthClass %s\" is deprecated; consider using "
2039 "\"Require user @SYSTEM\" on line %d.",
2044 cupsdLogMessage(CUPSD_LOG_WARN
,
2045 "Unknown authorization class %s on line %d.",
2050 else if (!strcasecmp(line
, "AuthGroupName"))
2052 cupsdAddName(loc
, value
);
2054 cupsdLogMessage(CUPSD_LOG_WARN
,
2055 "\"AuthGroupName %s\" directive is deprecated; consider "
2056 "using \"Require user @%s\" on line %d.",
2057 value
, value
, linenum
);
2059 else if (!strcasecmp(line
, "Require"))
2062 * Apache synonym for AuthClass and AuthGroupName...
2066 * Require valid-user
2067 * Require group names
2068 * Require user names
2071 for (valptr
= value
; !isspace(*valptr
& 255) && *valptr
; valptr
++);
2076 if (!strcasecmp(value
, "valid-user") ||
2077 !strcasecmp(value
, "user"))
2078 loc
->level
= CUPSD_AUTH_USER
;
2079 else if (!strcasecmp(value
, "group"))
2080 loc
->level
= CUPSD_AUTH_GROUP
;
2083 cupsdLogMessage(CUPSD_LOG_WARN
, "Unknown Require type %s on line %d.",
2089 * Get the list of names from the line...
2092 for (value
= valptr
; *value
;)
2094 while (isspace(*value
& 255))
2097 #ifdef HAVE_AUTHORIZATION_H
2098 if (!strncmp(value
, "@AUTHKEY(", 9))
2101 * Grab "@AUTHKEY(name)" value...
2104 for (valptr
= value
+ 9; *valptr
!= ')' && *valptr
; valptr
++);
2110 #endif /* HAVE_AUTHORIZATION_H */
2111 if (*value
== '\"' || *value
== '\'')
2114 * Grab quoted name...
2117 for (valptr
= value
+ 1; *valptr
!= *value
&& *valptr
; valptr
++);
2124 * Grab literal name.
2127 for (valptr
= value
; !isspace(*valptr
& 255) && *valptr
; valptr
++);
2133 cupsdAddName(loc
, value
);
2135 for (value
= valptr
; isspace(*value
& 255); value
++);
2138 else if (!strcasecmp(line
, "Satisfy"))
2140 if (!strcasecmp(value
, "all"))
2141 loc
->satisfy
= CUPSD_AUTH_SATISFY_ALL
;
2142 else if (!strcasecmp(value
, "any"))
2143 loc
->satisfy
= CUPSD_AUTH_SATISFY_ANY
;
2146 cupsdLogMessage(CUPSD_LOG_WARN
, "Unknown Satisfy value %s on line %d.",
2159 * 'parse_fatal_errors()' - Parse FatalErrors values in a string.
2162 static int /* O - FatalErrors bits */
2163 parse_fatal_errors(const char *s
) /* I - FatalErrors string */
2165 int fatal
; /* FatalErrors bits */
2166 char value
[1024], /* Value string */
2167 *valstart
, /* Pointer into value */
2168 *valend
; /* End of value */
2172 * Empty FatalErrors line yields NULL pointer...
2176 return (CUPSD_FATAL_NONE
);
2179 * Loop through the value string,...
2182 strlcpy(value
, s
, sizeof(value
));
2184 fatal
= CUPSD_FATAL_NONE
;
2186 for (valstart
= value
; *valstart
;)
2189 * Get the current space/comma-delimited kind name...
2192 for (valend
= valstart
; *valend
; valend
++)
2193 if (isspace(*valend
& 255) || *valend
== ',')
2200 * Add the error to the bitmask...
2203 if (!strcasecmp(valstart
, "all"))
2204 fatal
= CUPSD_FATAL_ALL
;
2205 else if (!strcasecmp(valstart
, "browse"))
2206 fatal
|= CUPSD_FATAL_BROWSE
;
2207 else if (!strcasecmp(valstart
, "-browse"))
2208 fatal
&= ~CUPSD_FATAL_BROWSE
;
2209 else if (!strcasecmp(valstart
, "config"))
2210 fatal
|= CUPSD_FATAL_CONFIG
;
2211 else if (!strcasecmp(valstart
, "-config"))
2212 fatal
&= ~CUPSD_FATAL_CONFIG
;
2213 else if (!strcasecmp(valstart
, "listen"))
2214 fatal
|= CUPSD_FATAL_LISTEN
;
2215 else if (!strcasecmp(valstart
, "-listen"))
2216 fatal
&= ~CUPSD_FATAL_LISTEN
;
2217 else if (!strcasecmp(valstart
, "log"))
2218 fatal
|= CUPSD_FATAL_LOG
;
2219 else if (!strcasecmp(valstart
, "-log"))
2220 fatal
&= ~CUPSD_FATAL_LOG
;
2221 else if (!strcasecmp(valstart
, "permissions"))
2222 fatal
|= CUPSD_FATAL_PERMISSIONS
;
2223 else if (!strcasecmp(valstart
, "-permissions"))
2224 fatal
&= ~CUPSD_FATAL_PERMISSIONS
;
2225 else if (strcasecmp(valstart
, "none"))
2226 cupsdLogMessage(CUPSD_LOG_ERROR
,
2227 "Unknown FatalErrors kind \"%s\" ignored!", valstart
);
2229 for (valstart
= valend
; *valstart
; valstart
++)
2230 if (!isspace(*valstart
& 255) || *valstart
!= ',')
2239 * 'parse_groups()' - Parse system group names in a string.
2242 static int /* O - 1 on success, 0 on failure */
2243 parse_groups(const char *s
) /* I - Space-delimited groups */
2245 int status
; /* Return status */
2246 char value
[1024], /* Value string */
2247 *valstart
, /* Pointer into value */
2248 *valend
, /* End of value */
2249 quote
; /* Quote character */
2250 struct group
*group
; /* Group */
2254 * Make a copy of the string and parse out the groups...
2257 strlcpy(value
, s
, sizeof(value
));
2262 while (*valstart
&& NumSystemGroups
< MAX_SYSTEM_GROUPS
)
2264 if (*valstart
== '\'' || *valstart
== '\"')
2267 * Scan quoted name...
2270 quote
= *valstart
++;
2272 for (valend
= valstart
; *valend
; valend
++)
2273 if (*valend
== quote
)
2279 * Scan space or comma-delimited name...
2282 for (valend
= valstart
; *valend
; valend
++)
2283 if (isspace(*valend
) || *valend
== ',')
2290 group
= getgrnam(valstart
);
2293 cupsdSetString(SystemGroups
+ NumSystemGroups
, valstart
);
2294 SystemGroupIDs
[NumSystemGroups
] = group
->gr_gid
;
2305 while (*valstart
== ',' || isspace(*valstart
))
2314 * 'parse_protocols()' - Parse browse protocols in a string.
2317 static int /* O - Browse protocol bits */
2318 parse_protocols(const char *s
) /* I - Space-delimited protocols */
2320 int protocols
; /* Browse protocol bits */
2321 char value
[1024], /* Value string */
2322 *valstart
, /* Pointer into value */
2323 *valend
; /* End of value */
2327 * Empty protocol line yields NULL pointer...
2334 * Loop through the value string,...
2337 strlcpy(value
, s
, sizeof(value
));
2341 for (valstart
= value
; *valstart
;)
2344 * Get the current space/comma-delimited protocol name...
2347 for (valend
= valstart
; *valend
; valend
++)
2348 if (isspace(*valend
& 255) || *valend
== ',')
2355 * Add the protocol to the bitmask...
2358 if (!strcasecmp(valstart
, "cups"))
2359 protocols
|= BROWSE_CUPS
;
2360 else if (!strcasecmp(valstart
, "slp"))
2361 protocols
|= BROWSE_SLP
;
2362 else if (!strcasecmp(valstart
, "ldap"))
2363 protocols
|= BROWSE_LDAP
;
2364 else if (!strcasecmp(valstart
, "dnssd") ||
2365 !strcasecmp(valstart
, "dns-sd") ||
2366 !strcasecmp(valstart
, "bonjour"))
2367 protocols
|= BROWSE_DNSSD
;
2368 else if (!strcasecmp(valstart
, "lpd"))
2369 protocols
|= BROWSE_LPD
;
2370 else if (!strcasecmp(valstart
, "smb"))
2371 protocols
|= BROWSE_SMB
;
2372 else if (!strcasecmp(valstart
, "all"))
2373 protocols
|= BROWSE_ALL
;
2374 else if (strcasecmp(valstart
, "none"))
2375 cupsdLogMessage(CUPSD_LOG_ERROR
,
2376 "Unknown browse protocol \"%s\" ignored!", valstart
);
2378 for (valstart
= valend
; *valstart
; valstart
++)
2379 if (!isspace(*valstart
& 255) || *valstart
!= ',')
2388 * 'read_configuration()' - Read a configuration file.
2391 static int /* O - 1 on success, 0 on failure */
2392 read_configuration(cups_file_t
*fp
) /* I - File to read from */
2394 int i
; /* Looping var */
2395 int linenum
; /* Current line number */
2396 char line
[HTTP_MAX_BUFFER
],
2397 /* Line from file */
2398 temp
[HTTP_MAX_BUFFER
],
2399 /* Temporary buffer for value */
2400 temp2
[HTTP_MAX_BUFFER
],
2401 /* Temporary buffer 2 for value */
2402 *ptr
, /* Pointer into line/temp */
2403 *value
, /* Pointer to value */
2404 *valueptr
; /* Pointer into value */
2405 int valuelen
; /* Length of value */
2406 cupsd_var_t
const *var
; /* Current variable */
2407 http_addrlist_t
*addrlist
, /* Address list */
2408 *addr
; /* Current address */
2409 unsigned ip
[4], /* Address value */
2410 mask
[4]; /* Netmask value */
2411 cupsd_dirsvc_relay_t
*relay
; /* Relay data */
2412 cupsd_dirsvc_poll_t
*pollp
; /* Polling data */
2413 cupsd_location_t
*location
; /* Browse location */
2414 cups_file_t
*incfile
; /* Include file */
2415 char incname
[1024]; /* Include filename */
2416 struct group
*group
; /* Group */
2420 * Loop through each line in the file...
2425 while (cupsFileGetConf(fp
, line
, sizeof(line
), &value
, &linenum
))
2428 * Decode the directive...
2431 if (!strcasecmp(line
, "Include") && value
)
2437 if (value
[0] == '/')
2438 strlcpy(incname
, value
, sizeof(incname
));
2440 snprintf(incname
, sizeof(incname
), "%s/%s", ServerRoot
, value
);
2442 if ((incfile
= cupsFileOpen(incname
, "rb")) == NULL
)
2443 cupsdLogMessage(CUPSD_LOG_ERROR
,
2444 "Unable to include config file \"%s\" - %s",
2445 incname
, strerror(errno
));
2448 read_configuration(incfile
);
2449 cupsFileClose(incfile
);
2452 else if (!strcasecmp(line
, "<Location") && value
)
2458 linenum
= read_location(fp
, value
, linenum
);
2462 else if (!strcasecmp(line
, "<Policy") && value
)
2468 linenum
= read_policy(fp
, value
, linenum
);
2472 else if (!strcasecmp(line
, "FatalErrors"))
2473 FatalErrors
= parse_fatal_errors(value
);
2474 else if (!strcasecmp(line
, "FaxRetryInterval") && value
)
2476 JobRetryInterval
= atoi(value
);
2477 cupsdLogMessage(CUPSD_LOG_WARN
,
2478 "FaxRetryInterval is deprecated; use "
2479 "JobRetryInterval on line %d.", linenum
);
2481 else if (!strcasecmp(line
, "FaxRetryLimit") && value
)
2483 JobRetryLimit
= atoi(value
);
2484 cupsdLogMessage(CUPSD_LOG_WARN
,
2485 "FaxRetryLimit is deprecated; use "
2486 "JobRetryLimit on line %d.", linenum
);
2488 else if (!strcasecmp(line
, "Port") || !strcasecmp(line
, "Listen")
2490 || !strcasecmp(line
, "SSLPort") || !strcasecmp(line
, "SSLListen")
2491 #endif /* HAVE_SSL */
2495 * Add listening address(es) to the list...
2498 cupsd_listener_t
*lis
; /* New listeners array */
2502 * Get the address list...
2505 addrlist
= get_address(value
, IPP_PORT
);
2509 cupsdLogMessage(CUPSD_LOG_ERROR
, "Bad %s address %s at line %d.", line
,
2515 * Add each address...
2518 for (addr
= addrlist
; addr
; addr
= addr
->next
)
2521 * See if this address is already present...
2524 for (lis
= (cupsd_listener_t
*)cupsArrayFirst(Listeners
);
2526 lis
= (cupsd_listener_t
*)cupsArrayNext(Listeners
))
2527 if (httpAddrEqual(&(addr
->addr
), &(lis
->address
)) &&
2528 _httpAddrPort(&(addr
->addr
)) == _httpAddrPort(&(lis
->address
)))
2533 httpAddrString(&lis
->address
, temp
, sizeof(temp
));
2534 cupsdLogMessage(CUPSD_LOG_WARN
,
2535 "Duplicate listen address \"%s\" ignored!", temp
);
2540 * Allocate another listener...
2544 Listeners
= cupsArrayNew(NULL
, NULL
);
2548 cupsdLogMessage(CUPSD_LOG_ERROR
,
2549 "Unable to allocate %s at line %d - %s.",
2550 line
, linenum
, strerror(errno
));
2554 if ((lis
= calloc(1, sizeof(cupsd_listener_t
))) == NULL
)
2556 cupsdLogMessage(CUPSD_LOG_ERROR
,
2557 "Unable to allocate %s at line %d - %s.",
2558 line
, linenum
, strerror(errno
));
2562 cupsArrayAdd(Listeners
, lis
);
2565 * Copy the current address and log it...
2568 memcpy(&(lis
->address
), &(addr
->addr
), sizeof(lis
->address
));
2572 if (!strcasecmp(line
, "SSLPort") || !strcasecmp(line
, "SSLListen"))
2573 lis
->encryption
= HTTP_ENCRYPT_ALWAYS
;
2574 #endif /* HAVE_SSL */
2576 httpAddrString(&lis
->address
, temp
, sizeof(temp
));
2579 if (lis
->address
.addr
.sa_family
== AF_INET6
)
2580 cupsdLogMessage(CUPSD_LOG_INFO
, "Listening to %s:%d (IPv6)", temp
,
2581 ntohs(lis
->address
.ipv6
.sin6_port
));
2583 #endif /* AF_INET6 */
2585 if (lis
->address
.addr
.sa_family
== AF_LOCAL
)
2586 cupsdLogMessage(CUPSD_LOG_INFO
, "Listening to %s (Domain)", temp
);
2588 #endif /* AF_LOCAL */
2589 cupsdLogMessage(CUPSD_LOG_INFO
, "Listening to %s:%d (IPv4)", temp
,
2590 ntohs(lis
->address
.ipv4
.sin_port
));
2592 if (!httpAddrLocalhost(&(lis
->address
)))
2595 if (lis
->address
.addr
.sa_family
== AF_INET6
)
2596 RemotePort
= ntohs(lis
->address
.ipv6
.sin6_port
);
2598 #endif /* AF_INET6 */
2599 RemotePort
= ntohs(lis
->address
.ipv4
.sin_port
);
2607 httpAddrFreeList(addrlist
);
2609 else if (!strcasecmp(line
, "BrowseAddress") && value
)
2612 * Add a browse address to the list...
2615 cupsd_dirsvc_addr_t
*dira
; /* New browse address array */
2618 if (NumBrowsers
== 0)
2619 dira
= malloc(sizeof(cupsd_dirsvc_addr_t
));
2621 dira
= realloc(Browsers
, (NumBrowsers
+ 1) * sizeof(cupsd_dirsvc_addr_t
));
2625 cupsdLogMessage(CUPSD_LOG_ERROR
,
2626 "Unable to allocate BrowseAddress at line %d - %s.",
2627 linenum
, strerror(errno
));
2632 dira
+= NumBrowsers
;
2634 memset(dira
, 0, sizeof(cupsd_dirsvc_addr_t
));
2636 if (!strcasecmp(value
, "@LOCAL"))
2639 * Send browse data to all local interfaces...
2642 strcpy(dira
->iface
, "*");
2645 else if (!strncasecmp(value
, "@IF(", 4))
2648 * Send browse data to the named interface...
2651 strlcpy(dira
->iface
, value
+ 4, sizeof(Browsers
[0].iface
));
2653 ptr
= dira
->iface
+ strlen(dira
->iface
) - 1;
2659 else if ((addrlist
= get_address(value
, BrowsePort
)) != NULL
)
2662 * Only IPv4 addresses are supported...
2665 for (addr
= addrlist
; addr
; addr
= addr
->next
)
2666 if (addr
->addr
.addr
.sa_family
== AF_INET
)
2671 memcpy(&(dira
->to
), &(addrlist
->addr
), sizeof(dira
->to
));
2672 httpAddrString(&(dira
->to
), temp
, sizeof(temp
));
2674 cupsdLogMessage(CUPSD_LOG_INFO
,
2675 "Sending browsing info to %s:%d (IPv4)",
2676 temp
, ntohs(dira
->to
.ipv4
.sin_port
));
2681 cupsdLogMessage(CUPSD_LOG_ERROR
, "Bad BrowseAddress %s at line %d.",
2684 httpAddrFreeList(addrlist
);
2687 cupsdLogMessage(CUPSD_LOG_ERROR
, "Bad BrowseAddress %s at line %d.",
2690 else if (!strcasecmp(line
, "BrowseOrder") && value
)
2693 * "BrowseOrder Deny,Allow" or "BrowseOrder Allow,Deny"...
2696 if ((location
= cupsdFindLocation("CUPS_INTERNAL_BROWSE_ACL")) == NULL
)
2697 location
= cupsdAddLocation("CUPS_INTERNAL_BROWSE_ACL");
2699 if (location
== NULL
)
2700 cupsdLogMessage(CUPSD_LOG_ERROR
,
2701 "Unable to initialize browse access control list!");
2702 else if (!strncasecmp(value
, "deny", 4))
2703 location
->order_type
= CUPSD_AUTH_ALLOW
;
2704 else if (!strncasecmp(value
, "allow", 5))
2705 location
->order_type
= CUPSD_AUTH_DENY
;
2707 cupsdLogMessage(CUPSD_LOG_ERROR
,
2708 "Unknown BrowseOrder value %s on line %d.",
2711 else if (!strcasecmp(line
, "BrowseProtocols") ||
2712 !strcasecmp(line
, "BrowseLocalProtocols") ||
2713 !strcasecmp(line
, "BrowseRemoteProtocols"))
2716 * "BrowseProtocols name [... name]"
2717 * "BrowseLocalProtocols name [... name]"
2718 * "BrowseRemoteProtocols name [... name]"
2721 int protocols
= parse_protocols(value
);
2725 cupsdLogMessage(CUPSD_LOG_ERROR
,
2726 "Unknown browse protocol \"%s\" on line %d.",
2731 if (strcasecmp(line
, "BrowseLocalProtocols"))
2732 BrowseRemoteProtocols
= protocols
;
2733 if (strcasecmp(line
, "BrowseRemoteProtocols"))
2734 BrowseLocalProtocols
= protocols
;
2736 else if ((!strcasecmp(line
, "BrowseAllow") ||
2737 !strcasecmp(line
, "BrowseDeny")) && value
)
2740 * BrowseAllow [From] host/ip...
2741 * BrowseDeny [From] host/ip...
2744 if ((location
= cupsdFindLocation("CUPS_INTERNAL_BROWSE_ACL")) == NULL
)
2745 location
= cupsdAddLocation("CUPS_INTERNAL_BROWSE_ACL");
2747 if (location
== NULL
)
2748 cupsdLogMessage(CUPSD_LOG_ERROR
,
2749 "Unable to initialize browse access control list!");
2754 if (!strncasecmp(value
, "from", 4))
2757 * Strip leading "from"...
2762 while (isspace(*value
& 255))
2770 * Find the end of the value...
2773 for (valueptr
= value
; *valueptr
&& !isspace(*valueptr
& 255); valueptr
++);
2775 while (isspace(*valueptr
& 255))
2779 * Figure out what form the allow/deny address takes:
2790 * nnn.nnn.nnn.nnn/mm
2791 * nnn.nnn.nnn.nnn/mmm.mmm.mmm.mmm
2794 if (!strcasecmp(value
, "all"))
2800 if (!strcasecmp(line
, "BrowseAllow"))
2801 cupsdAllowIP(location
, zeros
, zeros
);
2803 cupsdDenyIP(location
, zeros
, zeros
);
2805 else if (!strcasecmp(value
, "none"))
2811 if (!strcasecmp(line
, "BrowseAllow"))
2812 cupsdAllowIP(location
, ones
, zeros
);
2814 cupsdDenyIP(location
, ones
, zeros
);
2817 else if (value
[0] == '*' || value
[0] == '.' ||
2818 (!isdigit(value
[0] & 255) && value
[0] != '['))
2820 else if (value
[0] == '*' || value
[0] == '.' || !isdigit(value
[0] & 255))
2821 #endif /* AF_INET6 */
2824 * Host or domain name...
2827 if (value
[0] == '*')
2830 if (!strcasecmp(line
, "BrowseAllow"))
2831 cupsdAllowHost(location
, value
);
2833 cupsdDenyHost(location
, value
);
2838 * One of many IP address forms...
2841 if (!get_addr_and_mask(value
, ip
, mask
))
2843 cupsdLogMessage(CUPSD_LOG_ERROR
, "Bad netmask value %s on line %d.",
2848 if (!strcasecmp(line
, "BrowseAllow"))
2849 cupsdAllowIP(location
, ip
, mask
);
2851 cupsdDenyIP(location
, ip
, mask
);
2855 * Advance to next value...
2862 else if (!strcasecmp(line
, "BrowseRelay") && value
)
2865 * BrowseRelay [from] source [to] destination
2869 relay
= malloc(sizeof(cupsd_dirsvc_relay_t
));
2871 relay
= realloc(Relays
, (NumRelays
+ 1) * sizeof(cupsd_dirsvc_relay_t
));
2875 cupsdLogMessage(CUPSD_LOG_ERROR
,
2876 "Unable to allocate BrowseRelay at line %d - %s.",
2877 linenum
, strerror(errno
));
2884 memset(relay
, 0, sizeof(cupsd_dirsvc_relay_t
));
2886 if (!strncasecmp(value
, "from ", 5))
2889 * Strip leading "from"...
2894 while (isspace(*value
))
2899 * Figure out what form the from address takes:
2908 * nnn.nnn.nnn.nnn/mm
2909 * nnn.nnn.nnn.nnn/mmm.mmm.mmm.mmm
2913 if (value
[0] == '*' || value
[0] == '.' ||
2914 (!isdigit(value
[0] & 255) && value
[0] != '['))
2916 if (value
[0] == '*' || value
[0] == '.' || !isdigit(value
[0] & 255))
2917 #endif /* AF_INET6 */
2920 * Host or domain name...
2923 if (value
[0] == '*')
2926 strlcpy(temp
, value
, sizeof(temp
));
2927 if ((ptr
= strchr(temp
, ' ')) != NULL
)
2930 relay
->from
.type
= CUPSD_AUTH_NAME
;
2932 if ((relay
->from
.mask
.name
.name
= strdup(temp
)) == NULL
)
2934 cupsdLogMessage(CUPSD_LOG_ERROR
,
2935 "Unable to allocate BrowseRelay name at line %d - %s.",
2936 linenum
, strerror(errno
));
2940 relay
->from
.mask
.name
.length
= strlen(temp
);
2945 * One of many IP address forms...
2948 if (!get_addr_and_mask(value
, ip
, mask
))
2950 cupsdLogMessage(CUPSD_LOG_ERROR
, "Bad netmask value %s on line %d.",
2955 relay
->from
.type
= CUPSD_AUTH_IP
;
2956 memcpy(relay
->from
.mask
.ip
.address
, ip
,
2957 sizeof(relay
->from
.mask
.ip
.address
));
2958 memcpy(relay
->from
.mask
.ip
.netmask
, mask
,
2959 sizeof(relay
->from
.mask
.ip
.netmask
));
2963 * Skip value and trailing whitespace...
2966 for (; *value
; value
++)
2967 if (isspace(*value
))
2970 while (isspace(*value
))
2973 if (!strncasecmp(value
, "to ", 3))
2976 * Strip leading "to"...
2981 while (isspace(*value
))
2986 * Get "to" address and port...
2989 if ((addrlist
= get_address(value
, BrowsePort
)) != NULL
)
2992 * Only IPv4 addresses are supported...
2995 for (addr
= addrlist
; addr
; addr
= addr
->next
)
2996 if (addr
->addr
.addr
.sa_family
== AF_INET
)
3001 memcpy(&(relay
->to
), &(addrlist
->addr
), sizeof(relay
->to
));
3003 httpAddrString(&(relay
->to
), temp
, sizeof(temp
));
3005 if (relay
->from
.type
== CUPSD_AUTH_IP
)
3006 snprintf(temp2
, sizeof(temp2
), "%u.%u.%u.%u/%u.%u.%u.%u",
3007 relay
->from
.mask
.ip
.address
[0] >> 24,
3008 (relay
->from
.mask
.ip
.address
[0] >> 16) & 255,
3009 (relay
->from
.mask
.ip
.address
[0] >> 8) & 255,
3010 relay
->from
.mask
.ip
.address
[0] & 255,
3011 relay
->from
.mask
.ip
.netmask
[0] >> 24,
3012 (relay
->from
.mask
.ip
.netmask
[0] >> 16) & 255,
3013 (relay
->from
.mask
.ip
.netmask
[0] >> 8) & 255,
3014 relay
->from
.mask
.ip
.netmask
[0] & 255);
3016 strlcpy(temp2
, relay
->from
.mask
.name
.name
, sizeof(temp2
));
3018 cupsdLogMessage(CUPSD_LOG_INFO
, "Relaying from %s to %s:%d (IPv4)",
3019 temp2
, temp
, ntohs(relay
->to
.ipv4
.sin_port
));
3024 cupsdLogMessage(CUPSD_LOG_ERROR
, "Bad relay address %s at line %d.",
3027 httpAddrFreeList(addrlist
);
3031 if (relay
->from
.type
== CUPSD_AUTH_NAME
)
3032 free(relay
->from
.mask
.name
.name
);
3034 cupsdLogMessage(CUPSD_LOG_ERROR
, "Bad relay address %s at line %d.",
3038 else if (!strcasecmp(line
, "BrowsePoll") && value
)
3041 * BrowsePoll address[:port]
3044 char *portname
; /* Port name */
3045 int portnum
; /* Port number */
3046 struct servent
*service
; /* Service */
3050 * Extract the port name from the address...
3053 if ((portname
= strrchr(value
, ':')) != NULL
&& !strchr(portname
, ']'))
3057 if (isdigit(*portname
& 255))
3058 portnum
= atoi(portname
);
3059 else if ((service
= getservbyname(portname
, NULL
)) != NULL
)
3060 portnum
= ntohs(service
->s_port
);
3063 cupsdLogMessage(CUPSD_LOG_ERROR
, "Lookup of service \"%s\" failed!",
3069 portnum
= ippPort();
3072 * Add the poll entry...
3076 pollp
= malloc(sizeof(cupsd_dirsvc_poll_t
));
3078 pollp
= realloc(Polled
, (NumPolled
+ 1) * sizeof(cupsd_dirsvc_poll_t
));
3082 cupsdLogMessage(CUPSD_LOG_ERROR
,
3083 "Unable to allocate BrowsePoll at line %d - %s.",
3084 linenum
, strerror(errno
));
3092 memset(pollp
, 0, sizeof(cupsd_dirsvc_poll_t
));
3094 strlcpy(pollp
->hostname
, value
, sizeof(pollp
->hostname
));
3095 pollp
->port
= portnum
;
3097 cupsdLogMessage(CUPSD_LOG_INFO
, "Polling %s:%d", pollp
->hostname
,
3100 else if (!strcasecmp(line
, "DefaultAuthType") && value
)
3103 * DefaultAuthType {basic,digest,basicdigest,negotiate}
3106 if (!strcasecmp(value
, "none"))
3107 DefaultAuthType
= CUPSD_AUTH_NONE
;
3108 else if (!strcasecmp(value
, "basic"))
3109 DefaultAuthType
= CUPSD_AUTH_BASIC
;
3110 else if (!strcasecmp(value
, "digest"))
3111 DefaultAuthType
= CUPSD_AUTH_DIGEST
;
3112 else if (!strcasecmp(value
, "basicdigest"))
3113 DefaultAuthType
= CUPSD_AUTH_BASICDIGEST
;
3115 else if (!strcasecmp(value
, "negotiate"))
3116 DefaultAuthType
= CUPSD_AUTH_NEGOTIATE
;
3117 #endif /* HAVE_GSSAPI */
3120 cupsdLogMessage(CUPSD_LOG_WARN
,
3121 "Unknown default authorization type %s on line %d.",
3123 if (FatalErrors
& CUPSD_FATAL_CONFIG
)
3128 else if (!strcasecmp(line
, "DefaultEncryption"))
3131 * DefaultEncryption {Never,IfRequested,Required}
3134 if (!value
|| !strcasecmp(value
, "never"))
3135 DefaultEncryption
= HTTP_ENCRYPT_NEVER
;
3136 else if (!strcasecmp(value
, "required"))
3137 DefaultEncryption
= HTTP_ENCRYPT_REQUIRED
;
3138 else if (!strcasecmp(value
, "ifrequested"))
3139 DefaultEncryption
= HTTP_ENCRYPT_IF_REQUESTED
;
3142 cupsdLogMessage(CUPSD_LOG_WARN
,
3143 "Unknown default encryption %s on line %d.",
3145 if (FatalErrors
& CUPSD_FATAL_CONFIG
)
3149 #endif /* HAVE_SSL */
3150 else if (!strcasecmp(line
, "User") && value
)
3153 * User ID to run as...
3156 if (isdigit(value
[0] & 255))
3158 int uid
= atoi(value
);
3161 cupsdLogMessage(CUPSD_LOG_ERROR
,
3162 "Will not use User 0 as specified on line %d "
3163 "for security reasons. You must use a non-"
3164 "privileged account instead.",
3171 struct passwd
*p
; /* Password information */
3174 p
= getpwnam(value
);
3179 cupsdLogMessage(CUPSD_LOG_ERROR
,
3180 "Will not use User %s (UID=0) as specified on line "
3181 "%d for security reasons. You must use a non-"
3182 "privileged account instead.",
3188 cupsdLogMessage(CUPSD_LOG_ERROR
,
3189 "Unknown User \"%s\" on line %d, ignoring!",
3193 else if (!strcasecmp(line
, "Group") && value
)
3196 * Group ID to run as...
3199 if (isdigit(value
[0]))
3200 Group
= atoi(value
);
3204 group
= getgrnam(value
);
3207 Group
= group
->gr_gid
;
3209 cupsdLogMessage(CUPSD_LOG_ERROR
,
3210 "Unknown Group \"%s\" on line %d, ignoring!",
3214 else if (!strcasecmp(line
, "SystemGroup") && value
)
3217 * SystemGroup (admin) group(s)...
3220 if (!parse_groups(value
))
3221 cupsdLogMessage(CUPSD_LOG_ERROR
,
3222 "Unknown SystemGroup \"%s\" on line %d, ignoring!",
3225 else if (!strcasecmp(line
, "HostNameLookups") && value
)
3228 * Do hostname lookups?
3231 if (!strcasecmp(value
, "off") || !strcasecmp(value
, "no") ||
3232 !strcasecmp(value
, "false"))
3233 HostNameLookups
= 0;
3234 else if (!strcasecmp(value
, "on") || !strcasecmp(value
, "yes") ||
3235 !strcasecmp(value
, "true"))
3236 HostNameLookups
= 1;
3237 else if (!strcasecmp(value
, "double"))
3238 HostNameLookups
= 2;
3240 cupsdLogMessage(CUPSD_LOG_WARN
, "Unknown HostNameLookups %s on line %d.",
3243 else if (!strcasecmp(line
, "AccessLogLevel") && value
)
3246 * Amount of logging to do to access log...
3249 if (!strcasecmp(value
, "all"))
3250 AccessLogLevel
= CUPSD_ACCESSLOG_ALL
;
3251 else if (!strcasecmp(value
, "actions"))
3252 AccessLogLevel
= CUPSD_ACCESSLOG_ACTIONS
;
3253 else if (!strcasecmp(value
, "config"))
3254 AccessLogLevel
= CUPSD_ACCESSLOG_CONFIG
;
3256 cupsdLogMessage(CUPSD_LOG_WARN
, "Unknown AccessLogLevel %s on line %d.",
3259 else if (!strcasecmp(line
, "LogLevel") && value
)
3262 * Amount of logging to do to error log...
3265 if (!strcasecmp(value
, "debug2"))
3266 LogLevel
= CUPSD_LOG_DEBUG2
;
3267 else if (!strcasecmp(value
, "debug"))
3268 LogLevel
= CUPSD_LOG_DEBUG
;
3269 else if (!strcasecmp(value
, "info"))
3270 LogLevel
= CUPSD_LOG_INFO
;
3271 else if (!strcasecmp(value
, "notice"))
3272 LogLevel
= CUPSD_LOG_NOTICE
;
3273 else if (!strcasecmp(value
, "warn"))
3274 LogLevel
= CUPSD_LOG_WARN
;
3275 else if (!strcasecmp(value
, "error"))
3276 LogLevel
= CUPSD_LOG_ERROR
;
3277 else if (!strcasecmp(value
, "crit"))
3278 LogLevel
= CUPSD_LOG_CRIT
;
3279 else if (!strcasecmp(value
, "alert"))
3280 LogLevel
= CUPSD_LOG_ALERT
;
3281 else if (!strcasecmp(value
, "emerg"))
3282 LogLevel
= CUPSD_LOG_EMERG
;
3283 else if (!strcasecmp(value
, "none"))
3284 LogLevel
= CUPSD_LOG_NONE
;
3286 cupsdLogMessage(CUPSD_LOG_WARN
, "Unknown LogLevel %s on line %d.",
3289 else if (!strcasecmp(line
, "LogTimeFormat") && value
)
3292 * Amount of logging to do to error log...
3295 if (!strcasecmp(value
, "standard"))
3296 LogTimeFormat
= CUPSD_TIME_STANDARD
;
3297 else if (!strcasecmp(value
, "usecs"))
3298 LogTimeFormat
= CUPSD_TIME_USECS
;
3300 cupsdLogMessage(CUPSD_LOG_WARN
, "Unknown LogTimeFormat %s on line %d.",
3303 else if (!strcasecmp(line
, "PrintcapFormat") && value
)
3306 * Format of printcap file?
3309 if (!strcasecmp(value
, "bsd"))
3310 PrintcapFormat
= PRINTCAP_BSD
;
3311 else if (!strcasecmp(value
, "plist"))
3312 PrintcapFormat
= PRINTCAP_PLIST
;
3313 else if (!strcasecmp(value
, "solaris"))
3314 PrintcapFormat
= PRINTCAP_SOLARIS
;
3316 cupsdLogMessage(CUPSD_LOG_WARN
, "Unknown PrintcapFormat %s on line %d.",
3319 else if (!strcasecmp(line
, "ServerTokens") && value
)
3322 * Set the string used for the Server header...
3325 struct utsname plat
; /* Platform info */
3330 if (!strcasecmp(value
, "ProductOnly"))
3331 cupsdSetString(&ServerHeader
, "CUPS");
3332 else if (!strcasecmp(value
, "Major"))
3333 cupsdSetString(&ServerHeader
, "CUPS/1");
3334 else if (!strcasecmp(value
, "Minor"))
3335 cupsdSetString(&ServerHeader
, "CUPS/1.4");
3336 else if (!strcasecmp(value
, "Minimal"))
3337 cupsdSetString(&ServerHeader
, CUPS_MINIMAL
);
3338 else if (!strcasecmp(value
, "OS"))
3339 cupsdSetStringf(&ServerHeader
, CUPS_MINIMAL
" (%s)", plat
.sysname
);
3340 else if (!strcasecmp(value
, "Full"))
3341 cupsdSetStringf(&ServerHeader
, CUPS_MINIMAL
" (%s) IPP/1.1",
3343 else if (!strcasecmp(value
, "None"))
3344 cupsdClearString(&ServerHeader
);
3346 cupsdLogMessage(CUPSD_LOG_WARN
, "Unknown ServerTokens %s on line %d.",
3349 else if (!strcasecmp(line
, "PassEnv") && value
)
3352 * PassEnv variable [... variable]
3357 for (valuelen
= 0; value
[valuelen
]; valuelen
++)
3358 if (isspace(value
[valuelen
]) || value
[valuelen
] == ',')
3361 if (value
[valuelen
])
3363 value
[valuelen
] = '\0';
3367 cupsdSetEnv(value
, NULL
);
3369 for (value
+= valuelen
; *value
; value
++)
3370 if (!isspace(*value
) || *value
!= ',')
3374 else if (!strcasecmp(line
, "ServerAlias") && value
)
3377 ServerAlias
= cupsArrayNew(NULL
, NULL
);
3379 cupsdAddAlias(ServerAlias
, value
);
3381 else if (!strcasecmp(line
, "SetEnv") && value
)
3384 * SetEnv variable value
3387 for (valueptr
= value
; *valueptr
&& !isspace(*valueptr
& 255); valueptr
++);
3395 while (isspace(*valueptr
& 255))
3398 cupsdSetEnv(value
, valueptr
);
3401 cupsdLogMessage(CUPSD_LOG_ERROR
,
3402 "Missing value for SetEnv directive on line %d.",
3406 else if (!strcasecmp(line
, "SSLOptions"))
3409 * SSLOptions options
3412 if (!value
|| !strcasecmp(value
, "none"))
3413 SSLOptions
= CUPSD_SSL_NONE
;
3414 else if (!strcasecmp(value
, "noemptyfragments"))
3415 SSLOptions
= CUPSD_SSL_NOEMPTY
;
3417 cupsdLogMessage(CUPSD_LOG_ERROR
,
3418 "Unknown value \"%s\" for SSLOptions directive on "
3419 "line %d.", value
, linenum
);
3421 #endif /* HAVE_SSL */
3425 * Find a simple variable in the list...
3428 for (i
= NUM_VARS
, var
= variables
; i
> 0; i
--, var
++)
3429 if (!strcasecmp(line
, var
->name
))
3435 * Unknown directive! Output an error message and continue...
3439 cupsdLogMessage(CUPSD_LOG_ERROR
, "Missing value for %s on line %d.",
3442 cupsdLogMessage(CUPSD_LOG_ERROR
, "Unknown directive %s on line %d.",
3449 case CUPSD_VARTYPE_INTEGER
:
3451 cupsdLogMessage(CUPSD_LOG_ERROR
,
3452 "Missing integer value for %s on line %d!",
3457 char *units
; /* Units */
3460 n
= strtol(value
, &units
, 0);
3462 if (units
&& *units
)
3464 if (tolower(units
[0] & 255) == 'g')
3465 n
*= 1024 * 1024 * 1024;
3466 else if (tolower(units
[0] & 255) == 'm')
3468 else if (tolower(units
[0] & 255) == 'k')
3470 else if (tolower(units
[0] & 255) == 't')
3475 cupsdLogMessage(CUPSD_LOG_ERROR
,
3476 "Bad negative integer value for %s on line %d!",
3479 *((int *)var
->ptr
) = n
;
3483 case CUPSD_VARTYPE_BOOLEAN
:
3485 cupsdLogMessage(CUPSD_LOG_ERROR
,
3486 "Missing boolean value for %s on line %d!",
3488 else if (!strcasecmp(value
, "true") ||
3489 !strcasecmp(value
, "on") ||
3490 !strcasecmp(value
, "enabled") ||
3491 !strcasecmp(value
, "yes") ||
3493 *((int *)var
->ptr
) = TRUE
;
3494 else if (!strcasecmp(value
, "false") ||
3495 !strcasecmp(value
, "off") ||
3496 !strcasecmp(value
, "disabled") ||
3497 !strcasecmp(value
, "no") ||
3498 !strcasecmp(value
, "0"))
3499 *((int *)var
->ptr
) = FALSE
;
3501 cupsdLogMessage(CUPSD_LOG_ERROR
,
3502 "Unknown boolean value %s on line %d.",
3506 case CUPSD_VARTYPE_PATHNAME
:
3509 cupsdLogMessage(CUPSD_LOG_ERROR
,
3510 "Missing pathname value for %s on line %d!",
3515 if (value
[0] == '/')
3516 strlcpy(temp
, value
, sizeof(temp
));
3518 snprintf(temp
, sizeof(temp
), "%s/%s", ServerRoot
, value
);
3520 if (access(temp
, 0))
3522 cupsdLogMessage(CUPSD_LOG_ERROR
,
3523 "File or directory for \"%s %s\" on line %d "
3524 "does not exist!", line
, value
, linenum
);
3528 case CUPSD_VARTYPE_STRING
:
3529 cupsdSetString((char **)var
->ptr
, value
);
3540 * 'read_location()' - Read a <Location path> definition.
3543 static int /* O - New line number or 0 on error */
3544 read_location(cups_file_t
*fp
, /* I - Configuration file */
3545 char *location
, /* I - Location name/path */
3546 int linenum
) /* I - Current line number */
3548 cupsd_location_t
*loc
, /* New location */
3549 *parent
; /* Parent location */
3550 char line
[HTTP_MAX_BUFFER
],
3552 *value
, /* Value for directive */
3553 *valptr
; /* Pointer into value */
3556 if ((parent
= cupsdAddLocation(location
)) == NULL
)
3559 parent
->limit
= CUPSD_AUTH_LIMIT_ALL
;
3562 while (cupsFileGetConf(fp
, line
, sizeof(line
), &value
, &linenum
))
3565 * Decode the directive...
3568 if (!strcasecmp(line
, "</Location>"))
3570 else if (!strcasecmp(line
, "<Limit") ||
3571 !strcasecmp(line
, "<LimitExcept"))
3575 cupsdLogMessage(CUPSD_LOG_ERROR
, "Syntax error on line %d.", linenum
);
3576 if (FatalErrors
& CUPSD_FATAL_CONFIG
)
3582 if ((loc
= cupsdCopyLocation(&parent
)) == NULL
)
3588 for (valptr
= value
; !isspace(*valptr
& 255) && *valptr
; valptr
++);
3593 if (!strcmp(value
, "ALL"))
3594 loc
->limit
= CUPSD_AUTH_LIMIT_ALL
;
3595 else if (!strcmp(value
, "GET"))
3596 loc
->limit
|= CUPSD_AUTH_LIMIT_GET
;
3597 else if (!strcmp(value
, "HEAD"))
3598 loc
->limit
|= CUPSD_AUTH_LIMIT_HEAD
;
3599 else if (!strcmp(value
, "OPTIONS"))
3600 loc
->limit
|= CUPSD_AUTH_LIMIT_OPTIONS
;
3601 else if (!strcmp(value
, "POST"))
3602 loc
->limit
|= CUPSD_AUTH_LIMIT_POST
;
3603 else if (!strcmp(value
, "PUT"))
3604 loc
->limit
|= CUPSD_AUTH_LIMIT_PUT
;
3605 else if (!strcmp(value
, "TRACE"))
3606 loc
->limit
|= CUPSD_AUTH_LIMIT_TRACE
;
3608 cupsdLogMessage(CUPSD_LOG_WARN
, "Unknown request type %s on line %d!",
3611 for (value
= valptr
; isspace(*value
& 255); value
++);
3614 if (!strcasecmp(line
, "<LimitExcept"))
3615 loc
->limit
= CUPSD_AUTH_LIMIT_ALL
^ loc
->limit
;
3617 parent
->limit
&= ~loc
->limit
;
3619 else if (!strcasecmp(line
, "</Limit>") ||
3620 !strcasecmp(line
, "</LimitExcept>"))
3622 else if (!parse_aaa(loc
, line
, value
, linenum
))
3624 cupsdLogMessage(CUPSD_LOG_ERROR
,
3625 "Unknown Location directive %s on line %d.",
3627 if (FatalErrors
& CUPSD_FATAL_CONFIG
)
3632 cupsdLogMessage(CUPSD_LOG_ERROR
,
3633 "Unexpected end-of-file at line %d while reading location!",
3636 return ((FatalErrors
& CUPSD_FATAL_CONFIG
) ? 0 : linenum
);
3641 * 'read_policy()' - Read a <Policy name> definition.
3644 static int /* O - New line number or 0 on error */
3645 read_policy(cups_file_t
*fp
, /* I - Configuration file */
3646 char *policy
, /* I - Location name/path */
3647 int linenum
) /* I - Current line number */
3649 int i
; /* Looping var */
3650 cupsd_policy_t
*pol
; /* Policy */
3651 cupsd_location_t
*op
; /* Policy operation */
3652 int num_ops
; /* Number of IPP operations */
3653 ipp_op_t ops
[100]; /* Operations */
3654 char line
[HTTP_MAX_BUFFER
],
3656 *value
, /* Value for directive */
3657 *valptr
; /* Pointer into value */
3661 * Create the policy...
3664 if ((pol
= cupsdAddPolicy(policy
)) == NULL
)
3668 * Read from the file...
3674 while (cupsFileGetConf(fp
, line
, sizeof(line
), &value
, &linenum
))
3677 * Decode the directive...
3680 if (!strcasecmp(line
, "</Policy>"))
3683 cupsdLogMessage(CUPSD_LOG_WARN
,
3684 "Missing </Limit> before </Policy> on line %d!",
3688 * Verify that we have an explicit policy for CUPS-Get-Document
3689 * (ensures that upgrades do not introduce new security issues...)
3692 if ((op
= cupsdFindPolicyOp(pol
, CUPS_GET_DOCUMENT
)) == NULL
||
3693 op
->op
== IPP_ANY_OPERATION
)
3695 if ((op
= cupsdFindPolicyOp(pol
, IPP_SEND_DOCUMENT
)) != NULL
&&
3696 op
->op
!= IPP_ANY_OPERATION
)
3699 * Add a new limit for CUPS-Get-Document using the Send-Document
3700 * limit as a template...
3703 cupsdLogMessage(CUPSD_LOG_WARN
,
3704 "No limit for CUPS-Get-Document defined in policy %s "
3705 "- using Send-Document's policy", pol
->name
);
3707 cupsdAddPolicyOp(pol
, op
, CUPS_GET_DOCUMENT
);
3713 else if (!strcasecmp(line
, "<Limit") && !op
)
3717 cupsdLogMessage(CUPSD_LOG_ERROR
, "Syntax error on line %d.", linenum
);
3718 if (FatalErrors
& CUPSD_FATAL_CONFIG
)
3725 * Scan for IPP operation names...
3732 for (valptr
= value
; !isspace(*valptr
& 255) && *valptr
; valptr
++);
3737 if (num_ops
< (int)(sizeof(ops
) / sizeof(ops
[0])))
3739 if (!strcasecmp(value
, "All"))
3740 ops
[num_ops
] = IPP_ANY_OPERATION
;
3741 else if ((ops
[num_ops
] = ippOpValue(value
)) == IPP_BAD_OPERATION
)
3742 cupsdLogMessage(CUPSD_LOG_ERROR
,
3743 "Bad IPP operation name \"%s\" on line %d!",
3749 cupsdLogMessage(CUPSD_LOG_ERROR
,
3750 "Too many operations listed on line %d!",
3753 for (value
= valptr
; isspace(*value
& 255); value
++);
3757 * If none are specified, apply the policy to all operations...
3762 ops
[0] = IPP_ANY_OPERATION
;
3767 * Add a new policy for the first operation...
3770 op
= cupsdAddPolicyOp(pol
, NULL
, ops
[0]);
3772 else if (!strcasecmp(line
, "</Limit>") && op
)
3775 * Finish the current operation limit...
3781 * Copy the policy to the other operations...
3784 for (i
= 1; i
< num_ops
; i
++)
3785 cupsdAddPolicyOp(pol
, op
, ops
[i
]);
3792 cupsdLogMessage(CUPSD_LOG_ERROR
,
3793 "Missing <Limit ops> directive before %s on line %d.",
3795 if (FatalErrors
& CUPSD_FATAL_CONFIG
)
3798 else if (!parse_aaa(op
, line
, value
, linenum
))
3801 cupsdLogMessage(CUPSD_LOG_ERROR
,
3802 "Unknown Policy Limit directive %s on line %d.",
3805 cupsdLogMessage(CUPSD_LOG_ERROR
,
3806 "Unknown Policy directive %s on line %d.",
3809 if (FatalErrors
& CUPSD_FATAL_CONFIG
)
3814 cupsdLogMessage(CUPSD_LOG_ERROR
,
3815 "Unexpected end-of-file at line %d while reading policy \"%s\"!",
3818 return ((FatalErrors
& CUPSD_FATAL_CONFIG
) ? 0 : linenum
);
3823 * End of "$Id: conf.c 7952 2008-09-17 00:56:20Z mike $".