2 * "$Id: conf.c,v 1.77.2.48 2004/02/24 21:36:59 mike Exp $"
4 * Configuration routines for the Common UNIX Printing System (CUPS).
6 * Copyright 1997-2003 by Easy Software Products, all rights reserved.
8 * These coded instructions, statements, and computer programs are the
9 * property of Easy Software Products and are protected by Federal
10 * copyright law. Distribution and use rights are outlined in the file
11 * "LICENSE.txt" which should have been included with this file. If this
12 * file is missing or damaged please contact Easy Software Products
15 * Attn: CUPS Licensing Information
16 * Easy Software Products
17 * 44141 Airport View Drive, Suite 204
18 * Hollywood, Maryland 20636-3111 USA
20 * Voice: (301) 373-9603
21 * EMail: cups-info@cups.org
22 * WWW: http://www.cups.org
26 * ReadConfiguration() - Read the cupsd.conf file.
27 * read_configuration() - Read a configuration file.
28 * read_location() - Read a <Location path> definition.
29 * get_address() - Get an address + port number from a line.
30 * get_addr_and_mask() - Get an IP address and netmask.
31 * CDSAGetServerCerts() - Convert a keychain name into the CFArrayRef
32 * required by SSLSetCertificate.
36 * Include necessary headers...
45 # include <Security/SecureTransport.h>
46 # include <Security/SecIdentitySearch.h>
47 #endif /* HAVE_CDSASSL */
51 #endif /* HAVE_VSYSLOG */
55 * Possibly missing network definitions...
59 # define INADDR_NONE 0xffffffff
60 #endif /* !INADDR_NONE */
64 * Configuration variable structure...
69 char *name
; /* Name of variable */
70 void *ptr
; /* Pointer to variable */
71 int type
; /* Type (int, string, address) */
83 static var_t variables
[] =
85 { "AccessLog", &AccessLog
, VAR_STRING
},
86 { "AutoPurgeJobs", &JobAutoPurge
, VAR_BOOLEAN
},
87 { "BrowseInterval", &BrowseInterval
, VAR_INTEGER
},
88 { "BrowsePort", &BrowsePort
, VAR_INTEGER
},
89 { "BrowseShortNames", &BrowseShortNames
, VAR_BOOLEAN
},
90 { "BrowseTimeout", &BrowseTimeout
, VAR_INTEGER
},
91 { "Browsing", &Browsing
, VAR_BOOLEAN
},
92 { "Classification", &Classification
, VAR_STRING
},
93 { "ClassifyOverride", &ClassifyOverride
, VAR_BOOLEAN
},
94 { "ConfigFilePerm", &ConfigFilePerm
, VAR_INTEGER
},
95 { "DataDir", &DataDir
, VAR_STRING
},
96 { "DefaultCharset", &DefaultCharset
, VAR_STRING
},
97 { "DefaultLanguage", &DefaultLanguage
, VAR_STRING
},
98 { "DocumentRoot", &DocumentRoot
, VAR_STRING
},
99 { "ErrorLog", &ErrorLog
, VAR_STRING
},
100 { "FaxRetryLimit", &FaxRetryLimit
, VAR_INTEGER
},
101 { "FaxRetryInterval", &FaxRetryInterval
, VAR_INTEGER
},
102 { "FileDevice", &FileDevice
, VAR_BOOLEAN
},
103 { "FilterLimit", &FilterLimit
, VAR_INTEGER
},
104 { "FilterNice", &FilterNice
, VAR_INTEGER
},
105 { "FontPath", &FontPath
, VAR_STRING
},
106 { "HideImplicitMembers", &HideImplicitMembers
, VAR_BOOLEAN
},
107 { "ImplicitClasses", &ImplicitClasses
, VAR_BOOLEAN
},
108 { "ImplicitAnyClasses", &ImplicitAnyClasses
, VAR_BOOLEAN
},
109 { "KeepAliveTimeout", &KeepAliveTimeout
, VAR_INTEGER
},
110 { "KeepAlive", &KeepAlive
, VAR_BOOLEAN
},
111 { "LimitRequestBody", &MaxRequestSize
, VAR_INTEGER
},
112 { "ListenBackLog", &ListenBackLog
, VAR_INTEGER
},
113 { "LogFilePerm", &LogFilePerm
, VAR_INTEGER
},
114 { "MaxActiveJobs", &MaxActiveJobs
, VAR_INTEGER
},
115 { "MaxClients", &MaxClients
, VAR_INTEGER
},
116 { "MaxClientsPerHost", &MaxClientsPerHost
, VAR_INTEGER
},
117 { "MaxCopies", &MaxCopies
, VAR_INTEGER
},
118 { "MaxJobs", &MaxJobs
, VAR_INTEGER
},
119 { "MaxJobsPerPrinter", &MaxJobsPerPrinter
, VAR_INTEGER
},
120 { "MaxJobsPerUser", &MaxJobsPerUser
, VAR_INTEGER
},
121 { "MaxLogSize", &MaxLogSize
, VAR_INTEGER
},
122 { "MaxPrinterHistory", &MaxPrinterHistory
, VAR_INTEGER
},
123 { "MaxRequestSize", &MaxRequestSize
, VAR_INTEGER
},
124 { "PageLog", &PageLog
, VAR_STRING
},
125 { "PreserveJobFiles", &JobFiles
, VAR_BOOLEAN
},
126 { "PreserveJobHistory", &JobHistory
, VAR_BOOLEAN
},
127 { "Printcap", &Printcap
, VAR_STRING
},
128 { "PrintcapGUI", &PrintcapGUI
, VAR_STRING
},
129 { "RemoteRoot", &RemoteRoot
, VAR_STRING
},
130 { "RequestRoot", &RequestRoot
, VAR_STRING
},
131 { "RIPCache", &RIPCache
, VAR_STRING
},
132 { "RunAsUser", &RunAsUser
, VAR_BOOLEAN
},
133 { "RootCertDuration", &RootCertDuration
, VAR_INTEGER
},
134 { "ServerAdmin", &ServerAdmin
, VAR_STRING
},
135 { "ServerBin", &ServerBin
, VAR_STRING
},
137 { "ServerCertificate", &ServerCertificate
, VAR_STRING
},
138 # if defined(HAVE_LIBSSL) || defined(HAVE_GNUTLS)
139 { "ServerKey", &ServerKey
, VAR_STRING
},
140 # endif /* HAVE_LIBSSL || HAVE_GNUTLS */
141 #endif /* HAVE_SSL */
142 { "ServerName", &ServerName
, VAR_STRING
},
143 { "ServerRoot", &ServerRoot
, VAR_STRING
},
144 { "TempDir", &TempDir
, VAR_STRING
},
145 { "Timeout", &Timeout
, VAR_INTEGER
}
147 #define NUM_VARS (sizeof(variables) / sizeof(variables[0]))
150 static unsigned ones
[4] =
152 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff
154 static unsigned zeros
[4] =
156 0x00000000, 0x00000000, 0x00000000, 0x00000000
160 static CFArrayRef
CDSAGetServerCerts();
161 #endif /* HAVE_CDSASSL */
168 static int read_configuration(cups_file_t
*fp
);
169 static int read_location(cups_file_t
*fp
, char *name
, int linenum
);
170 static int get_address(const char *value
, unsigned defaddress
, int defport
,
171 int deffamily
, http_addr_t
*address
);
172 static int get_addr_and_mask(const char *value
, unsigned *ip
,
177 * 'ReadConfiguration()' - Read the cupsd.conf file.
180 int /* O - 1 on success, 0 otherwise */
181 ReadConfiguration(void)
183 int i
; /* Looping var */
184 cups_file_t
*fp
; /* Configuration file */
185 int status
; /* Return status */
186 char temp
[1024], /* Temporary buffer */
187 *slash
; /* Directory separator */
188 char type
[MIME_MAX_SUPER
+ MIME_MAX_TYPE
];
190 char *language
; /* Language string */
191 struct passwd
*user
; /* Default user */
192 struct group
*group
; /* Default group */
193 int run_user
; /* User that will be running cupsd */
194 char *old_serverroot
, /* Old ServerRoot */
195 *old_requestroot
; /* Old RequestRoot */
199 * Shutdown the server...
205 * Save the old root paths...
208 old_serverroot
= NULL
;
209 SetString(&old_serverroot
, ServerRoot
);
210 old_requestroot
= NULL
;
211 SetString(&old_requestroot
, RequestRoot
);
214 * Reset the server configuration data...
217 DeleteAllLocations();
235 for (i
= 0; i
< NumRelays
; i
++)
236 if (Relays
[i
].from
.type
== AUTH_NAME
)
237 free(Relays
[i
].from
.mask
.name
.name
);
244 if (NumListeners
> 0)
255 gethostname(temp
, sizeof(temp
));
256 SetString(&ServerName
, temp
);
257 SetStringf(&ServerAdmin
, "root@%s", temp
);
258 SetString(&ServerBin
, CUPS_SERVERBIN
);
259 SetString(&RequestRoot
, CUPS_REQUESTS
);
260 SetString(&DocumentRoot
, CUPS_DOCROOT
);
261 SetString(&DataDir
, CUPS_DATADIR
);
262 SetString(&AccessLog
, CUPS_LOGDIR
"/access_log");
263 SetString(&ErrorLog
, CUPS_LOGDIR
"/error_log");
264 SetString(&PageLog
, CUPS_LOGDIR
"/page_log");
265 SetString(&Printcap
, "/etc/printcap");
266 SetString(&PrintcapGUI
, "/usr/bin/glpoptions");
267 SetString(&FontPath
, CUPS_FONTPATH
);
268 SetString(&RemoteRoot
, "remroot");
270 strlcpy(temp
, ConfigurationFile
, sizeof(temp
));
271 if ((slash
= strrchr(temp
, '/')) != NULL
)
274 SetString(&ServerRoot
, temp
);
276 ClearString(&Classification
);
277 ClassifyOverride
= 0;
281 SetString(&ServerCertificate
, "/var/root/Library/Keychains/CUPS");
283 SetString(&ServerCertificate
, "ssl/server.crt");
284 SetString(&ServerKey
, "ssl/server.key");
285 # endif /* HAVE_CDSASSL */
286 #endif /* HAVE_SSL */
288 if ((language
= DEFAULT_LANGUAGE
) == NULL
)
290 else if (strcmp(language
, "C") == 0 || strcmp(language
, "POSIX") == 0)
293 SetString(&DefaultLanguage
, language
);
294 SetString(&DefaultCharset
, DEFAULT_CHARSET
);
296 SetString(&RIPCache
, "8m");
298 if (getenv("TMPDIR") == NULL
)
299 SetString(&TempDir
, CUPS_REQUESTS
"/tmp");
301 SetString(&TempDir
, getenv("TMPDIR"));
304 * Find the default system group: "sys", "system", or "root"...
307 group
= getgrnam(CUPS_DEFAULT_GROUP
);
314 SetString(&SystemGroups
[0], CUPS_DEFAULT_GROUP
);
315 Group
= group
->gr_gid
;
324 SetString(&SystemGroups
[0], group
->gr_name
);
329 SetString(&SystemGroups
[0], "unknown");
335 * Find the default user...
338 if ((user
= getpwnam(CUPS_DEFAULT_USER
)) == NULL
)
339 User
= 1; /* Force to a non-priviledged account */
349 ConfigFilePerm
= 0640;
353 FaxRetryInterval
= 300;
358 HostNameLookups
= FALSE
;
359 ImplicitClasses
= TRUE
;
360 ImplicitAnyClasses
= FALSE
;
361 HideImplicitMembers
= TRUE
;
363 KeepAliveTimeout
= DEFAULT_KEEPALIVE
;
364 ListenBackLog
= SOMAXCONN
;
367 MaxClientsPerHost
= 0;
368 MaxLogSize
= 1024 * 1024;
369 MaxPrinterHistory
= 10;
371 RootCertDuration
= 300;
373 Timeout
= DEFAULT_TIMEOUT
;
375 BrowseInterval
= DEFAULT_INTERVAL
;
376 BrowsePort
= ippPort();
377 BrowseProtocols
= BROWSE_CUPS
;
378 BrowseShortNames
= TRUE
;
379 BrowseTimeout
= DEFAULT_TIMEOUT
;
382 JobHistory
= DEFAULT_HISTORY
;
383 JobFiles
= DEFAULT_FILES
;
387 MaxJobsPerPrinter
= 0;
392 * Read the configuration file...
395 if ((fp
= cupsFileOpen(ConfigurationFile
, "r")) == NULL
)
398 status
= read_configuration(fp
);
411 * Use the default system group if none was supplied in cupsd.conf...
414 if (NumSystemGroups
== 0)
418 * Get the access control list for browsing...
421 BrowseACL
= FindLocation("CUPS_INTERNAL_BROWSE_ACL");
424 * Open the system log for cupsd if necessary...
428 if (strcmp(AccessLog
, "syslog") == 0 ||
429 strcmp(ErrorLog
, "syslog") == 0 ||
430 strcmp(PageLog
, "syslog") == 0)
431 openlog("cupsd", LOG_PID
| LOG_NOWAIT
| LOG_NDELAY
, LOG_LPR
);
432 #endif /* HAVE_VSYSLOG */
435 * Log the configuration file that was used...
438 LogMessage(L_INFO
, "Loaded configuration file \"%s\"", ConfigurationFile
);
441 * Check that we have at least one listen/port line; if not, report this
442 * as an error and exit!
445 if (NumListeners
== 0)
451 LogMessage(L_EMERG
, "No valid Listen or Port lines were found in the configuration file!");
457 kill(getpid(), SIGTERM
);
461 * Set the default locale using the language and charset...
464 SetStringf(&DefaultLocale
, "%s.%s", DefaultLanguage
, DefaultCharset
);
467 * Update all relative filenames to include the full path from ServerRoot...
470 if (DocumentRoot
[0] != '/')
471 SetStringf(&DocumentRoot
, "%s/%s", ServerRoot
, DocumentRoot
);
473 if (RequestRoot
[0] != '/')
474 SetStringf(&RequestRoot
, "%s/%s", ServerRoot
, RequestRoot
);
476 if (ServerBin
[0] != '/')
477 SetStringf(&ServerBin
, "%s/%s", ServerRoot
, ServerBin
);
480 if (ServerCertificate
[0] != '/')
481 SetStringf(&ServerCertificate
, "%s/%s", ServerRoot
, ServerCertificate
);
483 # if defined(HAVE_LIBSSL) || defined(HAVE_GNUTLS)
484 chown(ServerCertificate
, run_user
, Group
);
485 chmod(ServerCertificate
, ConfigFilePerm
);
487 if (ServerKey
[0] != '/')
488 SetStringf(&ServerKey
, "%s/%s", ServerRoot
, ServerKey
);
490 chown(ServerKey
, run_user
, Group
);
491 chmod(ServerKey
, ConfigFilePerm
);
492 # endif /* HAVE_LIBSSL || HAVE_GNUTLS */
493 #endif /* HAVE_SSL */
496 * Make sure that ServerRoot and the config files are owned and
497 * writable by the user and group in the cupsd.conf file...
500 chown(ServerRoot
, run_user
, Group
);
501 chmod(ServerRoot
, 0775);
503 snprintf(temp
, sizeof(temp
), "%s/certs", ServerRoot
);
504 chown(temp
, run_user
, Group
);
507 snprintf(temp
, sizeof(temp
), "%s/ppd", ServerRoot
);
508 chown(temp
, run_user
, Group
);
511 snprintf(temp
, sizeof(temp
), "%s/ssl", ServerRoot
);
512 chown(temp
, run_user
, Group
);
515 snprintf(temp
, sizeof(temp
), "%s/cupsd.conf", ServerRoot
);
516 chown(temp
, run_user
, Group
);
517 chmod(temp
, ConfigFilePerm
);
519 snprintf(temp
, sizeof(temp
), "%s/classes.conf", ServerRoot
);
520 chown(temp
, run_user
, Group
);
524 chmod(temp
, ConfigFilePerm
);
525 #endif /* __APPLE__ */
527 snprintf(temp
, sizeof(temp
), "%s/printers.conf", ServerRoot
);
528 chown(temp
, run_user
, Group
);
532 chmod(temp
, ConfigFilePerm
);
533 #endif /* __APPLE__ */
535 snprintf(temp
, sizeof(temp
), "%s/passwd.md5", ServerRoot
);
536 chown(temp
, User
, Group
);
540 * Make sure the request and temporary directories have the right
544 chown(RequestRoot
, run_user
, Group
);
545 chmod(RequestRoot
, 0710);
547 if (strncmp(TempDir
, RequestRoot
, strlen(RequestRoot
)) == 0)
550 * Only update ownership and permissions if the CUPS temp directory
551 * is under the spool directory...
554 chown(TempDir
, run_user
, Group
);
555 chmod(TempDir
, 01770);
559 * Check the MaxClients setting, and then allocate memory for it...
562 if (MaxClients
> (MaxFDs
/ 3) || MaxClients
<= 0)
565 LogMessage(L_INFO
, "MaxClients limited to 1/3 of the file descriptor limit (%d)...",
568 MaxClients
= MaxFDs
/ 3;
571 if ((Clients
= calloc(sizeof(client_t
), MaxClients
)) == NULL
)
573 LogMessage(L_ERROR
, "ReadConfiguration: Unable to allocate memory for %d clients: %s",
574 MaxClients
, strerror(errno
));
578 LogMessage(L_INFO
, "Configured for up to %d clients.", MaxClients
);
581 * Check the MaxActiveJobs setting; limit to 1/3 the available
582 * file descriptors, since we need a pipe for each job...
585 if (MaxActiveJobs
> (MaxFDs
/ 3))
586 MaxActiveJobs
= MaxFDs
/ 3;
588 if (Classification
&& strcasecmp(Classification
, "none") == 0)
589 ClearString(&Classification
);
592 LogMessage(L_INFO
, "Security set to \"%s\"", Classification
);
595 * Update the MaxClientsPerHost value, as needed...
598 if (MaxClientsPerHost
<= 0)
599 MaxClientsPerHost
= MaxClients
;
601 if (MaxClientsPerHost
> MaxClients
)
602 MaxClientsPerHost
= MaxClients
;
604 LogMessage(L_INFO
, "Allowing up to %d client connections per host.",
608 * If we are doing a full reload or the server root has changed, flush
609 * the jobs, printers, etc. and start from scratch...
612 if (NeedReload
== RELOAD_ALL
||
613 !old_serverroot
|| !ServerRoot
|| strcmp(old_serverroot
, ServerRoot
) ||
614 !old_requestroot
|| !RequestRoot
|| strcmp(old_requestroot
, RequestRoot
))
616 LogMessage(L_INFO
, "Full reload is required.");
626 DefaultPrinter
= NULL
;
640 if (MimeDatabase
!= NULL
)
641 mimeDelete(MimeDatabase
);
645 for (i
= 0; i
< NumMimeTypes
; i
++)
646 free((void *)MimeTypes
[i
]);
652 * Read the MIME type and conversion database...
655 snprintf(temp
, sizeof(temp
), "%s/filter", ServerBin
);
657 MimeDatabase
= mimeNew();
658 mimeMerge(MimeDatabase
, ServerRoot
, temp
);
661 * Create a list of MIME types for the document-format-supported
665 NumMimeTypes
= MimeDatabase
->num_types
;
666 if (!mimeType(MimeDatabase
, "application", "octet-stream"))
669 MimeTypes
= calloc(NumMimeTypes
, sizeof(const char *));
671 for (i
= 0; i
< MimeDatabase
->num_types
; i
++)
673 snprintf(type
, sizeof(type
), "%s/%s", MimeDatabase
->types
[i
]->super
,
674 MimeDatabase
->types
[i
]->type
);
676 MimeTypes
[i
] = strdup(type
);
679 if (i
< NumMimeTypes
)
680 MimeTypes
[i
] = strdup("application/octet-stream");
686 snprintf(temp
, sizeof(temp
), "%s/banners", DataDir
);
690 * Load printers and classes...
699 * Load devices and PPDs...
702 snprintf(temp
, sizeof(temp
), "%s/backend", ServerBin
);
705 snprintf(temp
, sizeof(temp
), "%s/model", DataDir
);
709 * Load queued jobs...
714 LogMessage(L_INFO
, "Full reload complete.");
720 LogMessage(L_INFO
, "Partial reload complete.");
724 * Reset the reload state...
727 NeedReload
= RELOAD_NONE
;
729 ClearString(&old_serverroot
);
730 ClearString(&old_requestroot
);
733 * Startup the server and return...
743 * 'read_configuration()' - Read a configuration file.
746 static int /* O - 1 on success, 0 on failure */
747 read_configuration(cups_file_t
*fp
) /* I - File to read from */
749 int i
; /* Looping var */
750 int linenum
; /* Current line number */
751 int len
; /* Length of line */
752 char line
[HTTP_MAX_BUFFER
], /* Line from file */
753 name
[256], /* Parameter name */
754 *nameptr
, /* Pointer into name */
755 *value
; /* Pointer to value */
756 int valuelen
; /* Length of value */
757 var_t
*var
; /* Current variable */
758 unsigned ip
[4], /* Address value */
759 mask
[4]; /* Netmask value */
760 dirsvc_relay_t
*relay
; /* Relay data */
761 dirsvc_poll_t
*poll
; /* Polling data */
762 http_addr_t polladdr
; /* Polling address */
763 location_t
*location
; /* Browse location */
764 cups_file_t
*incfile
; /* Include file */
765 char incname
[1024]; /* Include filename */
769 * Loop through each line in the file...
774 while (cupsFileGets(fp
, line
, sizeof(line
)) != NULL
)
779 * Skip comment lines...
786 * Strip trailing whitespace, if any...
791 while (len
> 0 && isspace(line
[len
- 1]))
798 * Extract the name from the beginning of the line...
801 for (value
= line
; isspace(*value
); value
++);
803 for (nameptr
= name
; *value
!= '\0' && !isspace(*value
) &&
804 nameptr
< (name
+ sizeof(name
) - 1);)
805 *nameptr
++ = *value
++;
808 while (isspace(*value
))
815 * Decode the directive...
818 if (strcasecmp(name
, "Include") == 0)
825 strlcpy(incname
, value
, sizeof(incname
));
827 snprintf(incname
, sizeof(incname
), "%s/%s", ServerRoot
, value
);
829 if ((incfile
= cupsFileOpen(incname
, "rb")) == NULL
)
830 LogMessage(L_ERROR
, "Unable to include config file \"%s\" - %s",
831 incname
, strerror(errno
));
834 read_configuration(incfile
);
835 cupsFileClose(incfile
);
838 else if (strcasecmp(name
, "<Location") == 0)
844 if (line
[len
- 1] == '>')
846 line
[len
- 1] = '\0';
848 linenum
= read_location(fp
, value
, linenum
);
854 LogMessage(L_ERROR
, "ReadConfiguration() Syntax error on line %d.",
859 else if (strcasecmp(name
, "Port") == 0 ||
860 strcasecmp(name
, "Listen") == 0)
863 * Add a listening address to the list...
866 listener_t
*temp
; /* New listeners array */
869 if (NumListeners
== 0)
870 temp
= malloc(sizeof(listener_t
));
872 temp
= realloc(Listeners
, (NumListeners
+ 1) * sizeof(listener_t
));
876 LogMessage(L_ERROR
, "Unable to allocate %s at line %d - %s.",
877 name
, linenum
, strerror(errno
));
882 temp
+= NumListeners
;
884 memset(temp
, 0, sizeof(listener_t
));
886 if (get_address(value
, INADDR_ANY
, IPP_PORT
, AF_INET
, &(temp
->address
)))
888 httpAddrString(&(temp
->address
), line
, sizeof(line
));
891 if (temp
->address
.addr
.sa_family
== AF_INET6
)
892 LogMessage(L_INFO
, "Listening to %s:%d (IPv6)", line
,
893 ntohs(temp
->address
.ipv6
.sin6_port
));
895 #endif /* AF_INET6 */
896 LogMessage(L_INFO
, "Listening to %s:%d", line
,
897 ntohs(temp
->address
.ipv4
.sin_port
));
901 LogMessage(L_ERROR
, "Bad %s address %s at line %d.", name
,
905 else if (strcasecmp(name
, "SSLPort") == 0 ||
906 strcasecmp(name
, "SSLListen") == 0)
909 * Add a listening address to the list...
912 listener_t
*temp
; /* New listeners array */
915 if (NumListeners
== 0)
916 temp
= malloc(sizeof(listener_t
));
918 temp
= realloc(Listeners
, (NumListeners
+ 1) * sizeof(listener_t
));
922 LogMessage(L_ERROR
, "Unable to allocate %s at line %d - %s.",
923 name
, linenum
, strerror(errno
));
928 temp
+= NumListeners
;
930 if (get_address(value
, INADDR_ANY
, IPP_PORT
, AF_INET
, &(temp
->address
)))
932 httpAddrString(&(temp
->address
), line
, sizeof(line
));
935 if (temp
->address
.addr
.sa_family
== AF_INET6
)
936 LogMessage(L_INFO
, "Listening to %s:%d (IPv6)", line
,
937 ntohs(temp
->address
.ipv6
.sin6_port
));
939 #endif /* AF_INET6 */
940 LogMessage(L_INFO
, "Listening to %s:%d", line
,
941 ntohs(temp
->address
.ipv4
.sin_port
));
942 temp
->encryption
= HTTP_ENCRYPT_ALWAYS
;
946 LogMessage(L_ERROR
, "Bad %s address %s at line %d.", name
,
949 #endif /* HAVE_SSL */
950 else if (strcasecmp(name
, "BrowseAddress") == 0)
953 * Add a browse address to the list...
956 dirsvc_addr_t
*temp
; /* New browse address array */
959 if (NumBrowsers
== 0)
960 temp
= malloc(sizeof(dirsvc_addr_t
));
962 temp
= realloc(Browsers
, (NumBrowsers
+ 1) * sizeof(dirsvc_addr_t
));
966 LogMessage(L_ERROR
, "Unable to allocate BrowseAddress at line %d - %s.",
967 linenum
, strerror(errno
));
974 memset(temp
, 0, sizeof(dirsvc_addr_t
));
976 if (strcasecmp(value
, "@LOCAL") == 0)
979 * Send browse data to all local interfaces...
982 strcpy(temp
->iface
, "*");
985 else if (strncasecmp(value
, "@IF(", 4) == 0)
988 * Send browse data to the named interface...
991 strlcpy(temp
->iface
, value
+ 4, sizeof(Browsers
[0].iface
));
993 nameptr
= temp
->iface
+ strlen(temp
->iface
) - 1;
999 else if (get_address(value
, INADDR_NONE
, BrowsePort
, AF_INET
, &(temp
->to
)))
1001 httpAddrString(&(temp
->to
), line
, sizeof(line
));
1004 if (temp
->to
.addr
.sa_family
== AF_INET6
)
1005 LogMessage(L_INFO
, "Sending browsing info to %s:%d (IPv6)", line
,
1006 ntohs(temp
->to
.ipv6
.sin6_port
));
1008 #endif /* AF_INET6 */
1009 LogMessage(L_INFO
, "Sending browsing info to %s:%d", line
,
1010 ntohs(temp
->to
.ipv4
.sin_port
));
1015 LogMessage(L_ERROR
, "Bad BrowseAddress %s at line %d.", value
,
1018 else if (strcasecmp(name
, "BrowseOrder") == 0)
1021 * "BrowseOrder Deny,Allow" or "BrowseOrder Allow,Deny"...
1024 if ((location
= FindLocation("CUPS_INTERNAL_BROWSE_ACL")) == NULL
)
1025 location
= AddLocation("CUPS_INTERNAL_BROWSE_ACL");
1027 if (location
== NULL
)
1028 LogMessage(L_ERROR
, "Unable to initialize browse access control list!");
1029 else if (strncasecmp(value
, "deny", 4) == 0)
1030 location
->order_type
= AUTH_ALLOW
;
1031 else if (strncasecmp(value
, "allow", 5) == 0)
1032 location
->order_type
= AUTH_DENY
;
1034 LogMessage(L_ERROR
, "Unknown BrowseOrder value %s on line %d.",
1037 else if (strcasecmp(name
, "BrowseProtocols") == 0)
1040 * "BrowseProtocol name [... name]"
1043 BrowseProtocols
= 0;
1047 for (valuelen
= 0; value
[valuelen
]; valuelen
++)
1048 if (isspace(value
[valuelen
]) || value
[valuelen
] == ',')
1051 if (value
[valuelen
])
1053 value
[valuelen
] = '\0';
1057 if (strcasecmp(value
, "cups") == 0)
1058 BrowseProtocols
|= BROWSE_CUPS
;
1059 else if (strcasecmp(value
, "slp") == 0)
1060 BrowseProtocols
|= BROWSE_SLP
;
1061 else if (strcasecmp(value
, "ldap") == 0)
1062 BrowseProtocols
|= BROWSE_LDAP
;
1063 else if (strcasecmp(value
, "all") == 0)
1064 BrowseProtocols
|= BROWSE_ALL
;
1067 LogMessage(L_ERROR
, "Unknown browse protocol \"%s\" on line %d.",
1072 for (value
+= valuelen
; *value
; value
++)
1073 if (!isspace(*value
) || *value
!= ',')
1077 else if (strcasecmp(name
, "BrowseAllow") == 0 ||
1078 strcasecmp(name
, "BrowseDeny") == 0)
1081 * BrowseAllow [From] host/ip...
1082 * BrowseDeny [From] host/ip...
1085 if ((location
= FindLocation("CUPS_INTERNAL_BROWSE_ACL")) == NULL
)
1086 location
= AddLocation("CUPS_INTERNAL_BROWSE_ACL");
1088 if (location
== NULL
)
1089 LogMessage(L_ERROR
, "Unable to initialize browse access control list!");
1092 if (strncasecmp(value
, "from ", 5) == 0)
1095 * Strip leading "from"...
1100 while (isspace(*value
))
1105 * Figure out what form the allow/deny address takes:
1116 * nnn.nnn.nnn.nnn/mm
1117 * nnn.nnn.nnn.nnn/mmm.mmm.mmm.mmm
1120 if (strcasecmp(value
, "all") == 0)
1126 if (strcasecmp(name
, "BrowseAllow") == 0)
1127 AllowIP(location
, zeros
, zeros
);
1129 DenyIP(location
, zeros
, zeros
);
1131 else if (strcasecmp(value
, "none") == 0)
1137 if (strcasecmp(name
, "BrowseAllow") == 0)
1138 AllowIP(location
, ones
, zeros
);
1140 DenyIP(location
, ones
, zeros
);
1142 else if (value
[0] == '*' || value
[0] == '.' || !isdigit(value
[0]))
1145 * Host or domain name...
1148 if (value
[0] == '*')
1151 if (strcasecmp(name
, "BrowseAllow") == 0)
1152 AllowHost(location
, value
);
1154 DenyHost(location
, value
);
1159 * One of many IP address forms...
1162 if (!get_addr_and_mask(value
, ip
, mask
))
1164 LogMessage(L_ERROR
, "Bad netmask value %s on line %d.",
1169 if (strcasecmp(name
, "BrowseAllow") == 0)
1170 AllowIP(location
, ip
, mask
);
1172 DenyIP(location
, ip
, mask
);
1176 else if (strcasecmp(name
, "BrowseRelay") == 0)
1179 * BrowseRelay [from] source [to] destination
1183 relay
= malloc(sizeof(dirsvc_relay_t
));
1185 relay
= realloc(Relays
, (NumRelays
+ 1) * sizeof(dirsvc_relay_t
));
1189 LogMessage(L_ERROR
, "Unable to allocate BrowseRelay at line %d - %s.",
1190 linenum
, strerror(errno
));
1197 memset(relay
, 0, sizeof(dirsvc_relay_t
));
1199 if (strncasecmp(value
, "from ", 5) == 0)
1202 * Strip leading "from"...
1207 while (isspace(*value
))
1212 * Figure out what form the from address takes:
1221 * nnn.nnn.nnn.nnn/mm
1222 * nnn.nnn.nnn.nnn/mmm.mmm.mmm.mmm
1225 if (value
[0] == '*' || value
[0] == '.' || !isdigit(value
[0]))
1228 * Host or domain name...
1231 if (value
[0] == '*')
1234 relay
->from
.type
= AUTH_NAME
;
1235 relay
->from
.mask
.name
.name
= strdup(value
);
1236 relay
->from
.mask
.name
.length
= strlen(value
);
1241 * One of many IP address forms...
1244 if (!get_addr_and_mask(value
, ip
, mask
))
1246 LogMessage(L_ERROR
, "Bad netmask value %s on line %d.",
1251 relay
->from
.type
= AUTH_IP
;
1252 memcpy(relay
->from
.mask
.ip
.address
, ip
,
1253 sizeof(relay
->from
.mask
.ip
.address
));
1254 memcpy(relay
->from
.mask
.ip
.netmask
, mask
,
1255 sizeof(relay
->from
.mask
.ip
.netmask
));
1259 * Skip value and trailing whitespace...
1262 for (; *value
; value
++)
1263 if (isspace(*value
))
1266 while (isspace(*value
))
1269 if (strncasecmp(value
, "to ", 3) == 0)
1272 * Strip leading "to"...
1277 while (isspace(*value
))
1282 * Get "to" address and port...
1285 if (get_address(value
, INADDR_BROADCAST
, BrowsePort
, AF_INET
, &(relay
->to
)))
1287 httpAddrString(&(relay
->to
), line
, sizeof(line
));
1289 if (relay
->from
.type
== AUTH_IP
)
1290 snprintf(name
, sizeof(name
), "%u.%u.%u.%u/%u.%u.%u.%u",
1291 relay
->from
.mask
.ip
.address
[0],
1292 relay
->from
.mask
.ip
.address
[1],
1293 relay
->from
.mask
.ip
.address
[2],
1294 relay
->from
.mask
.ip
.address
[3],
1295 relay
->from
.mask
.ip
.netmask
[0],
1296 relay
->from
.mask
.ip
.netmask
[1],
1297 relay
->from
.mask
.ip
.netmask
[2],
1298 relay
->from
.mask
.ip
.netmask
[3]);
1301 strncpy(name
, relay
->from
.mask
.name
.name
, sizeof(name
) - 1);
1302 name
[sizeof(name
) - 1] = '\0';
1306 if (relay
->to
.addr
.sa_family
== AF_INET6
)
1307 LogMessage(L_INFO
, "Relaying from %s to %s:%d", name
, line
,
1308 ntohs(relay
->to
.ipv6
.sin6_port
));
1310 #endif /* AF_INET6 */
1311 LogMessage(L_INFO
, "Relaying from %s to %s:%d", name
, line
,
1312 ntohs(relay
->to
.ipv4
.sin_port
));
1318 if (relay
->from
.type
== AUTH_NAME
)
1319 free(relay
->from
.mask
.name
.name
);
1321 LogMessage(L_ERROR
, "Bad relay address %s at line %d.", value
, linenum
);
1324 else if (strcasecmp(name
, "BrowsePoll") == 0)
1327 * BrowsePoll address[:port]
1331 poll
= malloc(sizeof(dirsvc_poll_t
));
1333 poll
= realloc(Polled
, (NumPolled
+ 1) * sizeof(dirsvc_poll_t
));
1337 LogMessage(L_ERROR
, "Unable to allocate BrowsePoll at line %d - %s.",
1338 linenum
, strerror(errno
));
1346 * Get poll address and port...
1349 if (get_address(value
, INADDR_NONE
, ippPort(), AF_INET
, &polladdr
))
1352 memset(poll
, 0, sizeof(dirsvc_poll_t
));
1354 httpAddrString(&polladdr
, poll
->hostname
, sizeof(poll
->hostname
));
1357 if (polladdr
.addr
.sa_family
== AF_INET6
)
1358 poll
->port
= ntohs(polladdr
.ipv6
.sin6_port
);
1360 #endif /* AF_INET6 */
1361 poll
->port
= ntohs(polladdr
.ipv4
.sin_port
);
1363 LogMessage(L_INFO
, "Polling %s:%d", poll
->hostname
, poll
->port
);
1366 LogMessage(L_ERROR
, "Bad poll address %s at line %d.", value
, linenum
);
1368 else if (strcasecmp(name
, "User") == 0)
1371 * User ID to run as...
1374 if (isdigit(value
[0]))
1378 struct passwd
*p
; /* Password information */
1381 p
= getpwnam(value
);
1386 LogMessage(L_WARN
, "ReadConfiguration() Unknown username \"%s\"",
1390 else if (strcasecmp(name
, "Group") == 0)
1393 * Group ID to run as...
1396 if (isdigit(value
[0]))
1397 Group
= atoi(value
);
1400 struct group
*g
; /* Group information */
1403 g
= getgrnam(value
);
1408 LogMessage(L_WARN
, "ReadConfiguration() Unknown groupname \"%s\"",
1412 else if (strcasecmp(name
, "SystemGroup") == 0)
1415 * System (admin) group(s)...
1418 char *valueptr
; /* Pointer into value */
1421 for (i
= NumSystemGroups
; *value
&& i
< MAX_SYSTEM_GROUPS
; i
++)
1423 for (valueptr
= value
; *valueptr
; valueptr
++)
1424 if (isspace(*valueptr
) || *valueptr
== ',')
1430 SetString(SystemGroups
+ i
, value
);
1434 while (*value
== ',' || isspace(*value
))
1439 NumSystemGroups
= i
;
1441 else if (strcasecmp(name
, "HostNameLookups") == 0)
1444 * Do hostname lookups?
1447 if (strcasecmp(value
, "off") == 0)
1448 HostNameLookups
= 0;
1449 else if (strcasecmp(value
, "on") == 0)
1450 HostNameLookups
= 1;
1451 else if (strcasecmp(value
, "double") == 0)
1452 HostNameLookups
= 2;
1454 LogMessage(L_WARN
, "ReadConfiguration() Unknown HostNameLookups %s on line %d.",
1457 else if (strcasecmp(name
, "LogLevel") == 0)
1460 * Amount of logging to do...
1463 if (strcasecmp(value
, "debug2") == 0)
1464 LogLevel
= L_DEBUG2
;
1465 else if (strcasecmp(value
, "debug") == 0)
1467 else if (strcasecmp(value
, "info") == 0)
1469 else if (strcasecmp(value
, "notice") == 0)
1470 LogLevel
= L_NOTICE
;
1471 else if (strcasecmp(value
, "warn") == 0)
1473 else if (strcasecmp(value
, "error") == 0)
1475 else if (strcasecmp(value
, "crit") == 0)
1477 else if (strcasecmp(value
, "alert") == 0)
1479 else if (strcasecmp(value
, "emerg") == 0)
1481 else if (strcasecmp(value
, "none") == 0)
1484 LogMessage(L_WARN
, "Unknown LogLevel %s on line %d.", value
, linenum
);
1486 else if (strcasecmp(name
, "PrintcapFormat") == 0)
1489 * Format of printcap file?
1492 if (strcasecmp(value
, "bsd") == 0)
1493 PrintcapFormat
= PRINTCAP_BSD
;
1494 else if (strcasecmp(value
, "solaris") == 0)
1495 PrintcapFormat
= PRINTCAP_SOLARIS
;
1497 LogMessage(L_WARN
, "ReadConfiguration() Unknown PrintcapFormat %s on line %d.",
1503 * Find a simple variable in the list...
1506 for (i
= NUM_VARS
, var
= variables
; i
> 0; i
--, var
++)
1507 if (strcasecmp(name
, var
->name
) == 0)
1513 * Unknown directive! Output an error message and continue...
1516 LogMessage(L_ERROR
, "Unknown directive %s on line %d.", name
,
1526 char *units
; /* Units */
1529 n
= strtol(value
, &units
, 0);
1531 if (units
&& *units
)
1533 if (tolower(units
[0]) == 'g')
1534 n
*= 1024 * 1024 * 1024;
1535 else if (tolower(units
[0]) == 'm')
1537 else if (tolower(units
[0]) == 'k')
1539 else if (tolower(units
[0]) == 't')
1543 *((int *)var
->ptr
) = n
;
1548 if (strcasecmp(value
, "true") == 0 ||
1549 strcasecmp(value
, "on") == 0 ||
1550 strcasecmp(value
, "enabled") == 0 ||
1551 strcasecmp(value
, "yes") == 0 ||
1553 *((int *)var
->ptr
) = TRUE
;
1554 else if (strcasecmp(value
, "false") == 0 ||
1555 strcasecmp(value
, "off") == 0 ||
1556 strcasecmp(value
, "disabled") == 0 ||
1557 strcasecmp(value
, "no") == 0 ||
1558 strcasecmp(value
, "0") == 0)
1559 *((int *)var
->ptr
) = FALSE
;
1561 LogMessage(L_ERROR
, "Unknown boolean value %s on line %d.",
1566 SetString((char **)var
->ptr
, value
);
1577 * 'read_location()' - Read a <Location path> definition.
1580 static int /* O - New line number or 0 on error */
1581 read_location(cups_file_t
*fp
, /* I - Configuration file */
1582 char *location
, /* I - Location name/path */
1583 int linenum
) /* I - Current line number */
1585 int i
; /* Looping var */
1586 location_t
*loc
, /* New location */
1587 *parent
; /* Parent location */
1588 int len
; /* Length of line */
1589 char line
[HTTP_MAX_BUFFER
], /* Line buffer */
1590 name
[256], /* Configuration directive */
1591 *nameptr
, /* Pointer into name */
1592 *value
, /* Value for directive */
1593 *valptr
; /* Pointer into value */
1594 unsigned ip
[4], /* IP address components */
1595 mask
[4]; /* IP netmask components */
1598 if ((parent
= AddLocation(location
)) == NULL
)
1601 parent
->limit
= AUTH_LIMIT_ALL
;
1604 while (cupsFileGets(fp
, line
, sizeof(line
)) != NULL
)
1609 * Skip comment lines...
1616 * Strip trailing whitespace, if any...
1621 while (len
> 0 && isspace(line
[len
- 1]))
1628 * Extract the name from the beginning of the line...
1631 for (value
= line
; isspace(*value
); value
++);
1633 for (nameptr
= name
; *value
!= '\0' && !isspace(*value
) &&
1634 nameptr
< (name
+ sizeof(name
) - 1);)
1635 *nameptr
++ = *value
++;
1638 while (isspace(*value
))
1641 if (name
[0] == '\0')
1645 * Decode the directive...
1648 if (strcasecmp(name
, "</Location>") == 0)
1650 else if (strcasecmp(name
, "<Limit") == 0 ||
1651 strcasecmp(name
, "<LimitExcept") == 0)
1653 if ((loc
= CopyLocation(&parent
)) == NULL
)
1659 for (valptr
= value
;
1660 !isspace(*valptr
) && *valptr
!= '>' && *valptr
;
1666 if (strcmp(value
, "ALL") == 0)
1667 loc
->limit
= AUTH_LIMIT_ALL
;
1668 else if (strcmp(value
, "GET") == 0)
1669 loc
->limit
|= AUTH_LIMIT_GET
;
1670 else if (strcmp(value
, "HEAD") == 0)
1671 loc
->limit
|= AUTH_LIMIT_HEAD
;
1672 else if (strcmp(value
, "OPTIONS") == 0)
1673 loc
->limit
|= AUTH_LIMIT_OPTIONS
;
1674 else if (strcmp(value
, "POST") == 0)
1675 loc
->limit
|= AUTH_LIMIT_POST
;
1676 else if (strcmp(value
, "PUT") == 0)
1677 loc
->limit
|= AUTH_LIMIT_PUT
;
1678 else if (strcmp(value
, "TRACE") == 0)
1679 loc
->limit
|= AUTH_LIMIT_TRACE
;
1681 LogMessage(L_WARN
, "Unknown request type %s on line %d!", value
,
1684 for (value
= valptr
; isspace(*value
) || *value
== '>'; value
++);
1687 if (strcasecmp(name
, "<LimitExcept") == 0)
1688 loc
->limit
= AUTH_LIMIT_ALL
^ loc
->limit
;
1690 parent
->limit
&= ~loc
->limit
;
1692 else if (strcasecmp(name
, "</Limit>") == 0)
1694 else if (strcasecmp(name
, "Encryption") == 0)
1697 * "Encryption xxx" - set required encryption level...
1700 if (strcasecmp(value
, "never") == 0)
1701 loc
->encryption
= HTTP_ENCRYPT_NEVER
;
1702 else if (strcasecmp(value
, "always") == 0)
1704 LogMessage(L_ERROR
, "Encryption value \"%s\" on line %d is invalid in this context. "
1705 "Using \"required\" instead.", value
, linenum
);
1707 loc
->encryption
= HTTP_ENCRYPT_REQUIRED
;
1709 else if (strcasecmp(value
, "required") == 0)
1710 loc
->encryption
= HTTP_ENCRYPT_REQUIRED
;
1711 else if (strcasecmp(value
, "ifrequested") == 0)
1712 loc
->encryption
= HTTP_ENCRYPT_IF_REQUESTED
;
1714 LogMessage(L_ERROR
, "Unknown Encryption value %s on line %d.",
1717 else if (strcasecmp(name
, "Order") == 0)
1720 * "Order Deny,Allow" or "Order Allow,Deny"...
1723 if (strncasecmp(value
, "deny", 4) == 0)
1724 loc
->order_type
= AUTH_ALLOW
;
1725 else if (strncasecmp(value
, "allow", 5) == 0)
1726 loc
->order_type
= AUTH_DENY
;
1728 LogMessage(L_ERROR
, "Unknown Order value %s on line %d.",
1731 else if (strcasecmp(name
, "Allow") == 0 ||
1732 strcasecmp(name
, "Deny") == 0)
1735 * Allow [From] host/ip...
1736 * Deny [From] host/ip...
1739 if (strncasecmp(value
, "from", 4) == 0)
1742 * Strip leading "from"...
1747 while (isspace(*value
))
1752 * Figure out what form the allow/deny address takes:
1763 * nnn.nnn.nnn.nnn/mm
1764 * nnn.nnn.nnn.nnn/mmm.mmm.mmm.mmm
1767 if (strcasecmp(value
, "all") == 0)
1773 if (strcasecmp(name
, "Allow") == 0)
1774 AllowIP(loc
, zeros
, zeros
);
1776 DenyIP(loc
, zeros
, zeros
);
1778 else if (strcasecmp(value
, "none") == 0)
1784 if (strcasecmp(name
, "Allow") == 0)
1785 AllowIP(loc
, ones
, zeros
);
1787 DenyIP(loc
, ones
, zeros
);
1789 else if (value
[0] == '*' || value
[0] == '.' || !isdigit(value
[0]))
1792 * Host or domain name...
1795 if (value
[0] == '*')
1798 if (strcasecmp(name
, "Allow") == 0)
1799 AllowHost(loc
, value
);
1801 DenyHost(loc
, value
);
1806 * One of many IP address forms...
1809 if (!get_addr_and_mask(value
, ip
, mask
))
1811 LogMessage(L_ERROR
, "Bad netmask value %s on line %d.",
1816 if (strcasecmp(name
, "Allow") == 0)
1817 AllowIP(loc
, ip
, mask
);
1819 DenyIP(loc
, ip
, mask
);
1822 else if (strcasecmp(name
, "AuthType") == 0)
1825 * AuthType {none,basic,digest,basicdigest}
1828 if (strcasecmp(value
, "none") == 0)
1830 loc
->type
= AUTH_NONE
;
1831 loc
->level
= AUTH_ANON
;
1833 else if (strcasecmp(value
, "basic") == 0)
1835 loc
->type
= AUTH_BASIC
;
1837 if (loc
->level
== AUTH_ANON
)
1838 loc
->level
= AUTH_USER
;
1840 else if (strcasecmp(value
, "digest") == 0)
1842 loc
->type
= AUTH_DIGEST
;
1844 if (loc
->level
== AUTH_ANON
)
1845 loc
->level
= AUTH_USER
;
1847 else if (strcasecmp(value
, "basicdigest") == 0)
1849 loc
->type
= AUTH_BASICDIGEST
;
1851 if (loc
->level
== AUTH_ANON
)
1852 loc
->level
= AUTH_USER
;
1855 LogMessage(L_WARN
, "Unknown authorization type %s on line %d.",
1858 else if (strcasecmp(name
, "AuthClass") == 0)
1861 * AuthClass anonymous, user, system, group
1864 if (strcasecmp(value
, "anonymous") == 0)
1866 loc
->type
= AUTH_NONE
;
1867 loc
->level
= AUTH_ANON
;
1869 else if (strcasecmp(value
, "user") == 0)
1870 loc
->level
= AUTH_USER
;
1871 else if (strcasecmp(value
, "group") == 0)
1872 loc
->level
= AUTH_GROUP
;
1873 else if (strcasecmp(value
, "system") == 0)
1875 loc
->level
= AUTH_GROUP
;
1878 * Use the default system group if none is defined so far...
1881 if (NumSystemGroups
== 0)
1882 NumSystemGroups
= 1;
1884 for (i
= 0; i
< NumSystemGroups
; i
++)
1885 AddName(loc
, SystemGroups
[i
]);
1888 LogMessage(L_WARN
, "Unknown authorization class %s on line %d.",
1891 else if (strcasecmp(name
, "AuthGroupName") == 0)
1892 AddName(loc
, value
);
1893 else if (strcasecmp(name
, "Require") == 0)
1896 * Apache synonym for AuthClass and AuthGroupName...
1900 * Require valid-user
1901 * Require group names
1902 * Require user names
1905 for (valptr
= value
;
1906 !isspace(*valptr
) && *valptr
!= '>' && *valptr
;
1912 if (strcasecmp(value
, "valid-user") == 0 ||
1913 strcasecmp(value
, "user") == 0)
1914 loc
->level
= AUTH_USER
;
1915 else if (strcasecmp(value
, "group") == 0)
1916 loc
->level
= AUTH_GROUP
;
1919 LogMessage(L_WARN
, "Unknown Require type %s on line %d.",
1925 * Get the list of names from the line...
1928 for (value
= valptr
; *value
;)
1930 for (valptr
= value
; !isspace(*valptr
) && *valptr
; valptr
++);
1935 AddName(loc
, value
);
1937 for (value
= valptr
; isspace(*value
); value
++);
1940 else if (strcasecmp(name
, "Satisfy") == 0)
1942 if (strcasecmp(value
, "all") == 0)
1943 loc
->satisfy
= AUTH_SATISFY_ALL
;
1944 else if (strcasecmp(value
, "any") == 0)
1945 loc
->satisfy
= AUTH_SATISFY_ANY
;
1947 LogMessage(L_WARN
, "Unknown Satisfy value %s on line %d.", value
,
1951 LogMessage(L_ERROR
, "Unknown Location directive %s on line %d.",
1960 * 'get_address()' - Get an address + port number from a line.
1963 static int /* O - 1 if address good, 0 if bad */
1964 get_address(const char *value
, /* I - Value string */
1965 unsigned defaddress
, /* I - Default address */
1966 int defport
, /* I - Default port */
1967 int deffamily
, /* I - Default family */
1968 http_addr_t
*address
) /* O - Socket address */
1970 char hostname
[256], /* Hostname or IP */
1971 portname
[256]; /* Port number or name */
1972 struct hostent
*host
; /* Host address */
1973 struct servent
*port
; /* Port number */
1977 * Initialize the socket address to the defaults...
1980 memset(address
, 0, sizeof(http_addr_t
));
1983 if (deffamily
== AF_INET6
)
1985 address
->ipv6
.sin6_family
= AF_INET6
;
1986 address
->ipv6
.sin6_addr
.s6_addr32
[0] = htonl(defaddress
);
1987 address
->ipv6
.sin6_addr
.s6_addr32
[1] = htonl(defaddress
);
1988 address
->ipv6
.sin6_addr
.s6_addr32
[2] = htonl(defaddress
);
1989 address
->ipv6
.sin6_addr
.s6_addr32
[3] = htonl(defaddress
);
1990 address
->ipv6
.sin6_port
= htons(defport
);
1993 #endif /* AF_INET6 */
1995 address
->ipv4
.sin_family
= AF_INET
;
1996 address
->ipv4
.sin_addr
.s_addr
= htonl(defaddress
);
1997 address
->ipv4
.sin_port
= htons(defport
);
2001 * Try to grab a hostname and port number...
2004 switch (sscanf(value
, "%255[^:]:%255s", hostname
, portname
))
2007 if (strchr(hostname
, '.') == NULL
&& defaddress
== INADDR_ANY
)
2010 * Hostname is a port number...
2013 strlcpy(portname
, hostname
, sizeof(portname
));
2024 LogMessage(L_ERROR
, "Unable to decode address \"%s\"!", value
);
2029 * Decode the hostname and port number as needed...
2032 if (hostname
[0] && strcmp(hostname
, "*"))
2034 if ((host
= httpGetHostByName(hostname
)) == NULL
)
2036 LogMessage(L_ERROR
, "httpGetHostByName(\"%s\") failed - %s!", hostname
,
2037 hstrerror(h_errno
));
2041 httpAddrLoad(host
, defport
, 0, address
);
2044 if (portname
[0] != '\0')
2046 if (isdigit(portname
[0]))
2049 if (address
->addr
.sa_family
== AF_INET6
)
2050 address
->ipv6
.sin6_port
= htons(atoi(portname
));
2052 #endif /* AF_INET6 */
2053 address
->ipv4
.sin_port
= htons(atoi(portname
));
2057 if ((port
= getservbyname(portname
, NULL
)) == NULL
)
2059 LogMessage(L_ERROR
, "getservbyname(\"%s\") failed - %s!", portname
,
2066 if (address
->addr
.sa_family
== AF_INET6
)
2067 address
->ipv6
.sin6_port
= htons(port
->s_port
);
2069 #endif /* AF_INET6 */
2070 address
->ipv4
.sin_port
= htons(port
->s_port
);
2080 * 'get_addr_and_mask()' - Get an IP address and netmask.
2083 static int /* O - 1 on success, 0 on failure */
2084 get_addr_and_mask(const char *value
, /* I - String from config file */
2085 unsigned *ip
, /* O - Address value */
2086 unsigned *mask
) /* O - Mask value */
2088 int i
, /* Looping var */
2089 family
, /* Address family */
2090 ipcount
; /* Count of fields in address */
2091 static unsigned netmasks
[4][4] = /* Standard netmasks... */
2093 { 0xffffffff, 0x00000000, 0x00000000, 0x00000000 },
2094 { 0xffffffff, 0xffffffff, 0x00000000, 0x00000000 },
2095 { 0xffffffff, 0xffffffff, 0xffffffff, 0x00000000 },
2096 { 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff }
2101 * Get the address...
2104 memset(ip
, 0, sizeof(unsigned) * 4);
2106 ipcount
= sscanf(value
, "%u.%u.%u.%u", ip
+ 0, ip
+ 1, ip
+ 2, ip
+ 3);
2110 * See if we have any values > 255; if so, this is an IPv6 address only.
2113 for (i
= 0; i
< ipcount
; i
++)
2119 #endif /* AF_INET6 */
2121 if ((value
= strchr(value
, '/')) != NULL
)
2124 * Get the netmask value(s)...
2128 memset(mask
, 0, sizeof(unsigned) * 4);
2129 switch (sscanf(value
, "%u.%u.%u.%u", mask
+ 0, mask
+ 1,
2130 mask
+ 2, mask
+ 3))
2137 if (family
== AF_INET6
)
2142 mask
[0] = 0xffffffff;
2144 mask
[0] = (0xffffffff << (128 - mask
[0])) & 0xffffffff;
2147 mask
[1] = 0xffffffff;
2151 mask
[1] = (0xffffffff << (96 - mask
[0])) & 0xffffffff;
2154 mask
[1] = 0xffffffff;
2158 mask
[1] = (0xffffffff << (64 - mask
[0])) & 0xffffffff;
2163 mask
[1] = (0xffffffff << (32 - mask
[0])) & 0xffffffff;
2166 #endif /* AF_INET6 */
2171 mask
[0] = 0xffffffff;
2173 mask
[0] = (0xffffffff << (32 - mask
[0])) & 0xffffffff;
2176 mask
[1] = 0xffffffff;
2180 mask
[1] = (0xffffffff << (24 - mask
[0])) & 0xffffffff;
2183 mask
[1] = 0xffffffff;
2187 mask
[1] = (0xffffffff << (16 - mask
[0])) & 0xffffffff;
2192 mask
[1] = (0xffffffff << (8 - mask
[0])) & 0xffffffff;
2203 memcpy(mask
, netmasks
[ipcount
- 1], sizeof(unsigned) * 4);
2206 * Check for a valid netmask; no fallback like in CUPS 1.1.x!
2209 if ((ip
[0] & ~mask
[0]) != 0 ||
2210 (ip
[1] & ~mask
[1]) != 0 ||
2211 (ip
[2] & ~mask
[2]) != 0 ||
2212 (ip
[3] & ~mask
[3]) != 0)
2221 * 'CDSAGetServerCerts()' - Convert a keychain name into the CFArrayRef
2222 * required by SSLSetCertificate.
2224 * For now we assumes that there is exactly one SecIdentity in the
2225 * keychain - i.e. there is exactly one matching cert/private key pair.
2226 * In the future we will search a keychain for a SecIdentity matching a
2227 * specific criteria. We also skip the operation of adding additional
2228 * non-signing certs from the keychain to the CFArrayRef.
2230 * To create a self-signed certificate for testing use the certtool.
2231 * Executing the following as root will do it:
2233 * certtool c c v k=CUPS
2237 CDSAGetServerCerts(void)
2239 OSStatus err
; /* Error info */
2240 SecKeychainRef kcRef
; /* Keychain reference */
2241 SecIdentitySearchRef srchRef
; /* Search reference */
2242 SecIdentityRef identity
; /* Identity */
2243 CFArrayRef ca
; /* Certificate array */
2250 err
= SecKeychainOpen(ServerCertificate
, &kcRef
);
2253 LogMessage(L_ERROR
, "Cannot open keychain \"%s\", error %d.",
2254 ServerCertificate
, err
);
2258 * Search for "any" identity matching specified key use;
2259 * in this app, we expect there to be exactly one.
2262 err
= SecIdentitySearchCreate(kcRef
, CSSM_KEYUSE_SIGN
, &srchRef
);
2266 "Cannot find signing key in keychain \"%s\", error %d",
2267 ServerCertificate
, err
);
2270 err
= SecIdentitySearchCopyNext(srchRef
, &identity
);
2274 "Cannot find signing key in keychain \"%s\", error %d",
2275 ServerCertificate
, err
);
2278 if (CFGetTypeID(identity
) != SecIdentityGetTypeID())
2279 LogMessage(L_ERROR
, "SecIdentitySearchCopyNext CFTypeID failure!");
2283 * Found one. Place it in a CFArray.
2284 * TBD: snag other (non-identity) certs from keychain and add them
2288 ca
= CFArrayCreate(NULL
, (const void **)&identity
, 1, NULL
);
2291 LogMessage(L_ERROR
, "CFArrayCreate error");
2294 /*CFRelease(identity);*/
2297 /*CFRelease(srchRef);*/
2300 /*CFRelease(kcRef);*/
2305 #endif /* HAVE_CDSASSL */
2309 * End of "$Id: conf.c,v 1.77.2.48 2004/02/24 21:36:59 mike Exp $".