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 * See if the ServerName is an IP address...
723 ServerAlias
= cupsArrayNew(NULL
, NULL
);
725 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Added auto ServerAlias %s", ServerName
);
729 if (gethostname(temp
, sizeof(temp
)))
731 cupsdLogMessage(CUPSD_LOG_ERROR
, "Unable to get hostname: %s",
733 strlcpy(temp
, "localhost", sizeof(temp
));
736 cupsdSetString(&ServerName
, temp
);
739 ServerAlias
= cupsArrayNew(NULL
, NULL
);
741 cupsdAddAlias(ServerAlias
, temp
);
742 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Added auto ServerAlias %s", temp
);
744 if (HostNameLookups
|| RemotePort
)
746 struct hostent
*host
; /* Host entry to get FQDN */
748 if ((host
= gethostbyname(temp
)) != NULL
)
750 if (strcasecmp(temp
, host
->h_name
))
752 cupsdSetString(&ServerName
, host
->h_name
);
753 cupsdAddAlias(ServerAlias
, host
->h_name
);
754 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Added auto ServerAlias %s",
760 for (i
= 0; host
->h_aliases
[i
]; i
++)
761 if (strcasecmp(temp
, host
->h_aliases
[i
]))
763 cupsdAddAlias(ServerAlias
, host
->h_aliases
[i
]);
764 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Added auto ServerAlias %s",
772 * Make sure we have the base hostname added as an alias, too!
775 if ((slash
= strchr(temp
, '.')) != NULL
)
778 cupsdAddAlias(ServerAlias
, temp
);
779 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Added auto ServerAlias %s", temp
);
783 for (slash
= ServerName
; isdigit(*slash
& 255) || *slash
== '.'; slash
++);
785 ServerNameIsIP
= !*slash
;
788 * Make sure ServerAdmin is initialized...
792 cupsdSetStringf(&ServerAdmin
, "root@%s", ServerName
);
795 * Use the default system group if none was supplied in cupsd.conf...
798 if (NumSystemGroups
== 0)
800 if (!parse_groups(CUPS_DEFAULT_SYSTEM_GROUPS
))
803 * Find the group associated with GID 0...
810 cupsdSetString(&SystemGroups
[0], group
->gr_name
);
812 cupsdSetString(&SystemGroups
[0], "unknown");
814 SystemGroupIDs
[0] = 0;
820 * Get the access control list for browsing...
823 BrowseACL
= cupsdFindLocation("CUPS_INTERNAL_BROWSE_ACL");
826 * Open the system log for cupsd if necessary...
830 if (!strcmp(AccessLog
, "syslog") ||
831 !strcmp(ErrorLog
, "syslog") ||
832 !strcmp(PageLog
, "syslog"))
833 openlog("cupsd", LOG_PID
| LOG_NOWAIT
| LOG_NDELAY
, LOG_LPR
);
834 #endif /* HAVE_VSYSLOG */
837 * Log the configuration file that was used...
840 cupsdLogMessage(CUPSD_LOG_INFO
, "Loaded configuration file \"%s\"",
844 * Validate the Group and SystemGroup settings - they cannot be the same,
845 * otherwise the CGI programs will be able to authenticate as root without
851 for (i
= 0; i
< NumSystemGroups
; i
++)
852 if (Group
== SystemGroupIDs
[i
])
855 if (i
< NumSystemGroups
)
858 * Log the error and reset the group to a safe value...
861 cupsdLogMessage(CUPSD_LOG_NOTICE
,
862 "Group and SystemGroup cannot use the same groups!");
863 cupsdLogMessage(CUPSD_LOG_INFO
, "Resetting Group to \"nobody\"...");
865 group
= getgrnam("nobody");
869 Group
= group
->gr_gid
;
873 * Use the (historical) NFS nobody group ID (-2 as a 16-bit twos-
874 * complement number...)
883 * Check that we have at least one listen/port line; if not, report this
884 * as an error and exit!
887 if (cupsArrayCount(Listeners
) == 0)
893 cupsdLogMessage(CUPSD_LOG_EMERG
,
894 "No valid Listen or Port lines were found in the "
895 "configuration file!");
901 cupsdEndProcess(getpid(), 0);
905 * Set the default locale using the language and charset...
908 cupsdSetStringf(&DefaultLocale
, "%s.UTF-8", DefaultLanguage
);
911 * Update all relative filenames to include the full path from ServerRoot...
914 if (DocumentRoot
[0] != '/')
915 cupsdSetStringf(&DocumentRoot
, "%s/%s", ServerRoot
, DocumentRoot
);
917 if (RequestRoot
[0] != '/')
918 cupsdSetStringf(&RequestRoot
, "%s/%s", ServerRoot
, RequestRoot
);
920 if (ServerBin
[0] != '/')
921 cupsdSetStringf(&ServerBin
, "%s/%s", ServerRoot
, ServerBin
);
923 if (StateDir
[0] != '/')
924 cupsdSetStringf(&StateDir
, "%s/%s", ServerRoot
, StateDir
);
926 if (CacheDir
[0] != '/')
927 cupsdSetStringf(&CacheDir
, "%s/%s", ServerRoot
, CacheDir
);
930 if (ServerCertificate
[0] != '/')
931 cupsdSetStringf(&ServerCertificate
, "%s/%s", ServerRoot
, ServerCertificate
);
933 if (!strncmp(ServerRoot
, ServerCertificate
, strlen(ServerRoot
)) &&
934 cupsdCheckPermissions(ServerCertificate
, NULL
, 0600, RunUser
, Group
,
936 (FatalErrors
& CUPSD_FATAL_PERMISSIONS
))
939 # if defined(HAVE_LIBSSL) || defined(HAVE_GNUTLS)
940 if (ServerKey
[0] != '/')
941 cupsdSetStringf(&ServerKey
, "%s/%s", ServerRoot
, ServerKey
);
943 if (!strncmp(ServerRoot
, ServerKey
, strlen(ServerRoot
)) &&
944 cupsdCheckPermissions(ServerKey
, NULL
, 0600, RunUser
, Group
, 0, 0) < 0 &&
945 (FatalErrors
& CUPSD_FATAL_PERMISSIONS
))
947 # endif /* HAVE_LIBSSL || HAVE_GNUTLS */
948 #endif /* HAVE_SSL */
951 * Make sure that directories and config files are owned and
952 * writable by the user and group in the cupsd.conf file...
955 snprintf(temp
, sizeof(temp
), "%s/rss", CacheDir
);
957 if ((cupsdCheckPermissions(RequestRoot
, NULL
, 0710, RunUser
,
959 cupsdCheckPermissions(CacheDir
, NULL
, 0775, RunUser
,
961 cupsdCheckPermissions(temp
, NULL
, 0775, RunUser
,
963 cupsdCheckPermissions(StateDir
, NULL
, 0755, RunUser
,
965 cupsdCheckPermissions(StateDir
, "certs", RunUser
? 0711 : 0511, User
,
966 SystemGroupIDs
[0], 1, 1) < 0 ||
967 cupsdCheckPermissions(ServerRoot
, NULL
, 0755, RunUser
,
969 cupsdCheckPermissions(ServerRoot
, "ppd", 0755, RunUser
,
971 cupsdCheckPermissions(ServerRoot
, "ssl", 0700, RunUser
,
973 cupsdCheckPermissions(ServerRoot
, "cupsd.conf", ConfigFilePerm
, RunUser
,
975 cupsdCheckPermissions(ServerRoot
, "classes.conf", 0600, RunUser
,
977 cupsdCheckPermissions(ServerRoot
, "printers.conf", 0600, RunUser
,
979 cupsdCheckPermissions(ServerRoot
, "passwd.md5", 0600, User
,
981 (FatalErrors
& CUPSD_FATAL_PERMISSIONS
))
985 * Update TempDir to the default if it hasn't been set already...
990 if ((tmpdir
= getenv("TMPDIR")) != NULL
)
993 * TMPDIR is defined, see if it is OK for us to use...
996 if (stat(tmpdir
, &tmpinfo
))
997 cupsdLogMessage(CUPSD_LOG_ERROR
, "Unable to access TMPDIR (%s): %s",
998 tmpdir
, strerror(errno
));
999 else if (!S_ISDIR(tmpinfo
.st_mode
))
1000 cupsdLogMessage(CUPSD_LOG_ERROR
, "TMPDIR (%s) is not a directory!",
1002 else if ((tmpinfo
.st_uid
!= User
|| !(tmpinfo
.st_mode
& S_IWUSR
)) &&
1003 (tmpinfo
.st_gid
!= Group
|| !(tmpinfo
.st_mode
& S_IWGRP
)) &&
1004 !(tmpinfo
.st_mode
& S_IWOTH
))
1005 cupsdLogMessage(CUPSD_LOG_ERROR
,
1006 "TMPDIR (%s) has the wrong permissions!", tmpdir
);
1008 cupsdSetString(&TempDir
, tmpdir
);
1013 cupsdLogMessage(CUPSD_LOG_INFO
, "Using default TempDir of %s/tmp...",
1015 cupsdSetStringf(&TempDir
, "%s/tmp", RequestRoot
);
1020 * Make sure the temporary directory has the right permissions...
1023 if (!strncmp(TempDir
, RequestRoot
, strlen(RequestRoot
)) ||
1027 * Update ownership and permissions if the CUPS temp directory
1028 * is under the spool directory or does not exist...
1031 if (cupsdCheckPermissions(TempDir
, NULL
, 01770, RunUser
, Group
, 1, 1) < 0 &&
1032 (FatalErrors
& CUPSD_FATAL_PERMISSIONS
))
1037 * Setup environment variables...
1043 * Update default paper size setting as needed...
1046 if (!DefaultPaperSize
)
1048 #ifdef HAVE_LIBPAPER
1049 char *paper_result
; /* Paper size name from libpaper */
1051 if ((paper_result
= systempapername()) != NULL
)
1052 cupsdSetString(&DefaultPaperSize
, paper_result
);
1054 #endif /* HAVE_LIBPAPER */
1055 if (!DefaultLanguage
||
1056 !strcasecmp(DefaultLanguage
, "C") ||
1057 !strcasecmp(DefaultLanguage
, "POSIX") ||
1058 !strcasecmp(DefaultLanguage
, "en") ||
1059 !strncasecmp(DefaultLanguage
, "en.", 3) ||
1060 !strncasecmp(DefaultLanguage
, "en_US", 5) ||
1061 !strncasecmp(DefaultLanguage
, "en_CA", 5) ||
1062 !strncasecmp(DefaultLanguage
, "fr_CA", 5))
1065 * These are the only locales that will default to "letter" size...
1068 cupsdSetString(&DefaultPaperSize
, "Letter");
1071 cupsdSetString(&DefaultPaperSize
, "A4");
1075 * Update classification setting as needed...
1078 if (Classification
&& !strcasecmp(Classification
, "none"))
1079 cupsdClearString(&Classification
);
1082 cupsdLogMessage(CUPSD_LOG_INFO
, "Security set to \"%s\"", Classification
);
1085 * Check the MaxClients setting, and then allocate memory for it...
1088 if (MaxClients
> (MaxFDs
/ 3) || MaxClients
<= 0)
1091 cupsdLogMessage(CUPSD_LOG_INFO
,
1092 "MaxClients limited to 1/3 (%d) of the file descriptor "
1094 MaxFDs
/ 3, MaxFDs
);
1096 MaxClients
= MaxFDs
/ 3;
1099 cupsdLogMessage(CUPSD_LOG_INFO
, "Configured for up to %d clients.",
1103 * Check the MaxActiveJobs setting; limit to 1/3 the available
1104 * file descriptors, since we need a pipe for each job...
1107 if (MaxActiveJobs
> (MaxFDs
/ 3))
1108 MaxActiveJobs
= MaxFDs
/ 3;
1111 * Update the MaxClientsPerHost value, as needed...
1114 if (MaxClientsPerHost
<= 0)
1115 MaxClientsPerHost
= MaxClients
;
1117 if (MaxClientsPerHost
> MaxClients
)
1118 MaxClientsPerHost
= MaxClients
;
1120 cupsdLogMessage(CUPSD_LOG_INFO
,
1121 "Allowing up to %d client connections per host.",
1125 * Make sure that BrowseTimeout is at least twice the interval...
1128 if (BrowseTimeout
< (2 * BrowseInterval
) || BrowseTimeout
<= 0)
1130 cupsdLogMessage(CUPSD_LOG_ALERT
, "Invalid BrowseTimeout value %d!",
1134 BrowseTimeout
= BrowseInterval
* 2;
1136 BrowseTimeout
= DEFAULT_TIMEOUT
;
1138 cupsdLogMessage(CUPSD_LOG_ALERT
, "Reset BrowseTimeout to %d!",
1143 * Update the default policy, as needed...
1147 DefaultPolicyPtr
= cupsdFindPolicy(DefaultPolicy
);
1149 DefaultPolicyPtr
= NULL
;
1151 if (!DefaultPolicyPtr
)
1153 cupsd_location_t
*po
; /* New policy operation */
1157 cupsdLogMessage(CUPSD_LOG_ERROR
, "Default policy \"%s\" not found!",
1160 cupsdSetString(&DefaultPolicy
, "default");
1162 if ((DefaultPolicyPtr
= cupsdFindPolicy("default")) != NULL
)
1163 cupsdLogMessage(CUPSD_LOG_INFO
,
1164 "Using policy \"default\" as the default!");
1167 cupsdLogMessage(CUPSD_LOG_INFO
,
1168 "Creating CUPS default administrative policy:");
1170 DefaultPolicyPtr
= p
= cupsdAddPolicy("default");
1172 cupsdLogMessage(CUPSD_LOG_INFO
, "<Policy default>");
1173 cupsdLogMessage(CUPSD_LOG_INFO
,
1174 "<Limit Send-Document Send-URI Cancel-Job Hold-Job "
1175 "Release-Job Restart-Job Purge-Jobs "
1176 "Set-Job-Attributes Create-Job-Subscription "
1177 "Renew-Subscription Cancel-Subscription "
1178 "Get-Notifications Reprocess-Job Cancel-Current-Job "
1179 "Suspend-Current-Job Resume-Job CUPS-Move-Job "
1180 "CUPS-Authenticate-Job CUPS-Get-Document>");
1181 cupsdLogMessage(CUPSD_LOG_INFO
, "Order Deny,Allow");
1183 po
= cupsdAddPolicyOp(p
, NULL
, IPP_SEND_DOCUMENT
);
1184 po
->order_type
= CUPSD_AUTH_ALLOW
;
1185 po
->level
= CUPSD_AUTH_USER
;
1187 cupsdAddName(po
, "@OWNER");
1188 cupsdAddName(po
, "@SYSTEM");
1189 cupsdLogMessage(CUPSD_LOG_INFO
, "Require user @OWNER @SYSTEM");
1191 cupsdAddPolicyOp(p
, po
, IPP_SEND_URI
);
1192 cupsdAddPolicyOp(p
, po
, IPP_CANCEL_JOB
);
1193 cupsdAddPolicyOp(p
, po
, IPP_HOLD_JOB
);
1194 cupsdAddPolicyOp(p
, po
, IPP_RELEASE_JOB
);
1195 cupsdAddPolicyOp(p
, po
, IPP_RESTART_JOB
);
1196 cupsdAddPolicyOp(p
, po
, IPP_PURGE_JOBS
);
1197 cupsdAddPolicyOp(p
, po
, IPP_SET_JOB_ATTRIBUTES
);
1198 cupsdAddPolicyOp(p
, po
, IPP_CREATE_JOB_SUBSCRIPTION
);
1199 cupsdAddPolicyOp(p
, po
, IPP_RENEW_SUBSCRIPTION
);
1200 cupsdAddPolicyOp(p
, po
, IPP_CANCEL_SUBSCRIPTION
);
1201 cupsdAddPolicyOp(p
, po
, IPP_GET_NOTIFICATIONS
);
1202 cupsdAddPolicyOp(p
, po
, IPP_REPROCESS_JOB
);
1203 cupsdAddPolicyOp(p
, po
, IPP_CANCEL_CURRENT_JOB
);
1204 cupsdAddPolicyOp(p
, po
, IPP_SUSPEND_CURRENT_JOB
);
1205 cupsdAddPolicyOp(p
, po
, IPP_RESUME_JOB
);
1206 cupsdAddPolicyOp(p
, po
, CUPS_MOVE_JOB
);
1207 cupsdAddPolicyOp(p
, po
, CUPS_AUTHENTICATE_JOB
);
1208 cupsdAddPolicyOp(p
, po
, CUPS_GET_DOCUMENT
);
1210 cupsdLogMessage(CUPSD_LOG_INFO
, "</Limit>");
1212 cupsdLogMessage(CUPSD_LOG_INFO
,
1213 "<Limit Pause-Printer Resume-Printer "
1214 "Set-Printer-Attributes Enable-Printer "
1215 "Disable-Printer Pause-Printer-After-Current-Job "
1216 "Hold-New-Jobs Release-Held-New-Jobs "
1217 "Deactivate-Printer Activate-Printer Restart-Printer "
1218 "Shutdown-Printer Startup-Printer Promote-Job "
1219 "Schedule-Job-After CUPS-Add-Printer "
1220 "CUPS-Delete-Printer CUPS-Add-Class CUPS-Delete-Class "
1221 "CUPS-Accept-Jobs CUPS-Reject-Jobs CUPS-Set-Default>");
1222 cupsdLogMessage(CUPSD_LOG_INFO
, "Order Deny,Allow");
1223 cupsdLogMessage(CUPSD_LOG_INFO
, "AuthType Default");
1225 po
= cupsdAddPolicyOp(p
, NULL
, IPP_PAUSE_PRINTER
);
1226 po
->order_type
= CUPSD_AUTH_ALLOW
;
1227 po
->type
= CUPSD_AUTH_DEFAULT
;
1228 po
->level
= CUPSD_AUTH_USER
;
1230 cupsdAddName(po
, "@SYSTEM");
1231 cupsdLogMessage(CUPSD_LOG_INFO
, "Require user @SYSTEM");
1233 cupsdAddPolicyOp(p
, po
, IPP_RESUME_PRINTER
);
1234 cupsdAddPolicyOp(p
, po
, IPP_SET_PRINTER_ATTRIBUTES
);
1235 cupsdAddPolicyOp(p
, po
, IPP_ENABLE_PRINTER
);
1236 cupsdAddPolicyOp(p
, po
, IPP_DISABLE_PRINTER
);
1237 cupsdAddPolicyOp(p
, po
, IPP_PAUSE_PRINTER_AFTER_CURRENT_JOB
);
1238 cupsdAddPolicyOp(p
, po
, IPP_HOLD_NEW_JOBS
);
1239 cupsdAddPolicyOp(p
, po
, IPP_RELEASE_HELD_NEW_JOBS
);
1240 cupsdAddPolicyOp(p
, po
, IPP_DEACTIVATE_PRINTER
);
1241 cupsdAddPolicyOp(p
, po
, IPP_ACTIVATE_PRINTER
);
1242 cupsdAddPolicyOp(p
, po
, IPP_RESTART_PRINTER
);
1243 cupsdAddPolicyOp(p
, po
, IPP_SHUTDOWN_PRINTER
);
1244 cupsdAddPolicyOp(p
, po
, IPP_STARTUP_PRINTER
);
1245 cupsdAddPolicyOp(p
, po
, IPP_PROMOTE_JOB
);
1246 cupsdAddPolicyOp(p
, po
, IPP_SCHEDULE_JOB_AFTER
);
1247 cupsdAddPolicyOp(p
, po
, CUPS_ADD_PRINTER
);
1248 cupsdAddPolicyOp(p
, po
, CUPS_DELETE_PRINTER
);
1249 cupsdAddPolicyOp(p
, po
, CUPS_ADD_CLASS
);
1250 cupsdAddPolicyOp(p
, po
, CUPS_DELETE_CLASS
);
1251 cupsdAddPolicyOp(p
, po
, CUPS_ACCEPT_JOBS
);
1252 cupsdAddPolicyOp(p
, po
, CUPS_REJECT_JOBS
);
1253 cupsdAddPolicyOp(p
, po
, CUPS_SET_DEFAULT
);
1255 cupsdLogMessage(CUPSD_LOG_INFO
, "</Limit>");
1257 cupsdLogMessage(CUPSD_LOG_INFO
, "<Limit All>");
1258 cupsdLogMessage(CUPSD_LOG_INFO
, "Order Deny,Allow");
1260 po
= cupsdAddPolicyOp(p
, NULL
, IPP_ANY_OPERATION
);
1261 po
->order_type
= CUPSD_AUTH_ALLOW
;
1263 cupsdLogMessage(CUPSD_LOG_INFO
, "</Limit>");
1264 cupsdLogMessage(CUPSD_LOG_INFO
, "</Policy>");
1268 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "cupsdReadConfiguration: NumPolicies=%d",
1269 cupsArrayCount(Policies
));
1270 for (i
= 0, p
= (cupsd_policy_t
*)cupsArrayFirst(Policies
);
1272 i
++, p
= (cupsd_policy_t
*)cupsArrayNext(Policies
))
1273 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
1274 "cupsdReadConfiguration: Policies[%d]=\"%s\"", i
, p
->name
);
1277 * If we are doing a full reload or the server root has changed, flush
1278 * the jobs, printers, etc. and start from scratch...
1281 if (NeedReload
== RELOAD_ALL
||
1282 old_remote_port
!= RemotePort
||
1283 !old_serverroot
|| !ServerRoot
|| strcmp(old_serverroot
, ServerRoot
) ||
1284 !old_requestroot
|| !RequestRoot
|| strcmp(old_requestroot
, RequestRoot
))
1286 mime_type_t
*type
; /* Current type */
1287 char mimetype
[MIME_MAX_SUPER
+ MIME_MAX_TYPE
];
1288 /* MIME type name */
1291 cupsdLogMessage(CUPSD_LOG_INFO
, "Full reload is required.");
1294 * Free all memory...
1297 cupsdDeleteAllSubscriptions();
1299 cupsdDeleteAllPrinters();
1301 DefaultPrinter
= NULL
;
1303 if (MimeDatabase
!= NULL
)
1304 mimeDelete(MimeDatabase
);
1308 for (i
= 0; i
< NumMimeTypes
; i
++)
1309 _cupsStrFree(MimeTypes
[i
]);
1315 * Read the MIME type and conversion database...
1318 snprintf(temp
, sizeof(temp
), "%s/filter", ServerBin
);
1319 snprintf(mimedir
, sizeof(mimedir
), "%s/mime", DataDir
);
1321 MimeDatabase
= mimeLoadTypes(NULL
, mimedir
);
1322 MimeDatabase
= mimeLoadTypes(MimeDatabase
, ServerRoot
);
1323 MimeDatabase
= mimeLoadFilters(MimeDatabase
, mimedir
, temp
);
1324 MimeDatabase
= mimeLoadFilters(MimeDatabase
, ServerRoot
, temp
);
1328 cupsdLogMessage(CUPSD_LOG_EMERG
,
1329 "Unable to load MIME database from \"%s\" or \"%s\"!",
1330 mimedir
, ServerRoot
);
1331 if (FatalErrors
& CUPSD_FATAL_CONFIG
)
1335 cupsdLogMessage(CUPSD_LOG_INFO
,
1336 "Loaded MIME database from \"%s\" and \"%s\": %d types, "
1337 "%d filters...", mimedir
, ServerRoot
,
1338 mimeNumTypes(MimeDatabase
), mimeNumFilters(MimeDatabase
));
1341 * Create a list of MIME types for the document-format-supported
1345 NumMimeTypes
= mimeNumTypes(MimeDatabase
);
1346 if (!mimeType(MimeDatabase
, "application", "octet-stream"))
1349 if ((MimeTypes
= calloc(NumMimeTypes
, sizeof(const char *))) == NULL
)
1351 cupsdLogMessage(CUPSD_LOG_ERROR
,
1352 "Unable to allocate memory for %d MIME types!",
1358 for (i
= 0, type
= mimeFirstType(MimeDatabase
);
1360 i
++, type
= mimeNextType(MimeDatabase
))
1362 snprintf(mimetype
, sizeof(mimetype
), "%s/%s", type
->super
, type
->type
);
1364 MimeTypes
[i
] = _cupsStrAlloc(mimetype
);
1367 if (i
< NumMimeTypes
)
1368 MimeTypes
[i
] = _cupsStrAlloc("application/octet-stream");
1371 if (LogLevel
== CUPSD_LOG_DEBUG2
)
1373 mime_filter_t
*filter
; /* Current filter */
1376 for (type
= mimeFirstType(MimeDatabase
);
1378 type
= mimeNextType(MimeDatabase
))
1379 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "cupsdReadConfiguration: type %s/%s",
1380 type
->super
, type
->type
);
1382 for (filter
= mimeFirstFilter(MimeDatabase
);
1384 filter
= mimeNextFilter(MimeDatabase
))
1385 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
1386 "cupsdReadConfiguration: filter %s/%s to %s/%s %d %s",
1387 filter
->src
->super
, filter
->src
->type
,
1388 filter
->dst
->super
, filter
->dst
->type
,
1389 filter
->cost
, filter
->filter
);
1396 snprintf(temp
, sizeof(temp
), "%s/banners", DataDir
);
1397 cupsdLoadBanners(temp
);
1400 * Load printers and classes...
1403 cupsdLoadAllPrinters();
1404 cupsdLoadAllClasses();
1405 cupsdLoadRemoteCache();
1407 cupsdCreateCommonData();
1410 * Update the printcap file as needed...
1413 if (Printcap
&& *Printcap
&& access(Printcap
, 0))
1414 cupsdWritePrintcap();
1417 * Load queued jobs...
1423 * Load subscriptions...
1426 cupsdLoadAllSubscriptions();
1428 cupsdLogMessage(CUPSD_LOG_INFO
, "Full reload complete.");
1433 * Not a full reload, so recreate the common printer attributes...
1436 cupsdCreateCommonData();
1439 * Update all printers as needed...
1442 cupsdUpdatePrinters();
1443 cupsdMarkDirty(CUPSD_DIRTY_PRINTCAP
);
1445 cupsdLogMessage(CUPSD_LOG_INFO
, "Partial reload complete.");
1449 * Reset the reload state...
1452 NeedReload
= RELOAD_NONE
;
1454 cupsdClearString(&old_serverroot
);
1455 cupsdClearString(&old_requestroot
);
1462 * 'get_address()' - Get an address + port number from a line.
1465 static http_addrlist_t
* /* O - Pointer to list if address good, NULL if bad */
1466 get_address(const char *value
, /* I - Value string */
1467 int defport
) /* I - Default port */
1469 char buffer
[1024], /* Hostname + port number buffer */
1470 defpname
[255], /* Default port name */
1471 *hostname
, /* Hostname or IP */
1472 *portname
; /* Port number or name */
1473 http_addrlist_t
*addrlist
; /* Address list */
1477 * Check for an empty value...
1482 cupsdLogMessage(CUPSD_LOG_ERROR
, "Bad (empty) address!");
1487 * Grab a hostname and port number; if there is no colon and the port name
1488 * is only digits, then we have a port number by itself...
1491 strlcpy(buffer
, value
, sizeof(buffer
));
1493 if ((portname
= strrchr(buffer
, ':')) != NULL
&& !strchr(portname
, ']'))
1500 for (portname
= buffer
; isdigit(*portname
& 255); portname
++);
1505 * Use the default port...
1508 sprintf(defpname
, "%d", defport
);
1509 portname
= defpname
;
1515 * The buffer contains just a port number...
1523 if (hostname
&& !strcmp(hostname
, "*"))
1527 * Now lookup the address using httpAddrGetList()...
1530 if ((addrlist
= httpAddrGetList(hostname
, AF_UNSPEC
, portname
)) == NULL
)
1531 cupsdLogMessage(CUPSD_LOG_ERROR
, "Hostname lookup for \"%s\" failed!",
1532 hostname
? hostname
: "(nil)");
1539 * 'get_addr_and_mask()' - Get an IP address and netmask.
1542 static int /* O - 1 on success, 0 on failure */
1543 get_addr_and_mask(const char *value
, /* I - String from config file */
1544 unsigned *ip
, /* O - Address value */
1545 unsigned *mask
) /* O - Mask value */
1547 int i
, j
, /* Looping vars */
1548 family
, /* Address family */
1549 ipcount
; /* Count of fields in address */
1550 unsigned ipval
; /* Value */
1551 const char *maskval
, /* Pointer to start of mask value */
1552 *ptr
, /* Pointer into value */
1557 * Get the address...
1560 ip
[0] = ip
[1] = ip
[2] = ip
[3] = 0x00000000;
1561 mask
[0] = mask
[1] = mask
[2] = mask
[3] = 0xffffffff;
1563 if ((maskval
= strchr(value
, '/')) != NULL
)
1566 maskval
= value
+ strlen(value
);
1570 * Check for an IPv6 address...
1576 * Parse hexadecimal IPv6 address...
1581 for (i
= 0, ptr
= value
+ 1; *ptr
&& i
< 8; i
++)
1585 else if (!strncmp(ptr
, "::", 2))
1587 for (ptr2
= strchr(ptr
+ 2, ':'), j
= 0;
1589 ptr2
= strchr(ptr2
+ 1, ':'), j
++);
1594 else if (isxdigit(*ptr
& 255))
1596 ipval
= strtoul(ptr
, (char **)&ptr
, 16);
1604 ip
[i
/ 2] |= ipval
<< 16;
1618 if (*ptr
&& *ptr
!= '/')
1622 #endif /* AF_INET6 */
1625 * Parse dotted-decimal IPv4 address...
1628 unsigned val
[4]; /* IPv4 address values */
1632 ipcount
= sscanf(value
, "%u.%u.%u.%u", val
+ 0, val
+ 1, val
+ 2, val
+ 3);
1635 * Range check the IP numbers...
1638 for (i
= 0; i
< ipcount
; i
++)
1643 * Make sure the trailing values are zeroed, as some C libraries like
1644 * glibc apparently like to fill the unused arguments with garbage...
1647 for (i
= ipcount
; i
< 4; i
++)
1651 * Merge everything into a 32-bit IPv4 address in ip[3]...
1654 ip
[3] = (((((val
[0] << 8) | val
[1]) << 8) | val
[2]) << 8) | val
[3];
1657 mask
[3] = (0xffffffff << (32 - 8 * ipcount
)) & 0xffffffff;
1663 * Get the netmask value(s)...
1666 memset(mask
, 0, sizeof(unsigned) * 4);
1668 if (strchr(maskval
, '.'))
1671 * Get dotted-decimal mask...
1674 if (family
!= AF_INET
)
1677 if (sscanf(maskval
, "%u.%u.%u.%u", mask
+ 0, mask
+ 1, mask
+ 2, mask
+ 3) != 4)
1680 mask
[3] |= ((((mask
[0] << 8) | mask
[1]) << 8) | mask
[2]) << 8;
1681 mask
[0] = mask
[1] = mask
[2] = 0;
1686 * Get address/bits format...
1692 if (family
== AF_INET6
)
1700 mask
[0] = 0xffffffff;
1702 mask
[0] = (0xffffffff << (i
- 96)) & 0xffffffff;
1705 mask
[1] = 0xffffffff;
1709 mask
[1] = (0xffffffff << (i
- 64)) & 0xffffffff;
1712 mask
[2] = 0xffffffff;
1716 mask
[2] = (0xffffffff << (i
- 32)) & 0xffffffff;
1719 mask
[3] = 0xffffffff;
1723 mask
[3] = (0xffffffff << i
) & 0xffffffff;
1726 #endif /* AF_INET6 */
1731 mask
[0] = 0xffffffff;
1732 mask
[1] = 0xffffffff;
1733 mask
[2] = 0xffffffff;
1736 mask
[3] = (0xffffffff << (32 - i
)) & 0xffffffff;
1738 mask
[3] = 0xffffffff;
1743 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
1744 "get_addr_and_mask(value=\"%s\", "
1745 "ip=[%08x:%08x:%08x:%08x], mask=[%08x:%08x:%08x:%08x])",
1746 value
, ip
[0], ip
[1], ip
[2], ip
[3], mask
[0], mask
[1], mask
[2],
1750 * Check for a valid netmask; no fallback like in CUPS 1.1.x!
1753 if ((ip
[0] & ~mask
[0]) != 0 ||
1754 (ip
[1] & ~mask
[1]) != 0 ||
1755 (ip
[2] & ~mask
[2]) != 0 ||
1756 (ip
[3] & ~mask
[3]) != 0)
1764 * 'parse_aaa()' - Parse authentication, authorization, and access control lines.
1767 static int /* O - 1 on success, 0 on failure */
1768 parse_aaa(cupsd_location_t
*loc
, /* I - Location */
1769 char *line
, /* I - Line from file */
1770 char *value
, /* I - Start of value data */
1771 int linenum
) /* I - Current line number */
1773 char *valptr
; /* Pointer into value */
1774 unsigned ip
[4], /* IP address components */
1775 mask
[4]; /* IP netmask components */
1778 if (!strcasecmp(line
, "Encryption"))
1781 * "Encryption xxx" - set required encryption level...
1784 if (!strcasecmp(value
, "never"))
1785 loc
->encryption
= HTTP_ENCRYPT_NEVER
;
1786 else if (!strcasecmp(value
, "always"))
1788 cupsdLogMessage(CUPSD_LOG_ERROR
,
1789 "Encryption value \"%s\" on line %d is invalid in this "
1790 "context. Using \"required\" instead.", value
, linenum
);
1792 loc
->encryption
= HTTP_ENCRYPT_REQUIRED
;
1794 else if (!strcasecmp(value
, "required"))
1795 loc
->encryption
= HTTP_ENCRYPT_REQUIRED
;
1796 else if (!strcasecmp(value
, "ifrequested"))
1797 loc
->encryption
= HTTP_ENCRYPT_IF_REQUESTED
;
1800 cupsdLogMessage(CUPSD_LOG_ERROR
,
1801 "Unknown Encryption value %s on line %d.", value
, linenum
);
1805 else if (!strcasecmp(line
, "Order"))
1808 * "Order Deny,Allow" or "Order Allow,Deny"...
1811 if (!strncasecmp(value
, "deny", 4))
1812 loc
->order_type
= CUPSD_AUTH_ALLOW
;
1813 else if (!strncasecmp(value
, "allow", 5))
1814 loc
->order_type
= CUPSD_AUTH_DENY
;
1817 cupsdLogMessage(CUPSD_LOG_ERROR
, "Unknown Order value %s on line %d.",
1822 else if (!strcasecmp(line
, "Allow") || !strcasecmp(line
, "Deny"))
1825 * Allow [From] host/ip...
1826 * Deny [From] host/ip...
1831 if (!strncasecmp(value
, "from", 4))
1834 * Strip leading "from"...
1839 while (isspace(*value
& 255))
1847 * Find the end of the value...
1850 for (valptr
= value
; *valptr
&& !isspace(*valptr
& 255); valptr
++);
1852 while (isspace(*valptr
& 255))
1856 * Figure out what form the allow/deny address takes:
1867 * nnn.nnn.nnn.nnn/mm
1868 * nnn.nnn.nnn.nnn/mmm.mmm.mmm.mmm
1871 if (!strcasecmp(value
, "all"))
1877 if (!strcasecmp(line
, "Allow"))
1878 cupsdAllowIP(loc
, zeros
, zeros
);
1880 cupsdDenyIP(loc
, zeros
, zeros
);
1882 else if (!strcasecmp(value
, "none"))
1888 if (!strcasecmp(line
, "Allow"))
1889 cupsdAllowIP(loc
, ones
, zeros
);
1891 cupsdDenyIP(loc
, ones
, zeros
);
1894 else if (value
[0] == '*' || value
[0] == '.' ||
1895 (!isdigit(value
[0] & 255) && value
[0] != '['))
1897 else if (value
[0] == '*' || value
[0] == '.' || !isdigit(value
[0] & 255))
1898 #endif /* AF_INET6 */
1901 * Host or domain name...
1904 if (value
[0] == '*')
1907 if (!strcasecmp(line
, "Allow"))
1908 cupsdAllowHost(loc
, value
);
1910 cupsdDenyHost(loc
, value
);
1915 * One of many IP address forms...
1918 if (!get_addr_and_mask(value
, ip
, mask
))
1920 cupsdLogMessage(CUPSD_LOG_ERROR
, "Bad netmask value %s on line %d.",
1925 if (!strcasecmp(line
, "Allow"))
1926 cupsdAllowIP(loc
, ip
, mask
);
1928 cupsdDenyIP(loc
, ip
, mask
);
1932 * Advance to next value...
1938 else if (!strcasecmp(line
, "AuthType"))
1941 * AuthType {none,basic,digest,basicdigest,negotiate,default}
1944 if (!strcasecmp(value
, "none"))
1946 loc
->type
= CUPSD_AUTH_NONE
;
1947 loc
->level
= CUPSD_AUTH_ANON
;
1949 else if (!strcasecmp(value
, "basic"))
1951 loc
->type
= CUPSD_AUTH_BASIC
;
1953 if (loc
->level
== CUPSD_AUTH_ANON
)
1954 loc
->level
= CUPSD_AUTH_USER
;
1956 else if (!strcasecmp(value
, "digest"))
1958 loc
->type
= CUPSD_AUTH_DIGEST
;
1960 if (loc
->level
== CUPSD_AUTH_ANON
)
1961 loc
->level
= CUPSD_AUTH_USER
;
1963 else if (!strcasecmp(value
, "basicdigest"))
1965 loc
->type
= CUPSD_AUTH_BASICDIGEST
;
1967 if (loc
->level
== CUPSD_AUTH_ANON
)
1968 loc
->level
= CUPSD_AUTH_USER
;
1970 else if (!strcasecmp(value
, "default"))
1972 loc
->type
= CUPSD_AUTH_DEFAULT
;
1974 if (loc
->level
== CUPSD_AUTH_ANON
)
1975 loc
->level
= CUPSD_AUTH_USER
;
1978 else if (!strcasecmp(value
, "negotiate"))
1980 loc
->type
= CUPSD_AUTH_NEGOTIATE
;
1982 if (loc
->level
== CUPSD_AUTH_ANON
)
1983 loc
->level
= CUPSD_AUTH_USER
;
1985 #endif /* HAVE_GSSAPI */
1988 cupsdLogMessage(CUPSD_LOG_WARN
,
1989 "Unknown authorization type %s on line %d.",
1994 else if (!strcasecmp(line
, "AuthClass"))
1997 * AuthClass anonymous, user, system, group
2000 if (!strcasecmp(value
, "anonymous"))
2002 loc
->type
= CUPSD_AUTH_NONE
;
2003 loc
->level
= CUPSD_AUTH_ANON
;
2005 cupsdLogMessage(CUPSD_LOG_WARN
,
2006 "\"AuthClass %s\" is deprecated; consider removing "
2010 else if (!strcasecmp(value
, "user"))
2012 loc
->level
= CUPSD_AUTH_USER
;
2014 cupsdLogMessage(CUPSD_LOG_WARN
,
2015 "\"AuthClass %s\" is deprecated; consider using "
2016 "\"Require valid-user\" on line %d.",
2019 else if (!strcasecmp(value
, "group"))
2021 loc
->level
= CUPSD_AUTH_GROUP
;
2023 cupsdLogMessage(CUPSD_LOG_WARN
,
2024 "\"AuthClass %s\" is deprecated; consider using "
2025 "\"Require user @groupname\" on line %d.",
2028 else if (!strcasecmp(value
, "system"))
2030 loc
->level
= CUPSD_AUTH_GROUP
;
2032 cupsdAddName(loc
, "@SYSTEM");
2034 cupsdLogMessage(CUPSD_LOG_WARN
,
2035 "\"AuthClass %s\" is deprecated; consider using "
2036 "\"Require user @SYSTEM\" on line %d.",
2041 cupsdLogMessage(CUPSD_LOG_WARN
,
2042 "Unknown authorization class %s on line %d.",
2047 else if (!strcasecmp(line
, "AuthGroupName"))
2049 cupsdAddName(loc
, value
);
2051 cupsdLogMessage(CUPSD_LOG_WARN
,
2052 "\"AuthGroupName %s\" directive is deprecated; consider "
2053 "using \"Require user @%s\" on line %d.",
2054 value
, value
, linenum
);
2056 else if (!strcasecmp(line
, "Require"))
2059 * Apache synonym for AuthClass and AuthGroupName...
2063 * Require valid-user
2064 * Require group names
2065 * Require user names
2068 for (valptr
= value
; !isspace(*valptr
& 255) && *valptr
; valptr
++);
2073 if (!strcasecmp(value
, "valid-user") ||
2074 !strcasecmp(value
, "user"))
2075 loc
->level
= CUPSD_AUTH_USER
;
2076 else if (!strcasecmp(value
, "group"))
2077 loc
->level
= CUPSD_AUTH_GROUP
;
2080 cupsdLogMessage(CUPSD_LOG_WARN
, "Unknown Require type %s on line %d.",
2086 * Get the list of names from the line...
2089 for (value
= valptr
; *value
;)
2091 while (isspace(*value
& 255))
2094 #ifdef HAVE_AUTHORIZATION_H
2095 if (!strncmp(value
, "@AUTHKEY(", 9))
2098 * Grab "@AUTHKEY(name)" value...
2101 for (valptr
= value
+ 9; *valptr
!= ')' && *valptr
; valptr
++);
2107 #endif /* HAVE_AUTHORIZATION_H */
2108 if (*value
== '\"' || *value
== '\'')
2111 * Grab quoted name...
2114 for (valptr
= value
+ 1; *valptr
!= *value
&& *valptr
; valptr
++);
2121 * Grab literal name.
2124 for (valptr
= value
; !isspace(*valptr
& 255) && *valptr
; valptr
++);
2130 cupsdAddName(loc
, value
);
2132 for (value
= valptr
; isspace(*value
& 255); value
++);
2135 else if (!strcasecmp(line
, "Satisfy"))
2137 if (!strcasecmp(value
, "all"))
2138 loc
->satisfy
= CUPSD_AUTH_SATISFY_ALL
;
2139 else if (!strcasecmp(value
, "any"))
2140 loc
->satisfy
= CUPSD_AUTH_SATISFY_ANY
;
2143 cupsdLogMessage(CUPSD_LOG_WARN
, "Unknown Satisfy value %s on line %d.",
2156 * 'parse_fatal_errors()' - Parse FatalErrors values in a string.
2159 static int /* O - FatalErrors bits */
2160 parse_fatal_errors(const char *s
) /* I - FatalErrors string */
2162 int fatal
; /* FatalErrors bits */
2163 char value
[1024], /* Value string */
2164 *valstart
, /* Pointer into value */
2165 *valend
; /* End of value */
2169 * Empty FatalErrors line yields NULL pointer...
2173 return (CUPSD_FATAL_NONE
);
2176 * Loop through the value string,...
2179 strlcpy(value
, s
, sizeof(value
));
2181 fatal
= CUPSD_FATAL_NONE
;
2183 for (valstart
= value
; *valstart
;)
2186 * Get the current space/comma-delimited kind name...
2189 for (valend
= valstart
; *valend
; valend
++)
2190 if (isspace(*valend
& 255) || *valend
== ',')
2197 * Add the error to the bitmask...
2200 if (!strcasecmp(valstart
, "all"))
2201 fatal
= CUPSD_FATAL_ALL
;
2202 else if (!strcasecmp(valstart
, "browse"))
2203 fatal
|= CUPSD_FATAL_BROWSE
;
2204 else if (!strcasecmp(valstart
, "-browse"))
2205 fatal
&= ~CUPSD_FATAL_BROWSE
;
2206 else if (!strcasecmp(valstart
, "config"))
2207 fatal
|= CUPSD_FATAL_CONFIG
;
2208 else if (!strcasecmp(valstart
, "-config"))
2209 fatal
&= ~CUPSD_FATAL_CONFIG
;
2210 else if (!strcasecmp(valstart
, "listen"))
2211 fatal
|= CUPSD_FATAL_LISTEN
;
2212 else if (!strcasecmp(valstart
, "-listen"))
2213 fatal
&= ~CUPSD_FATAL_LISTEN
;
2214 else if (!strcasecmp(valstart
, "log"))
2215 fatal
|= CUPSD_FATAL_LOG
;
2216 else if (!strcasecmp(valstart
, "-log"))
2217 fatal
&= ~CUPSD_FATAL_LOG
;
2218 else if (!strcasecmp(valstart
, "permissions"))
2219 fatal
|= CUPSD_FATAL_PERMISSIONS
;
2220 else if (!strcasecmp(valstart
, "-permissions"))
2221 fatal
&= ~CUPSD_FATAL_PERMISSIONS
;
2222 else if (strcasecmp(valstart
, "none"))
2223 cupsdLogMessage(CUPSD_LOG_ERROR
,
2224 "Unknown FatalErrors kind \"%s\" ignored!", valstart
);
2226 for (valstart
= valend
; *valstart
; valstart
++)
2227 if (!isspace(*valstart
& 255) || *valstart
!= ',')
2236 * 'parse_groups()' - Parse system group names in a string.
2239 static int /* O - 1 on success, 0 on failure */
2240 parse_groups(const char *s
) /* I - Space-delimited groups */
2242 int status
; /* Return status */
2243 char value
[1024], /* Value string */
2244 *valstart
, /* Pointer into value */
2245 *valend
, /* End of value */
2246 quote
; /* Quote character */
2247 struct group
*group
; /* Group */
2251 * Make a copy of the string and parse out the groups...
2254 strlcpy(value
, s
, sizeof(value
));
2259 while (*valstart
&& NumSystemGroups
< MAX_SYSTEM_GROUPS
)
2261 if (*valstart
== '\'' || *valstart
== '\"')
2264 * Scan quoted name...
2267 quote
= *valstart
++;
2269 for (valend
= valstart
; *valend
; valend
++)
2270 if (*valend
== quote
)
2276 * Scan space or comma-delimited name...
2279 for (valend
= valstart
; *valend
; valend
++)
2280 if (isspace(*valend
) || *valend
== ',')
2287 group
= getgrnam(valstart
);
2290 cupsdSetString(SystemGroups
+ NumSystemGroups
, valstart
);
2291 SystemGroupIDs
[NumSystemGroups
] = group
->gr_gid
;
2302 while (*valstart
== ',' || isspace(*valstart
))
2311 * 'parse_protocols()' - Parse browse protocols in a string.
2314 static int /* O - Browse protocol bits */
2315 parse_protocols(const char *s
) /* I - Space-delimited protocols */
2317 int protocols
; /* Browse protocol bits */
2318 char value
[1024], /* Value string */
2319 *valstart
, /* Pointer into value */
2320 *valend
; /* End of value */
2324 * Empty protocol line yields NULL pointer...
2331 * Loop through the value string,...
2334 strlcpy(value
, s
, sizeof(value
));
2338 for (valstart
= value
; *valstart
;)
2341 * Get the current space/comma-delimited protocol name...
2344 for (valend
= valstart
; *valend
; valend
++)
2345 if (isspace(*valend
& 255) || *valend
== ',')
2352 * Add the protocol to the bitmask...
2355 if (!strcasecmp(valstart
, "cups"))
2356 protocols
|= BROWSE_CUPS
;
2357 else if (!strcasecmp(valstart
, "slp"))
2358 protocols
|= BROWSE_SLP
;
2359 else if (!strcasecmp(valstart
, "ldap"))
2360 protocols
|= BROWSE_LDAP
;
2361 else if (!strcasecmp(valstart
, "dnssd") ||
2362 !strcasecmp(valstart
, "dns-sd") ||
2363 !strcasecmp(valstart
, "bonjour"))
2364 protocols
|= BROWSE_DNSSD
;
2365 else if (!strcasecmp(valstart
, "lpd"))
2366 protocols
|= BROWSE_LPD
;
2367 else if (!strcasecmp(valstart
, "smb"))
2368 protocols
|= BROWSE_SMB
;
2369 else if (!strcasecmp(valstart
, "all"))
2370 protocols
|= BROWSE_ALL
;
2371 else if (strcasecmp(valstart
, "none"))
2372 cupsdLogMessage(CUPSD_LOG_ERROR
,
2373 "Unknown browse protocol \"%s\" ignored!", valstart
);
2375 for (valstart
= valend
; *valstart
; valstart
++)
2376 if (!isspace(*valstart
& 255) || *valstart
!= ',')
2385 * 'read_configuration()' - Read a configuration file.
2388 static int /* O - 1 on success, 0 on failure */
2389 read_configuration(cups_file_t
*fp
) /* I - File to read from */
2391 int i
; /* Looping var */
2392 int linenum
; /* Current line number */
2393 char line
[HTTP_MAX_BUFFER
],
2394 /* Line from file */
2395 temp
[HTTP_MAX_BUFFER
],
2396 /* Temporary buffer for value */
2397 temp2
[HTTP_MAX_BUFFER
],
2398 /* Temporary buffer 2 for value */
2399 *ptr
, /* Pointer into line/temp */
2400 *value
, /* Pointer to value */
2401 *valueptr
; /* Pointer into value */
2402 int valuelen
; /* Length of value */
2403 cupsd_var_t
const *var
; /* Current variable */
2404 http_addrlist_t
*addrlist
, /* Address list */
2405 *addr
; /* Current address */
2406 unsigned ip
[4], /* Address value */
2407 mask
[4]; /* Netmask value */
2408 cupsd_dirsvc_relay_t
*relay
; /* Relay data */
2409 cupsd_dirsvc_poll_t
*pollp
; /* Polling data */
2410 cupsd_location_t
*location
; /* Browse location */
2411 cups_file_t
*incfile
; /* Include file */
2412 char incname
[1024]; /* Include filename */
2413 struct group
*group
; /* Group */
2417 * Loop through each line in the file...
2422 while (cupsFileGetConf(fp
, line
, sizeof(line
), &value
, &linenum
))
2425 * Decode the directive...
2428 if (!strcasecmp(line
, "Include") && value
)
2434 if (value
[0] == '/')
2435 strlcpy(incname
, value
, sizeof(incname
));
2437 snprintf(incname
, sizeof(incname
), "%s/%s", ServerRoot
, value
);
2439 if ((incfile
= cupsFileOpen(incname
, "rb")) == NULL
)
2440 cupsdLogMessage(CUPSD_LOG_ERROR
,
2441 "Unable to include config file \"%s\" - %s",
2442 incname
, strerror(errno
));
2445 read_configuration(incfile
);
2446 cupsFileClose(incfile
);
2449 else if (!strcasecmp(line
, "<Location") && value
)
2455 linenum
= read_location(fp
, value
, linenum
);
2459 else if (!strcasecmp(line
, "<Policy") && value
)
2465 linenum
= read_policy(fp
, value
, linenum
);
2469 else if (!strcasecmp(line
, "FatalErrors"))
2470 FatalErrors
= parse_fatal_errors(value
);
2471 else if (!strcasecmp(line
, "FaxRetryInterval") && value
)
2473 JobRetryInterval
= atoi(value
);
2474 cupsdLogMessage(CUPSD_LOG_WARN
,
2475 "FaxRetryInterval is deprecated; use "
2476 "JobRetryInterval on line %d.", linenum
);
2478 else if (!strcasecmp(line
, "FaxRetryLimit") && value
)
2480 JobRetryLimit
= atoi(value
);
2481 cupsdLogMessage(CUPSD_LOG_WARN
,
2482 "FaxRetryLimit is deprecated; use "
2483 "JobRetryLimit on line %d.", linenum
);
2485 else if (!strcasecmp(line
, "Port") || !strcasecmp(line
, "Listen")
2487 || !strcasecmp(line
, "SSLPort") || !strcasecmp(line
, "SSLListen")
2488 #endif /* HAVE_SSL */
2492 * Add listening address(es) to the list...
2495 cupsd_listener_t
*lis
; /* New listeners array */
2499 * Get the address list...
2502 addrlist
= get_address(value
, IPP_PORT
);
2506 cupsdLogMessage(CUPSD_LOG_ERROR
, "Bad %s address %s at line %d.", line
,
2512 * Add each address...
2515 for (addr
= addrlist
; addr
; addr
= addr
->next
)
2518 * See if this address is already present...
2521 for (lis
= (cupsd_listener_t
*)cupsArrayFirst(Listeners
);
2523 lis
= (cupsd_listener_t
*)cupsArrayNext(Listeners
))
2524 if (httpAddrEqual(&(addr
->addr
), &(lis
->address
)) &&
2525 _httpAddrPort(&(addr
->addr
)) == _httpAddrPort(&(lis
->address
)))
2530 httpAddrString(&lis
->address
, temp
, sizeof(temp
));
2531 cupsdLogMessage(CUPSD_LOG_WARN
,
2532 "Duplicate listen address \"%s\" ignored!", temp
);
2537 * Allocate another listener...
2541 Listeners
= cupsArrayNew(NULL
, NULL
);
2545 cupsdLogMessage(CUPSD_LOG_ERROR
,
2546 "Unable to allocate %s at line %d - %s.",
2547 line
, linenum
, strerror(errno
));
2551 if ((lis
= calloc(1, sizeof(cupsd_listener_t
))) == NULL
)
2553 cupsdLogMessage(CUPSD_LOG_ERROR
,
2554 "Unable to allocate %s at line %d - %s.",
2555 line
, linenum
, strerror(errno
));
2559 cupsArrayAdd(Listeners
, lis
);
2562 * Copy the current address and log it...
2565 memcpy(&(lis
->address
), &(addr
->addr
), sizeof(lis
->address
));
2569 if (!strcasecmp(line
, "SSLPort") || !strcasecmp(line
, "SSLListen"))
2570 lis
->encryption
= HTTP_ENCRYPT_ALWAYS
;
2571 #endif /* HAVE_SSL */
2573 httpAddrString(&lis
->address
, temp
, sizeof(temp
));
2576 if (lis
->address
.addr
.sa_family
== AF_INET6
)
2577 cupsdLogMessage(CUPSD_LOG_INFO
, "Listening to %s:%d (IPv6)", temp
,
2578 ntohs(lis
->address
.ipv6
.sin6_port
));
2580 #endif /* AF_INET6 */
2582 if (lis
->address
.addr
.sa_family
== AF_LOCAL
)
2583 cupsdLogMessage(CUPSD_LOG_INFO
, "Listening to %s (Domain)", temp
);
2585 #endif /* AF_LOCAL */
2586 cupsdLogMessage(CUPSD_LOG_INFO
, "Listening to %s:%d (IPv4)", temp
,
2587 ntohs(lis
->address
.ipv4
.sin_port
));
2589 if (!httpAddrLocalhost(&(lis
->address
)))
2592 if (lis
->address
.addr
.sa_family
== AF_INET6
)
2593 RemotePort
= ntohs(lis
->address
.ipv6
.sin6_port
);
2595 #endif /* AF_INET6 */
2596 RemotePort
= ntohs(lis
->address
.ipv4
.sin_port
);
2604 httpAddrFreeList(addrlist
);
2606 else if (!strcasecmp(line
, "BrowseAddress") && value
)
2609 * Add a browse address to the list...
2612 cupsd_dirsvc_addr_t
*dira
; /* New browse address array */
2615 if (NumBrowsers
== 0)
2616 dira
= malloc(sizeof(cupsd_dirsvc_addr_t
));
2618 dira
= realloc(Browsers
, (NumBrowsers
+ 1) * sizeof(cupsd_dirsvc_addr_t
));
2622 cupsdLogMessage(CUPSD_LOG_ERROR
,
2623 "Unable to allocate BrowseAddress at line %d - %s.",
2624 linenum
, strerror(errno
));
2629 dira
+= NumBrowsers
;
2631 memset(dira
, 0, sizeof(cupsd_dirsvc_addr_t
));
2633 if (!strcasecmp(value
, "@LOCAL"))
2636 * Send browse data to all local interfaces...
2639 strcpy(dira
->iface
, "*");
2642 else if (!strncasecmp(value
, "@IF(", 4))
2645 * Send browse data to the named interface...
2648 strlcpy(dira
->iface
, value
+ 4, sizeof(Browsers
[0].iface
));
2650 ptr
= dira
->iface
+ strlen(dira
->iface
) - 1;
2656 else if ((addrlist
= get_address(value
, BrowsePort
)) != NULL
)
2659 * Only IPv4 addresses are supported...
2662 for (addr
= addrlist
; addr
; addr
= addr
->next
)
2663 if (addr
->addr
.addr
.sa_family
== AF_INET
)
2668 memcpy(&(dira
->to
), &(addrlist
->addr
), sizeof(dira
->to
));
2669 httpAddrString(&(dira
->to
), temp
, sizeof(temp
));
2671 cupsdLogMessage(CUPSD_LOG_INFO
,
2672 "Sending browsing info to %s:%d (IPv4)",
2673 temp
, ntohs(dira
->to
.ipv4
.sin_port
));
2678 cupsdLogMessage(CUPSD_LOG_ERROR
, "Bad BrowseAddress %s at line %d.",
2681 httpAddrFreeList(addrlist
);
2684 cupsdLogMessage(CUPSD_LOG_ERROR
, "Bad BrowseAddress %s at line %d.",
2687 else if (!strcasecmp(line
, "BrowseOrder") && value
)
2690 * "BrowseOrder Deny,Allow" or "BrowseOrder Allow,Deny"...
2693 if ((location
= cupsdFindLocation("CUPS_INTERNAL_BROWSE_ACL")) == NULL
)
2694 location
= cupsdAddLocation("CUPS_INTERNAL_BROWSE_ACL");
2696 if (location
== NULL
)
2697 cupsdLogMessage(CUPSD_LOG_ERROR
,
2698 "Unable to initialize browse access control list!");
2699 else if (!strncasecmp(value
, "deny", 4))
2700 location
->order_type
= CUPSD_AUTH_ALLOW
;
2701 else if (!strncasecmp(value
, "allow", 5))
2702 location
->order_type
= CUPSD_AUTH_DENY
;
2704 cupsdLogMessage(CUPSD_LOG_ERROR
,
2705 "Unknown BrowseOrder value %s on line %d.",
2708 else if (!strcasecmp(line
, "BrowseProtocols") ||
2709 !strcasecmp(line
, "BrowseLocalProtocols") ||
2710 !strcasecmp(line
, "BrowseRemoteProtocols"))
2713 * "BrowseProtocols name [... name]"
2714 * "BrowseLocalProtocols name [... name]"
2715 * "BrowseRemoteProtocols name [... name]"
2718 int protocols
= parse_protocols(value
);
2722 cupsdLogMessage(CUPSD_LOG_ERROR
,
2723 "Unknown browse protocol \"%s\" on line %d.",
2728 if (strcasecmp(line
, "BrowseLocalProtocols"))
2729 BrowseRemoteProtocols
= protocols
;
2730 if (strcasecmp(line
, "BrowseRemoteProtocols"))
2731 BrowseLocalProtocols
= protocols
;
2733 else if ((!strcasecmp(line
, "BrowseAllow") ||
2734 !strcasecmp(line
, "BrowseDeny")) && value
)
2737 * BrowseAllow [From] host/ip...
2738 * BrowseDeny [From] host/ip...
2741 if ((location
= cupsdFindLocation("CUPS_INTERNAL_BROWSE_ACL")) == NULL
)
2742 location
= cupsdAddLocation("CUPS_INTERNAL_BROWSE_ACL");
2744 if (location
== NULL
)
2745 cupsdLogMessage(CUPSD_LOG_ERROR
,
2746 "Unable to initialize browse access control list!");
2751 if (!strncasecmp(value
, "from", 4))
2754 * Strip leading "from"...
2759 while (isspace(*value
& 255))
2767 * Find the end of the value...
2770 for (valueptr
= value
; *valueptr
&& !isspace(*valueptr
& 255); valueptr
++);
2772 while (isspace(*valueptr
& 255))
2776 * Figure out what form the allow/deny address takes:
2787 * nnn.nnn.nnn.nnn/mm
2788 * nnn.nnn.nnn.nnn/mmm.mmm.mmm.mmm
2791 if (!strcasecmp(value
, "all"))
2797 if (!strcasecmp(line
, "BrowseAllow"))
2798 cupsdAllowIP(location
, zeros
, zeros
);
2800 cupsdDenyIP(location
, zeros
, zeros
);
2802 else if (!strcasecmp(value
, "none"))
2808 if (!strcasecmp(line
, "BrowseAllow"))
2809 cupsdAllowIP(location
, ones
, zeros
);
2811 cupsdDenyIP(location
, ones
, zeros
);
2814 else if (value
[0] == '*' || value
[0] == '.' ||
2815 (!isdigit(value
[0] & 255) && value
[0] != '['))
2817 else if (value
[0] == '*' || value
[0] == '.' || !isdigit(value
[0] & 255))
2818 #endif /* AF_INET6 */
2821 * Host or domain name...
2824 if (value
[0] == '*')
2827 if (!strcasecmp(line
, "BrowseAllow"))
2828 cupsdAllowHost(location
, value
);
2830 cupsdDenyHost(location
, value
);
2835 * One of many IP address forms...
2838 if (!get_addr_and_mask(value
, ip
, mask
))
2840 cupsdLogMessage(CUPSD_LOG_ERROR
, "Bad netmask value %s on line %d.",
2845 if (!strcasecmp(line
, "BrowseAllow"))
2846 cupsdAllowIP(location
, ip
, mask
);
2848 cupsdDenyIP(location
, ip
, mask
);
2852 * Advance to next value...
2859 else if (!strcasecmp(line
, "BrowseRelay") && value
)
2862 * BrowseRelay [from] source [to] destination
2866 relay
= malloc(sizeof(cupsd_dirsvc_relay_t
));
2868 relay
= realloc(Relays
, (NumRelays
+ 1) * sizeof(cupsd_dirsvc_relay_t
));
2872 cupsdLogMessage(CUPSD_LOG_ERROR
,
2873 "Unable to allocate BrowseRelay at line %d - %s.",
2874 linenum
, strerror(errno
));
2881 memset(relay
, 0, sizeof(cupsd_dirsvc_relay_t
));
2883 if (!strncasecmp(value
, "from ", 5))
2886 * Strip leading "from"...
2891 while (isspace(*value
))
2896 * Figure out what form the from address takes:
2905 * nnn.nnn.nnn.nnn/mm
2906 * nnn.nnn.nnn.nnn/mmm.mmm.mmm.mmm
2910 if (value
[0] == '*' || value
[0] == '.' ||
2911 (!isdigit(value
[0] & 255) && value
[0] != '['))
2913 if (value
[0] == '*' || value
[0] == '.' || !isdigit(value
[0] & 255))
2914 #endif /* AF_INET6 */
2917 * Host or domain name...
2920 if (value
[0] == '*')
2923 strlcpy(temp
, value
, sizeof(temp
));
2924 if ((ptr
= strchr(temp
, ' ')) != NULL
)
2927 relay
->from
.type
= CUPSD_AUTH_NAME
;
2929 if ((relay
->from
.mask
.name
.name
= strdup(temp
)) == NULL
)
2931 cupsdLogMessage(CUPSD_LOG_ERROR
,
2932 "Unable to allocate BrowseRelay name at line %d - %s.",
2933 linenum
, strerror(errno
));
2937 relay
->from
.mask
.name
.length
= strlen(temp
);
2942 * One of many IP address forms...
2945 if (!get_addr_and_mask(value
, ip
, mask
))
2947 cupsdLogMessage(CUPSD_LOG_ERROR
, "Bad netmask value %s on line %d.",
2952 relay
->from
.type
= CUPSD_AUTH_IP
;
2953 memcpy(relay
->from
.mask
.ip
.address
, ip
,
2954 sizeof(relay
->from
.mask
.ip
.address
));
2955 memcpy(relay
->from
.mask
.ip
.netmask
, mask
,
2956 sizeof(relay
->from
.mask
.ip
.netmask
));
2960 * Skip value and trailing whitespace...
2963 for (; *value
; value
++)
2964 if (isspace(*value
))
2967 while (isspace(*value
))
2970 if (!strncasecmp(value
, "to ", 3))
2973 * Strip leading "to"...
2978 while (isspace(*value
))
2983 * Get "to" address and port...
2986 if ((addrlist
= get_address(value
, BrowsePort
)) != NULL
)
2989 * Only IPv4 addresses are supported...
2992 for (addr
= addrlist
; addr
; addr
= addr
->next
)
2993 if (addr
->addr
.addr
.sa_family
== AF_INET
)
2998 memcpy(&(relay
->to
), &(addrlist
->addr
), sizeof(relay
->to
));
3000 httpAddrString(&(relay
->to
), temp
, sizeof(temp
));
3002 if (relay
->from
.type
== CUPSD_AUTH_IP
)
3003 snprintf(temp2
, sizeof(temp2
), "%u.%u.%u.%u/%u.%u.%u.%u",
3004 relay
->from
.mask
.ip
.address
[0] >> 24,
3005 (relay
->from
.mask
.ip
.address
[0] >> 16) & 255,
3006 (relay
->from
.mask
.ip
.address
[0] >> 8) & 255,
3007 relay
->from
.mask
.ip
.address
[0] & 255,
3008 relay
->from
.mask
.ip
.netmask
[0] >> 24,
3009 (relay
->from
.mask
.ip
.netmask
[0] >> 16) & 255,
3010 (relay
->from
.mask
.ip
.netmask
[0] >> 8) & 255,
3011 relay
->from
.mask
.ip
.netmask
[0] & 255);
3013 strlcpy(temp2
, relay
->from
.mask
.name
.name
, sizeof(temp2
));
3015 cupsdLogMessage(CUPSD_LOG_INFO
, "Relaying from %s to %s:%d (IPv4)",
3016 temp2
, temp
, ntohs(relay
->to
.ipv4
.sin_port
));
3021 cupsdLogMessage(CUPSD_LOG_ERROR
, "Bad relay address %s at line %d.",
3024 httpAddrFreeList(addrlist
);
3028 if (relay
->from
.type
== CUPSD_AUTH_NAME
)
3029 free(relay
->from
.mask
.name
.name
);
3031 cupsdLogMessage(CUPSD_LOG_ERROR
, "Bad relay address %s at line %d.",
3035 else if (!strcasecmp(line
, "BrowsePoll") && value
)
3038 * BrowsePoll address[:port]
3041 char *portname
; /* Port name */
3042 int portnum
; /* Port number */
3043 struct servent
*service
; /* Service */
3047 * Extract the port name from the address...
3050 if ((portname
= strrchr(value
, ':')) != NULL
&& !strchr(portname
, ']'))
3054 if (isdigit(*portname
& 255))
3055 portnum
= atoi(portname
);
3056 else if ((service
= getservbyname(portname
, NULL
)) != NULL
)
3057 portnum
= ntohs(service
->s_port
);
3060 cupsdLogMessage(CUPSD_LOG_ERROR
, "Lookup of service \"%s\" failed!",
3066 portnum
= ippPort();
3069 * Add the poll entry...
3073 pollp
= malloc(sizeof(cupsd_dirsvc_poll_t
));
3075 pollp
= realloc(Polled
, (NumPolled
+ 1) * sizeof(cupsd_dirsvc_poll_t
));
3079 cupsdLogMessage(CUPSD_LOG_ERROR
,
3080 "Unable to allocate BrowsePoll at line %d - %s.",
3081 linenum
, strerror(errno
));
3089 memset(pollp
, 0, sizeof(cupsd_dirsvc_poll_t
));
3091 strlcpy(pollp
->hostname
, value
, sizeof(pollp
->hostname
));
3092 pollp
->port
= portnum
;
3094 cupsdLogMessage(CUPSD_LOG_INFO
, "Polling %s:%d", pollp
->hostname
,
3097 else if (!strcasecmp(line
, "DefaultAuthType") && value
)
3100 * DefaultAuthType {basic,digest,basicdigest,negotiate}
3103 if (!strcasecmp(value
, "none"))
3104 DefaultAuthType
= CUPSD_AUTH_NONE
;
3105 else if (!strcasecmp(value
, "basic"))
3106 DefaultAuthType
= CUPSD_AUTH_BASIC
;
3107 else if (!strcasecmp(value
, "digest"))
3108 DefaultAuthType
= CUPSD_AUTH_DIGEST
;
3109 else if (!strcasecmp(value
, "basicdigest"))
3110 DefaultAuthType
= CUPSD_AUTH_BASICDIGEST
;
3112 else if (!strcasecmp(value
, "negotiate"))
3113 DefaultAuthType
= CUPSD_AUTH_NEGOTIATE
;
3114 #endif /* HAVE_GSSAPI */
3117 cupsdLogMessage(CUPSD_LOG_WARN
,
3118 "Unknown default authorization type %s on line %d.",
3120 if (FatalErrors
& CUPSD_FATAL_CONFIG
)
3125 else if (!strcasecmp(line
, "DefaultEncryption"))
3128 * DefaultEncryption {Never,IfRequested,Required}
3131 if (!value
|| !strcasecmp(value
, "never"))
3132 DefaultEncryption
= HTTP_ENCRYPT_NEVER
;
3133 else if (!strcasecmp(value
, "required"))
3134 DefaultEncryption
= HTTP_ENCRYPT_REQUIRED
;
3135 else if (!strcasecmp(value
, "ifrequested"))
3136 DefaultEncryption
= HTTP_ENCRYPT_IF_REQUESTED
;
3139 cupsdLogMessage(CUPSD_LOG_WARN
,
3140 "Unknown default encryption %s on line %d.",
3142 if (FatalErrors
& CUPSD_FATAL_CONFIG
)
3146 #endif /* HAVE_SSL */
3147 else if (!strcasecmp(line
, "User") && value
)
3150 * User ID to run as...
3153 if (isdigit(value
[0] & 255))
3155 int uid
= atoi(value
);
3158 cupsdLogMessage(CUPSD_LOG_ERROR
,
3159 "Will not use User 0 as specified on line %d "
3160 "for security reasons. You must use a non-"
3161 "privileged account instead.",
3168 struct passwd
*p
; /* Password information */
3171 p
= getpwnam(value
);
3176 cupsdLogMessage(CUPSD_LOG_ERROR
,
3177 "Will not use User %s (UID=0) as specified on line "
3178 "%d for security reasons. You must use a non-"
3179 "privileged account instead.",
3185 cupsdLogMessage(CUPSD_LOG_ERROR
,
3186 "Unknown User \"%s\" on line %d, ignoring!",
3190 else if (!strcasecmp(line
, "Group") && value
)
3193 * Group ID to run as...
3196 if (isdigit(value
[0]))
3197 Group
= atoi(value
);
3201 group
= getgrnam(value
);
3204 Group
= group
->gr_gid
;
3206 cupsdLogMessage(CUPSD_LOG_ERROR
,
3207 "Unknown Group \"%s\" on line %d, ignoring!",
3211 else if (!strcasecmp(line
, "SystemGroup") && value
)
3214 * SystemGroup (admin) group(s)...
3217 if (!parse_groups(value
))
3218 cupsdLogMessage(CUPSD_LOG_ERROR
,
3219 "Unknown SystemGroup \"%s\" on line %d, ignoring!",
3222 else if (!strcasecmp(line
, "HostNameLookups") && value
)
3225 * Do hostname lookups?
3228 if (!strcasecmp(value
, "off") || !strcasecmp(value
, "no") ||
3229 !strcasecmp(value
, "false"))
3230 HostNameLookups
= 0;
3231 else if (!strcasecmp(value
, "on") || !strcasecmp(value
, "yes") ||
3232 !strcasecmp(value
, "true"))
3233 HostNameLookups
= 1;
3234 else if (!strcasecmp(value
, "double"))
3235 HostNameLookups
= 2;
3237 cupsdLogMessage(CUPSD_LOG_WARN
, "Unknown HostNameLookups %s on line %d.",
3240 else if (!strcasecmp(line
, "AccessLogLevel") && value
)
3243 * Amount of logging to do to access log...
3246 if (!strcasecmp(value
, "all"))
3247 AccessLogLevel
= CUPSD_ACCESSLOG_ALL
;
3248 else if (!strcasecmp(value
, "actions"))
3249 AccessLogLevel
= CUPSD_ACCESSLOG_ACTIONS
;
3250 else if (!strcasecmp(value
, "config"))
3251 AccessLogLevel
= CUPSD_ACCESSLOG_CONFIG
;
3253 cupsdLogMessage(CUPSD_LOG_WARN
, "Unknown AccessLogLevel %s on line %d.",
3256 else if (!strcasecmp(line
, "LogLevel") && value
)
3259 * Amount of logging to do to error log...
3262 if (!strcasecmp(value
, "debug2"))
3263 LogLevel
= CUPSD_LOG_DEBUG2
;
3264 else if (!strcasecmp(value
, "debug"))
3265 LogLevel
= CUPSD_LOG_DEBUG
;
3266 else if (!strcasecmp(value
, "info"))
3267 LogLevel
= CUPSD_LOG_INFO
;
3268 else if (!strcasecmp(value
, "notice"))
3269 LogLevel
= CUPSD_LOG_NOTICE
;
3270 else if (!strcasecmp(value
, "warn"))
3271 LogLevel
= CUPSD_LOG_WARN
;
3272 else if (!strcasecmp(value
, "error"))
3273 LogLevel
= CUPSD_LOG_ERROR
;
3274 else if (!strcasecmp(value
, "crit"))
3275 LogLevel
= CUPSD_LOG_CRIT
;
3276 else if (!strcasecmp(value
, "alert"))
3277 LogLevel
= CUPSD_LOG_ALERT
;
3278 else if (!strcasecmp(value
, "emerg"))
3279 LogLevel
= CUPSD_LOG_EMERG
;
3280 else if (!strcasecmp(value
, "none"))
3281 LogLevel
= CUPSD_LOG_NONE
;
3283 cupsdLogMessage(CUPSD_LOG_WARN
, "Unknown LogLevel %s on line %d.",
3286 else if (!strcasecmp(line
, "LogTimeFormat") && value
)
3289 * Amount of logging to do to error log...
3292 if (!strcasecmp(value
, "standard"))
3293 LogTimeFormat
= CUPSD_TIME_STANDARD
;
3294 else if (!strcasecmp(value
, "usecs"))
3295 LogTimeFormat
= CUPSD_TIME_USECS
;
3297 cupsdLogMessage(CUPSD_LOG_WARN
, "Unknown LogTimeFormat %s on line %d.",
3300 else if (!strcasecmp(line
, "PrintcapFormat") && value
)
3303 * Format of printcap file?
3306 if (!strcasecmp(value
, "bsd"))
3307 PrintcapFormat
= PRINTCAP_BSD
;
3308 else if (!strcasecmp(value
, "plist"))
3309 PrintcapFormat
= PRINTCAP_PLIST
;
3310 else if (!strcasecmp(value
, "solaris"))
3311 PrintcapFormat
= PRINTCAP_SOLARIS
;
3313 cupsdLogMessage(CUPSD_LOG_WARN
, "Unknown PrintcapFormat %s on line %d.",
3316 else if (!strcasecmp(line
, "ServerTokens") && value
)
3319 * Set the string used for the Server header...
3322 struct utsname plat
; /* Platform info */
3327 if (!strcasecmp(value
, "ProductOnly"))
3328 cupsdSetString(&ServerHeader
, "CUPS");
3329 else if (!strcasecmp(value
, "Major"))
3330 cupsdSetString(&ServerHeader
, "CUPS/1");
3331 else if (!strcasecmp(value
, "Minor"))
3332 cupsdSetString(&ServerHeader
, "CUPS/1.4");
3333 else if (!strcasecmp(value
, "Minimal"))
3334 cupsdSetString(&ServerHeader
, CUPS_MINIMAL
);
3335 else if (!strcasecmp(value
, "OS"))
3336 cupsdSetStringf(&ServerHeader
, CUPS_MINIMAL
" (%s)", plat
.sysname
);
3337 else if (!strcasecmp(value
, "Full"))
3338 cupsdSetStringf(&ServerHeader
, CUPS_MINIMAL
" (%s) IPP/1.1",
3340 else if (!strcasecmp(value
, "None"))
3341 cupsdClearString(&ServerHeader
);
3343 cupsdLogMessage(CUPSD_LOG_WARN
, "Unknown ServerTokens %s on line %d.",
3346 else if (!strcasecmp(line
, "PassEnv") && value
)
3349 * PassEnv variable [... variable]
3354 for (valuelen
= 0; value
[valuelen
]; valuelen
++)
3355 if (isspace(value
[valuelen
]) || value
[valuelen
] == ',')
3358 if (value
[valuelen
])
3360 value
[valuelen
] = '\0';
3364 cupsdSetEnv(value
, NULL
);
3366 for (value
+= valuelen
; *value
; value
++)
3367 if (!isspace(*value
) || *value
!= ',')
3371 else if (!strcasecmp(line
, "ServerAlias") && value
)
3374 ServerAlias
= cupsArrayNew(NULL
, NULL
);
3376 cupsdAddAlias(ServerAlias
, value
);
3378 else if (!strcasecmp(line
, "SetEnv") && value
)
3381 * SetEnv variable value
3384 for (valueptr
= value
; *valueptr
&& !isspace(*valueptr
& 255); valueptr
++);
3392 while (isspace(*valueptr
& 255))
3395 cupsdSetEnv(value
, valueptr
);
3398 cupsdLogMessage(CUPSD_LOG_ERROR
,
3399 "Missing value for SetEnv directive on line %d.",
3403 else if (!strcasecmp(line
, "SSLOptions"))
3406 * SSLOptions options
3409 if (!value
|| !strcasecmp(value
, "none"))
3410 SSLOptions
= CUPSD_SSL_NONE
;
3411 else if (!strcasecmp(value
, "noemptyfragments"))
3412 SSLOptions
= CUPSD_SSL_NOEMPTY
;
3414 cupsdLogMessage(CUPSD_LOG_ERROR
,
3415 "Unknown value \"%s\" for SSLOptions directive on "
3416 "line %d.", value
, linenum
);
3418 #endif /* HAVE_SSL */
3422 * Find a simple variable in the list...
3425 for (i
= NUM_VARS
, var
= variables
; i
> 0; i
--, var
++)
3426 if (!strcasecmp(line
, var
->name
))
3432 * Unknown directive! Output an error message and continue...
3436 cupsdLogMessage(CUPSD_LOG_ERROR
, "Missing value for %s on line %d.",
3439 cupsdLogMessage(CUPSD_LOG_ERROR
, "Unknown directive %s on line %d.",
3446 case CUPSD_VARTYPE_INTEGER
:
3448 cupsdLogMessage(CUPSD_LOG_ERROR
,
3449 "Missing integer value for %s on line %d!",
3454 char *units
; /* Units */
3457 n
= strtol(value
, &units
, 0);
3459 if (units
&& *units
)
3461 if (tolower(units
[0] & 255) == 'g')
3462 n
*= 1024 * 1024 * 1024;
3463 else if (tolower(units
[0] & 255) == 'm')
3465 else if (tolower(units
[0] & 255) == 'k')
3467 else if (tolower(units
[0] & 255) == 't')
3472 cupsdLogMessage(CUPSD_LOG_ERROR
,
3473 "Bad negative integer value for %s on line %d!",
3476 *((int *)var
->ptr
) = n
;
3480 case CUPSD_VARTYPE_BOOLEAN
:
3482 cupsdLogMessage(CUPSD_LOG_ERROR
,
3483 "Missing boolean value for %s on line %d!",
3485 else if (!strcasecmp(value
, "true") ||
3486 !strcasecmp(value
, "on") ||
3487 !strcasecmp(value
, "enabled") ||
3488 !strcasecmp(value
, "yes") ||
3490 *((int *)var
->ptr
) = TRUE
;
3491 else if (!strcasecmp(value
, "false") ||
3492 !strcasecmp(value
, "off") ||
3493 !strcasecmp(value
, "disabled") ||
3494 !strcasecmp(value
, "no") ||
3495 !strcasecmp(value
, "0"))
3496 *((int *)var
->ptr
) = FALSE
;
3498 cupsdLogMessage(CUPSD_LOG_ERROR
,
3499 "Unknown boolean value %s on line %d.",
3503 case CUPSD_VARTYPE_PATHNAME
:
3506 cupsdLogMessage(CUPSD_LOG_ERROR
,
3507 "Missing pathname value for %s on line %d!",
3512 if (value
[0] == '/')
3513 strlcpy(temp
, value
, sizeof(temp
));
3515 snprintf(temp
, sizeof(temp
), "%s/%s", ServerRoot
, value
);
3517 if (access(temp
, 0))
3519 cupsdLogMessage(CUPSD_LOG_ERROR
,
3520 "File or directory for \"%s %s\" on line %d "
3521 "does not exist!", line
, value
, linenum
);
3525 case CUPSD_VARTYPE_STRING
:
3526 cupsdSetString((char **)var
->ptr
, value
);
3537 * 'read_location()' - Read a <Location path> definition.
3540 static int /* O - New line number or 0 on error */
3541 read_location(cups_file_t
*fp
, /* I - Configuration file */
3542 char *location
, /* I - Location name/path */
3543 int linenum
) /* I - Current line number */
3545 cupsd_location_t
*loc
, /* New location */
3546 *parent
; /* Parent location */
3547 char line
[HTTP_MAX_BUFFER
],
3549 *value
, /* Value for directive */
3550 *valptr
; /* Pointer into value */
3553 if ((parent
= cupsdAddLocation(location
)) == NULL
)
3556 parent
->limit
= CUPSD_AUTH_LIMIT_ALL
;
3559 while (cupsFileGetConf(fp
, line
, sizeof(line
), &value
, &linenum
))
3562 * Decode the directive...
3565 if (!strcasecmp(line
, "</Location>"))
3567 else if (!strcasecmp(line
, "<Limit") ||
3568 !strcasecmp(line
, "<LimitExcept"))
3572 cupsdLogMessage(CUPSD_LOG_ERROR
, "Syntax error on line %d.", linenum
);
3573 if (FatalErrors
& CUPSD_FATAL_CONFIG
)
3579 if ((loc
= cupsdCopyLocation(&parent
)) == NULL
)
3585 for (valptr
= value
; !isspace(*valptr
& 255) && *valptr
; valptr
++);
3590 if (!strcmp(value
, "ALL"))
3591 loc
->limit
= CUPSD_AUTH_LIMIT_ALL
;
3592 else if (!strcmp(value
, "GET"))
3593 loc
->limit
|= CUPSD_AUTH_LIMIT_GET
;
3594 else if (!strcmp(value
, "HEAD"))
3595 loc
->limit
|= CUPSD_AUTH_LIMIT_HEAD
;
3596 else if (!strcmp(value
, "OPTIONS"))
3597 loc
->limit
|= CUPSD_AUTH_LIMIT_OPTIONS
;
3598 else if (!strcmp(value
, "POST"))
3599 loc
->limit
|= CUPSD_AUTH_LIMIT_POST
;
3600 else if (!strcmp(value
, "PUT"))
3601 loc
->limit
|= CUPSD_AUTH_LIMIT_PUT
;
3602 else if (!strcmp(value
, "TRACE"))
3603 loc
->limit
|= CUPSD_AUTH_LIMIT_TRACE
;
3605 cupsdLogMessage(CUPSD_LOG_WARN
, "Unknown request type %s on line %d!",
3608 for (value
= valptr
; isspace(*value
& 255); value
++);
3611 if (!strcasecmp(line
, "<LimitExcept"))
3612 loc
->limit
= CUPSD_AUTH_LIMIT_ALL
^ loc
->limit
;
3614 parent
->limit
&= ~loc
->limit
;
3616 else if (!strcasecmp(line
, "</Limit>") ||
3617 !strcasecmp(line
, "</LimitExcept>"))
3619 else if (!parse_aaa(loc
, line
, value
, linenum
))
3621 cupsdLogMessage(CUPSD_LOG_ERROR
,
3622 "Unknown Location directive %s on line %d.",
3624 if (FatalErrors
& CUPSD_FATAL_CONFIG
)
3629 cupsdLogMessage(CUPSD_LOG_ERROR
,
3630 "Unexpected end-of-file at line %d while reading location!",
3633 return ((FatalErrors
& CUPSD_FATAL_CONFIG
) ? 0 : linenum
);
3638 * 'read_policy()' - Read a <Policy name> definition.
3641 static int /* O - New line number or 0 on error */
3642 read_policy(cups_file_t
*fp
, /* I - Configuration file */
3643 char *policy
, /* I - Location name/path */
3644 int linenum
) /* I - Current line number */
3646 int i
; /* Looping var */
3647 cupsd_policy_t
*pol
; /* Policy */
3648 cupsd_location_t
*op
; /* Policy operation */
3649 int num_ops
; /* Number of IPP operations */
3650 ipp_op_t ops
[100]; /* Operations */
3651 char line
[HTTP_MAX_BUFFER
],
3653 *value
, /* Value for directive */
3654 *valptr
; /* Pointer into value */
3658 * Create the policy...
3661 if ((pol
= cupsdAddPolicy(policy
)) == NULL
)
3665 * Read from the file...
3671 while (cupsFileGetConf(fp
, line
, sizeof(line
), &value
, &linenum
))
3674 * Decode the directive...
3677 if (!strcasecmp(line
, "</Policy>"))
3680 cupsdLogMessage(CUPSD_LOG_WARN
,
3681 "Missing </Limit> before </Policy> on line %d!",
3685 * Verify that we have an explicit policy for CUPS-Get-Document
3686 * (ensures that upgrades do not introduce new security issues...)
3689 if ((op
= cupsdFindPolicyOp(pol
, CUPS_GET_DOCUMENT
)) == NULL
||
3690 op
->op
== IPP_ANY_OPERATION
)
3692 if ((op
= cupsdFindPolicyOp(pol
, IPP_SEND_DOCUMENT
)) != NULL
&&
3693 op
->op
!= IPP_ANY_OPERATION
)
3696 * Add a new limit for CUPS-Get-Document using the Send-Document
3697 * limit as a template...
3700 cupsdLogMessage(CUPSD_LOG_WARN
,
3701 "No limit for CUPS-Get-Document defined in policy %s "
3702 "- using Send-Document's policy", pol
->name
);
3704 cupsdAddPolicyOp(pol
, op
, CUPS_GET_DOCUMENT
);
3710 else if (!strcasecmp(line
, "<Limit") && !op
)
3714 cupsdLogMessage(CUPSD_LOG_ERROR
, "Syntax error on line %d.", linenum
);
3715 if (FatalErrors
& CUPSD_FATAL_CONFIG
)
3722 * Scan for IPP operation names...
3729 for (valptr
= value
; !isspace(*valptr
& 255) && *valptr
; valptr
++);
3734 if (num_ops
< (int)(sizeof(ops
) / sizeof(ops
[0])))
3736 if (!strcasecmp(value
, "All"))
3737 ops
[num_ops
] = IPP_ANY_OPERATION
;
3738 else if ((ops
[num_ops
] = ippOpValue(value
)) == IPP_BAD_OPERATION
)
3739 cupsdLogMessage(CUPSD_LOG_ERROR
,
3740 "Bad IPP operation name \"%s\" on line %d!",
3746 cupsdLogMessage(CUPSD_LOG_ERROR
,
3747 "Too many operations listed on line %d!",
3750 for (value
= valptr
; isspace(*value
& 255); value
++);
3754 * If none are specified, apply the policy to all operations...
3759 ops
[0] = IPP_ANY_OPERATION
;
3764 * Add a new policy for the first operation...
3767 op
= cupsdAddPolicyOp(pol
, NULL
, ops
[0]);
3769 else if (!strcasecmp(line
, "</Limit>") && op
)
3772 * Finish the current operation limit...
3778 * Copy the policy to the other operations...
3781 for (i
= 1; i
< num_ops
; i
++)
3782 cupsdAddPolicyOp(pol
, op
, ops
[i
]);
3789 cupsdLogMessage(CUPSD_LOG_ERROR
,
3790 "Missing <Limit ops> directive before %s on line %d.",
3792 if (FatalErrors
& CUPSD_FATAL_CONFIG
)
3795 else if (!parse_aaa(op
, line
, value
, linenum
))
3798 cupsdLogMessage(CUPSD_LOG_ERROR
,
3799 "Unknown Policy Limit directive %s on line %d.",
3802 cupsdLogMessage(CUPSD_LOG_ERROR
,
3803 "Unknown Policy directive %s on line %d.",
3806 if (FatalErrors
& CUPSD_FATAL_CONFIG
)
3811 cupsdLogMessage(CUPSD_LOG_ERROR
,
3812 "Unexpected end-of-file at line %d while reading policy \"%s\"!",
3815 return ((FatalErrors
& CUPSD_FATAL_CONFIG
) ? 0 : linenum
);
3820 * End of "$Id: conf.c 7952 2008-09-17 00:56:20Z mike $".