2 * "$Id: conf.c,v 1.152 2005/01/03 19:29:59 mike Exp $"
4 * Configuration routines for the Common UNIX Printing System (CUPS).
6 * Copyright 1997-2005 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 USA
20 * Voice: (301) 373-9600
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 * CDSAGetServerCerts() - Convert a keychain name into the CFArrayRef
31 * required by SSLSetCertificate.
35 * Include necessary headers...
42 #include <sys/utsname.h>
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 { "MaxClients", &MaxClients
, VAR_INTEGER
},
115 { "MaxClientsPerHost", &MaxClientsPerHost
, VAR_INTEGER
},
116 { "MaxCopies", &MaxCopies
, VAR_INTEGER
},
117 { "MaxJobs", &MaxJobs
, VAR_INTEGER
},
118 { "MaxJobsPerPrinter", &MaxJobsPerPrinter
, VAR_INTEGER
},
119 { "MaxJobsPerUser", &MaxJobsPerUser
, VAR_INTEGER
},
120 { "MaxLogSize", &MaxLogSize
, VAR_INTEGER
},
121 { "MaxPrinterHistory", &MaxPrinterHistory
, VAR_INTEGER
},
122 { "MaxRequestSize", &MaxRequestSize
, VAR_INTEGER
},
123 { "PageLog", &PageLog
, VAR_STRING
},
124 { "PreserveJobFiles", &JobFiles
, VAR_BOOLEAN
},
125 { "PreserveJobHistory", &JobHistory
, VAR_BOOLEAN
},
126 { "Printcap", &Printcap
, VAR_STRING
},
127 { "PrintcapGUI", &PrintcapGUI
, VAR_STRING
},
128 { "ReloadTimeout", &ReloadTimeout
, VAR_INTEGER
},
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]))
154 static int read_configuration(cups_file_t
*fp
);
155 static int read_location(cups_file_t
*fp
, char *name
, int linenum
);
156 static int get_address(char *value
, unsigned defaddress
, int defport
,
157 struct sockaddr_in
*address
);
160 static CFArrayRef
CDSAGetServerCerts();
161 #endif /* HAVE_CDSASSL */
165 * 'ReadConfiguration()' - Read the cupsd.conf file.
168 int /* O - 1 on success, 0 otherwise */
169 ReadConfiguration(void)
171 int i
; /* Looping var */
172 cups_file_t
*fp
; /* Configuration file */
173 int status
; /* Return status */
174 char temp
[1024], /* Temporary buffer */
175 *slash
; /* Directory separator */
176 char type
[MIME_MAX_SUPER
+ MIME_MAX_TYPE
];
178 char *language
; /* Language string */
179 struct passwd
*user
; /* Default user */
180 struct group
*group
; /* Default group */
181 char *old_serverroot
, /* Old ServerRoot */
182 *old_requestroot
; /* Old RequestRoot */
186 * Shutdown the server...
192 * Save the old root paths...
195 old_serverroot
= NULL
;
196 SetString(&old_serverroot
, ServerRoot
);
197 old_requestroot
= NULL
;
198 SetString(&old_requestroot
, RequestRoot
);
201 * Reset the server configuration data...
204 DeleteAllLocations();
222 for (i
= 0; i
< NumRelays
; i
++)
223 if (Relays
[i
].from
.type
== AUTH_NAME
)
224 free(Relays
[i
].from
.mask
.name
.name
);
231 if (NumListeners
> 0)
242 gethostname(temp
, sizeof(temp
));
243 SetString(&ServerName
, temp
);
244 SetStringf(&ServerAdmin
, "root@%s", temp
);
245 SetString(&ServerBin
, CUPS_SERVERBIN
);
246 SetString(&RequestRoot
, CUPS_REQUESTS
);
247 SetString(&DocumentRoot
, CUPS_DOCROOT
);
248 SetString(&DataDir
, CUPS_DATADIR
);
249 SetString(&AccessLog
, CUPS_LOGDIR
"/access_log");
250 SetString(&ErrorLog
, CUPS_LOGDIR
"/error_log");
251 SetString(&PageLog
, CUPS_LOGDIR
"/page_log");
252 SetString(&Printcap
, "/etc/printcap");
253 SetString(&PrintcapGUI
, "/usr/bin/glpoptions");
254 SetString(&FontPath
, CUPS_FONTPATH
);
255 SetString(&RemoteRoot
, "remroot");
256 SetString(&ServerHeader
, "CUPS/1.1");
258 strlcpy(temp
, ConfigurationFile
, sizeof(temp
));
259 if ((slash
= strrchr(temp
, '/')) != NULL
)
262 SetString(&ServerRoot
, temp
);
264 ClearString(&Classification
);
265 ClassifyOverride
= 0;
269 SetString(&ServerCertificate
, "/var/root/Library/Keychains/CUPS");
271 SetString(&ServerCertificate
, "ssl/server.crt");
272 SetString(&ServerKey
, "ssl/server.key");
273 # endif /* HAVE_CDSASSL */
274 #endif /* HAVE_SSL */
276 if ((language
= DEFAULT_LANGUAGE
) == NULL
)
278 else if (strcmp(language
, "C") == 0 || strcmp(language
, "POSIX") == 0)
281 SetString(&DefaultLanguage
, language
);
282 SetString(&DefaultCharset
, DEFAULT_CHARSET
);
284 SetString(&RIPCache
, "8m");
286 if (getenv("TMPDIR") == NULL
)
287 SetString(&TempDir
, CUPS_REQUESTS
"/tmp");
289 SetString(&TempDir
, getenv("TMPDIR"));
292 * Find the default system group: "sys", "system", or "root"...
295 group
= getgrnam(CUPS_DEFAULT_GROUP
);
302 SetString(&SystemGroups
[0], CUPS_DEFAULT_GROUP
);
303 Group
= group
->gr_gid
;
312 SetString(&SystemGroups
[0], group
->gr_name
);
317 SetString(&SystemGroups
[0], "unknown");
323 * Find the default user...
326 if ((user
= getpwnam(CUPS_DEFAULT_USER
)) == NULL
)
327 User
= 1; /* Force to a non-priviledged account */
337 ConfigFilePerm
= 0640;
341 FaxRetryInterval
= 300;
346 HostNameLookups
= FALSE
;
347 ImplicitClasses
= TRUE
;
348 ImplicitAnyClasses
= FALSE
;
349 HideImplicitMembers
= TRUE
;
351 KeepAliveTimeout
= DEFAULT_KEEPALIVE
;
352 ListenBackLog
= SOMAXCONN
;
355 MaxClientsPerHost
= 0;
356 MaxLogSize
= 1024 * 1024;
357 MaxPrinterHistory
= 10;
360 RootCertDuration
= 300;
362 Timeout
= DEFAULT_TIMEOUT
;
364 BrowseInterval
= DEFAULT_INTERVAL
;
365 BrowsePort
= ippPort();
366 BrowseProtocols
= BROWSE_CUPS
;
367 BrowseShortNames
= TRUE
;
368 BrowseTimeout
= DEFAULT_TIMEOUT
;
371 JobHistory
= DEFAULT_HISTORY
;
372 JobFiles
= DEFAULT_FILES
;
376 MaxJobsPerPrinter
= 0;
380 * Read the configuration file...
383 if ((fp
= cupsFileOpen(ConfigurationFile
, "r")) == NULL
)
386 status
= read_configuration(fp
);
399 * Use the default system group if none was supplied in cupsd.conf...
402 if (NumSystemGroups
== 0)
406 * Get the access control list for browsing...
409 BrowseACL
= FindLocation("CUPS_INTERNAL_BROWSE_ACL");
412 * Open the system log for cupsd if necessary...
416 if (strcmp(AccessLog
, "syslog") == 0 ||
417 strcmp(ErrorLog
, "syslog") == 0 ||
418 strcmp(PageLog
, "syslog") == 0)
419 openlog("cupsd", LOG_PID
| LOG_NOWAIT
| LOG_NDELAY
, LOG_LPR
);
420 #endif /* HAVE_VSYSLOG */
423 * Log the configuration file that was used...
426 LogMessage(L_INFO
, "Loaded configuration file \"%s\"", ConfigurationFile
);
429 * Check that we have at least one listen/port line; if not, report this
430 * as an error and exit!
433 if (NumListeners
== 0)
439 LogMessage(L_EMERG
, "No valid Listen or Port lines were found in the configuration file!");
445 kill(getpid(), SIGTERM
);
449 * Set the default locale using the language and charset...
452 SetStringf(&DefaultLocale
, "%s.%s", DefaultLanguage
, DefaultCharset
);
455 * Update all relative filenames to include the full path from ServerRoot...
458 if (DocumentRoot
[0] != '/')
459 SetStringf(&DocumentRoot
, "%s/%s", ServerRoot
, DocumentRoot
);
461 if (RequestRoot
[0] != '/')
462 SetStringf(&RequestRoot
, "%s/%s", ServerRoot
, RequestRoot
);
464 if (ServerBin
[0] != '/')
465 SetStringf(&ServerBin
, "%s/%s", ServerRoot
, ServerBin
);
468 if (ServerCertificate
[0] != '/')
469 SetStringf(&ServerCertificate
, "%s/%s", ServerRoot
, ServerCertificate
);
471 # if defined(HAVE_LIBSSL) || defined(HAVE_GNUTLS)
472 chown(ServerCertificate
, RunUser
, Group
);
473 chmod(ServerCertificate
, ConfigFilePerm
);
475 if (ServerKey
[0] != '/')
476 SetStringf(&ServerKey
, "%s/%s", ServerRoot
, ServerKey
);
478 chown(ServerKey
, RunUser
, Group
);
479 chmod(ServerKey
, ConfigFilePerm
);
480 # endif /* HAVE_LIBSSL || HAVE_GNUTLS */
481 #endif /* HAVE_SSL */
484 * Make sure that ServerRoot and the config files are owned and
485 * writable by the user and group in the cupsd.conf file...
488 chown(ServerRoot
, RunUser
, Group
);
489 chmod(ServerRoot
, 0775);
491 snprintf(temp
, sizeof(temp
), "%s/certs", ServerRoot
);
492 chown(temp
, RunUser
, Group
);
495 snprintf(temp
, sizeof(temp
), "%s/ppd", ServerRoot
);
496 chown(temp
, RunUser
, Group
);
499 snprintf(temp
, sizeof(temp
), "%s/ssl", ServerRoot
);
500 chown(temp
, RunUser
, Group
);
503 snprintf(temp
, sizeof(temp
), "%s/cupsd.conf", ServerRoot
);
504 chown(temp
, RunUser
, Group
);
505 chmod(temp
, ConfigFilePerm
);
507 snprintf(temp
, sizeof(temp
), "%s/classes.conf", ServerRoot
);
508 chown(temp
, RunUser
, Group
);
512 chmod(temp
, ConfigFilePerm
);
513 #endif /* __APPLE__ */
515 snprintf(temp
, sizeof(temp
), "%s/printers.conf", ServerRoot
);
516 chown(temp
, RunUser
, Group
);
520 chmod(temp
, ConfigFilePerm
);
521 #endif /* __APPLE__ */
523 snprintf(temp
, sizeof(temp
), "%s/passwd.md5", ServerRoot
);
524 chown(temp
, User
, Group
);
528 * Make sure the request and temporary directories have the right
532 chown(RequestRoot
, RunUser
, Group
);
533 chmod(RequestRoot
, 0710);
535 if (strncmp(TempDir
, RequestRoot
, strlen(RequestRoot
)) == 0)
538 * Only update ownership and permissions if the CUPS temp directory
539 * is under the spool directory...
542 chown(TempDir
, RunUser
, Group
);
543 chmod(TempDir
, 01770);
547 * Check the MaxClients setting, and then allocate memory for it...
550 if (MaxClients
> (MaxFDs
/ 3) || MaxClients
<= 0)
553 LogMessage(L_INFO
, "MaxClients limited to 1/3 of the file descriptor limit (%d)...",
556 MaxClients
= MaxFDs
/ 3;
559 if ((Clients
= calloc(sizeof(client_t
), MaxClients
)) == NULL
)
561 LogMessage(L_ERROR
, "ReadConfiguration: Unable to allocate memory for %d clients: %s",
562 MaxClients
, strerror(errno
));
566 LogMessage(L_INFO
, "Configured for up to %d clients.", MaxClients
);
568 if (Classification
&& strcasecmp(Classification
, "none") == 0)
569 ClearString(&Classification
);
572 LogMessage(L_INFO
, "Security set to \"%s\"", Classification
);
575 * Update the MaxClientsPerHost value, as needed...
578 if (MaxClientsPerHost
<= 0)
579 MaxClientsPerHost
= MaxClients
;
581 if (MaxClientsPerHost
> MaxClients
)
582 MaxClientsPerHost
= MaxClients
;
584 LogMessage(L_INFO
, "Allowing up to %d client connections per host.",
588 * If we are doing a full reload or the server root has changed, flush
589 * the jobs, printers, etc. and start from scratch...
592 if (NeedReload
== RELOAD_ALL
||
593 !old_serverroot
|| !ServerRoot
|| strcmp(old_serverroot
, ServerRoot
) ||
594 !old_requestroot
|| !RequestRoot
|| strcmp(old_requestroot
, RequestRoot
))
596 LogMessage(L_INFO
, "Full reload is required.");
606 DefaultPrinter
= NULL
;
620 if (MimeDatabase
!= NULL
)
621 mimeDelete(MimeDatabase
);
625 for (i
= 0; i
< NumMimeTypes
; i
++)
626 free((void *)MimeTypes
[i
]);
632 * Read the MIME type and conversion database...
635 snprintf(temp
, sizeof(temp
), "%s/filter", ServerBin
);
637 MimeDatabase
= mimeNew();
638 mimeMerge(MimeDatabase
, ServerRoot
, temp
);
641 * Create a list of MIME types for the document-format-supported
645 NumMimeTypes
= MimeDatabase
->num_types
;
646 if (!mimeType(MimeDatabase
, "application", "octet-stream"))
649 MimeTypes
= calloc(NumMimeTypes
, sizeof(const char *));
651 for (i
= 0; i
< MimeDatabase
->num_types
; i
++)
653 snprintf(type
, sizeof(type
), "%s/%s", MimeDatabase
->types
[i
]->super
,
654 MimeDatabase
->types
[i
]->type
);
656 MimeTypes
[i
] = strdup(type
);
659 if (i
< NumMimeTypes
)
660 MimeTypes
[i
] = strdup("application/octet-stream");
666 snprintf(temp
, sizeof(temp
), "%s/banners", DataDir
);
670 * Load printers and classes...
679 * Load devices and PPDs...
682 snprintf(temp
, sizeof(temp
), "%s/backend", ServerBin
);
685 snprintf(temp
, sizeof(temp
), "%s/model", DataDir
);
689 * Load queued jobs...
694 LogMessage(L_INFO
, "Full reload complete.");
700 LogMessage(L_INFO
, "Partial reload complete.");
704 * Reset the reload state...
707 NeedReload
= RELOAD_NONE
;
709 ClearString(&old_serverroot
);
710 ClearString(&old_requestroot
);
713 * Startup the server and return...
723 * 'read_configuration()' - Read a configuration file.
726 static int /* O - 1 on success, 0 on failure */
727 read_configuration(cups_file_t
*fp
) /* I - File to read from */
729 int i
; /* Looping var */
730 int linenum
; /* Current line number */
731 int len
; /* Length of line */
732 char line
[HTTP_MAX_BUFFER
], /* Line from file */
733 name
[256], /* Parameter name */
734 *nameptr
, /* Pointer into name */
735 *value
; /* Pointer to value */
736 int valuelen
; /* Length of value */
737 var_t
*var
; /* Current variable */
738 unsigned address
, /* Address value */
739 netmask
; /* Netmask value */
740 int ip
[4], /* IP address components */
741 ipcount
, /* Number of components provided */
742 mask
[4]; /* IP netmask components */
743 dirsvc_relay_t
*relay
; /* Relay data */
744 dirsvc_poll_t
*poll
; /* Polling data */
745 struct sockaddr_in polladdr
; /* Polling address */
746 location_t
*location
; /* Browse location */
747 cups_file_t
*incfile
; /* Include file */
748 char incname
[1024]; /* Include filename */
749 static unsigned netmasks
[4] = /* Standard netmasks... */
759 * Loop through each line in the file...
764 while (cupsFileGets(fp
, line
, sizeof(line
)) != NULL
)
769 * Skip comment lines...
776 * Strip trailing whitespace, if any...
781 while (len
> 0 && isspace(line
[len
- 1]))
788 * Extract the name from the beginning of the line...
791 for (value
= line
; isspace(*value
); value
++);
793 for (nameptr
= name
; *value
!= '\0' && !isspace(*value
) &&
794 nameptr
< (name
+ sizeof(name
) - 1);)
795 *nameptr
++ = *value
++;
798 while (isspace(*value
))
805 * Decode the directive...
808 if (strcasecmp(name
, "Include") == 0)
815 strlcpy(incname
, value
, sizeof(incname
));
817 snprintf(incname
, sizeof(incname
), "%s/%s", ServerRoot
, value
);
819 if ((incfile
= cupsFileOpen(incname
, "rb")) == NULL
)
820 LogMessage(L_ERROR
, "Unable to include config file \"%s\" - %s",
821 incname
, strerror(errno
));
824 read_configuration(incfile
);
825 cupsFileClose(incfile
);
828 else if (strcasecmp(name
, "<Location") == 0)
834 if (line
[len
- 1] == '>')
836 line
[len
- 1] = '\0';
838 linenum
= read_location(fp
, value
, linenum
);
844 LogMessage(L_ERROR
, "Syntax error on line %d.",
849 else if (strcasecmp(name
, "Port") == 0 ||
850 strcasecmp(name
, "Listen") == 0)
853 * Add a listening address to the list...
856 listener_t
*temp
; /* New listeners array */
859 if (NumListeners
== 0)
860 temp
= malloc(sizeof(listener_t
));
862 temp
= realloc(Listeners
, (NumListeners
+ 1) * sizeof(listener_t
));
866 LogMessage(L_ERROR
, "Unable to allocate %s at line %d - %s.",
867 name
, linenum
, strerror(errno
));
872 temp
+= NumListeners
;
874 memset(temp
, 0, sizeof(listener_t
));
876 if (get_address(value
, INADDR_ANY
, IPP_PORT
, &(temp
->address
)))
878 LogMessage(L_INFO
, "Listening to %x:%d",
879 (unsigned)ntohl(temp
->address
.sin_addr
.s_addr
),
880 ntohs(temp
->address
.sin_port
));
884 LogMessage(L_ERROR
, "Bad %s address %s at line %d.", name
,
888 else if (strcasecmp(name
, "SSLPort") == 0 ||
889 strcasecmp(name
, "SSLListen") == 0)
892 * Add a listening address to the list...
895 listener_t
*temp
; /* New listeners array */
898 if (NumListeners
== 0)
899 temp
= malloc(sizeof(listener_t
));
901 temp
= realloc(Listeners
, (NumListeners
+ 1) * sizeof(listener_t
));
905 LogMessage(L_ERROR
, "Unable to allocate %s at line %d - %s.",
906 name
, linenum
, strerror(errno
));
911 temp
+= NumListeners
;
913 if (get_address(value
, INADDR_ANY
, IPP_PORT
, &(temp
->address
)))
915 LogMessage(L_INFO
, "Listening to %x:%d (SSL)",
916 (unsigned)ntohl(temp
->address
.sin_addr
.s_addr
),
917 ntohs(temp
->address
.sin_port
));
918 temp
->encryption
= HTTP_ENCRYPT_ALWAYS
;
922 LogMessage(L_ERROR
, "Bad %s address %s at line %d.", name
,
925 #endif /* HAVE_SSL */
926 else if (strcasecmp(name
, "BrowseAddress") == 0)
929 * Add a browse address to the list...
932 dirsvc_addr_t
*temp
; /* New browse address array */
935 if (NumBrowsers
== 0)
936 temp
= malloc(sizeof(dirsvc_addr_t
));
938 temp
= realloc(Browsers
, (NumBrowsers
+ 1) * sizeof(dirsvc_addr_t
));
942 LogMessage(L_ERROR
, "Unable to allocate BrowseAddress at line %d - %s.",
943 linenum
, strerror(errno
));
950 memset(temp
, 0, sizeof(dirsvc_addr_t
));
952 if (strcasecmp(value
, "@LOCAL") == 0)
955 * Send browse data to all local interfaces...
958 strcpy(temp
->iface
, "*");
961 else if (strncasecmp(value
, "@IF(", 4) == 0)
964 * Send browse data to the named interface...
967 strlcpy(temp
->iface
, value
+ 4, sizeof(Browsers
[0].iface
));
969 nameptr
= temp
->iface
+ strlen(temp
->iface
) - 1;
975 else if (get_address(value
, INADDR_NONE
, BrowsePort
, &(temp
->to
)))
977 LogMessage(L_INFO
, "Sending browsing info to %x:%d",
978 (unsigned)ntohl(temp
->to
.sin_addr
.s_addr
),
979 ntohs(temp
->to
.sin_port
));
984 LogMessage(L_ERROR
, "Bad BrowseAddress %s at line %d.", value
,
987 else if (strcasecmp(name
, "BrowseOrder") == 0)
990 * "BrowseOrder Deny,Allow" or "BrowseOrder Allow,Deny"...
993 if ((location
= FindLocation("CUPS_INTERNAL_BROWSE_ACL")) == NULL
)
994 location
= AddLocation("CUPS_INTERNAL_BROWSE_ACL");
996 if (location
== NULL
)
997 LogMessage(L_ERROR
, "Unable to initialize browse access control list!");
998 else if (strncasecmp(value
, "deny", 4) == 0)
999 location
->order_type
= AUTH_ALLOW
;
1000 else if (strncasecmp(value
, "allow", 5) == 0)
1001 location
->order_type
= AUTH_DENY
;
1003 LogMessage(L_ERROR
, "Unknown BrowseOrder value %s on line %d.",
1006 else if (strcasecmp(name
, "BrowseProtocols") == 0)
1009 * "BrowseProtocol name [... name]"
1012 BrowseProtocols
= 0;
1016 for (valuelen
= 0; value
[valuelen
]; valuelen
++)
1017 if (isspace(value
[valuelen
]) || value
[valuelen
] == ',')
1020 if (value
[valuelen
])
1022 value
[valuelen
] = '\0';
1026 if (strcasecmp(value
, "cups") == 0)
1027 BrowseProtocols
|= BROWSE_CUPS
;
1028 else if (strcasecmp(value
, "slp") == 0)
1029 BrowseProtocols
|= BROWSE_SLP
;
1030 else if (strcasecmp(value
, "ldap") == 0)
1031 BrowseProtocols
|= BROWSE_LDAP
;
1032 else if (strcasecmp(value
, "all") == 0)
1033 BrowseProtocols
|= BROWSE_ALL
;
1036 LogMessage(L_ERROR
, "Unknown browse protocol \"%s\" on line %d.",
1041 for (value
+= valuelen
; *value
; value
++)
1042 if (!isspace(*value
) || *value
!= ',')
1046 else if (strcasecmp(name
, "BrowseAllow") == 0 ||
1047 strcasecmp(name
, "BrowseDeny") == 0)
1050 * BrowseAllow [From] host/ip...
1051 * BrowseDeny [From] host/ip...
1054 if ((location
= FindLocation("CUPS_INTERNAL_BROWSE_ACL")) == NULL
)
1055 location
= AddLocation("CUPS_INTERNAL_BROWSE_ACL");
1057 if (location
== NULL
)
1058 LogMessage(L_ERROR
, "Unable to initialize browse access control list!");
1061 if (strncasecmp(value
, "from ", 5) == 0)
1064 * Strip leading "from"...
1069 while (isspace(*value
))
1074 * Figure out what form the allow/deny address takes:
1085 * nnn.nnn.nnn.nnn/mm
1086 * nnn.nnn.nnn.nnn/mmm.mmm.mmm.mmm
1089 if (strcasecmp(value
, "all") == 0)
1095 if (strcasecmp(name
, "BrowseAllow") == 0)
1096 AllowIP(location
, 0, 0);
1098 DenyIP(location
, 0, 0);
1100 else if (strcasecmp(value
, "none") == 0)
1106 if (strcasecmp(name
, "BrowseAllow") == 0)
1107 AllowIP(location
, ~0, 0);
1109 DenyIP(location
, ~0, 0);
1111 else if (value
[0] == '*' || value
[0] == '.' || !isdigit(value
[0]))
1114 * Host or domain name...
1117 if (value
[0] == '*')
1120 if (strcasecmp(name
, "BrowseAllow") == 0)
1121 AllowHost(location
, value
);
1123 DenyHost(location
, value
);
1128 * One of many IP address forms...
1131 memset(ip
, 0, sizeof(ip
));
1132 ipcount
= sscanf(value
, "%d.%d.%d.%d", ip
+ 0, ip
+ 1, ip
+ 2, ip
+ 3);
1133 address
= (((((ip
[0] << 8) | ip
[1]) << 8) | ip
[2]) << 8) | ip
[3];
1135 if ((value
= strchr(value
, '/')) != NULL
)
1138 memset(mask
, 0, sizeof(mask
));
1139 switch (sscanf(value
, "%d.%d.%d.%d", mask
+ 0, mask
+ 1,
1140 mask
+ 2, mask
+ 3))
1143 netmask
= (0xffffffff << (32 - mask
[0])) & 0xffffffff;
1146 netmask
= (((((mask
[0] << 8) | mask
[1]) << 8) |
1147 mask
[2]) << 8) | mask
[3];
1150 LogMessage(L_ERROR
, "Bad netmask value %s on line %d.",
1152 netmask
= 0xffffffff;
1157 netmask
= netmasks
[ipcount
- 1];
1159 if ((address
& ~netmask
) != 0)
1161 LogMessage(L_WARN
, "Discarding extra bits in %s address %08x for netmask %08x...",
1162 name
, address
, netmask
);
1166 if (strcasecmp(name
, "BrowseAllow") == 0)
1167 AllowIP(location
, address
, netmask
);
1169 DenyIP(location
, address
, netmask
);
1173 else if (strcasecmp(name
, "BrowseRelay") == 0)
1176 * BrowseRelay [from] source [to] destination
1180 relay
= malloc(sizeof(dirsvc_relay_t
));
1182 relay
= realloc(Relays
, (NumRelays
+ 1) * sizeof(dirsvc_relay_t
));
1186 LogMessage(L_ERROR
, "Unable to allocate BrowseRelay at line %d - %s.",
1187 linenum
, strerror(errno
));
1194 memset(relay
, 0, sizeof(dirsvc_relay_t
));
1196 if (strncasecmp(value
, "from ", 5) == 0)
1199 * Strip leading "from"...
1204 while (isspace(*value
))
1209 * Figure out what form the from address takes:
1218 * nnn.nnn.nnn.nnn/mm
1219 * nnn.nnn.nnn.nnn/mmm.mmm.mmm.mmm
1222 if (value
[0] == '*' || value
[0] == '.' || !isdigit(value
[0]))
1225 * Host or domain name...
1228 if (value
[0] == '*')
1231 strlcpy(name
, value
, sizeof(name
));
1232 if ((nameptr
= strchr(name
, ' ')) != NULL
)
1235 relay
->from
.type
= AUTH_NAME
;
1236 relay
->from
.mask
.name
.name
= strdup(name
);
1237 relay
->from
.mask
.name
.length
= strlen(name
);
1242 * One of many IP address forms...
1245 memset(ip
, 0, sizeof(ip
));
1246 ipcount
= sscanf(value
, "%d.%d.%d.%d", ip
+ 0, ip
+ 1, ip
+ 2, ip
+ 3);
1247 address
= (((((ip
[0] << 8) | ip
[1]) << 8) | ip
[2]) << 8) | ip
[3];
1249 for (; *value
; value
++)
1250 if (*value
== '/' || isspace(*value
))
1256 memset(mask
, 0, sizeof(mask
));
1257 switch (sscanf(value
, "%d.%d.%d.%d", mask
+ 0, mask
+ 1,
1258 mask
+ 2, mask
+ 3))
1261 netmask
= (0xffffffff << (32 - mask
[0])) & 0xffffffff;
1264 netmask
= (((((mask
[0] << 8) | mask
[1]) << 8) |
1265 mask
[2]) << 8) | mask
[3];
1268 LogMessage(L_ERROR
, "Bad netmask value %s on line %d.",
1270 netmask
= 0xffffffff;
1275 netmask
= netmasks
[ipcount
- 1];
1277 relay
->from
.type
= AUTH_IP
;
1278 relay
->from
.mask
.ip
.address
= address
;
1279 relay
->from
.mask
.ip
.netmask
= netmask
;
1283 * Skip value and trailing whitespace...
1286 for (; *value
; value
++)
1287 if (isspace(*value
))
1290 while (isspace(*value
))
1293 if (strncasecmp(value
, "to ", 3) == 0)
1296 * Strip leading "to"...
1301 while (isspace(*value
))
1306 * Get "to" address and port...
1309 if (get_address(value
, INADDR_BROADCAST
, BrowsePort
, &(relay
->to
)))
1311 if (relay
->from
.type
== AUTH_NAME
)
1312 LogMessage(L_INFO
, "Relaying from %s to %x:%d",
1313 relay
->from
.mask
.name
.name
,
1314 (unsigned)ntohl(relay
->to
.sin_addr
.s_addr
),
1315 ntohs(relay
->to
.sin_port
));
1317 LogMessage(L_INFO
, "Relaying from %x/%x to %x:%d",
1318 relay
->from
.mask
.ip
.address
, relay
->from
.mask
.ip
.netmask
,
1319 (unsigned)ntohl(relay
->to
.sin_addr
.s_addr
),
1320 ntohs(relay
->to
.sin_port
));
1326 if (relay
->from
.type
== AUTH_NAME
)
1327 free(relay
->from
.mask
.name
.name
);
1329 LogMessage(L_ERROR
, "Bad relay address %s at line %d.", value
, linenum
);
1332 else if (strcasecmp(name
, "BrowsePoll") == 0)
1335 * BrowsePoll address[:port]
1339 poll
= malloc(sizeof(dirsvc_poll_t
));
1341 poll
= realloc(Polled
, (NumPolled
+ 1) * sizeof(dirsvc_poll_t
));
1345 LogMessage(L_ERROR
, "Unable to allocate BrowsePoll at line %d - %s.",
1346 linenum
, strerror(errno
));
1354 * Get poll address and port...
1357 if (get_address(value
, INADDR_NONE
, ippPort(), &polladdr
))
1359 LogMessage(L_INFO
, "Polling %x:%d",
1360 (unsigned)ntohl(polladdr
.sin_addr
.s_addr
),
1361 ntohs(polladdr
.sin_port
));
1364 memset(poll
, 0, sizeof(dirsvc_poll_t
));
1366 address
= ntohl(polladdr
.sin_addr
.s_addr
);
1368 sprintf(poll
->hostname
, "%d.%d.%d.%d", address
>> 24,
1369 (address
>> 16) & 255, (address
>> 8) & 255, address
& 255);
1370 poll
->port
= ntohs(polladdr
.sin_port
);
1373 LogMessage(L_ERROR
, "Bad poll address %s at line %d.", value
, linenum
);
1375 else if (strcasecmp(name
, "User") == 0)
1378 * User ID to run as...
1381 if (isdigit(value
[0]))
1385 struct passwd
*p
; /* Password information */
1388 p
= getpwnam(value
);
1393 LogMessage(L_WARN
, "Unknown username \"%s\"",
1397 else if (strcasecmp(name
, "Group") == 0)
1400 * Group ID to run as...
1403 if (isdigit(value
[0]))
1404 Group
= atoi(value
);
1407 struct group
*g
; /* Group information */
1410 g
= getgrnam(value
);
1415 LogMessage(L_WARN
, "Unknown groupname \"%s\"",
1419 else if (strcasecmp(name
, "SystemGroup") == 0)
1422 * System (admin) group(s)...
1425 char *valueptr
, /* Pointer into value */
1426 quote
; /* Quote character */
1429 for (i
= NumSystemGroups
; *value
&& i
< MAX_SYSTEM_GROUPS
; i
++)
1431 if (*value
== '\'' || *value
== '\"')
1434 * Scan quoted name...
1439 for (valueptr
= value
; *valueptr
; valueptr
++)
1440 if (*valueptr
== quote
)
1446 * Scan space or comma-delimited name...
1449 for (valueptr
= value
; *valueptr
; valueptr
++)
1450 if (isspace(*valueptr
) || *valueptr
== ',')
1457 SetString(SystemGroups
+ i
, value
);
1461 while (*value
== ',' || isspace(*value
))
1466 NumSystemGroups
= i
;
1468 else if (strcasecmp(name
, "HostNameLookups") == 0)
1471 * Do hostname lookups?
1474 if (strcasecmp(value
, "off") == 0)
1475 HostNameLookups
= 0;
1476 else if (strcasecmp(value
, "on") == 0)
1477 HostNameLookups
= 1;
1478 else if (strcasecmp(value
, "double") == 0)
1479 HostNameLookups
= 2;
1481 LogMessage(L_WARN
, "Unknown HostNameLookups %s on line %d.",
1484 else if (strcasecmp(name
, "LogLevel") == 0)
1487 * Amount of logging to do...
1490 if (strcasecmp(value
, "debug2") == 0)
1491 LogLevel
= L_DEBUG2
;
1492 else if (strcasecmp(value
, "debug") == 0)
1494 else if (strcasecmp(value
, "info") == 0)
1496 else if (strcasecmp(value
, "notice") == 0)
1497 LogLevel
= L_NOTICE
;
1498 else if (strcasecmp(value
, "warn") == 0)
1500 else if (strcasecmp(value
, "error") == 0)
1502 else if (strcasecmp(value
, "crit") == 0)
1504 else if (strcasecmp(value
, "alert") == 0)
1506 else if (strcasecmp(value
, "emerg") == 0)
1508 else if (strcasecmp(value
, "none") == 0)
1511 LogMessage(L_WARN
, "Unknown LogLevel %s on line %d.", value
, linenum
);
1513 else if (strcasecmp(name
, "PrintcapFormat") == 0)
1516 * Format of printcap file?
1519 if (strcasecmp(value
, "bsd") == 0)
1520 PrintcapFormat
= PRINTCAP_BSD
;
1521 else if (strcasecmp(value
, "solaris") == 0)
1522 PrintcapFormat
= PRINTCAP_SOLARIS
;
1524 LogMessage(L_WARN
, "Unknown PrintcapFormat %s on line %d.",
1527 else if (!strcasecmp(name
, "ServerTokens"))
1530 * Set the string used for the Server header...
1533 struct utsname plat
; /* Platform info */
1538 if (!strcasecmp(value
, "ProductOnly"))
1539 SetString(&ServerHeader
, "CUPS");
1540 else if (!strcasecmp(value
, "Major"))
1541 SetString(&ServerHeader
, "CUPS/1");
1542 else if (!strcasecmp(value
, "Minor"))
1543 SetString(&ServerHeader
, "CUPS/1.1");
1544 else if (!strcasecmp(value
, "Minimal"))
1545 SetString(&ServerHeader
, CUPS_MINIMAL
);
1546 else if (!strcasecmp(value
, "OS"))
1547 SetStringf(&ServerHeader
, CUPS_MINIMAL
" (%s)", plat
.sysname
);
1548 else if (!strcasecmp(value
, "Full"))
1549 SetStringf(&ServerHeader
, CUPS_MINIMAL
" (%s) IPP/1.1", plat
.sysname
);
1550 else if (!strcasecmp(value
, "None"))
1551 ClearString(&ServerHeader
);
1553 LogMessage(L_WARN
, "Unknown ServerTokens %s on line %d.", value
, linenum
);
1558 * Find a simple variable in the list...
1561 for (i
= NUM_VARS
, var
= variables
; i
> 0; i
--, var
++)
1562 if (strcasecmp(name
, var
->name
) == 0)
1568 * Unknown directive! Output an error message and continue...
1571 LogMessage(L_ERROR
, "Unknown directive %s on line %d.", name
,
1581 char *units
; /* Units */
1584 n
= strtol(value
, &units
, 0);
1586 if (units
&& *units
)
1588 if (tolower(units
[0] & 255) == 'g')
1589 n
*= 1024 * 1024 * 1024;
1590 else if (tolower(units
[0] & 255) == 'm')
1592 else if (tolower(units
[0] & 255) == 'k')
1594 else if (tolower(units
[0] & 255) == 't')
1598 *((int *)var
->ptr
) = n
;
1603 if (strcasecmp(value
, "true") == 0 ||
1604 strcasecmp(value
, "on") == 0 ||
1605 strcasecmp(value
, "enabled") == 0 ||
1606 strcasecmp(value
, "yes") == 0 ||
1608 *((int *)var
->ptr
) = TRUE
;
1609 else if (strcasecmp(value
, "false") == 0 ||
1610 strcasecmp(value
, "off") == 0 ||
1611 strcasecmp(value
, "disabled") == 0 ||
1612 strcasecmp(value
, "no") == 0 ||
1613 strcasecmp(value
, "0") == 0)
1614 *((int *)var
->ptr
) = FALSE
;
1616 LogMessage(L_ERROR
, "Unknown boolean value %s on line %d.",
1621 SetString((char **)var
->ptr
, value
);
1632 * 'read_location()' - Read a <Location path> definition.
1635 static int /* O - New line number or 0 on error */
1636 read_location(cups_file_t
*fp
, /* I - Configuration file */
1637 char *location
, /* I - Location name/path */
1638 int linenum
) /* I - Current line number */
1640 int i
; /* Looping var */
1641 location_t
*loc
, /* New location */
1642 *parent
; /* Parent location */
1643 int len
; /* Length of line */
1644 char line
[HTTP_MAX_BUFFER
], /* Line buffer */
1645 name
[256], /* Configuration directive */
1646 *nameptr
, /* Pointer into name */
1647 *value
, /* Value for directive */
1648 *valptr
; /* Pointer into value */
1649 unsigned address
, /* Address value */
1650 netmask
; /* Netmask value */
1651 int ip
[4], /* IP address components */
1652 ipcount
, /* Number of components provided */
1653 mask
[4]; /* IP netmask components */
1654 static unsigned netmasks
[4] = /* Standard netmasks... */
1663 if ((parent
= AddLocation(location
)) == NULL
)
1666 parent
->limit
= AUTH_LIMIT_ALL
;
1669 while (cupsFileGets(fp
, line
, sizeof(line
)) != NULL
)
1674 * Skip comment lines...
1681 * Strip trailing whitespace, if any...
1686 while (len
> 0 && isspace(line
[len
- 1] & 255))
1693 * Extract the name from the beginning of the line...
1696 for (value
= line
; isspace(*value
& 255); value
++);
1698 for (nameptr
= name
; *value
!= '\0' && !isspace(*value
& 255) &&
1699 nameptr
< (name
+ sizeof(name
) - 1);)
1700 *nameptr
++ = *value
++;
1703 while (isspace(*value
& 255))
1706 if (name
[0] == '\0')
1710 * Decode the directive...
1713 if (strcasecmp(name
, "</Location>") == 0)
1715 else if (strcasecmp(name
, "<Limit") == 0 ||
1716 strcasecmp(name
, "<LimitExcept") == 0)
1718 if ((loc
= CopyLocation(&parent
)) == NULL
)
1724 for (valptr
= value
;
1725 !isspace(*valptr
& 255) && *valptr
!= '>' && *valptr
;
1731 if (strcmp(value
, "ALL") == 0)
1732 loc
->limit
= AUTH_LIMIT_ALL
;
1733 else if (strcmp(value
, "GET") == 0)
1734 loc
->limit
|= AUTH_LIMIT_GET
;
1735 else if (strcmp(value
, "HEAD") == 0)
1736 loc
->limit
|= AUTH_LIMIT_HEAD
;
1737 else if (strcmp(value
, "OPTIONS") == 0)
1738 loc
->limit
|= AUTH_LIMIT_OPTIONS
;
1739 else if (strcmp(value
, "POST") == 0)
1740 loc
->limit
|= AUTH_LIMIT_POST
;
1741 else if (strcmp(value
, "PUT") == 0)
1742 loc
->limit
|= AUTH_LIMIT_PUT
;
1743 else if (strcmp(value
, "TRACE") == 0)
1744 loc
->limit
|= AUTH_LIMIT_TRACE
;
1746 LogMessage(L_WARN
, "Unknown request type %s on line %d!", value
,
1749 for (value
= valptr
; isspace(*value
& 255) || *value
== '>'; value
++);
1752 if (strcasecmp(name
, "<LimitExcept") == 0)
1753 loc
->limit
= AUTH_LIMIT_ALL
^ loc
->limit
;
1755 parent
->limit
&= ~loc
->limit
;
1757 else if (strcasecmp(name
, "</Limit>") == 0)
1759 else if (strcasecmp(name
, "Encryption") == 0)
1762 * "Encryption xxx" - set required encryption level...
1765 if (strcasecmp(value
, "never") == 0)
1766 loc
->encryption
= HTTP_ENCRYPT_NEVER
;
1767 else if (strcasecmp(value
, "always") == 0)
1769 LogMessage(L_ERROR
, "Encryption value \"%s\" on line %d is invalid in this context. "
1770 "Using \"required\" instead.", value
, linenum
);
1772 loc
->encryption
= HTTP_ENCRYPT_REQUIRED
;
1774 else if (strcasecmp(value
, "required") == 0)
1775 loc
->encryption
= HTTP_ENCRYPT_REQUIRED
;
1776 else if (strcasecmp(value
, "ifrequested") == 0)
1777 loc
->encryption
= HTTP_ENCRYPT_IF_REQUESTED
;
1779 LogMessage(L_ERROR
, "Unknown Encryption value %s on line %d.",
1782 else if (strcasecmp(name
, "Order") == 0)
1785 * "Order Deny,Allow" or "Order Allow,Deny"...
1788 if (strncasecmp(value
, "deny", 4) == 0)
1789 loc
->order_type
= AUTH_ALLOW
;
1790 else if (strncasecmp(value
, "allow", 5) == 0)
1791 loc
->order_type
= AUTH_DENY
;
1793 LogMessage(L_ERROR
, "Unknown Order value %s on line %d.",
1796 else if (strcasecmp(name
, "Allow") == 0 ||
1797 strcasecmp(name
, "Deny") == 0)
1800 * Allow [From] host/ip...
1801 * Deny [From] host/ip...
1804 if (strncasecmp(value
, "from", 4) == 0)
1807 * Strip leading "from"...
1812 while (isspace(*value
& 255))
1817 * Figure out what form the allow/deny address takes:
1828 * nnn.nnn.nnn.nnn/mm
1829 * nnn.nnn.nnn.nnn/mmm.mmm.mmm.mmm
1832 if (strcasecmp(value
, "all") == 0)
1838 if (strcasecmp(name
, "Allow") == 0)
1843 else if (strcasecmp(value
, "none") == 0)
1849 if (strcasecmp(name
, "Allow") == 0)
1850 AllowIP(loc
, ~0, 0);
1854 else if (value
[0] == '*' || value
[0] == '.' || !isdigit(value
[0] & 255))
1857 * Host or domain name...
1860 if (value
[0] == '*')
1863 if (strcasecmp(name
, "Allow") == 0)
1864 AllowHost(loc
, value
);
1866 DenyHost(loc
, value
);
1871 * One of many IP address forms...
1874 memset(ip
, 0, sizeof(ip
));
1875 ipcount
= sscanf(value
, "%d.%d.%d.%d", ip
+ 0, ip
+ 1, ip
+ 2, ip
+ 3);
1876 address
= (((((ip
[0] << 8) | ip
[1]) << 8) | ip
[2]) << 8) | ip
[3];
1878 if ((value
= strchr(value
, '/')) != NULL
)
1881 memset(mask
, 0, sizeof(mask
));
1882 switch (sscanf(value
, "%d.%d.%d.%d", mask
+ 0, mask
+ 1,
1883 mask
+ 2, mask
+ 3))
1886 netmask
= (0xffffffff << (32 - mask
[0])) & 0xffffffff;
1889 netmask
= (((((mask
[0] << 8) | mask
[1]) << 8) |
1890 mask
[2]) << 8) | mask
[3];
1893 LogMessage(L_ERROR
, "Bad netmask value %s on line %d.",
1895 netmask
= 0xffffffff;
1900 netmask
= netmasks
[ipcount
- 1];
1902 if ((address
& ~netmask
) != 0)
1904 LogMessage(L_WARN
, "Discarding extra bits in %s address %08x for netmask %08x...",
1905 name
, address
, netmask
);
1909 if (strcasecmp(name
, "Allow") == 0)
1910 AllowIP(loc
, address
, netmask
);
1912 DenyIP(loc
, address
, netmask
);
1915 else if (strcasecmp(name
, "AuthType") == 0)
1918 * AuthType {none,basic,digest,basicdigest}
1921 if (strcasecmp(value
, "none") == 0)
1923 loc
->type
= AUTH_NONE
;
1924 loc
->level
= AUTH_ANON
;
1926 else if (strcasecmp(value
, "basic") == 0)
1928 loc
->type
= AUTH_BASIC
;
1930 if (loc
->level
== AUTH_ANON
)
1931 loc
->level
= AUTH_USER
;
1933 else if (strcasecmp(value
, "digest") == 0)
1935 loc
->type
= AUTH_DIGEST
;
1937 if (loc
->level
== AUTH_ANON
)
1938 loc
->level
= AUTH_USER
;
1940 else if (strcasecmp(value
, "basicdigest") == 0)
1942 loc
->type
= AUTH_BASICDIGEST
;
1944 if (loc
->level
== AUTH_ANON
)
1945 loc
->level
= AUTH_USER
;
1948 LogMessage(L_WARN
, "Unknown authorization type %s on line %d.",
1951 else if (strcasecmp(name
, "AuthClass") == 0)
1954 * AuthClass anonymous, user, system, group
1957 if (strcasecmp(value
, "anonymous") == 0)
1959 loc
->type
= AUTH_NONE
;
1960 loc
->level
= AUTH_ANON
;
1962 else if (strcasecmp(value
, "user") == 0)
1963 loc
->level
= AUTH_USER
;
1964 else if (strcasecmp(value
, "group") == 0)
1965 loc
->level
= AUTH_GROUP
;
1966 else if (strcasecmp(value
, "system") == 0)
1968 loc
->level
= AUTH_GROUP
;
1971 * Use the default system group if none is defined so far...
1974 if (NumSystemGroups
== 0)
1975 NumSystemGroups
= 1;
1977 for (i
= 0; i
< NumSystemGroups
; i
++)
1978 AddName(loc
, SystemGroups
[i
]);
1981 LogMessage(L_WARN
, "Unknown authorization class %s on line %d.",
1984 else if (strcasecmp(name
, "AuthGroupName") == 0)
1985 AddName(loc
, value
);
1986 else if (strcasecmp(name
, "Require") == 0)
1989 * Apache synonym for AuthClass and AuthGroupName...
1993 * Require valid-user
1994 * Require group names
1995 * Require user names
1998 for (valptr
= value
;
1999 !isspace(*valptr
& 255) && *valptr
!= '>' && *valptr
;
2005 if (strcasecmp(value
, "valid-user") == 0 ||
2006 strcasecmp(value
, "user") == 0)
2007 loc
->level
= AUTH_USER
;
2008 else if (strcasecmp(value
, "group") == 0)
2009 loc
->level
= AUTH_GROUP
;
2012 LogMessage(L_WARN
, "Unknown Require type %s on line %d.",
2018 * Get the list of names from the line...
2021 for (value
= valptr
; *value
;)
2023 for (valptr
= value
; !isspace(*valptr
& 255) && *valptr
; valptr
++);
2028 AddName(loc
, value
);
2030 for (value
= valptr
; isspace(*value
& 255); value
++);
2033 else if (strcasecmp(name
, "Satisfy") == 0)
2035 if (strcasecmp(value
, "all") == 0)
2036 loc
->satisfy
= AUTH_SATISFY_ALL
;
2037 else if (strcasecmp(value
, "any") == 0)
2038 loc
->satisfy
= AUTH_SATISFY_ANY
;
2040 LogMessage(L_WARN
, "Unknown Satisfy value %s on line %d.", value
,
2044 LogMessage(L_ERROR
, "Unknown Location directive %s on line %d.",
2053 * 'get_address()' - Get an address + port number from a line.
2056 static int /* O - 1 if address good, 0 if bad */
2057 get_address(char *value
, /* I - Value string */
2058 unsigned defaddress
, /* I - Default address */
2059 int defport
, /* I - Default port */
2060 struct sockaddr_in
*address
) /* O - Socket address */
2062 char hostname
[256], /* Hostname or IP */
2063 portname
[256]; /* Port number or name */
2064 struct hostent
*host
; /* Host address */
2065 struct servent
*port
; /* Port number */
2069 * Initialize the socket address to the defaults...
2072 memset(address
, 0, sizeof(struct sockaddr_in
));
2073 address
->sin_family
= AF_INET
;
2074 address
->sin_addr
.s_addr
= htonl(defaddress
);
2075 address
->sin_port
= htons(defport
);
2078 * Try to grab a hostname and port number...
2081 switch (sscanf(value
, "%255[^:]:%255s", hostname
, portname
))
2084 if (strchr(hostname
, '.') == NULL
&& defaddress
== INADDR_ANY
)
2087 * Hostname is a port number...
2090 strlcpy(portname
, hostname
, sizeof(portname
));
2099 LogMessage(L_ERROR
, "Unable to decode address \"%s\"!", value
);
2104 * Decode the hostname and port number as needed...
2107 if (hostname
[0] && strcmp(hostname
, "*"))
2109 if ((host
= httpGetHostByName(hostname
)) == NULL
)
2111 LogMessage(L_ERROR
, "httpGetHostByName(\"%s\") failed - %s!", hostname
,
2112 hstrerror(h_errno
));
2116 memcpy(&(address
->sin_addr
), host
->h_addr
, host
->h_length
);
2117 address
->sin_port
= htons(defport
);
2120 if (portname
[0] != '\0')
2122 if (isdigit(portname
[0] & 255))
2123 address
->sin_port
= htons(atoi(portname
));
2126 if ((port
= getservbyname(portname
, NULL
)) == NULL
)
2128 LogMessage(L_ERROR
, "getservbyname(\"%s\") failed - %s!", portname
,
2133 address
->sin_port
= htons(port
->s_port
);
2143 * 'CDSAGetServerCerts()' - Convert a keychain name into the CFArrayRef
2144 * required by SSLSetCertificate.
2146 * For now we assumes that there is exactly one SecIdentity in the
2147 * keychain - i.e. there is exactly one matching cert/private key pair.
2148 * In the future we will search a keychain for a SecIdentity matching a
2149 * specific criteria. We also skip the operation of adding additional
2150 * non-signing certs from the keychain to the CFArrayRef.
2152 * To create a self-signed certificate for testing use the certtool.
2153 * Executing the following as root will do it:
2155 * certtool c c v k=CUPS
2159 CDSAGetServerCerts(void)
2161 OSStatus err
; /* Error info */
2162 SecKeychainRef kcRef
; /* Keychain reference */
2163 SecIdentitySearchRef srchRef
; /* Search reference */
2164 SecIdentityRef identity
; /* Identity */
2165 CFArrayRef ca
; /* Certificate array */
2172 err
= SecKeychainOpen(ServerCertificate
, &kcRef
);
2175 LogMessage(L_ERROR
, "Cannot open keychain \"%s\", error %d.",
2176 ServerCertificate
, err
);
2180 * Search for "any" identity matching specified key use;
2181 * in this app, we expect there to be exactly one.
2184 err
= SecIdentitySearchCreate(kcRef
, CSSM_KEYUSE_SIGN
, &srchRef
);
2188 "Cannot find signing key in keychain \"%s\", error %d",
2189 ServerCertificate
, err
);
2192 err
= SecIdentitySearchCopyNext(srchRef
, &identity
);
2196 "Cannot find signing key in keychain \"%s\", error %d",
2197 ServerCertificate
, err
);
2200 if (CFGetTypeID(identity
) != SecIdentityGetTypeID())
2201 LogMessage(L_ERROR
, "SecIdentitySearchCopyNext CFTypeID failure!");
2205 * Found one. Place it in a CFArray.
2206 * TBD: snag other (non-identity) certs from keychain and add them
2210 ca
= CFArrayCreate(NULL
, (const void **)&identity
, 1, NULL
);
2213 LogMessage(L_ERROR
, "CFArrayCreate error");
2216 /*CFRelease(identity);*/
2219 /*CFRelease(srchRef);*/
2222 /*CFRelease(kcRef);*/
2227 #endif /* HAVE_CDSASSL */
2231 * End of "$Id: conf.c,v 1.152 2005/01/03 19:29:59 mike Exp $".