2 * "$Id: conf.c 6746 2007-07-30 16:47:10Z mike $"
4 * Configuration routines for the Common UNIX Printing System (CUPS).
6 * Copyright 2007 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 * cupsdCheckPermissions() - Fix the mode and ownership of a file or
19 * cupsdReadConfiguration() - Read the cupsd.conf file.
20 * get_address() - Get an address + port number from a line.
21 * get_addr_and_mask() - Get an IP address and netmask.
22 * parse_aaa() - Parse authentication, authorization, and
23 * access control lines.
24 * parse_groups() - Parse system group names in a string.
25 * parse_protocols() - Parse browse protocols in a string.
26 * read_configuration() - Read a configuration file.
27 * read_location() - Read a <Location path> definition.
28 * read_policy() - Read a <Policy name> definition.
32 * Include necessary headers...
38 #include <sys/utsname.h>
43 * Possibly missing network definitions...
47 # define INADDR_NONE 0xffffffff
48 #endif /* !INADDR_NONE */
52 * Configuration variable structure...
57 CUPSD_VARTYPE_INTEGER
, /* Integer option */
58 CUPSD_VARTYPE_STRING
, /* String option */
59 CUPSD_VARTYPE_BOOLEAN
/* Boolean option */
64 char *name
; /* Name of variable */
65 void *ptr
; /* Pointer to variable */
66 cupsd_vartype_t type
; /* Type (int, string, address) */
74 static cupsd_var_t variables
[] =
76 { "AccessLog", &AccessLog
, CUPSD_VARTYPE_STRING
},
78 { "AppleQuotas", &AppleQuotas
, CUPSD_VARTYPE_BOOLEAN
},
79 #endif /* __APPLE__ */
80 { "AutoPurgeJobs", &JobAutoPurge
, CUPSD_VARTYPE_BOOLEAN
},
81 { "BrowseInterval", &BrowseInterval
, CUPSD_VARTYPE_INTEGER
},
83 { "BrowseLDAPBindDN", &BrowseLDAPBindDN
, CUPSD_VARTYPE_STRING
},
84 { "BrowseLDAPCACertFile", &BrowseLDAPCACertFile
, CUPSD_VARTYPE_STRING
},
85 { "BrowseLDAPDN", &BrowseLDAPDN
, CUPSD_VARTYPE_STRING
},
86 { "BrowseLDAPPassword", &BrowseLDAPPassword
, CUPSD_VARTYPE_STRING
},
87 { "BrowseLDAPServer", &BrowseLDAPServer
, CUPSD_VARTYPE_STRING
},
88 #endif /* HAVE_LDAP */
89 { "BrowseLocalOptions", &BrowseLocalOptions
, CUPSD_VARTYPE_STRING
},
90 { "BrowsePort", &BrowsePort
, CUPSD_VARTYPE_INTEGER
},
91 { "BrowseRemoteOptions", &BrowseRemoteOptions
, CUPSD_VARTYPE_STRING
},
92 { "BrowseShortNames", &BrowseShortNames
, CUPSD_VARTYPE_BOOLEAN
},
93 { "BrowseTimeout", &BrowseTimeout
, CUPSD_VARTYPE_INTEGER
},
94 { "Browsing", &Browsing
, CUPSD_VARTYPE_BOOLEAN
},
95 { "CacheDir", &CacheDir
, CUPSD_VARTYPE_STRING
},
96 { "Classification", &Classification
, CUPSD_VARTYPE_STRING
},
97 { "ClassifyOverride", &ClassifyOverride
, CUPSD_VARTYPE_BOOLEAN
},
98 { "ConfigFilePerm", &ConfigFilePerm
, CUPSD_VARTYPE_INTEGER
},
99 { "DataDir", &DataDir
, CUPSD_VARTYPE_STRING
},
100 { "DefaultCharset", &DefaultCharset
, CUPSD_VARTYPE_STRING
},
101 { "DefaultLanguage", &DefaultLanguage
, CUPSD_VARTYPE_STRING
},
102 { "DefaultLeaseDuration", &DefaultLeaseDuration
, CUPSD_VARTYPE_INTEGER
},
103 { "DefaultPolicy", &DefaultPolicy
, CUPSD_VARTYPE_STRING
},
104 { "DefaultShared", &DefaultShared
, CUPSD_VARTYPE_BOOLEAN
},
105 { "DocumentRoot", &DocumentRoot
, CUPSD_VARTYPE_STRING
},
106 { "ErrorLog", &ErrorLog
, CUPSD_VARTYPE_STRING
},
107 { "ErrorPolicy", &ErrorPolicy
, CUPSD_VARTYPE_STRING
},
108 { "FileDevice", &FileDevice
, CUPSD_VARTYPE_BOOLEAN
},
109 { "FilterLimit", &FilterLimit
, CUPSD_VARTYPE_INTEGER
},
110 { "FilterNice", &FilterNice
, CUPSD_VARTYPE_INTEGER
},
111 { "FontPath", &FontPath
, CUPSD_VARTYPE_STRING
},
113 { "GSSServiceName", &GSSServiceName
, CUPSD_VARTYPE_STRING
},
114 #endif /* HAVE_GSSAPI */
115 { "ImplicitClasses", &ImplicitClasses
, CUPSD_VARTYPE_BOOLEAN
},
116 { "ImplicitAnyClasses", &ImplicitAnyClasses
, CUPSD_VARTYPE_BOOLEAN
},
117 { "JobRetryLimit", &JobRetryLimit
, CUPSD_VARTYPE_INTEGER
},
118 { "JobRetryInterval", &JobRetryInterval
, CUPSD_VARTYPE_INTEGER
},
119 { "KeepAliveTimeout", &KeepAliveTimeout
, CUPSD_VARTYPE_INTEGER
},
120 { "KeepAlive", &KeepAlive
, CUPSD_VARTYPE_BOOLEAN
},
122 { "LaunchdTimeout", &LaunchdTimeout
, CUPSD_VARTYPE_INTEGER
},
123 { "LaunchdConf", &LaunchdConf
, CUPSD_VARTYPE_STRING
},
124 #endif /* HAVE_LAUNCHD */
125 { "LimitRequestBody", &MaxRequestSize
, CUPSD_VARTYPE_INTEGER
},
126 { "ListenBackLog", &ListenBackLog
, CUPSD_VARTYPE_INTEGER
},
127 { "LogFilePerm", &LogFilePerm
, CUPSD_VARTYPE_INTEGER
},
128 { "MaxActiveJobs", &MaxActiveJobs
, CUPSD_VARTYPE_INTEGER
},
129 { "MaxClients", &MaxClients
, CUPSD_VARTYPE_INTEGER
},
130 { "MaxClientsPerHost", &MaxClientsPerHost
, CUPSD_VARTYPE_INTEGER
},
131 { "MaxCopies", &MaxCopies
, CUPSD_VARTYPE_INTEGER
},
132 { "MaxEvents", &MaxEvents
, CUPSD_VARTYPE_INTEGER
},
133 { "MaxJobs", &MaxJobs
, CUPSD_VARTYPE_INTEGER
},
134 { "MaxJobsPerPrinter", &MaxJobsPerPrinter
, CUPSD_VARTYPE_INTEGER
},
135 { "MaxJobsPerUser", &MaxJobsPerUser
, CUPSD_VARTYPE_INTEGER
},
136 { "MaxLeaseDuration", &MaxLeaseDuration
, CUPSD_VARTYPE_INTEGER
},
137 { "MaxLogSize", &MaxLogSize
, CUPSD_VARTYPE_INTEGER
},
138 { "MaxPrinterHistory", &MaxPrinterHistory
, CUPSD_VARTYPE_INTEGER
},
139 { "MaxRequestSize", &MaxRequestSize
, CUPSD_VARTYPE_INTEGER
},
140 { "MaxSubscriptions", &MaxSubscriptions
, CUPSD_VARTYPE_INTEGER
},
141 { "MaxSubscriptionsPerJob", &MaxSubscriptionsPerJob
, CUPSD_VARTYPE_INTEGER
},
142 { "MaxSubscriptionsPerPrinter",&MaxSubscriptionsPerPrinter
, CUPSD_VARTYPE_INTEGER
},
143 { "MaxSubscriptionsPerUser", &MaxSubscriptionsPerUser
, CUPSD_VARTYPE_INTEGER
},
144 { "PageLog", &PageLog
, CUPSD_VARTYPE_STRING
},
145 { "PreserveJobFiles", &JobFiles
, CUPSD_VARTYPE_BOOLEAN
},
146 { "PreserveJobHistory", &JobHistory
, CUPSD_VARTYPE_BOOLEAN
},
147 { "Printcap", &Printcap
, CUPSD_VARTYPE_STRING
},
148 { "PrintcapGUI", &PrintcapGUI
, CUPSD_VARTYPE_STRING
},
149 { "ReloadTimeout", &ReloadTimeout
, CUPSD_VARTYPE_INTEGER
},
150 { "RemoteRoot", &RemoteRoot
, CUPSD_VARTYPE_STRING
},
151 { "RequestRoot", &RequestRoot
, CUPSD_VARTYPE_STRING
},
152 { "RIPCache", &RIPCache
, CUPSD_VARTYPE_STRING
},
153 { "RootCertDuration", &RootCertDuration
, CUPSD_VARTYPE_INTEGER
},
154 { "ServerAdmin", &ServerAdmin
, CUPSD_VARTYPE_STRING
},
155 { "ServerBin", &ServerBin
, CUPSD_VARTYPE_STRING
},
157 { "ServerCertificate", &ServerCertificate
, CUPSD_VARTYPE_STRING
},
158 # if defined(HAVE_LIBSSL) || defined(HAVE_GNUTLS)
159 { "ServerKey", &ServerKey
, CUPSD_VARTYPE_STRING
},
160 # endif /* HAVE_LIBSSL || HAVE_GNUTLS */
161 #endif /* HAVE_SSL */
162 { "ServerName", &ServerName
, CUPSD_VARTYPE_STRING
},
163 { "ServerRoot", &ServerRoot
, CUPSD_VARTYPE_STRING
},
164 { "StateDir", &StateDir
, CUPSD_VARTYPE_STRING
},
165 #ifdef HAVE_AUTHORIZATION_H
166 { "SystemGroupAuthKey", &SystemGroupAuthKey
, CUPSD_VARTYPE_STRING
},
167 #endif /* HAVE_AUTHORIZATION_H */
168 { "TempDir", &TempDir
, CUPSD_VARTYPE_STRING
},
169 { "Timeout", &Timeout
, CUPSD_VARTYPE_INTEGER
},
170 { "UseNetworkDefault", &UseNetworkDefault
, CUPSD_VARTYPE_BOOLEAN
}
172 #define NUM_VARS (sizeof(variables) / sizeof(variables[0]))
175 static unsigned ones
[4] =
177 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff
179 static unsigned zeros
[4] =
181 0x00000000, 0x00000000, 0x00000000, 0x00000000
188 static http_addrlist_t
*get_address(const char *value
, int defport
);
189 static int get_addr_and_mask(const char *value
, unsigned *ip
,
191 static int parse_aaa(cupsd_location_t
*loc
, char *line
,
192 char *value
, int linenum
);
193 static int parse_groups(const char *s
);
194 static int parse_protocols(const char *s
);
195 static int read_configuration(cups_file_t
*fp
);
196 static int read_location(cups_file_t
*fp
, char *name
, int linenum
);
197 static int read_policy(cups_file_t
*fp
, char *name
, int linenum
);
201 * 'cupsdCheckPermissions()' - Fix the mode and ownership of a file or directory.
204 int /* O - 0 on success, -1 on error, 1 on warning */
205 cupsdCheckPermissions(
206 const char *filename
, /* I - File/directory name */
207 const char *suffix
, /* I - Additional file/directory name */
208 int mode
, /* I - Permissions */
209 int user
, /* I - Owner */
210 int group
, /* I - Group */
211 int is_dir
, /* I - 1 = directory, 0 = file */
212 int create_dir
) /* I - 1 = create directory, -1 = create w/o logging, 0 = not */
214 int dir_created
= 0; /* Did we create a directory? */
215 char pathname
[1024]; /* File name with prefix */
216 struct stat fileinfo
; /* Stat buffer */
220 * Prepend the given root to the filename before testing it...
225 snprintf(pathname
, sizeof(pathname
), "%s/%s", filename
, suffix
);
230 * See if we can stat the file/directory...
233 if (stat(filename
, &fileinfo
))
235 if (errno
== ENOENT
&& create_dir
)
238 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Creating missing directory \"%s\"",
241 if (mkdir(filename
, mode
))
244 cupsdLogMessage(CUPSD_LOG_ERROR
,
245 "Unable to create directory \"%s\" - %s", filename
,
248 syslog(LOG_ERR
, "Unable to create directory \"%s\" - %s", filename
,
257 return (create_dir
? -1 : 1);
261 * Make sure it's a regular file...
264 if (!dir_created
&& !is_dir
&& !S_ISREG(fileinfo
.st_mode
))
266 cupsdLogMessage(CUPSD_LOG_ERROR
, "\"%s\" is not a regular file!", filename
);
270 if (!dir_created
&& is_dir
&& !S_ISDIR(fileinfo
.st_mode
))
273 cupsdLogMessage(CUPSD_LOG_ERROR
, "\"%s\" is not a directory!", filename
);
275 syslog(LOG_ERR
, "\"%s\" is not a directory!", filename
);
281 * Fix owner, group, and mode as needed...
284 if (dir_created
|| fileinfo
.st_uid
!= user
|| fileinfo
.st_gid
!= group
)
287 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Repairing ownership of \"%s\"",
290 if (chown(filename
, user
, group
) && !getuid())
293 cupsdLogMessage(CUPSD_LOG_ERROR
,
294 "Unable to change ownership of \"%s\" - %s", filename
,
297 syslog(LOG_ERR
, "Unable to change ownership of \"%s\" - %s", filename
,
304 if (dir_created
|| (fileinfo
.st_mode
& 07777) != mode
)
307 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Repairing access permissions of \"%s\"",
310 if (chmod(filename
, mode
))
313 cupsdLogMessage(CUPSD_LOG_ERROR
,
314 "Unable to change permissions of \"%s\" - %s", filename
,
317 syslog(LOG_ERR
, "Unable to change permissions of \"%s\" - %s", filename
,
325 * Everything is OK...
333 * 'cupsdReadConfiguration()' - Read the cupsd.conf file.
336 int /* O - 1 on success, 0 otherwise */
337 cupsdReadConfiguration(void)
339 int i
; /* Looping var */
340 cups_file_t
*fp
; /* Configuration file */
341 int status
; /* Return status */
342 char temp
[1024], /* Temporary buffer */
343 *slash
; /* Directory separator */
344 cups_lang_t
*language
; /* Language */
345 struct passwd
*user
; /* Default user */
346 struct group
*group
; /* Default group */
347 char *old_serverroot
, /* Old ServerRoot */
348 *old_requestroot
; /* Old RequestRoot */
349 const char *tmpdir
; /* TMPDIR environment variable */
350 struct stat tmpinfo
; /* Temporary directory info */
354 * Save the old root paths...
357 old_serverroot
= NULL
;
358 cupsdSetString(&old_serverroot
, ServerRoot
);
359 old_requestroot
= NULL
;
360 cupsdSetString(&old_requestroot
, RequestRoot
);
363 * Reset the server configuration data...
366 cupsdDeleteAllLocations();
385 for (i
= 0; i
< NumRelays
; i
++)
386 if (Relays
[i
].from
.type
== AUTH_NAME
)
387 free(Relays
[i
].from
.mask
.name
.name
);
394 cupsdDeleteAllListeners();
400 cupsdSetString(&ServerName
, httpGetHostname(NULL
, temp
, sizeof(temp
)));
401 cupsdSetStringf(&ServerAdmin
, "root@%s", temp
);
402 cupsdSetString(&ServerBin
, CUPS_SERVERBIN
);
403 cupsdSetString(&RequestRoot
, CUPS_REQUESTS
);
404 cupsdSetString(&CacheDir
, CUPS_CACHEDIR
);
405 cupsdSetString(&DataDir
, CUPS_DATADIR
);
406 cupsdSetString(&DocumentRoot
, CUPS_DOCROOT
);
407 cupsdSetString(&AccessLog
, CUPS_LOGDIR
"/access_log");
408 cupsdSetString(&ErrorLog
, CUPS_LOGDIR
"/error_log");
409 cupsdSetString(&PageLog
, CUPS_LOGDIR
"/page_log");
410 cupsdSetString(&Printcap
, CUPS_DEFAULT_PRINTCAP
);
411 cupsdSetString(&PrintcapGUI
, "/usr/bin/glpoptions");
412 cupsdSetString(&FontPath
, CUPS_FONTPATH
);
413 cupsdSetString(&RemoteRoot
, "remroot");
414 cupsdSetString(&ServerHeader
, "CUPS/1.2");
415 cupsdSetString(&StateDir
, CUPS_STATEDIR
);
417 cupsdSetString(&GSSServiceName
, CUPS_DEFAULT_GSSSERVICENAME
);
418 #endif /* HAVE_GSSAPI */
420 if (!strcmp(CUPS_DEFAULT_PRINTCAP
, "/etc/printers.conf"))
421 PrintcapFormat
= PRINTCAP_SOLARIS
;
423 PrintcapFormat
= PRINTCAP_BSD
;
425 strlcpy(temp
, ConfigurationFile
, sizeof(temp
));
426 if ((slash
= strrchr(temp
, '/')) != NULL
)
429 cupsdSetString(&ServerRoot
, temp
);
431 cupsdClearString(&Classification
);
432 ClassifyOverride
= 0;
436 cupsdSetString(&ServerCertificate
, "/Library/Keychains/System.keychain");
438 cupsdSetString(&ServerCertificate
, "ssl/server.crt");
439 cupsdSetString(&ServerKey
, "ssl/server.key");
440 # endif /* HAVE_CDSASSL */
441 #endif /* HAVE_SSL */
443 language
= cupsLangDefault();
445 if (!strcmp(language
->language
, "C") || !strcmp(language
->language
, "POSIX"))
446 cupsdSetString(&DefaultLanguage
, "en");
448 cupsdSetString(&DefaultLanguage
, language
->language
);
450 cupsdSetString(&DefaultCharset
, _cupsEncodingName(language
->encoding
));
452 cupsdSetString(&RIPCache
, "8m");
454 cupsdSetString(&TempDir
, NULL
);
457 * Find the default user...
460 if ((user
= getpwnam(CUPS_DEFAULT_USER
)) != NULL
)
465 * Use the (historical) NFS nobody user ID (-2 as a 16-bit twos-
466 * complement number...)
475 * Find the default group...
478 group
= getgrnam(CUPS_DEFAULT_GROUP
);
482 Group
= group
->gr_gid
;
486 * Fallback to group "nobody"...
489 group
= getgrnam("nobody");
493 Group
= group
->gr_gid
;
497 * Use the (historical) NFS nobody group ID (-2 as a 16-bit twos-
498 * complement number...)
509 ConfigFilePerm
= CUPS_DEFAULT_CONFIG_FILE_PERM
;
510 DefaultAuthType
= AUTH_BASIC
;
512 DefaultEncryption
= HTTP_ENCRYPT_REQUIRED
;
513 #endif /* HAVE_SSL */
515 JobRetryInterval
= 300;
520 HostNameLookups
= FALSE
;
521 ImplicitClasses
= CUPS_DEFAULT_IMPLICIT_CLASSES
;
522 ImplicitAnyClasses
= FALSE
;
523 HideImplicitMembers
= TRUE
;
525 KeepAliveTimeout
= DEFAULT_KEEPALIVE
;
526 ListenBackLog
= SOMAXCONN
;
527 LogFilePerm
= CUPS_DEFAULT_LOG_FILE_PERM
;
528 LogLevel
= CUPSD_LOG_ERROR
;
530 MaxClientsPerHost
= 0;
531 MaxLogSize
= 1024 * 1024;
532 MaxPrinterHistory
= 10;
535 RootCertDuration
= 300;
536 Timeout
= DEFAULT_TIMEOUT
;
539 BrowseInterval
= DEFAULT_INTERVAL
;
540 BrowsePort
= ippPort();
541 BrowseLocalProtocols
= parse_protocols(CUPS_DEFAULT_BROWSE_LOCAL_PROTOCOLS
);
542 BrowseRemoteProtocols
= parse_protocols(CUPS_DEFAULT_BROWSE_REMOTE_PROTOCOLS
);
543 BrowseShortNames
= CUPS_DEFAULT_BROWSE_SHORT_NAMES
;
544 BrowseTimeout
= DEFAULT_TIMEOUT
;
545 Browsing
= CUPS_DEFAULT_BROWSING
;
546 DefaultShared
= CUPS_DEFAULT_DEFAULT_SHARED
;
548 cupsdClearString(&BrowseLocalOptions
);
549 cupsdClearString(&BrowseRemoteOptions
);
551 cupsdSetString(&ErrorPolicy
, "stop-printer");
554 cupsdClearString(&BrowseLDAPBindDN
);
555 cupsdClearString(&BrowseLDAPDN
);
556 cupsdClearString(&BrowseLDAPPassword
);
557 cupsdClearString(&BrowseLDAPServer
);
558 cupsdClearString(&BrowseLDAPCACertFile
);
559 #endif /* HAVE_LDAP */
561 JobHistory
= DEFAULT_HISTORY
;
562 JobFiles
= DEFAULT_FILES
;
567 MaxJobsPerPrinter
= 0;
568 MaxCopies
= CUPS_DEFAULT_MAX_COPIES
;
570 cupsdDeleteAllPolicies();
571 cupsdClearString(&DefaultPolicy
);
573 #ifdef HAVE_AUTHORIZATION_H
574 cupsdClearString(&SystemGroupAuthKey
);
575 #endif /* HAVE_AUTHORIZATION_H */
577 MaxSubscriptions
= 100;
578 MaxSubscriptionsPerJob
= 0;
579 MaxSubscriptionsPerPrinter
= 0;
580 MaxSubscriptionsPerUser
= 0;
581 DefaultLeaseDuration
= 86400;
582 MaxLeaseDuration
= 0;
585 LaunchdTimeout
= DEFAULT_TIMEOUT
+ 10;
586 cupsdSetString(&LaunchdConf
, CUPS_DEFAULT_LAUNCHD_CONF
);
587 #endif /* HAVE_LAUNCHD */
591 #endif /* __APPLE__ */
594 * Read the configuration file...
597 if ((fp
= cupsFileOpen(ConfigurationFile
, "r")) == NULL
)
600 status
= read_configuration(fp
);
610 * See if the ServerName is an IP address...
613 for (slash
= ServerName
; isdigit(*slash
& 255) || *slash
== '.'; slash
++);
615 ServerNameIsIP
= !*slash
;
618 * Use the default system group if none was supplied in cupsd.conf...
621 if (NumSystemGroups
== 0)
623 if (!parse_groups(CUPS_DEFAULT_SYSTEM_GROUPS
))
626 * Find the group associated with GID 0...
633 cupsdSetString(&SystemGroups
[0], group
->gr_name
);
635 cupsdSetString(&SystemGroups
[0], "unknown");
637 SystemGroupIDs
[0] = 0;
643 * Get the access control list for browsing...
646 BrowseACL
= cupsdFindLocation("CUPS_INTERNAL_BROWSE_ACL");
649 * Open the system log for cupsd if necessary...
653 if (!strcmp(AccessLog
, "syslog") ||
654 !strcmp(ErrorLog
, "syslog") ||
655 !strcmp(PageLog
, "syslog"))
656 openlog("cupsd", LOG_PID
| LOG_NOWAIT
| LOG_NDELAY
, LOG_LPR
);
657 #endif /* HAVE_VSYSLOG */
660 * Log the configuration file that was used...
663 cupsdLogMessage(CUPSD_LOG_INFO
, "Loaded configuration file \"%s\"",
667 * Validate the Group and SystemGroup settings - they cannot be the same,
668 * otherwise the CGI programs will be able to authenticate as root without
674 for (i
= 0; i
< NumSystemGroups
; i
++)
675 if (Group
== SystemGroupIDs
[i
])
678 if (i
< NumSystemGroups
)
681 * Log the error and reset the group to a safe value...
684 cupsdLogMessage(CUPSD_LOG_NOTICE
,
685 "Group and SystemGroup cannot use the same groups!");
686 cupsdLogMessage(CUPSD_LOG_INFO
, "Resetting Group to \"nobody\"...");
688 group
= getgrnam("nobody");
692 Group
= group
->gr_gid
;
696 * Use the (historical) NFS nobody group ID (-2 as a 16-bit twos-
697 * complement number...)
706 * Check that we have at least one listen/port line; if not, report this
707 * as an error and exit!
710 if (cupsArrayCount(Listeners
) == 0)
716 cupsdLogMessage(CUPSD_LOG_EMERG
,
717 "No valid Listen or Port lines were found in the configuration file!");
723 cupsdEndProcess(getpid(), 0);
727 * Set the default locale using the language and charset...
730 cupsdSetStringf(&DefaultLocale
, "%s.%s", DefaultLanguage
, DefaultCharset
);
733 * Update all relative filenames to include the full path from ServerRoot...
736 if (DocumentRoot
[0] != '/')
737 cupsdSetStringf(&DocumentRoot
, "%s/%s", ServerRoot
, DocumentRoot
);
739 if (RequestRoot
[0] != '/')
740 cupsdSetStringf(&RequestRoot
, "%s/%s", ServerRoot
, RequestRoot
);
742 if (ServerBin
[0] != '/')
743 cupsdSetStringf(&ServerBin
, "%s/%s", ServerRoot
, ServerBin
);
745 if (StateDir
[0] != '/')
746 cupsdSetStringf(&StateDir
, "%s/%s", ServerRoot
, StateDir
);
748 if (CacheDir
[0] != '/')
749 cupsdSetStringf(&CacheDir
, "%s/%s", ServerRoot
, CacheDir
);
752 if (ServerCertificate
[0] != '/')
753 cupsdSetStringf(&ServerCertificate
, "%s/%s", ServerRoot
, ServerCertificate
);
755 if (!strncmp(ServerRoot
, ServerCertificate
, strlen(ServerRoot
)))
757 chown(ServerCertificate
, RunUser
, Group
);
758 chmod(ServerCertificate
, 0600);
761 # if defined(HAVE_LIBSSL) || defined(HAVE_GNUTLS)
762 if (ServerKey
[0] != '/')
763 cupsdSetStringf(&ServerKey
, "%s/%s", ServerRoot
, ServerKey
);
765 if (!strncmp(ServerRoot
, ServerKey
, strlen(ServerRoot
)))
767 chown(ServerKey
, RunUser
, Group
);
768 chmod(ServerKey
, 0600);
770 # endif /* HAVE_LIBSSL || HAVE_GNUTLS */
771 #endif /* HAVE_SSL */
774 * Make sure that directories and config files are owned and
775 * writable by the user and group in the cupsd.conf file...
778 if (cupsdCheckPermissions(RequestRoot
, NULL
, 0710, RunUser
,
780 cupsdCheckPermissions(CacheDir
, NULL
, 0775, RunUser
,
782 cupsdCheckPermissions(StateDir
, NULL
, 0755, RunUser
,
784 cupsdCheckPermissions(StateDir
, "certs", RunUser
? 0711 : 0511, User
,
785 SystemGroupIDs
[0], 1, 1) < 0 ||
786 cupsdCheckPermissions(ServerRoot
, NULL
, 0755, RunUser
,
788 cupsdCheckPermissions(ServerRoot
, "ppd", 0755, RunUser
,
790 cupsdCheckPermissions(ServerRoot
, "ssl", 0700, RunUser
,
792 cupsdCheckPermissions(ServerRoot
, "cupsd.conf", ConfigFilePerm
, RunUser
,
794 cupsdCheckPermissions(ServerRoot
, "classes.conf", 0600, RunUser
,
796 cupsdCheckPermissions(ServerRoot
, "printers.conf", 0600, RunUser
,
798 cupsdCheckPermissions(ServerRoot
, "passwd.md5", 0600, User
,
803 * Update TempDir to the default if it hasn't been set already...
808 if ((tmpdir
= getenv("TMPDIR")) != NULL
)
811 * TMPDIR is defined, see if it is OK for us to use...
814 if (stat(tmpdir
, &tmpinfo
))
815 cupsdLogMessage(CUPSD_LOG_ERROR
, "Unable to access TMPDIR (%s): %s",
816 tmpdir
, strerror(errno
));
817 else if (!S_ISDIR(tmpinfo
.st_mode
))
818 cupsdLogMessage(CUPSD_LOG_ERROR
, "TMPDIR (%s) is not a directory!",
820 else if ((tmpinfo
.st_uid
!= User
|| !(tmpinfo
.st_mode
& S_IWUSR
)) &&
821 (tmpinfo
.st_gid
!= Group
|| !(tmpinfo
.st_mode
& S_IWGRP
)) &&
822 !(tmpinfo
.st_mode
& S_IWOTH
))
823 cupsdLogMessage(CUPSD_LOG_ERROR
,
824 "TMPDIR (%s) has the wrong permissions!", tmpdir
);
826 cupsdSetString(&TempDir
, tmpdir
);
831 cupsdLogMessage(CUPSD_LOG_INFO
, "Using default TempDir of %s/tmp...",
833 cupsdSetStringf(&TempDir
, "%s/tmp", RequestRoot
);
838 * Make sure the temporary directory has the right permissions...
841 if (!strncmp(TempDir
, RequestRoot
, strlen(RequestRoot
)) ||
845 * Update ownership and permissions if the CUPS temp directory
846 * is under the spool directory or does not exist...
849 if (cupsdCheckPermissions(TempDir
, NULL
, 01770, RunUser
, Group
, 1, 1) < 0)
854 * Setup environment variables...
860 * Check the MaxClients setting, and then allocate memory for it...
863 if (MaxClients
> (MaxFDs
/ 3) || MaxClients
<= 0)
866 cupsdLogMessage(CUPSD_LOG_INFO
, "MaxClients limited to 1/3 (%d) of the file descriptor limit (%d)...",
869 MaxClients
= MaxFDs
/ 3;
872 cupsdLogMessage(CUPSD_LOG_INFO
, "Configured for up to %d clients.",
876 * Check the MaxActiveJobs setting; limit to 1/3 the available
877 * file descriptors, since we need a pipe for each job...
880 if (MaxActiveJobs
> (MaxFDs
/ 3))
881 MaxActiveJobs
= MaxFDs
/ 3;
883 if (Classification
&& !strcasecmp(Classification
, "none"))
884 cupsdClearString(&Classification
);
887 cupsdLogMessage(CUPSD_LOG_INFO
, "Security set to \"%s\"", Classification
);
890 * Update the MaxClientsPerHost value, as needed...
893 if (MaxClientsPerHost
<= 0)
894 MaxClientsPerHost
= MaxClients
;
896 if (MaxClientsPerHost
> MaxClients
)
897 MaxClientsPerHost
= MaxClients
;
899 cupsdLogMessage(CUPSD_LOG_INFO
,
900 "Allowing up to %d client connections per host.",
904 * Make sure that BrowseTimeout is at least twice the interval...
907 if (BrowseTimeout
< (2 * BrowseInterval
) || BrowseTimeout
<= 0)
909 cupsdLogMessage(CUPSD_LOG_ALERT
, "Invalid BrowseTimeout value %d!",
913 BrowseTimeout
= BrowseInterval
* 2;
915 BrowseTimeout
= DEFAULT_TIMEOUT
;
917 cupsdLogMessage(CUPSD_LOG_ALERT
, "Reset BrowseTimeout to %d!",
922 * Update the default policy, as needed...
926 DefaultPolicyPtr
= cupsdFindPolicy(DefaultPolicy
);
928 DefaultPolicyPtr
= NULL
;
930 if (!DefaultPolicyPtr
)
932 cupsd_policy_t
*p
; /* New policy */
933 cupsd_location_t
*po
; /* New policy operation */
937 cupsdLogMessage(CUPSD_LOG_ERROR
, "Default policy \"%s\" not found!",
940 cupsdSetString(&DefaultPolicy
, "default");
942 if ((DefaultPolicyPtr
= cupsdFindPolicy("default")) != NULL
)
943 cupsdLogMessage(CUPSD_LOG_INFO
,
944 "Using policy \"default\" as the default!");
947 cupsdLogMessage(CUPSD_LOG_INFO
,
948 "Creating CUPS default administrative policy:");
950 DefaultPolicyPtr
= p
= cupsdAddPolicy("default");
952 cupsdLogMessage(CUPSD_LOG_INFO
, "<Policy default>");
953 cupsdLogMessage(CUPSD_LOG_INFO
,
954 "<Limit Send-Document Send-URI Cancel-Job Hold-Job "
955 "Release-Job Restart-Job Purge-Jobs "
956 "Set-Job-Attributes Create-Job-Subscription "
957 "Renew-Subscription Cancel-Subscription "
958 "Get-Notifications Reprocess-Job Cancel-Current-Job "
959 "Suspend-Current-Job Resume-Job CUPS-Move-Job "
960 "CUPS-Authenticate-Job>");
961 cupsdLogMessage(CUPSD_LOG_INFO
, "Order Deny,Allow");
963 po
= cupsdAddPolicyOp(p
, NULL
, IPP_SEND_DOCUMENT
);
964 po
->order_type
= AUTH_ALLOW
;
965 po
->level
= AUTH_USER
;
967 cupsdAddName(po
, "@OWNER");
968 cupsdAddName(po
, "@SYSTEM");
969 cupsdLogMessage(CUPSD_LOG_INFO
, "Require user @OWNER @SYSTEM");
971 cupsdAddPolicyOp(p
, po
, IPP_SEND_URI
);
972 cupsdAddPolicyOp(p
, po
, IPP_CANCEL_JOB
);
973 cupsdAddPolicyOp(p
, po
, IPP_HOLD_JOB
);
974 cupsdAddPolicyOp(p
, po
, IPP_RELEASE_JOB
);
975 cupsdAddPolicyOp(p
, po
, IPP_RESTART_JOB
);
976 cupsdAddPolicyOp(p
, po
, IPP_PURGE_JOBS
);
977 cupsdAddPolicyOp(p
, po
, IPP_SET_JOB_ATTRIBUTES
);
978 cupsdAddPolicyOp(p
, po
, IPP_CREATE_JOB_SUBSCRIPTION
);
979 cupsdAddPolicyOp(p
, po
, IPP_RENEW_SUBSCRIPTION
);
980 cupsdAddPolicyOp(p
, po
, IPP_CANCEL_SUBSCRIPTION
);
981 cupsdAddPolicyOp(p
, po
, IPP_GET_NOTIFICATIONS
);
982 cupsdAddPolicyOp(p
, po
, IPP_REPROCESS_JOB
);
983 cupsdAddPolicyOp(p
, po
, IPP_CANCEL_CURRENT_JOB
);
984 cupsdAddPolicyOp(p
, po
, IPP_SUSPEND_CURRENT_JOB
);
985 cupsdAddPolicyOp(p
, po
, IPP_RESUME_JOB
);
986 cupsdAddPolicyOp(p
, po
, CUPS_MOVE_JOB
);
987 cupsdAddPolicyOp(p
, po
, CUPS_AUTHENTICATE_JOB
);
989 cupsdLogMessage(CUPSD_LOG_INFO
, "</Limit>");
991 cupsdLogMessage(CUPSD_LOG_INFO
,
992 "<Limit Pause-Printer Resume-Printer "
993 "Set-Printer-Attributes Enable-Printer "
994 "Disable-Printer Pause-Printer-After-Current-Job "
995 "Hold-New-Jobs Release-Held-New-Jobs "
996 "Deactivate-Printer Activate-Printer Restart-Printer "
997 "Shutdown-Printer Startup-Printer Promote-Job "
998 "Schedule-Job-After CUPS-Add-Printer "
999 "CUPS-Delete-Printer CUPS-Add-Class CUPS-Delete-Class "
1000 "CUPS-Accept-Jobs CUPS-Reject-Jobs CUPS-Set-Default>");
1001 cupsdLogMessage(CUPSD_LOG_INFO
, "Order Deny,Allow");
1002 cupsdLogMessage(CUPSD_LOG_INFO
, "AuthType Default");
1004 po
= cupsdAddPolicyOp(p
, NULL
, IPP_PAUSE_PRINTER
);
1005 po
->order_type
= AUTH_ALLOW
;
1006 po
->type
= DefaultAuthType
;
1007 po
->level
= AUTH_USER
;
1009 cupsdAddName(po
, "@SYSTEM");
1010 cupsdLogMessage(CUPSD_LOG_INFO
, "Require user @SYSTEM");
1012 cupsdAddPolicyOp(p
, po
, IPP_RESUME_PRINTER
);
1013 cupsdAddPolicyOp(p
, po
, IPP_SET_PRINTER_ATTRIBUTES
);
1014 cupsdAddPolicyOp(p
, po
, IPP_ENABLE_PRINTER
);
1015 cupsdAddPolicyOp(p
, po
, IPP_DISABLE_PRINTER
);
1016 cupsdAddPolicyOp(p
, po
, IPP_PAUSE_PRINTER_AFTER_CURRENT_JOB
);
1017 cupsdAddPolicyOp(p
, po
, IPP_HOLD_NEW_JOBS
);
1018 cupsdAddPolicyOp(p
, po
, IPP_RELEASE_HELD_NEW_JOBS
);
1019 cupsdAddPolicyOp(p
, po
, IPP_DEACTIVATE_PRINTER
);
1020 cupsdAddPolicyOp(p
, po
, IPP_ACTIVATE_PRINTER
);
1021 cupsdAddPolicyOp(p
, po
, IPP_RESTART_PRINTER
);
1022 cupsdAddPolicyOp(p
, po
, IPP_SHUTDOWN_PRINTER
);
1023 cupsdAddPolicyOp(p
, po
, IPP_STARTUP_PRINTER
);
1024 cupsdAddPolicyOp(p
, po
, IPP_PROMOTE_JOB
);
1025 cupsdAddPolicyOp(p
, po
, IPP_SCHEDULE_JOB_AFTER
);
1026 cupsdAddPolicyOp(p
, po
, CUPS_ADD_PRINTER
);
1027 cupsdAddPolicyOp(p
, po
, CUPS_DELETE_PRINTER
);
1028 cupsdAddPolicyOp(p
, po
, CUPS_ADD_CLASS
);
1029 cupsdAddPolicyOp(p
, po
, CUPS_DELETE_CLASS
);
1030 cupsdAddPolicyOp(p
, po
, CUPS_ACCEPT_JOBS
);
1031 cupsdAddPolicyOp(p
, po
, CUPS_REJECT_JOBS
);
1032 cupsdAddPolicyOp(p
, po
, CUPS_SET_DEFAULT
);
1034 cupsdLogMessage(CUPSD_LOG_INFO
, "</Limit>");
1036 cupsdLogMessage(CUPSD_LOG_INFO
, "<Limit All>");
1037 cupsdLogMessage(CUPSD_LOG_INFO
, "Order Deny,Allow");
1039 po
= cupsdAddPolicyOp(p
, NULL
, IPP_ANY_OPERATION
);
1040 po
->order_type
= AUTH_ALLOW
;
1042 cupsdLogMessage(CUPSD_LOG_INFO
, "</Limit>");
1043 cupsdLogMessage(CUPSD_LOG_INFO
, "</Policy>");
1047 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "cupsdReadConfiguration: NumPolicies=%d",
1049 for (i
= 0; i
< NumPolicies
; i
++)
1050 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
1051 "cupsdReadConfiguration: Policies[%d]=\"%s\"", i
,
1055 * If we are doing a full reload or the server root has changed, flush
1056 * the jobs, printers, etc. and start from scratch...
1059 if (NeedReload
== RELOAD_ALL
||
1060 !old_serverroot
|| !ServerRoot
|| strcmp(old_serverroot
, ServerRoot
) ||
1061 !old_requestroot
|| !RequestRoot
|| strcmp(old_requestroot
, RequestRoot
))
1063 mime_type_t
*type
; /* Current type */
1064 char mimetype
[MIME_MAX_SUPER
+ MIME_MAX_TYPE
];
1065 /* MIME type name */
1068 cupsdLogMessage(CUPSD_LOG_INFO
, "Full reload is required.");
1071 * Free all memory...
1074 cupsdDeleteAllSubscriptions();
1076 cupsdDeleteAllClasses();
1077 cupsdDeleteAllPrinters();
1079 DefaultPrinter
= NULL
;
1081 if (MimeDatabase
!= NULL
)
1082 mimeDelete(MimeDatabase
);
1086 for (i
= 0; i
< NumMimeTypes
; i
++)
1087 _cupsStrFree(MimeTypes
[i
]);
1093 * Read the MIME type and conversion database...
1096 snprintf(temp
, sizeof(temp
), "%s/filter", ServerBin
);
1098 MimeDatabase
= mimeLoad(ServerRoot
, temp
);
1102 cupsdLogMessage(CUPSD_LOG_EMERG
,
1103 "Unable to load MIME database from \'%s\'!", ServerRoot
);
1107 cupsdLogMessage(CUPSD_LOG_INFO
,
1108 "Loaded MIME database from \'%s\': %d types, %d filters...",
1109 ServerRoot
, mimeNumTypes(MimeDatabase
),
1110 mimeNumFilters(MimeDatabase
));
1113 * Create a list of MIME types for the document-format-supported
1117 NumMimeTypes
= mimeNumTypes(MimeDatabase
);
1118 if (!mimeType(MimeDatabase
, "application", "octet-stream"))
1121 MimeTypes
= calloc(NumMimeTypes
, sizeof(const char *));
1123 for (i
= 0, type
= mimeFirstType(MimeDatabase
);
1125 i
++, type
= mimeNextType(MimeDatabase
))
1127 snprintf(mimetype
, sizeof(mimetype
), "%s/%s", type
->super
, type
->type
);
1129 MimeTypes
[i
] = _cupsStrAlloc(mimetype
);
1132 if (i
< NumMimeTypes
)
1133 MimeTypes
[i
] = _cupsStrAlloc("application/octet-stream");
1135 if (LogLevel
== CUPSD_LOG_DEBUG2
)
1137 mime_filter_t
*filter
; /* Current filter */
1140 for (type
= mimeFirstType(MimeDatabase
);
1142 type
= mimeNextType(MimeDatabase
))
1143 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "cupsdReadConfiguration: type %s/%s",
1144 type
->super
, type
->type
);
1146 for (filter
= mimeFirstFilter(MimeDatabase
);
1148 filter
= mimeNextFilter(MimeDatabase
))
1149 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
1150 "cupsdReadConfiguration: filter %s/%s to %s/%s %d %s",
1151 filter
->src
->super
, filter
->src
->type
,
1152 filter
->dst
->super
, filter
->dst
->type
,
1153 filter
->cost
, filter
->filter
);
1160 snprintf(temp
, sizeof(temp
), "%s/banners", DataDir
);
1161 cupsdLoadBanners(temp
);
1164 * Load printers and classes...
1167 cupsdLoadAllPrinters();
1168 cupsdLoadAllClasses();
1169 cupsdLoadRemoteCache();
1170 cupsdWritePrintcap();
1172 cupsdCreateCommonData();
1175 * Load queued jobs...
1181 * Load subscriptions...
1184 cupsdLoadAllSubscriptions();
1186 cupsdLogMessage(CUPSD_LOG_INFO
, "Full reload complete.");
1191 * Not a full reload, so recreate the common printer attributes...
1194 cupsdCreateCommonData();
1197 * Update all printers as needed...
1200 cupsdUpdatePrinters();
1201 cupsdWritePrintcap();
1203 cupsdLogMessage(CUPSD_LOG_INFO
, "Partial reload complete.");
1207 * Reset the reload state...
1210 NeedReload
= RELOAD_NONE
;
1212 cupsdClearString(&old_serverroot
);
1213 cupsdClearString(&old_requestroot
);
1220 * 'get_address()' - Get an address + port number from a line.
1223 static http_addrlist_t
* /* O - Pointer to list if address good, NULL if bad */
1224 get_address(const char *value
, /* I - Value string */
1225 int defport
) /* I - Default port */
1227 char buffer
[1024], /* Hostname + port number buffer */
1228 defpname
[255], /* Default port name */
1229 *hostname
, /* Hostname or IP */
1230 *portname
; /* Port number or name */
1231 http_addrlist_t
*addrlist
; /* Address list */
1235 * Check for an empty value...
1240 cupsdLogMessage(CUPSD_LOG_ERROR
, "Bad (empty) address!");
1245 * Grab a hostname and port number; if there is no colon and the port name
1246 * is only digits, then we have a port number by itself...
1249 strlcpy(buffer
, value
, sizeof(buffer
));
1251 if ((portname
= strrchr(buffer
, ':')) != NULL
&& !strchr(portname
, ']'))
1258 for (portname
= buffer
; isdigit(*portname
& 255); portname
++);
1263 * Use the default port...
1266 sprintf(defpname
, "%d", defport
);
1267 portname
= defpname
;
1273 * The buffer contains just a port number...
1281 if (hostname
&& !strcmp(hostname
, "*"))
1285 * Now lookup the address using httpAddrGetList()...
1288 if ((addrlist
= httpAddrGetList(hostname
, AF_UNSPEC
, portname
)) == NULL
)
1289 cupsdLogMessage(CUPSD_LOG_ERROR
, "Hostname lookup for \"%s\" failed!",
1290 hostname
? hostname
: "(nil)");
1297 * 'get_addr_and_mask()' - Get an IP address and netmask.
1300 static int /* O - 1 on success, 0 on failure */
1301 get_addr_and_mask(const char *value
, /* I - String from config file */
1302 unsigned *ip
, /* O - Address value */
1303 unsigned *mask
) /* O - Mask value */
1305 int i
, j
, /* Looping vars */
1306 family
, /* Address family */
1307 ipcount
; /* Count of fields in address */
1308 unsigned ipval
; /* Value */
1309 const char *maskval
, /* Pointer to start of mask value */
1310 *ptr
, /* Pointer into value */
1315 * Get the address...
1318 ip
[0] = ip
[1] = ip
[2] = ip
[3] = 0x00000000;
1319 mask
[0] = mask
[1] = mask
[2] = mask
[3] = 0xffffffff;
1321 if ((maskval
= strchr(value
, '/')) != NULL
)
1324 maskval
= value
+ strlen(value
);
1328 * Check for an IPv6 address...
1334 * Parse hexadecimal IPv6 address...
1339 for (i
= 0, ptr
= value
+ 1; *ptr
&& i
< 8; i
++)
1343 else if (!strncmp(ptr
, "::", 2))
1345 for (ptr2
= strchr(ptr
+ 2, ':'), j
= 0;
1347 ptr2
= strchr(ptr2
+ 1, ':'), j
++);
1352 else if (isxdigit(*ptr
& 255))
1354 ipval
= strtoul(ptr
, (char **)&ptr
, 16);
1362 ip
[i
/ 2] |= ipval
<< 16;
1376 if (*ptr
&& *ptr
!= '/')
1380 #endif /* AF_INET6 */
1383 * Parse dotted-decimal IPv4 address...
1386 unsigned val
[4]; /* IPv4 address values */
1390 ipcount
= sscanf(value
, "%u.%u.%u.%u", val
+ 0, val
+ 1, val
+ 2, val
+ 3);
1393 * Range check the IP numbers...
1396 for (i
= 0; i
< ipcount
; i
++)
1401 * Make sure the trailing values are zeroed, as some C libraries like
1402 * glibc apparently like to fill the unused arguments with garbage...
1405 for (i
= ipcount
; i
< 4; i
++)
1409 * Merge everything into a 32-bit IPv4 address in ip[3]...
1412 ip
[3] = (((((val
[0] << 8) | val
[1]) << 8) | val
[2]) << 8) | val
[3];
1415 mask
[3] = (0xffffffff << (32 - 8 * ipcount
)) & 0xffffffff;
1421 * Get the netmask value(s)...
1424 memset(mask
, 0, sizeof(unsigned) * 4);
1426 if (strchr(maskval
, '.'))
1429 * Get dotted-decimal mask...
1432 if (family
!= AF_INET
)
1435 if (sscanf(maskval
, "%u.%u.%u.%u", mask
+ 0, mask
+ 1, mask
+ 2, mask
+ 3) != 4)
1438 mask
[3] |= ((((mask
[0] << 8) | mask
[1]) << 8) | mask
[2]) << 8;
1439 mask
[0] = mask
[1] = mask
[2] = 0;
1444 * Get address/bits format...
1450 if (family
== AF_INET6
)
1458 mask
[0] = 0xffffffff;
1460 mask
[0] = (0xffffffff << (i
- 96)) & 0xffffffff;
1463 mask
[1] = 0xffffffff;
1467 mask
[1] = (0xffffffff << (i
- 64)) & 0xffffffff;
1470 mask
[2] = 0xffffffff;
1474 mask
[2] = (0xffffffff << (i
- 32)) & 0xffffffff;
1477 mask
[3] = 0xffffffff;
1481 mask
[3] = (0xffffffff << i
) & 0xffffffff;
1484 #endif /* AF_INET6 */
1489 mask
[0] = 0xffffffff;
1490 mask
[1] = 0xffffffff;
1491 mask
[2] = 0xffffffff;
1494 mask
[3] = (0xffffffff << (32 - i
)) & 0xffffffff;
1496 mask
[3] = 0xffffffff;
1501 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
1502 "get_addr_and_mask(value=\"%s\", "
1503 "ip=[%08x:%08x:%08x:%08x], mask=[%08x:%08x:%08x:%08x])",
1504 value
, ip
[0], ip
[1], ip
[2], ip
[3], mask
[0], mask
[1], mask
[2],
1508 * Check for a valid netmask; no fallback like in CUPS 1.1.x!
1511 if ((ip
[0] & ~mask
[0]) != 0 ||
1512 (ip
[1] & ~mask
[1]) != 0 ||
1513 (ip
[2] & ~mask
[2]) != 0 ||
1514 (ip
[3] & ~mask
[3]) != 0)
1522 * 'parse_aaa()' - Parse authentication, authorization, and access control lines.
1525 static int /* O - 1 on success, 0 on failure */
1526 parse_aaa(cupsd_location_t
*loc
, /* I - Location */
1527 char *line
, /* I - Line from file */
1528 char *value
, /* I - Start of value data */
1529 int linenum
) /* I - Current line number */
1531 char *valptr
; /* Pointer into value */
1532 unsigned ip
[4], /* IP address components */
1533 mask
[4]; /* IP netmask components */
1536 if (!strcasecmp(line
, "Encryption"))
1539 * "Encryption xxx" - set required encryption level...
1542 if (!strcasecmp(value
, "never"))
1543 loc
->encryption
= HTTP_ENCRYPT_NEVER
;
1544 else if (!strcasecmp(value
, "always"))
1546 cupsdLogMessage(CUPSD_LOG_ERROR
,
1547 "Encryption value \"%s\" on line %d is invalid in this "
1548 "context. Using \"required\" instead.", value
, linenum
);
1550 loc
->encryption
= HTTP_ENCRYPT_REQUIRED
;
1552 else if (!strcasecmp(value
, "required"))
1553 loc
->encryption
= HTTP_ENCRYPT_REQUIRED
;
1554 else if (!strcasecmp(value
, "ifrequested"))
1555 loc
->encryption
= HTTP_ENCRYPT_IF_REQUESTED
;
1558 cupsdLogMessage(CUPSD_LOG_ERROR
,
1559 "Unknown Encryption value %s on line %d.", value
, linenum
);
1563 else if (!strcasecmp(line
, "Order"))
1566 * "Order Deny,Allow" or "Order Allow,Deny"...
1569 if (!strncasecmp(value
, "deny", 4))
1570 loc
->order_type
= AUTH_ALLOW
;
1571 else if (!strncasecmp(value
, "allow", 5))
1572 loc
->order_type
= AUTH_DENY
;
1575 cupsdLogMessage(CUPSD_LOG_ERROR
, "Unknown Order value %s on line %d.",
1580 else if (!strcasecmp(line
, "Allow") || !strcasecmp(line
, "Deny"))
1583 * Allow [From] host/ip...
1584 * Deny [From] host/ip...
1587 if (!strncasecmp(value
, "from", 4))
1590 * Strip leading "from"...
1595 while (isspace(*value
& 255))
1600 * Figure out what form the allow/deny address takes:
1611 * nnn.nnn.nnn.nnn/mm
1612 * nnn.nnn.nnn.nnn/mmm.mmm.mmm.mmm
1615 if (!strcasecmp(value
, "all"))
1621 if (!strcasecmp(line
, "Allow"))
1622 cupsdAllowIP(loc
, zeros
, zeros
);
1624 cupsdDenyIP(loc
, zeros
, zeros
);
1626 else if (!strcasecmp(value
, "none"))
1632 if (!strcasecmp(line
, "Allow"))
1633 cupsdAllowIP(loc
, ones
, zeros
);
1635 cupsdDenyIP(loc
, ones
, zeros
);
1638 else if (value
[0] == '*' || value
[0] == '.' ||
1639 (!isdigit(value
[0] & 255) && value
[0] != '['))
1641 else if (value
[0] == '*' || value
[0] == '.' || !isdigit(value
[0] & 255))
1642 #endif /* AF_INET6 */
1645 * Host or domain name...
1648 if (value
[0] == '*')
1651 if (!strcasecmp(line
, "Allow"))
1652 cupsdAllowHost(loc
, value
);
1654 cupsdDenyHost(loc
, value
);
1659 * One of many IP address forms...
1662 if (!get_addr_and_mask(value
, ip
, mask
))
1664 cupsdLogMessage(CUPSD_LOG_ERROR
, "Bad netmask value %s on line %d.",
1669 if (!strcasecmp(line
, "Allow"))
1670 cupsdAllowIP(loc
, ip
, mask
);
1672 cupsdDenyIP(loc
, ip
, mask
);
1675 else if (!strcasecmp(line
, "AuthType"))
1678 * AuthType {none,basic,digest,basicdigest,negotiate,default}
1681 if (!strcasecmp(value
, "none"))
1683 loc
->type
= AUTH_NONE
;
1684 loc
->level
= AUTH_ANON
;
1686 else if (!strcasecmp(value
, "basic"))
1688 loc
->type
= AUTH_BASIC
;
1690 if (loc
->level
== AUTH_ANON
)
1691 loc
->level
= AUTH_USER
;
1693 else if (!strcasecmp(value
, "digest"))
1695 loc
->type
= AUTH_DIGEST
;
1697 if (loc
->level
== AUTH_ANON
)
1698 loc
->level
= AUTH_USER
;
1700 else if (!strcasecmp(value
, "basicdigest"))
1702 loc
->type
= AUTH_BASICDIGEST
;
1704 if (loc
->level
== AUTH_ANON
)
1705 loc
->level
= AUTH_USER
;
1707 else if (!strcasecmp(value
, "default"))
1709 loc
->type
= DefaultAuthType
;
1711 if (loc
->level
== AUTH_ANON
)
1712 loc
->level
= AUTH_USER
;
1715 else if (!strcasecmp(value
, "negotiate"))
1717 loc
->type
= AUTH_NEGOTIATE
;
1719 if (loc
->level
== AUTH_ANON
)
1720 loc
->level
= AUTH_USER
;
1722 #endif /* HAVE_GSSAPI */
1725 cupsdLogMessage(CUPSD_LOG_WARN
,
1726 "Unknown authorization type %s on line %d.",
1731 else if (!strcasecmp(line
, "AuthClass"))
1734 * AuthClass anonymous, user, system, group
1737 if (!strcasecmp(value
, "anonymous"))
1739 loc
->type
= AUTH_NONE
;
1740 loc
->level
= AUTH_ANON
;
1742 cupsdLogMessage(CUPSD_LOG_WARN
,
1743 "\"AuthClass %s\" is deprecated; consider removing "
1747 else if (!strcasecmp(value
, "user"))
1749 loc
->level
= AUTH_USER
;
1751 cupsdLogMessage(CUPSD_LOG_WARN
,
1752 "\"AuthClass %s\" is deprecated; consider using "
1753 "\"Require valid-user\" on line %d.",
1756 else if (!strcasecmp(value
, "group"))
1758 loc
->level
= AUTH_GROUP
;
1760 cupsdLogMessage(CUPSD_LOG_WARN
,
1761 "\"AuthClass %s\" is deprecated; consider using "
1762 "\"Require user @groupname\" on line %d.",
1765 else if (!strcasecmp(value
, "system"))
1767 loc
->level
= AUTH_GROUP
;
1769 cupsdAddName(loc
, "@SYSTEM");
1771 cupsdLogMessage(CUPSD_LOG_WARN
,
1772 "\"AuthClass %s\" is deprecated; consider using "
1773 "\"Require user @SYSTEM\" on line %d.",
1778 cupsdLogMessage(CUPSD_LOG_WARN
,
1779 "Unknown authorization class %s on line %d.",
1784 else if (!strcasecmp(line
, "AuthGroupName"))
1786 cupsdAddName(loc
, value
);
1788 cupsdLogMessage(CUPSD_LOG_WARN
,
1789 "\"AuthGroupName %s\" directive is deprecated; consider "
1790 "using \"Require user @%s\" on line %d.",
1791 value
, value
, linenum
);
1793 else if (!strcasecmp(line
, "Require"))
1796 * Apache synonym for AuthClass and AuthGroupName...
1800 * Require valid-user
1801 * Require group names
1802 * Require user names
1805 for (valptr
= value
; !isspace(*valptr
& 255) && *valptr
; valptr
++);
1810 if (!strcasecmp(value
, "valid-user") ||
1811 !strcasecmp(value
, "user"))
1812 loc
->level
= AUTH_USER
;
1813 else if (!strcasecmp(value
, "group"))
1814 loc
->level
= AUTH_GROUP
;
1817 cupsdLogMessage(CUPSD_LOG_WARN
, "Unknown Require type %s on line %d.",
1823 * Get the list of names from the line...
1826 for (value
= valptr
; *value
;)
1828 while (isspace(*value
& 255))
1831 #ifdef HAVE_AUTHORIZATION_H
1832 if (!strncmp(value
, "@AUTHKEY(", 9))
1835 * Grab "@AUTHKEY(name)" value...
1838 for (valptr
= value
+ 9; *valptr
!= ')' && *valptr
; valptr
++);
1844 #endif /* HAVE_AUTHORIZATION_H */
1845 if (*value
== '\"' || *value
== '\'')
1848 * Grab quoted name...
1851 for (valptr
= value
+ 1; *valptr
!= *value
&& *valptr
; valptr
++);
1858 * Grab literal name.
1861 for (valptr
= value
; !isspace(*valptr
& 255) && *valptr
; valptr
++);
1867 cupsdAddName(loc
, value
);
1869 for (value
= valptr
; isspace(*value
& 255); value
++);
1872 else if (!strcasecmp(line
, "Satisfy"))
1874 if (!strcasecmp(value
, "all"))
1875 loc
->satisfy
= AUTH_SATISFY_ALL
;
1876 else if (!strcasecmp(value
, "any"))
1877 loc
->satisfy
= AUTH_SATISFY_ANY
;
1880 cupsdLogMessage(CUPSD_LOG_WARN
, "Unknown Satisfy value %s on line %d.",
1893 * 'parse_groups()' - Parse system group names in a string.
1896 static int /* O - 1 on success, 0 on failure */
1897 parse_groups(const char *s
) /* I - Space-delimited groups */
1899 int status
; /* Return status */
1900 char value
[1024], /* Value string */
1901 *valstart
, /* Pointer into value */
1902 *valend
, /* End of value */
1903 quote
; /* Quote character */
1904 struct group
*group
; /* Group */
1908 * Make a copy of the string and parse out the groups...
1911 strlcpy(value
, s
, sizeof(value
));
1916 while (*valstart
&& NumSystemGroups
< MAX_SYSTEM_GROUPS
)
1918 if (*valstart
== '\'' || *valstart
== '\"')
1921 * Scan quoted name...
1924 quote
= *valstart
++;
1926 for (valend
= valstart
; *valend
; valend
++)
1927 if (*valend
== quote
)
1933 * Scan space or comma-delimited name...
1936 for (valend
= valstart
; *valend
; valend
++)
1937 if (isspace(*valend
) || *valend
== ',')
1944 group
= getgrnam(valstart
);
1947 cupsdSetString(SystemGroups
+ NumSystemGroups
, valstart
);
1948 SystemGroupIDs
[NumSystemGroups
] = group
->gr_gid
;
1959 while (*valstart
== ',' || isspace(*valstart
))
1968 * 'parse_protocols()' - Parse browse protocols in a string.
1971 static int /* O - Browse protocol bits */
1972 parse_protocols(const char *s
) /* I - Space-delimited protocols */
1974 int protocols
; /* Browse protocol bits */
1975 char value
[1024], /* Value string */
1976 *valstart
, /* Pointer into value */
1977 *valend
; /* End of value */
1981 * Empty protocol line yields NULL pointer...
1988 * Loop through the value string,...
1991 strlcpy(value
, s
, sizeof(value
));
1995 for (valstart
= value
; *valstart
;)
1998 * Get the current space/comma-delimited protocol name...
2001 for (valend
= valstart
; *valend
; valend
++)
2002 if (isspace(*valend
& 255) || *valend
== ',')
2009 * Add the protocol to the bitmask...
2012 if (!strcasecmp(valstart
, "cups"))
2013 protocols
|= BROWSE_CUPS
;
2014 else if (!strcasecmp(valstart
, "slp"))
2015 protocols
|= BROWSE_SLP
;
2016 else if (!strcasecmp(valstart
, "ldap"))
2017 protocols
|= BROWSE_LDAP
;
2018 else if (!strcasecmp(valstart
, "dnssd") || !strcasecmp(valstart
, "bonjour"))
2019 protocols
|= BROWSE_DNSSD
;
2020 else if (!strcasecmp(valstart
, "all"))
2021 protocols
|= BROWSE_ALL
;
2022 else if (strcasecmp(valstart
, "none"))
2025 for (valstart
= valend
; *valstart
; valstart
++)
2026 if (!isspace(*valstart
& 255) || *valstart
!= ',')
2035 * 'read_configuration()' - Read a configuration file.
2038 static int /* O - 1 on success, 0 on failure */
2039 read_configuration(cups_file_t
*fp
) /* I - File to read from */
2041 int i
; /* Looping var */
2042 int linenum
; /* Current line number */
2043 char line
[HTTP_MAX_BUFFER
],
2044 /* Line from file */
2045 temp
[HTTP_MAX_BUFFER
],
2046 /* Temporary buffer for value */
2047 temp2
[HTTP_MAX_BUFFER
],
2048 /* Temporary buffer 2 for value */
2049 *ptr
, /* Pointer into line/temp */
2050 *value
, /* Pointer to value */
2051 *valueptr
; /* Pointer into value */
2052 int valuelen
; /* Length of value */
2053 cupsd_var_t
*var
; /* Current variable */
2054 http_addrlist_t
*addrlist
, /* Address list */
2055 *addr
; /* Current address */
2056 unsigned ip
[4], /* Address value */
2057 mask
[4]; /* Netmask value */
2058 cupsd_dirsvc_relay_t
*relay
; /* Relay data */
2059 cupsd_dirsvc_poll_t
*pollp
; /* Polling data */
2060 cupsd_location_t
*location
; /* Browse location */
2061 cups_file_t
*incfile
; /* Include file */
2062 char incname
[1024]; /* Include filename */
2063 struct group
*group
; /* Group */
2067 * Loop through each line in the file...
2072 while (cupsFileGetConf(fp
, line
, sizeof(line
), &value
, &linenum
))
2075 * Decode the directive...
2078 if (!strcasecmp(line
, "Include"))
2084 if (value
[0] == '/')
2085 strlcpy(incname
, value
, sizeof(incname
));
2087 snprintf(incname
, sizeof(incname
), "%s/%s", ServerRoot
, value
);
2089 if ((incfile
= cupsFileOpen(incname
, "rb")) == NULL
)
2090 cupsdLogMessage(CUPSD_LOG_ERROR
,
2091 "Unable to include config file \"%s\" - %s",
2092 incname
, strerror(errno
));
2095 read_configuration(incfile
);
2096 cupsFileClose(incfile
);
2099 else if (!strcasecmp(line
, "<Location"))
2107 linenum
= read_location(fp
, value
, linenum
);
2113 cupsdLogMessage(CUPSD_LOG_ERROR
, "Syntax error on line %d.",
2118 else if (!strcasecmp(line
, "<Policy"))
2126 linenum
= read_policy(fp
, value
, linenum
);
2132 cupsdLogMessage(CUPSD_LOG_ERROR
, "Syntax error on line %d.", linenum
);
2136 else if (!strcasecmp(line
, "FaxRetryInterval"))
2140 JobRetryInterval
= atoi(value
);
2141 cupsdLogMessage(CUPSD_LOG_WARN
,
2142 "FaxRetryInterval is deprecated; use "
2143 "JobRetryInterval on line %d.", linenum
);
2147 cupsdLogMessage(CUPSD_LOG_ERROR
, "Syntax error on line %d.", linenum
);
2151 else if (!strcasecmp(line
, "FaxRetryLimit"))
2155 JobRetryLimit
= atoi(value
);
2156 cupsdLogMessage(CUPSD_LOG_WARN
,
2157 "FaxRetryLimit is deprecated; use "
2158 "JobRetryLimit on line %d.", linenum
);
2162 cupsdLogMessage(CUPSD_LOG_ERROR
, "Syntax error on line %d.", linenum
);
2166 else if (!strcasecmp(line
, "Port") || !strcasecmp(line
, "Listen")
2168 || !strcasecmp(line
, "SSLPort") || !strcasecmp(line
, "SSLListen")
2169 #endif /* HAVE_SSL */
2173 * Add listening address(es) to the list...
2176 cupsd_listener_t
*lis
; /* New listeners array */
2180 * Get the address list...
2183 addrlist
= get_address(value
, IPP_PORT
);
2187 cupsdLogMessage(CUPSD_LOG_ERROR
, "Bad %s address %s at line %d.", line
,
2193 * Add each address...
2196 for (addr
= addrlist
; addr
; addr
= addr
->next
)
2199 * Allocate another listener...
2203 Listeners
= cupsArrayNew(NULL
, NULL
);
2207 cupsdLogMessage(CUPSD_LOG_ERROR
,
2208 "Unable to allocate %s at line %d - %s.",
2209 line
, linenum
, strerror(errno
));
2213 if ((lis
= calloc(1, sizeof(cupsd_listener_t
))) == NULL
)
2215 cupsdLogMessage(CUPSD_LOG_ERROR
,
2216 "Unable to allocate %s at line %d - %s.",
2217 line
, linenum
, strerror(errno
));
2221 cupsArrayAdd(Listeners
, lis
);
2224 * Copy the current address and log it...
2227 memcpy(&(lis
->address
), &(addr
->addr
), sizeof(lis
->address
));
2231 if (!strcasecmp(line
, "SSLPort") || !strcasecmp(line
, "SSLListen"))
2232 lis
->encryption
= HTTP_ENCRYPT_ALWAYS
;
2233 #endif /* HAVE_SSL */
2235 httpAddrString(&lis
->address
, temp
, sizeof(temp
));
2238 if (lis
->address
.addr
.sa_family
== AF_INET6
)
2239 cupsdLogMessage(CUPSD_LOG_INFO
, "Listening to %s:%d (IPv6)", temp
,
2240 ntohs(lis
->address
.ipv6
.sin6_port
));
2242 #endif /* AF_INET6 */
2244 if (lis
->address
.addr
.sa_family
== AF_LOCAL
)
2245 cupsdLogMessage(CUPSD_LOG_INFO
, "Listening to %s (Domain)", temp
);
2247 #endif /* AF_LOCAL */
2248 cupsdLogMessage(CUPSD_LOG_INFO
, "Listening to %s:%d (IPv4)", temp
,
2249 ntohs(lis
->address
.ipv4
.sin_port
));
2256 httpAddrFreeList(addrlist
);
2258 else if (!strcasecmp(line
, "BrowseAddress"))
2261 * Add a browse address to the list...
2264 cupsd_dirsvc_addr_t
*dira
; /* New browse address array */
2267 if (NumBrowsers
== 0)
2268 dira
= malloc(sizeof(cupsd_dirsvc_addr_t
));
2270 dira
= realloc(Browsers
, (NumBrowsers
+ 1) * sizeof(cupsd_dirsvc_addr_t
));
2274 cupsdLogMessage(CUPSD_LOG_ERROR
,
2275 "Unable to allocate BrowseAddress at line %d - %s.",
2276 linenum
, strerror(errno
));
2281 dira
+= NumBrowsers
;
2283 memset(dira
, 0, sizeof(cupsd_dirsvc_addr_t
));
2285 if (!strcasecmp(value
, "@LOCAL"))
2288 * Send browse data to all local interfaces...
2291 strcpy(dira
->iface
, "*");
2294 else if (!strncasecmp(value
, "@IF(", 4))
2297 * Send browse data to the named interface...
2300 strlcpy(dira
->iface
, value
+ 4, sizeof(Browsers
[0].iface
));
2302 ptr
= dira
->iface
+ strlen(dira
->iface
) - 1;
2308 else if ((addrlist
= get_address(value
, BrowsePort
)) != NULL
)
2311 * Only IPv4 addresses are supported...
2314 for (addr
= addrlist
; addr
; addr
= addr
->next
)
2315 if (addr
->addr
.addr
.sa_family
== AF_INET
)
2320 memcpy(&(dira
->to
), &(addrlist
->addr
), sizeof(dira
->to
));
2321 httpAddrString(&(dira
->to
), temp
, sizeof(temp
));
2323 cupsdLogMessage(CUPSD_LOG_INFO
,
2324 "Sending browsing info to %s:%d (IPv4)",
2325 temp
, ntohs(dira
->to
.ipv4
.sin_port
));
2330 cupsdLogMessage(CUPSD_LOG_ERROR
, "Bad BrowseAddress %s at line %d.",
2333 httpAddrFreeList(addrlist
);
2336 cupsdLogMessage(CUPSD_LOG_ERROR
, "Bad BrowseAddress %s at line %d.",
2339 else if (!strcasecmp(line
, "BrowseOrder"))
2342 * "BrowseOrder Deny,Allow" or "BrowseOrder Allow,Deny"...
2345 if ((location
= cupsdFindLocation("CUPS_INTERNAL_BROWSE_ACL")) == NULL
)
2346 location
= cupsdAddLocation("CUPS_INTERNAL_BROWSE_ACL");
2348 if (location
== NULL
)
2349 cupsdLogMessage(CUPSD_LOG_ERROR
,
2350 "Unable to initialize browse access control list!");
2351 else if (!strncasecmp(value
, "deny", 4))
2352 location
->order_type
= AUTH_ALLOW
;
2353 else if (!strncasecmp(value
, "allow", 5))
2354 location
->order_type
= AUTH_DENY
;
2356 cupsdLogMessage(CUPSD_LOG_ERROR
,
2357 "Unknown BrowseOrder value %s on line %d.",
2360 else if (!strcasecmp(line
, "BrowseProtocols") ||
2361 !strcasecmp(line
, "BrowseLocalProtocols") ||
2362 !strcasecmp(line
, "BrowseRemoteProtocols"))
2365 * "BrowseProtocols name [... name]"
2366 * "BrowseLocalProtocols name [... name]"
2367 * "BrowseRemoteProtocols name [... name]"
2370 int protocols
= parse_protocols(value
);
2374 cupsdLogMessage(CUPSD_LOG_ERROR
,
2375 "Unknown browse protocol \"%s\" on line %d.",
2380 if (strcasecmp(line
, "BrowseLocalProtocols"))
2381 BrowseRemoteProtocols
= protocols
;
2382 if (strcasecmp(line
, "BrowseRemoteProtocols"))
2383 BrowseLocalProtocols
= protocols
;
2385 else if (!strcasecmp(line
, "BrowseAllow") ||
2386 !strcasecmp(line
, "BrowseDeny"))
2389 * BrowseAllow [From] host/ip...
2390 * BrowseDeny [From] host/ip...
2393 if ((location
= cupsdFindLocation("CUPS_INTERNAL_BROWSE_ACL")) == NULL
)
2394 location
= cupsdAddLocation("CUPS_INTERNAL_BROWSE_ACL");
2396 if (location
== NULL
)
2397 cupsdLogMessage(CUPSD_LOG_ERROR
,
2398 "Unable to initialize browse access control list!");
2401 if (!strncasecmp(value
, "from ", 5))
2404 * Strip leading "from"...
2409 while (isspace(*value
))
2414 * Figure out what form the allow/deny address takes:
2425 * nnn.nnn.nnn.nnn/mm
2426 * nnn.nnn.nnn.nnn/mmm.mmm.mmm.mmm
2429 if (!strcasecmp(value
, "all"))
2435 if (!strcasecmp(line
, "BrowseAllow"))
2436 cupsdAllowIP(location
, zeros
, zeros
);
2438 cupsdDenyIP(location
, zeros
, zeros
);
2440 else if (!strcasecmp(value
, "none"))
2446 if (!strcasecmp(line
, "BrowseAllow"))
2447 cupsdAllowIP(location
, ones
, zeros
);
2449 cupsdDenyIP(location
, ones
, zeros
);
2452 else if (value
[0] == '*' || value
[0] == '.' ||
2453 (!isdigit(value
[0] & 255) && value
[0] != '['))
2455 else if (value
[0] == '*' || value
[0] == '.' || !isdigit(value
[0] & 255))
2456 #endif /* AF_INET6 */
2459 * Host or domain name...
2462 if (value
[0] == '*')
2465 if (!strcasecmp(line
, "BrowseAllow"))
2466 cupsdAllowHost(location
, value
);
2468 cupsdDenyHost(location
, value
);
2473 * One of many IP address forms...
2476 if (!get_addr_and_mask(value
, ip
, mask
))
2478 cupsdLogMessage(CUPSD_LOG_ERROR
, "Bad netmask value %s on line %d.",
2483 if (!strcasecmp(line
, "BrowseAllow"))
2484 cupsdAllowIP(location
, ip
, mask
);
2486 cupsdDenyIP(location
, ip
, mask
);
2490 else if (!strcasecmp(line
, "BrowseRelay"))
2493 * BrowseRelay [from] source [to] destination
2497 relay
= malloc(sizeof(cupsd_dirsvc_relay_t
));
2499 relay
= realloc(Relays
, (NumRelays
+ 1) * sizeof(cupsd_dirsvc_relay_t
));
2503 cupsdLogMessage(CUPSD_LOG_ERROR
,
2504 "Unable to allocate BrowseRelay at line %d - %s.",
2505 linenum
, strerror(errno
));
2512 memset(relay
, 0, sizeof(cupsd_dirsvc_relay_t
));
2514 if (!strncasecmp(value
, "from ", 5))
2517 * Strip leading "from"...
2522 while (isspace(*value
))
2527 * Figure out what form the from address takes:
2536 * nnn.nnn.nnn.nnn/mm
2537 * nnn.nnn.nnn.nnn/mmm.mmm.mmm.mmm
2541 if (value
[0] == '*' || value
[0] == '.' ||
2542 (!isdigit(value
[0] & 255) && value
[0] != '['))
2544 if (value
[0] == '*' || value
[0] == '.' || !isdigit(value
[0] & 255))
2545 #endif /* AF_INET6 */
2548 * Host or domain name...
2551 if (value
[0] == '*')
2554 strlcpy(temp
, value
, sizeof(temp
));
2555 if ((ptr
= strchr(temp
, ' ')) != NULL
)
2558 relay
->from
.type
= AUTH_NAME
;
2559 relay
->from
.mask
.name
.name
= strdup(temp
);
2560 relay
->from
.mask
.name
.length
= strlen(temp
);
2565 * One of many IP address forms...
2568 if (!get_addr_and_mask(value
, ip
, mask
))
2570 cupsdLogMessage(CUPSD_LOG_ERROR
, "Bad netmask value %s on line %d.",
2575 relay
->from
.type
= AUTH_IP
;
2576 memcpy(relay
->from
.mask
.ip
.address
, ip
,
2577 sizeof(relay
->from
.mask
.ip
.address
));
2578 memcpy(relay
->from
.mask
.ip
.netmask
, mask
,
2579 sizeof(relay
->from
.mask
.ip
.netmask
));
2583 * Skip value and trailing whitespace...
2586 for (; *value
; value
++)
2587 if (isspace(*value
))
2590 while (isspace(*value
))
2593 if (!strncasecmp(value
, "to ", 3))
2596 * Strip leading "to"...
2601 while (isspace(*value
))
2606 * Get "to" address and port...
2609 if ((addrlist
= get_address(value
, BrowsePort
)) != NULL
)
2612 * Only IPv4 addresses are supported...
2615 for (addr
= addrlist
; addr
; addr
= addr
->next
)
2616 if (addr
->addr
.addr
.sa_family
== AF_INET
)
2621 memcpy(&(relay
->to
), &(addrlist
->addr
), sizeof(relay
->to
));
2623 httpAddrString(&(relay
->to
), temp
, sizeof(temp
));
2625 if (relay
->from
.type
== AUTH_IP
)
2626 snprintf(temp2
, sizeof(temp2
), "%u.%u.%u.%u/%u.%u.%u.%u",
2627 relay
->from
.mask
.ip
.address
[0] >> 24,
2628 (relay
->from
.mask
.ip
.address
[0] >> 16) & 255,
2629 (relay
->from
.mask
.ip
.address
[0] >> 8) & 255,
2630 relay
->from
.mask
.ip
.address
[0] & 255,
2631 relay
->from
.mask
.ip
.netmask
[0] >> 24,
2632 (relay
->from
.mask
.ip
.netmask
[0] >> 16) & 255,
2633 (relay
->from
.mask
.ip
.netmask
[0] >> 8) & 255,
2634 relay
->from
.mask
.ip
.netmask
[0] & 255);
2636 strlcpy(temp2
, relay
->from
.mask
.name
.name
, sizeof(temp2
));
2638 cupsdLogMessage(CUPSD_LOG_INFO
, "Relaying from %s to %s:%d (IPv4)",
2639 temp2
, temp
, ntohs(relay
->to
.ipv4
.sin_port
));
2644 cupsdLogMessage(CUPSD_LOG_ERROR
, "Bad relay address %s at line %d.",
2647 httpAddrFreeList(addrlist
);
2651 if (relay
->from
.type
== AUTH_NAME
)
2652 free(relay
->from
.mask
.name
.name
);
2654 cupsdLogMessage(CUPSD_LOG_ERROR
, "Bad relay address %s at line %d.",
2658 else if (!strcasecmp(line
, "BrowsePoll"))
2661 * BrowsePoll address[:port]
2664 char *portname
; /* Port name */
2665 int portnum
; /* Port number */
2666 struct servent
*service
; /* Service */
2670 * Extract the port name from the address...
2673 if ((portname
= strrchr(value
, ':')) != NULL
&& !strchr(portname
, ']'))
2677 if (isdigit(*portname
& 255))
2678 portnum
= atoi(portname
);
2679 else if ((service
= getservbyname(portname
, NULL
)) != NULL
)
2680 portnum
= ntohs(service
->s_port
);
2683 cupsdLogMessage(CUPSD_LOG_ERROR
, "Lookup of service \"%s\" failed!",
2689 portnum
= ippPort();
2692 * Add the poll entry...
2696 pollp
= malloc(sizeof(cupsd_dirsvc_poll_t
));
2698 pollp
= realloc(Polled
, (NumPolled
+ 1) * sizeof(cupsd_dirsvc_poll_t
));
2702 cupsdLogMessage(CUPSD_LOG_ERROR
,
2703 "Unable to allocate BrowsePoll at line %d - %s.",
2704 linenum
, strerror(errno
));
2712 memset(pollp
, 0, sizeof(cupsd_dirsvc_poll_t
));
2714 strlcpy(pollp
->hostname
, value
, sizeof(pollp
->hostname
));
2715 pollp
->port
= portnum
;
2717 cupsdLogMessage(CUPSD_LOG_INFO
, "Polling %s:%d", pollp
->hostname
,
2720 else if (!strcasecmp(line
, "DefaultAuthType"))
2723 * DefaultAuthType {basic,digest,basicdigest,negotiate}
2726 if (!strcasecmp(value
, "none"))
2727 DefaultAuthType
= AUTH_NONE
;
2728 else if (!strcasecmp(value
, "basic"))
2729 DefaultAuthType
= AUTH_BASIC
;
2730 else if (!strcasecmp(value
, "digest"))
2731 DefaultAuthType
= AUTH_DIGEST
;
2732 else if (!strcasecmp(value
, "basicdigest"))
2733 DefaultAuthType
= AUTH_BASICDIGEST
;
2735 else if (!strcasecmp(value
, "negotiate"))
2736 DefaultAuthType
= AUTH_NEGOTIATE
;
2737 #endif /* HAVE_GSSAPI */
2740 cupsdLogMessage(CUPSD_LOG_WARN
,
2741 "Unknown default authorization type %s on line %d.",
2747 else if (!strcasecmp(line
, "DefaultEncryption"))
2750 * DefaultEncryption {Never,IfRequested,Required}
2753 if (!value
|| !strcasecmp(value
, "never"))
2754 DefaultEncryption
= HTTP_ENCRYPT_NEVER
;
2755 else if (!strcasecmp(value
, "required"))
2756 DefaultEncryption
= HTTP_ENCRYPT_REQUIRED
;
2757 else if (!strcasecmp(value
, "ifrequested"))
2758 DefaultEncryption
= HTTP_ENCRYPT_IF_REQUESTED
;
2761 cupsdLogMessage(CUPSD_LOG_WARN
,
2762 "Unknown default encryption %s on line %d.",
2767 #endif /* HAVE_SSL */
2769 else if (!strcasecmp(line
, "Krb5Keytab"))
2771 cupsdSetStringf(&Krb5Keytab
, "KRB5_KTNAME=%s", value
);
2774 # ifdef HAVE_GSSKRB5_REGISTER_ACCEPTOR_IDENTITY
2775 gsskrb5_register_acceptor_identity(value
);
2777 cupsdSetEnv("KRB5_KTNAME", value
);
2778 # endif /* HAVE_GSSKRB5_REGISTER_ACCEPTOR_IDENTITY */
2780 #endif /* HAVE_GSSAPI */
2781 else if (!strcasecmp(line
, "User"))
2784 * User ID to run as...
2787 if (value
&& isdigit(value
[0] & 255))
2789 int uid
= atoi(value
);
2792 cupsdLogMessage(CUPSD_LOG_ERROR
,
2793 "Will not use User 0 as specified on line %d "
2794 "for security reasons. You must use a non-"
2795 "privileged account instead.",
2802 struct passwd
*p
; /* Password information */
2805 p
= getpwnam(value
);
2810 cupsdLogMessage(CUPSD_LOG_ERROR
,
2811 "Will not use User %s (UID=0) as specified on line "
2812 "%d for security reasons. You must use a non-"
2813 "privileged account instead.",
2819 cupsdLogMessage(CUPSD_LOG_ERROR
,
2820 "Unknown User \"%s\" on line %d, ignoring!",
2824 cupsdLogMessage(CUPSD_LOG_ERROR
,
2825 "User directive on line %d missing the username!",
2828 else if (!strcasecmp(line
, "Group"))
2831 * Group ID to run as...
2834 if (isdigit(value
[0]))
2835 Group
= atoi(value
);
2839 group
= getgrnam(value
);
2842 Group
= group
->gr_gid
;
2844 cupsdLogMessage(CUPSD_LOG_ERROR
,
2845 "Unknown Group \"%s\" on line %d, ignoring!",
2849 else if (!strcasecmp(line
, "SystemGroup"))
2852 * SystemGroup (admin) group(s)...
2855 if (!parse_groups(value
))
2856 cupsdLogMessage(CUPSD_LOG_ERROR
,
2857 "Unknown SystemGroup \"%s\" on line %d, ignoring!",
2860 else if (!strcasecmp(line
, "HostNameLookups"))
2863 * Do hostname lookups?
2866 if (!strcasecmp(value
, "off"))
2867 HostNameLookups
= 0;
2868 else if (!strcasecmp(value
, "on"))
2869 HostNameLookups
= 1;
2870 else if (!strcasecmp(value
, "double"))
2871 HostNameLookups
= 2;
2873 cupsdLogMessage(CUPSD_LOG_WARN
, "Unknown HostNameLookups %s on line %d.",
2876 else if (!strcasecmp(line
, "LogLevel"))
2879 * Amount of logging to do...
2882 if (!strcasecmp(value
, "debug2"))
2883 LogLevel
= CUPSD_LOG_DEBUG2
;
2884 else if (!strcasecmp(value
, "debug"))
2885 LogLevel
= CUPSD_LOG_DEBUG
;
2886 else if (!strcasecmp(value
, "info"))
2887 LogLevel
= CUPSD_LOG_INFO
;
2888 else if (!strcasecmp(value
, "notice"))
2889 LogLevel
= CUPSD_LOG_NOTICE
;
2890 else if (!strcasecmp(value
, "warn"))
2891 LogLevel
= CUPSD_LOG_WARN
;
2892 else if (!strcasecmp(value
, "error"))
2893 LogLevel
= CUPSD_LOG_ERROR
;
2894 else if (!strcasecmp(value
, "crit"))
2895 LogLevel
= CUPSD_LOG_CRIT
;
2896 else if (!strcasecmp(value
, "alert"))
2897 LogLevel
= CUPSD_LOG_ALERT
;
2898 else if (!strcasecmp(value
, "emerg"))
2899 LogLevel
= CUPSD_LOG_EMERG
;
2900 else if (!strcasecmp(value
, "none"))
2901 LogLevel
= CUPSD_LOG_NONE
;
2903 cupsdLogMessage(CUPSD_LOG_WARN
, "Unknown LogLevel %s on line %d.",
2906 else if (!strcasecmp(line
, "PrintcapFormat"))
2909 * Format of printcap file?
2912 if (!strcasecmp(value
, "bsd"))
2913 PrintcapFormat
= PRINTCAP_BSD
;
2914 else if (!strcasecmp(value
, "solaris"))
2915 PrintcapFormat
= PRINTCAP_SOLARIS
;
2917 cupsdLogMessage(CUPSD_LOG_WARN
, "Unknown PrintcapFormat %s on line %d.",
2920 else if (!strcasecmp(line
, "ServerTokens"))
2923 * Set the string used for the Server header...
2926 struct utsname plat
; /* Platform info */
2931 if (!strcasecmp(value
, "ProductOnly"))
2932 cupsdSetString(&ServerHeader
, "CUPS");
2933 else if (!strcasecmp(value
, "Major"))
2934 cupsdSetString(&ServerHeader
, "CUPS/1");
2935 else if (!strcasecmp(value
, "Minor"))
2936 cupsdSetString(&ServerHeader
, "CUPS/1.2");
2937 else if (!strcasecmp(value
, "Minimal"))
2938 cupsdSetString(&ServerHeader
, CUPS_MINIMAL
);
2939 else if (!strcasecmp(value
, "OS"))
2940 cupsdSetStringf(&ServerHeader
, CUPS_MINIMAL
" (%s)", plat
.sysname
);
2941 else if (!strcasecmp(value
, "Full"))
2942 cupsdSetStringf(&ServerHeader
, CUPS_MINIMAL
" (%s) IPP/1.1",
2944 else if (!strcasecmp(value
, "None"))
2945 cupsdClearString(&ServerHeader
);
2947 cupsdLogMessage(CUPSD_LOG_WARN
, "Unknown ServerTokens %s on line %d.",
2950 else if (!strcasecmp(line
, "PassEnv"))
2953 * PassEnv variable [... variable]
2958 for (valuelen
= 0; value
[valuelen
]; valuelen
++)
2959 if (isspace(value
[valuelen
]) || value
[valuelen
] == ',')
2962 if (value
[valuelen
])
2964 value
[valuelen
] = '\0';
2968 cupsdSetEnv(value
, NULL
);
2970 for (value
+= valuelen
; *value
; value
++)
2971 if (!isspace(*value
) || *value
!= ',')
2975 else if (!strcasecmp(line
, "SetEnv"))
2978 * SetEnv variable value
2981 for (valueptr
= value
; *valueptr
&& !isspace(*valueptr
& 255); valueptr
++);
2989 while (isspace(*valueptr
& 255))
2992 cupsdSetEnv(value
, valueptr
);
2995 cupsdLogMessage(CUPSD_LOG_ERROR
,
2996 "Missing value for SetEnv directive on line %d.",
3002 * Find a simple variable in the list...
3005 for (i
= NUM_VARS
, var
= variables
; i
> 0; i
--, var
++)
3006 if (!strcasecmp(line
, var
->name
))
3012 * Unknown directive! Output an error message and continue...
3015 cupsdLogMessage(CUPSD_LOG_ERROR
, "Unknown directive %s on line %d.",
3022 case CUPSD_VARTYPE_INTEGER
:
3024 cupsdLogMessage(CUPSD_LOG_ERROR
,
3025 "Missing integer value for %s on line %d!",
3030 char *units
; /* Units */
3033 n
= strtol(value
, &units
, 0);
3035 if (units
&& *units
)
3037 if (tolower(units
[0] & 255) == 'g')
3038 n
*= 1024 * 1024 * 1024;
3039 else if (tolower(units
[0] & 255) == 'm')
3041 else if (tolower(units
[0] & 255) == 'k')
3043 else if (tolower(units
[0] & 255) == 't')
3048 cupsdLogMessage(CUPSD_LOG_ERROR
,
3049 "Bad negative integer value for %s on line %d!",
3052 *((int *)var
->ptr
) = n
;
3056 case CUPSD_VARTYPE_BOOLEAN
:
3058 cupsdLogMessage(CUPSD_LOG_ERROR
,
3059 "Missing boolean value for %s on line %d!",
3061 else if (!strcasecmp(value
, "true") ||
3062 !strcasecmp(value
, "on") ||
3063 !strcasecmp(value
, "enabled") ||
3064 !strcasecmp(value
, "yes") ||
3066 *((int *)var
->ptr
) = TRUE
;
3067 else if (!strcasecmp(value
, "false") ||
3068 !strcasecmp(value
, "off") ||
3069 !strcasecmp(value
, "disabled") ||
3070 !strcasecmp(value
, "no") ||
3071 !strcasecmp(value
, "0"))
3072 *((int *)var
->ptr
) = FALSE
;
3074 cupsdLogMessage(CUPSD_LOG_ERROR
,
3075 "Unknown boolean value %s on line %d.",
3079 case CUPSD_VARTYPE_STRING
:
3080 cupsdSetString((char **)var
->ptr
, value
);
3091 * 'read_location()' - Read a <Location path> definition.
3094 static int /* O - New line number or 0 on error */
3095 read_location(cups_file_t
*fp
, /* I - Configuration file */
3096 char *location
, /* I - Location name/path */
3097 int linenum
) /* I - Current line number */
3099 cupsd_location_t
*loc
, /* New location */
3100 *parent
; /* Parent location */
3101 char line
[HTTP_MAX_BUFFER
],
3103 *value
, /* Value for directive */
3104 *valptr
; /* Pointer into value */
3107 if ((parent
= cupsdAddLocation(location
)) == NULL
)
3110 parent
->limit
= AUTH_LIMIT_ALL
;
3113 while (cupsFileGetConf(fp
, line
, sizeof(line
), &value
, &linenum
))
3116 * Decode the directive...
3119 if (!strcasecmp(line
, "</Location>"))
3121 else if (!strcasecmp(line
, "<Limit") ||
3122 !strcasecmp(line
, "<LimitExcept"))
3126 cupsdLogMessage(CUPSD_LOG_ERROR
, "Syntax error on line %d.", linenum
);
3130 if ((loc
= cupsdCopyLocation(&parent
)) == NULL
)
3136 for (valptr
= value
; !isspace(*valptr
& 255) && *valptr
; valptr
++);
3141 if (!strcmp(value
, "ALL"))
3142 loc
->limit
= AUTH_LIMIT_ALL
;
3143 else if (!strcmp(value
, "GET"))
3144 loc
->limit
|= AUTH_LIMIT_GET
;
3145 else if (!strcmp(value
, "HEAD"))
3146 loc
->limit
|= AUTH_LIMIT_HEAD
;
3147 else if (!strcmp(value
, "OPTIONS"))
3148 loc
->limit
|= AUTH_LIMIT_OPTIONS
;
3149 else if (!strcmp(value
, "POST"))
3150 loc
->limit
|= AUTH_LIMIT_POST
;
3151 else if (!strcmp(value
, "PUT"))
3152 loc
->limit
|= AUTH_LIMIT_PUT
;
3153 else if (!strcmp(value
, "TRACE"))
3154 loc
->limit
|= AUTH_LIMIT_TRACE
;
3156 cupsdLogMessage(CUPSD_LOG_WARN
, "Unknown request type %s on line %d!",
3159 for (value
= valptr
; isspace(*value
& 255); value
++);
3162 if (!strcasecmp(line
, "<LimitExcept"))
3163 loc
->limit
= AUTH_LIMIT_ALL
^ loc
->limit
;
3165 parent
->limit
&= ~loc
->limit
;
3167 else if (!strcasecmp(line
, "</Limit>"))
3169 else if (!parse_aaa(loc
, line
, value
, linenum
))
3171 cupsdLogMessage(CUPSD_LOG_ERROR
,
3172 "Unknown Location directive %s on line %d.",
3178 cupsdLogMessage(CUPSD_LOG_ERROR
,
3179 "Unexpected end-of-file at line %d while reading location!",
3187 * 'read_policy()' - Read a <Policy name> definition.
3190 static int /* O - New line number or 0 on error */
3191 read_policy(cups_file_t
*fp
, /* I - Configuration file */
3192 char *policy
, /* I - Location name/path */
3193 int linenum
) /* I - Current line number */
3195 int i
; /* Looping var */
3196 cupsd_policy_t
*pol
; /* Policy */
3197 cupsd_location_t
*op
; /* Policy operation */
3198 int num_ops
; /* Number of IPP operations */
3199 ipp_op_t ops
[100]; /* Operations */
3200 char line
[HTTP_MAX_BUFFER
],
3202 *value
, /* Value for directive */
3203 *valptr
; /* Pointer into value */
3207 * Create the policy...
3210 if ((pol
= cupsdAddPolicy(policy
)) == NULL
)
3214 * Read from the file...
3220 while (cupsFileGetConf(fp
, line
, sizeof(line
), &value
, &linenum
))
3223 * Decode the directive...
3226 if (!strcasecmp(line
, "</Policy>"))
3229 cupsdLogMessage(CUPSD_LOG_WARN
,
3230 "Missing </Limit> before </Policy> on line %d!",
3235 else if (!strcasecmp(line
, "<Limit") && !op
)
3239 cupsdLogMessage(CUPSD_LOG_ERROR
, "Syntax error on line %d.", linenum
);
3244 * Scan for IPP operation names...
3251 for (valptr
= value
; !isspace(*valptr
& 255) && *valptr
; valptr
++);
3256 if (num_ops
< (int)(sizeof(ops
) / sizeof(ops
[0])))
3258 if (!strcasecmp(value
, "All"))
3259 ops
[num_ops
] = IPP_ANY_OPERATION
;
3260 else if ((ops
[num_ops
] = ippOpValue(value
)) == IPP_BAD_OPERATION
)
3261 cupsdLogMessage(CUPSD_LOG_ERROR
,
3262 "Bad IPP operation name \"%s\" on line %d!",
3268 cupsdLogMessage(CUPSD_LOG_ERROR
,
3269 "Too many operations listed on line %d!",
3272 for (value
= valptr
; isspace(*value
& 255); value
++);
3276 * If none are specified, apply the policy to all operations...
3281 ops
[0] = IPP_ANY_OPERATION
;
3286 * Add a new policy for the first operation...
3289 op
= cupsdAddPolicyOp(pol
, NULL
, ops
[0]);
3291 else if (!strcasecmp(line
, "</Limit>") && op
)
3294 * Finish the current operation limit...
3300 * Copy the policy to the other operations...
3303 for (i
= 1; i
< num_ops
; i
++)
3304 cupsdAddPolicyOp(pol
, op
, ops
[i
]);
3311 cupsdLogMessage(CUPSD_LOG_ERROR
,
3312 "Missing <Limit ops> directive before %s on line %d.",
3316 else if (!parse_aaa(op
, line
, value
, linenum
))
3319 cupsdLogMessage(CUPSD_LOG_ERROR
,
3320 "Unknown Policy Limit directive %s on line %d.",
3323 cupsdLogMessage(CUPSD_LOG_ERROR
,
3324 "Unknown Policy directive %s on line %d.",
3331 cupsdLogMessage(CUPSD_LOG_ERROR
,
3332 "Unexpected end-of-file at line %d while reading policy \"%s\"!",
3340 * End of "$Id: conf.c 6746 2007-07-30 16:47:10Z mike $".