2 * "$Id: conf.c,v 1.142 2004/02/24 21:34:37 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 * CDSAGetServerCerts() - Convert a keychain name into the CFArrayRef
31 * required by SSLSetCertificate.
35 * Include necessary headers...
44 # include <Security/SecureTransport.h>
45 # include <Security/SecIdentitySearch.h>
46 #endif /* HAVE_CDSASSL */
50 #endif /* HAVE_VSYSLOG */
54 * Possibly missing network definitions...
58 # define INADDR_NONE 0xffffffff
59 #endif /* !INADDR_NONE */
63 * Configuration variable structure...
68 char *name
; /* Name of variable */
69 void *ptr
; /* Pointer to variable */
70 int type
; /* Type (int, string, address) */
82 static var_t variables
[] =
84 { "AccessLog", &AccessLog
, VAR_STRING
},
85 { "AutoPurgeJobs", &JobAutoPurge
, VAR_BOOLEAN
},
86 { "BrowseInterval", &BrowseInterval
, VAR_INTEGER
},
87 { "BrowsePort", &BrowsePort
, VAR_INTEGER
},
88 { "BrowseShortNames", &BrowseShortNames
, VAR_BOOLEAN
},
89 { "BrowseTimeout", &BrowseTimeout
, VAR_INTEGER
},
90 { "Browsing", &Browsing
, VAR_BOOLEAN
},
91 { "Classification", &Classification
, VAR_STRING
},
92 { "ClassifyOverride", &ClassifyOverride
, VAR_BOOLEAN
},
93 { "ConfigFilePerm", &ConfigFilePerm
, VAR_INTEGER
},
94 { "DataDir", &DataDir
, VAR_STRING
},
95 { "DefaultCharset", &DefaultCharset
, VAR_STRING
},
96 { "DefaultLanguage", &DefaultLanguage
, VAR_STRING
},
97 { "DocumentRoot", &DocumentRoot
, VAR_STRING
},
98 { "ErrorLog", &ErrorLog
, VAR_STRING
},
99 { "FaxRetryLimit", &FaxRetryLimit
, VAR_INTEGER
},
100 { "FaxRetryInterval", &FaxRetryInterval
, VAR_INTEGER
},
101 { "FileDevice", &FileDevice
, VAR_BOOLEAN
},
102 { "FilterLimit", &FilterLimit
, VAR_INTEGER
},
103 { "FilterNice", &FilterNice
, VAR_INTEGER
},
104 { "FontPath", &FontPath
, VAR_STRING
},
105 { "HideImplicitMembers", &HideImplicitMembers
, VAR_BOOLEAN
},
106 { "ImplicitClasses", &ImplicitClasses
, VAR_BOOLEAN
},
107 { "ImplicitAnyClasses", &ImplicitAnyClasses
, VAR_BOOLEAN
},
108 { "KeepAliveTimeout", &KeepAliveTimeout
, VAR_INTEGER
},
109 { "KeepAlive", &KeepAlive
, VAR_BOOLEAN
},
110 { "LimitRequestBody", &MaxRequestSize
, VAR_INTEGER
},
111 { "ListenBackLog", &ListenBackLog
, VAR_INTEGER
},
112 { "LogFilePerm", &LogFilePerm
, VAR_INTEGER
},
113 { "MaxClients", &MaxClients
, VAR_INTEGER
},
114 { "MaxClientsPerHost", &MaxClientsPerHost
, VAR_INTEGER
},
115 { "MaxCopies", &MaxCopies
, VAR_INTEGER
},
116 { "MaxJobs", &MaxJobs
, VAR_INTEGER
},
117 { "MaxJobsPerPrinter", &MaxJobsPerPrinter
, VAR_INTEGER
},
118 { "MaxJobsPerUser", &MaxJobsPerUser
, VAR_INTEGER
},
119 { "MaxLogSize", &MaxLogSize
, VAR_INTEGER
},
120 { "MaxPrinterHistory", &MaxPrinterHistory
, VAR_INTEGER
},
121 { "MaxRequestSize", &MaxRequestSize
, VAR_INTEGER
},
122 { "PageLog", &PageLog
, VAR_STRING
},
123 { "PreserveJobFiles", &JobFiles
, VAR_BOOLEAN
},
124 { "PreserveJobHistory", &JobHistory
, VAR_BOOLEAN
},
125 { "Printcap", &Printcap
, VAR_STRING
},
126 { "PrintcapGUI", &PrintcapGUI
, VAR_STRING
},
127 { "RemoteRoot", &RemoteRoot
, VAR_STRING
},
128 { "RequestRoot", &RequestRoot
, VAR_STRING
},
129 { "RIPCache", &RIPCache
, VAR_STRING
},
130 { "RunAsUser", &RunAsUser
, VAR_BOOLEAN
},
131 { "RootCertDuration", &RootCertDuration
, VAR_INTEGER
},
132 { "ServerAdmin", &ServerAdmin
, VAR_STRING
},
133 { "ServerBin", &ServerBin
, VAR_STRING
},
135 { "ServerCertificate", &ServerCertificate
, VAR_STRING
},
136 # if defined(HAVE_LIBSSL) || defined(HAVE_GNUTLS)
137 { "ServerKey", &ServerKey
, VAR_STRING
},
138 # endif /* HAVE_LIBSSL || HAVE_GNUTLS */
139 #endif /* HAVE_SSL */
140 { "ServerName", &ServerName
, VAR_STRING
},
141 { "ServerRoot", &ServerRoot
, VAR_STRING
},
142 { "TempDir", &TempDir
, VAR_STRING
},
143 { "Timeout", &Timeout
, VAR_INTEGER
}
145 #define NUM_VARS (sizeof(variables) / sizeof(variables[0]))
152 static int read_configuration(cups_file_t
*fp
);
153 static int read_location(cups_file_t
*fp
, char *name
, int linenum
);
154 static int get_address(char *value
, unsigned defaddress
, int defport
,
155 struct sockaddr_in
*address
);
158 static CFArrayRef
CDSAGetServerCerts();
159 #endif /* HAVE_CDSASSL */
163 * 'ReadConfiguration()' - Read the cupsd.conf file.
166 int /* O - 1 on success, 0 otherwise */
167 ReadConfiguration(void)
169 int i
; /* Looping var */
170 cups_file_t
*fp
; /* Configuration file */
171 int status
; /* Return status */
172 char temp
[1024], /* Temporary buffer */
173 *slash
; /* Directory separator */
174 char type
[MIME_MAX_SUPER
+ MIME_MAX_TYPE
];
176 char *language
; /* Language string */
177 struct passwd
*user
; /* Default user */
178 struct group
*group
; /* Default group */
179 int run_user
; /* User that will be running cupsd */
180 char *old_serverroot
, /* Old ServerRoot */
181 *old_requestroot
; /* Old RequestRoot */
185 * Shutdown the server...
191 * Save the old root paths...
194 old_serverroot
= NULL
;
195 SetString(&old_serverroot
, ServerRoot
);
196 old_requestroot
= NULL
;
197 SetString(&old_requestroot
, RequestRoot
);
200 * Reset the server configuration data...
203 DeleteAllLocations();
221 for (i
= 0; i
< NumRelays
; i
++)
222 if (Relays
[i
].from
.type
== AUTH_NAME
)
223 free(Relays
[i
].from
.mask
.name
.name
);
230 if (NumListeners
> 0)
241 gethostname(temp
, sizeof(temp
));
242 SetString(&ServerName
, temp
);
243 SetStringf(&ServerAdmin
, "root@%s", temp
);
244 SetString(&ServerBin
, CUPS_SERVERBIN
);
245 SetString(&RequestRoot
, CUPS_REQUESTS
);
246 SetString(&DocumentRoot
, CUPS_DOCROOT
);
247 SetString(&DataDir
, CUPS_DATADIR
);
248 SetString(&AccessLog
, CUPS_LOGDIR
"/access_log");
249 SetString(&ErrorLog
, CUPS_LOGDIR
"/error_log");
250 SetString(&PageLog
, CUPS_LOGDIR
"/page_log");
251 SetString(&Printcap
, "/etc/printcap");
252 SetString(&PrintcapGUI
, "/usr/bin/glpoptions");
253 SetString(&FontPath
, CUPS_FONTPATH
);
254 SetString(&RemoteRoot
, "remroot");
256 strlcpy(temp
, ConfigurationFile
, sizeof(temp
));
257 if ((slash
= strrchr(temp
, '/')) != NULL
)
260 SetString(&ServerRoot
, temp
);
262 ClearString(&Classification
);
263 ClassifyOverride
= 0;
267 SetString(&ServerCertificate
, "/var/root/Library/Keychains/CUPS");
269 SetString(&ServerCertificate
, "ssl/server.crt");
270 SetString(&ServerKey
, "ssl/server.key");
271 # endif /* HAVE_CDSASSL */
272 #endif /* HAVE_SSL */
274 if ((language
= DEFAULT_LANGUAGE
) == NULL
)
276 else if (strcmp(language
, "C") == 0 || strcmp(language
, "POSIX") == 0)
279 SetString(&DefaultLanguage
, language
);
280 SetString(&DefaultCharset
, DEFAULT_CHARSET
);
282 SetString(&RIPCache
, "8m");
284 if (getenv("TMPDIR") == NULL
)
285 SetString(&TempDir
, CUPS_REQUESTS
"/tmp");
287 SetString(&TempDir
, getenv("TMPDIR"));
290 * Find the default system group: "sys", "system", or "root"...
293 group
= getgrnam(CUPS_DEFAULT_GROUP
);
300 SetString(&SystemGroups
[0], CUPS_DEFAULT_GROUP
);
301 Group
= group
->gr_gid
;
310 SetString(&SystemGroups
[0], group
->gr_name
);
315 SetString(&SystemGroups
[0], "unknown");
321 * Find the default user...
324 if ((user
= getpwnam(CUPS_DEFAULT_USER
)) == NULL
)
325 User
= 1; /* Force to a non-priviledged account */
335 ConfigFilePerm
= 0640;
339 FaxRetryInterval
= 300;
344 HostNameLookups
= FALSE
;
345 ImplicitClasses
= TRUE
;
346 ImplicitAnyClasses
= FALSE
;
347 HideImplicitMembers
= TRUE
;
349 KeepAliveTimeout
= DEFAULT_KEEPALIVE
;
350 ListenBackLog
= SOMAXCONN
;
353 MaxClientsPerHost
= 0;
354 MaxLogSize
= 1024 * 1024;
355 MaxPrinterHistory
= 10;
357 RootCertDuration
= 300;
359 Timeout
= DEFAULT_TIMEOUT
;
361 BrowseInterval
= DEFAULT_INTERVAL
;
362 BrowsePort
= ippPort();
363 BrowseProtocols
= BROWSE_CUPS
;
364 BrowseShortNames
= TRUE
;
365 BrowseTimeout
= DEFAULT_TIMEOUT
;
368 JobHistory
= DEFAULT_HISTORY
;
369 JobFiles
= DEFAULT_FILES
;
373 MaxJobsPerPrinter
= 0;
377 * Read the configuration file...
380 if ((fp
= cupsFileOpen(ConfigurationFile
, "r")) == NULL
)
383 status
= read_configuration(fp
);
396 * Use the default system group if none was supplied in cupsd.conf...
399 if (NumSystemGroups
== 0)
403 * Get the access control list for browsing...
406 BrowseACL
= FindLocation("CUPS_INTERNAL_BROWSE_ACL");
409 * Open the system log for cupsd if necessary...
413 if (strcmp(AccessLog
, "syslog") == 0 ||
414 strcmp(ErrorLog
, "syslog") == 0 ||
415 strcmp(PageLog
, "syslog") == 0)
416 openlog("cupsd", LOG_PID
| LOG_NOWAIT
| LOG_NDELAY
, LOG_LPR
);
417 #endif /* HAVE_VSYSLOG */
420 * Log the configuration file that was used...
423 LogMessage(L_INFO
, "Loaded configuration file \"%s\"", ConfigurationFile
);
426 * Check that we have at least one listen/port line; if not, report this
427 * as an error and exit!
430 if (NumListeners
== 0)
436 LogMessage(L_EMERG
, "No valid Listen or Port lines were found in the configuration file!");
442 kill(getpid(), SIGTERM
);
446 * Set the default locale using the language and charset...
449 SetStringf(&DefaultLocale
, "%s.%s", DefaultLanguage
, DefaultCharset
);
452 * Update all relative filenames to include the full path from ServerRoot...
455 if (DocumentRoot
[0] != '/')
456 SetStringf(&DocumentRoot
, "%s/%s", ServerRoot
, DocumentRoot
);
458 if (RequestRoot
[0] != '/')
459 SetStringf(&RequestRoot
, "%s/%s", ServerRoot
, RequestRoot
);
461 if (ServerBin
[0] != '/')
462 SetStringf(&ServerBin
, "%s/%s", ServerRoot
, ServerBin
);
465 if (ServerCertificate
[0] != '/')
466 SetStringf(&ServerCertificate
, "%s/%s", ServerRoot
, ServerCertificate
);
468 # if defined(HAVE_LIBSSL) || defined(HAVE_GNUTLS)
469 chown(ServerCertificate
, run_user
, Group
);
470 chmod(ServerCertificate
, ConfigFilePerm
);
472 if (ServerKey
[0] != '/')
473 SetStringf(&ServerKey
, "%s/%s", ServerRoot
, ServerKey
);
475 chown(ServerKey
, run_user
, Group
);
476 chmod(ServerKey
, ConfigFilePerm
);
477 # endif /* HAVE_LIBSSL || HAVE_GNUTLS */
478 #endif /* HAVE_SSL */
481 * Make sure that ServerRoot and the config files are owned and
482 * writable by the user and group in the cupsd.conf file...
485 chown(ServerRoot
, run_user
, Group
);
486 chmod(ServerRoot
, 0775);
488 snprintf(temp
, sizeof(temp
), "%s/certs", ServerRoot
);
489 chown(temp
, run_user
, Group
);
492 snprintf(temp
, sizeof(temp
), "%s/ppd", ServerRoot
);
493 chown(temp
, run_user
, Group
);
496 snprintf(temp
, sizeof(temp
), "%s/ssl", ServerRoot
);
497 chown(temp
, run_user
, Group
);
500 snprintf(temp
, sizeof(temp
), "%s/cupsd.conf", ServerRoot
);
501 chown(temp
, run_user
, Group
);
502 chmod(temp
, ConfigFilePerm
);
504 snprintf(temp
, sizeof(temp
), "%s/classes.conf", ServerRoot
);
505 chown(temp
, run_user
, Group
);
509 chmod(temp
, ConfigFilePerm
);
510 #endif /* __APPLE__ */
512 snprintf(temp
, sizeof(temp
), "%s/printers.conf", ServerRoot
);
513 chown(temp
, run_user
, Group
);
517 chmod(temp
, ConfigFilePerm
);
518 #endif /* __APPLE__ */
520 snprintf(temp
, sizeof(temp
), "%s/passwd.md5", ServerRoot
);
521 chown(temp
, User
, Group
);
525 * Make sure the request and temporary directories have the right
529 chown(RequestRoot
, run_user
, Group
);
530 chmod(RequestRoot
, 0710);
532 if (strncmp(TempDir
, RequestRoot
, strlen(RequestRoot
)) == 0)
535 * Only update ownership and permissions if the CUPS temp directory
536 * is under the spool directory...
539 chown(TempDir
, run_user
, Group
);
540 chmod(TempDir
, 01770);
544 * Check the MaxClients setting, and then allocate memory for it...
547 if (MaxClients
> (MaxFDs
/ 3) || MaxClients
<= 0)
550 LogMessage(L_INFO
, "MaxClients limited to 1/3 of the file descriptor limit (%d)...",
553 MaxClients
= MaxFDs
/ 3;
556 if ((Clients
= calloc(sizeof(client_t
), MaxClients
)) == NULL
)
558 LogMessage(L_ERROR
, "ReadConfiguration: Unable to allocate memory for %d clients: %s",
559 MaxClients
, strerror(errno
));
563 LogMessage(L_INFO
, "Configured for up to %d clients.", MaxClients
);
565 if (Classification
&& strcasecmp(Classification
, "none") == 0)
566 ClearString(&Classification
);
569 LogMessage(L_INFO
, "Security set to \"%s\"", Classification
);
572 * Update the MaxClientsPerHost value, as needed...
575 if (MaxClientsPerHost
<= 0)
576 MaxClientsPerHost
= MaxClients
;
578 if (MaxClientsPerHost
> MaxClients
)
579 MaxClientsPerHost
= MaxClients
;
581 LogMessage(L_INFO
, "Allowing up to %d client connections per host.",
585 * If we are doing a full reload or the server root has changed, flush
586 * the jobs, printers, etc. and start from scratch...
589 if (NeedReload
== RELOAD_ALL
||
590 !old_serverroot
|| !ServerRoot
|| strcmp(old_serverroot
, ServerRoot
) ||
591 !old_requestroot
|| !RequestRoot
|| strcmp(old_requestroot
, RequestRoot
))
593 LogMessage(L_INFO
, "Full reload is required.");
603 DefaultPrinter
= NULL
;
617 if (MimeDatabase
!= NULL
)
618 mimeDelete(MimeDatabase
);
622 for (i
= 0; i
< NumMimeTypes
; i
++)
623 free((void *)MimeTypes
[i
]);
629 * Read the MIME type and conversion database...
632 snprintf(temp
, sizeof(temp
), "%s/filter", ServerBin
);
634 MimeDatabase
= mimeNew();
635 mimeMerge(MimeDatabase
, ServerRoot
, temp
);
638 * Create a list of MIME types for the document-format-supported
642 NumMimeTypes
= MimeDatabase
->num_types
;
643 if (!mimeType(MimeDatabase
, "application", "octet-stream"))
646 MimeTypes
= calloc(NumMimeTypes
, sizeof(const char *));
648 for (i
= 0; i
< MimeDatabase
->num_types
; i
++)
650 snprintf(type
, sizeof(type
), "%s/%s", MimeDatabase
->types
[i
]->super
,
651 MimeDatabase
->types
[i
]->type
);
653 MimeTypes
[i
] = strdup(type
);
656 if (i
< NumMimeTypes
)
657 MimeTypes
[i
] = strdup("application/octet-stream");
663 snprintf(temp
, sizeof(temp
), "%s/banners", DataDir
);
667 * Load printers and classes...
676 * Load devices and PPDs...
679 snprintf(temp
, sizeof(temp
), "%s/backend", ServerBin
);
682 snprintf(temp
, sizeof(temp
), "%s/model", DataDir
);
686 * Load queued jobs...
691 LogMessage(L_INFO
, "Full reload complete.");
697 LogMessage(L_INFO
, "Partial reload complete.");
701 * Reset the reload state...
704 NeedReload
= RELOAD_NONE
;
706 ClearString(&old_serverroot
);
707 ClearString(&old_requestroot
);
710 * Startup the server and return...
720 * 'read_configuration()' - Read a configuration file.
723 static int /* O - 1 on success, 0 on failure */
724 read_configuration(cups_file_t
*fp
) /* I - File to read from */
726 int i
; /* Looping var */
727 int linenum
; /* Current line number */
728 int len
; /* Length of line */
729 char line
[HTTP_MAX_BUFFER
], /* Line from file */
730 name
[256], /* Parameter name */
731 *nameptr
, /* Pointer into name */
732 *value
; /* Pointer to value */
733 int valuelen
; /* Length of value */
734 var_t
*var
; /* Current variable */
735 unsigned address
, /* Address value */
736 netmask
; /* Netmask value */
737 int ip
[4], /* IP address components */
738 ipcount
, /* Number of components provided */
739 mask
[4]; /* IP netmask components */
740 dirsvc_relay_t
*relay
; /* Relay data */
741 dirsvc_poll_t
*poll
; /* Polling data */
742 struct sockaddr_in polladdr
; /* Polling address */
743 location_t
*location
; /* Browse location */
744 cups_file_t
*incfile
; /* Include file */
745 char incname
[1024]; /* Include filename */
746 static unsigned netmasks
[4] = /* Standard netmasks... */
756 * Loop through each line in the file...
761 while (cupsFileGets(fp
, line
, sizeof(line
)) != NULL
)
766 * Skip comment lines...
773 * Strip trailing whitespace, if any...
778 while (len
> 0 && isspace(line
[len
- 1]))
785 * Extract the name from the beginning of the line...
788 for (value
= line
; isspace(*value
); value
++);
790 for (nameptr
= name
; *value
!= '\0' && !isspace(*value
) &&
791 nameptr
< (name
+ sizeof(name
) - 1);)
792 *nameptr
++ = *value
++;
795 while (isspace(*value
))
802 * Decode the directive...
805 if (strcasecmp(name
, "Include") == 0)
812 strlcpy(incname
, value
, sizeof(incname
));
814 snprintf(incname
, sizeof(incname
), "%s/%s", ServerRoot
, value
);
816 if ((incfile
= cupsFileOpen(incname
, "rb")) == NULL
)
817 LogMessage(L_ERROR
, "Unable to include config file \"%s\" - %s",
818 incname
, strerror(errno
));
821 read_configuration(incfile
);
822 cupsFileClose(incfile
);
825 else if (strcasecmp(name
, "<Location") == 0)
831 if (line
[len
- 1] == '>')
833 line
[len
- 1] = '\0';
835 linenum
= read_location(fp
, value
, linenum
);
841 LogMessage(L_ERROR
, "ReadConfiguration() Syntax error on line %d.",
846 else if (strcasecmp(name
, "Port") == 0 ||
847 strcasecmp(name
, "Listen") == 0)
850 * Add a listening address to the list...
853 listener_t
*temp
; /* New listeners array */
856 if (NumListeners
== 0)
857 temp
= malloc(sizeof(listener_t
));
859 temp
= realloc(Listeners
, (NumListeners
+ 1) * sizeof(listener_t
));
863 LogMessage(L_ERROR
, "Unable to allocate %s at line %d - %s.",
864 name
, linenum
, strerror(errno
));
869 temp
+= NumListeners
;
871 memset(temp
, 0, sizeof(listener_t
));
873 if (get_address(value
, INADDR_ANY
, IPP_PORT
, &(temp
->address
)))
875 LogMessage(L_INFO
, "Listening to %x:%d",
876 (unsigned)ntohl(temp
->address
.sin_addr
.s_addr
),
877 ntohs(temp
->address
.sin_port
));
881 LogMessage(L_ERROR
, "Bad %s address %s at line %d.", name
,
885 else if (strcasecmp(name
, "SSLPort") == 0 ||
886 strcasecmp(name
, "SSLListen") == 0)
889 * Add a listening address to the list...
892 listener_t
*temp
; /* New listeners array */
895 if (NumListeners
== 0)
896 temp
= malloc(sizeof(listener_t
));
898 temp
= realloc(Listeners
, (NumListeners
+ 1) * sizeof(listener_t
));
902 LogMessage(L_ERROR
, "Unable to allocate %s at line %d - %s.",
903 name
, linenum
, strerror(errno
));
908 temp
+= NumListeners
;
910 if (get_address(value
, INADDR_ANY
, IPP_PORT
, &(temp
->address
)))
912 LogMessage(L_INFO
, "Listening to %x:%d (SSL)",
913 (unsigned)ntohl(temp
->address
.sin_addr
.s_addr
),
914 ntohs(temp
->address
.sin_port
));
915 temp
->encryption
= HTTP_ENCRYPT_ALWAYS
;
919 LogMessage(L_ERROR
, "Bad %s address %s at line %d.", name
,
922 #endif /* HAVE_SSL */
923 else if (strcasecmp(name
, "BrowseAddress") == 0)
926 * Add a browse address to the list...
929 dirsvc_addr_t
*temp
; /* New browse address array */
932 if (NumBrowsers
== 0)
933 temp
= malloc(sizeof(dirsvc_addr_t
));
935 temp
= realloc(Browsers
, (NumBrowsers
+ 1) * sizeof(dirsvc_addr_t
));
939 LogMessage(L_ERROR
, "Unable to allocate BrowseAddress at line %d - %s.",
940 linenum
, strerror(errno
));
947 memset(temp
, 0, sizeof(dirsvc_addr_t
));
949 if (strcasecmp(value
, "@LOCAL") == 0)
952 * Send browse data to all local interfaces...
955 strcpy(temp
->iface
, "*");
958 else if (strncasecmp(value
, "@IF(", 4) == 0)
961 * Send browse data to the named interface...
964 strlcpy(temp
->iface
, value
+ 4, sizeof(Browsers
[0].iface
));
966 nameptr
= temp
->iface
+ strlen(temp
->iface
) - 1;
972 else if (get_address(value
, INADDR_NONE
, BrowsePort
, &(temp
->to
)))
974 LogMessage(L_INFO
, "Sending browsing info to %x:%d",
975 (unsigned)ntohl(temp
->to
.sin_addr
.s_addr
),
976 ntohs(temp
->to
.sin_port
));
981 LogMessage(L_ERROR
, "Bad BrowseAddress %s at line %d.", value
,
984 else if (strcasecmp(name
, "BrowseOrder") == 0)
987 * "BrowseOrder Deny,Allow" or "BrowseOrder Allow,Deny"...
990 if ((location
= FindLocation("CUPS_INTERNAL_BROWSE_ACL")) == NULL
)
991 location
= AddLocation("CUPS_INTERNAL_BROWSE_ACL");
993 if (location
== NULL
)
994 LogMessage(L_ERROR
, "Unable to initialize browse access control list!");
995 else if (strncasecmp(value
, "deny", 4) == 0)
996 location
->order_type
= AUTH_ALLOW
;
997 else if (strncasecmp(value
, "allow", 5) == 0)
998 location
->order_type
= AUTH_DENY
;
1000 LogMessage(L_ERROR
, "Unknown BrowseOrder value %s on line %d.",
1003 else if (strcasecmp(name
, "BrowseProtocols") == 0)
1006 * "BrowseProtocol name [... name]"
1009 BrowseProtocols
= 0;
1013 for (valuelen
= 0; value
[valuelen
]; valuelen
++)
1014 if (isspace(value
[valuelen
]) || value
[valuelen
] == ',')
1017 if (value
[valuelen
])
1019 value
[valuelen
] = '\0';
1023 if (strcasecmp(value
, "cups") == 0)
1024 BrowseProtocols
|= BROWSE_CUPS
;
1025 else if (strcasecmp(value
, "slp") == 0)
1026 BrowseProtocols
|= BROWSE_SLP
;
1027 else if (strcasecmp(value
, "ldap") == 0)
1028 BrowseProtocols
|= BROWSE_LDAP
;
1029 else if (strcasecmp(value
, "all") == 0)
1030 BrowseProtocols
|= BROWSE_ALL
;
1033 LogMessage(L_ERROR
, "Unknown browse protocol \"%s\" on line %d.",
1038 for (value
+= valuelen
; *value
; value
++)
1039 if (!isspace(*value
) || *value
!= ',')
1043 else if (strcasecmp(name
, "BrowseAllow") == 0 ||
1044 strcasecmp(name
, "BrowseDeny") == 0)
1047 * BrowseAllow [From] host/ip...
1048 * BrowseDeny [From] host/ip...
1051 if ((location
= FindLocation("CUPS_INTERNAL_BROWSE_ACL")) == NULL
)
1052 location
= AddLocation("CUPS_INTERNAL_BROWSE_ACL");
1054 if (location
== NULL
)
1055 LogMessage(L_ERROR
, "Unable to initialize browse access control list!");
1058 if (strncasecmp(value
, "from ", 5) == 0)
1061 * Strip leading "from"...
1066 while (isspace(*value
))
1071 * Figure out what form the allow/deny address takes:
1082 * nnn.nnn.nnn.nnn/mm
1083 * nnn.nnn.nnn.nnn/mmm.mmm.mmm.mmm
1086 if (strcasecmp(value
, "all") == 0)
1092 if (strcasecmp(name
, "BrowseAllow") == 0)
1093 AllowIP(location
, 0, 0);
1095 DenyIP(location
, 0, 0);
1097 else if (strcasecmp(value
, "none") == 0)
1103 if (strcasecmp(name
, "BrowseAllow") == 0)
1104 AllowIP(location
, ~0, 0);
1106 DenyIP(location
, ~0, 0);
1108 else if (value
[0] == '*' || value
[0] == '.' || !isdigit(value
[0]))
1111 * Host or domain name...
1114 if (value
[0] == '*')
1117 if (strcasecmp(name
, "BrowseAllow") == 0)
1118 AllowHost(location
, value
);
1120 DenyHost(location
, value
);
1125 * One of many IP address forms...
1128 memset(ip
, 0, sizeof(ip
));
1129 ipcount
= sscanf(value
, "%d.%d.%d.%d", ip
+ 0, ip
+ 1, ip
+ 2, ip
+ 3);
1130 address
= (((((ip
[0] << 8) | ip
[1]) << 8) | ip
[2]) << 8) | ip
[3];
1132 if ((value
= strchr(value
, '/')) != NULL
)
1135 memset(mask
, 0, sizeof(mask
));
1136 switch (sscanf(value
, "%d.%d.%d.%d", mask
+ 0, mask
+ 1,
1137 mask
+ 2, mask
+ 3))
1140 netmask
= (0xffffffff << (32 - mask
[0])) & 0xffffffff;
1143 netmask
= (((((mask
[0] << 8) | mask
[1]) << 8) |
1144 mask
[2]) << 8) | mask
[3];
1147 LogMessage(L_ERROR
, "Bad netmask value %s on line %d.",
1149 netmask
= 0xffffffff;
1154 netmask
= netmasks
[ipcount
- 1];
1156 if ((address
& ~netmask
) != 0)
1158 LogMessage(L_WARN
, "Discarding extra bits in %s address %08x for netmask %08x...",
1159 name
, address
, netmask
);
1163 if (strcasecmp(name
, "BrowseAllow") == 0)
1164 AllowIP(location
, address
, netmask
);
1166 DenyIP(location
, address
, netmask
);
1170 else if (strcasecmp(name
, "BrowseRelay") == 0)
1173 * BrowseRelay [from] source [to] destination
1177 relay
= malloc(sizeof(dirsvc_relay_t
));
1179 relay
= realloc(Relays
, (NumRelays
+ 1) * sizeof(dirsvc_relay_t
));
1183 LogMessage(L_ERROR
, "Unable to allocate BrowseRelay at line %d - %s.",
1184 linenum
, strerror(errno
));
1191 memset(relay
, 0, sizeof(dirsvc_relay_t
));
1193 if (strncasecmp(value
, "from ", 5) == 0)
1196 * Strip leading "from"...
1201 while (isspace(*value
))
1206 * Figure out what form the from address takes:
1215 * nnn.nnn.nnn.nnn/mm
1216 * nnn.nnn.nnn.nnn/mmm.mmm.mmm.mmm
1219 if (value
[0] == '*' || value
[0] == '.' || !isdigit(value
[0]))
1222 * Host or domain name...
1225 if (value
[0] == '*')
1228 relay
->from
.type
= AUTH_NAME
;
1229 relay
->from
.mask
.name
.name
= strdup(value
);
1230 relay
->from
.mask
.name
.length
= strlen(value
);
1235 * One of many IP address forms...
1238 memset(ip
, 0, sizeof(ip
));
1239 ipcount
= sscanf(value
, "%d.%d.%d.%d", ip
+ 0, ip
+ 1, ip
+ 2, ip
+ 3);
1240 address
= (((((ip
[0] << 8) | ip
[1]) << 8) | ip
[2]) << 8) | ip
[3];
1242 for (; *value
; value
++)
1243 if (*value
== '/' || isspace(*value
))
1249 memset(mask
, 0, sizeof(mask
));
1250 switch (sscanf(value
, "%d.%d.%d.%d", mask
+ 0, mask
+ 1,
1251 mask
+ 2, mask
+ 3))
1254 netmask
= (0xffffffff << (32 - mask
[0])) & 0xffffffff;
1257 netmask
= (((((mask
[0] << 8) | mask
[1]) << 8) |
1258 mask
[2]) << 8) | mask
[3];
1261 LogMessage(L_ERROR
, "Bad netmask value %s on line %d.",
1263 netmask
= 0xffffffff;
1268 netmask
= netmasks
[ipcount
- 1];
1270 relay
->from
.type
= AUTH_IP
;
1271 relay
->from
.mask
.ip
.address
= address
;
1272 relay
->from
.mask
.ip
.netmask
= netmask
;
1276 * Skip value and trailing whitespace...
1279 for (; *value
; value
++)
1280 if (isspace(*value
))
1283 while (isspace(*value
))
1286 if (strncasecmp(value
, "to ", 3) == 0)
1289 * Strip leading "to"...
1294 while (isspace(*value
))
1299 * Get "to" address and port...
1302 if (get_address(value
, INADDR_BROADCAST
, BrowsePort
, &(relay
->to
)))
1304 if (relay
->from
.type
== AUTH_NAME
)
1305 LogMessage(L_INFO
, "Relaying from %s to %x:%d",
1306 relay
->from
.mask
.name
.name
,
1307 (unsigned)ntohl(relay
->to
.sin_addr
.s_addr
),
1308 ntohs(relay
->to
.sin_port
));
1310 LogMessage(L_INFO
, "Relaying from %x/%x to %x:%d",
1311 relay
->from
.mask
.ip
.address
, relay
->from
.mask
.ip
.netmask
,
1312 (unsigned)ntohl(relay
->to
.sin_addr
.s_addr
),
1313 ntohs(relay
->to
.sin_port
));
1319 if (relay
->from
.type
== AUTH_NAME
)
1320 free(relay
->from
.mask
.name
.name
);
1322 LogMessage(L_ERROR
, "Bad relay address %s at line %d.", value
, linenum
);
1325 else if (strcasecmp(name
, "BrowsePoll") == 0)
1328 * BrowsePoll address[:port]
1332 poll
= malloc(sizeof(dirsvc_poll_t
));
1334 poll
= realloc(Polled
, (NumPolled
+ 1) * sizeof(dirsvc_poll_t
));
1338 LogMessage(L_ERROR
, "Unable to allocate BrowsePoll at line %d - %s.",
1339 linenum
, strerror(errno
));
1347 * Get poll address and port...
1350 if (get_address(value
, INADDR_NONE
, ippPort(), &polladdr
))
1352 LogMessage(L_INFO
, "Polling %x:%d",
1353 (unsigned)ntohl(polladdr
.sin_addr
.s_addr
),
1354 ntohs(polladdr
.sin_port
));
1357 memset(poll
, 0, sizeof(dirsvc_poll_t
));
1359 address
= ntohl(polladdr
.sin_addr
.s_addr
);
1361 sprintf(poll
->hostname
, "%d.%d.%d.%d", address
>> 24,
1362 (address
>> 16) & 255, (address
>> 8) & 255, address
& 255);
1363 poll
->port
= ntohs(polladdr
.sin_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 address
, /* Address value */
1595 netmask
; /* Netmask value */
1596 int ip
[4], /* IP address components */
1597 ipcount
, /* Number of components provided */
1598 mask
[4]; /* IP netmask components */
1599 static unsigned netmasks
[4] = /* Standard netmasks... */
1608 if ((parent
= AddLocation(location
)) == NULL
)
1611 parent
->limit
= AUTH_LIMIT_ALL
;
1614 while (cupsFileGets(fp
, line
, sizeof(line
)) != NULL
)
1619 * Skip comment lines...
1626 * Strip trailing whitespace, if any...
1631 while (len
> 0 && isspace(line
[len
- 1]))
1638 * Extract the name from the beginning of the line...
1641 for (value
= line
; isspace(*value
); value
++);
1643 for (nameptr
= name
; *value
!= '\0' && !isspace(*value
) &&
1644 nameptr
< (name
+ sizeof(name
) - 1);)
1645 *nameptr
++ = *value
++;
1648 while (isspace(*value
))
1651 if (name
[0] == '\0')
1655 * Decode the directive...
1658 if (strcasecmp(name
, "</Location>") == 0)
1660 else if (strcasecmp(name
, "<Limit") == 0 ||
1661 strcasecmp(name
, "<LimitExcept") == 0)
1663 if ((loc
= CopyLocation(&parent
)) == NULL
)
1669 for (valptr
= value
;
1670 !isspace(*valptr
) && *valptr
!= '>' && *valptr
;
1676 if (strcmp(value
, "ALL") == 0)
1677 loc
->limit
= AUTH_LIMIT_ALL
;
1678 else if (strcmp(value
, "GET") == 0)
1679 loc
->limit
|= AUTH_LIMIT_GET
;
1680 else if (strcmp(value
, "HEAD") == 0)
1681 loc
->limit
|= AUTH_LIMIT_HEAD
;
1682 else if (strcmp(value
, "OPTIONS") == 0)
1683 loc
->limit
|= AUTH_LIMIT_OPTIONS
;
1684 else if (strcmp(value
, "POST") == 0)
1685 loc
->limit
|= AUTH_LIMIT_POST
;
1686 else if (strcmp(value
, "PUT") == 0)
1687 loc
->limit
|= AUTH_LIMIT_PUT
;
1688 else if (strcmp(value
, "TRACE") == 0)
1689 loc
->limit
|= AUTH_LIMIT_TRACE
;
1691 LogMessage(L_WARN
, "Unknown request type %s on line %d!", value
,
1694 for (value
= valptr
; isspace(*value
) || *value
== '>'; value
++);
1697 if (strcasecmp(name
, "<LimitExcept") == 0)
1698 loc
->limit
= AUTH_LIMIT_ALL
^ loc
->limit
;
1700 parent
->limit
&= ~loc
->limit
;
1702 else if (strcasecmp(name
, "</Limit>") == 0)
1704 else if (strcasecmp(name
, "Encryption") == 0)
1707 * "Encryption xxx" - set required encryption level...
1710 if (strcasecmp(value
, "never") == 0)
1711 loc
->encryption
= HTTP_ENCRYPT_NEVER
;
1712 else if (strcasecmp(value
, "always") == 0)
1714 LogMessage(L_ERROR
, "Encryption value \"%s\" on line %d is invalid in this context. "
1715 "Using \"required\" instead.", value
, linenum
);
1717 loc
->encryption
= HTTP_ENCRYPT_REQUIRED
;
1719 else if (strcasecmp(value
, "required") == 0)
1720 loc
->encryption
= HTTP_ENCRYPT_REQUIRED
;
1721 else if (strcasecmp(value
, "ifrequested") == 0)
1722 loc
->encryption
= HTTP_ENCRYPT_IF_REQUESTED
;
1724 LogMessage(L_ERROR
, "Unknown Encryption value %s on line %d.",
1727 else if (strcasecmp(name
, "Order") == 0)
1730 * "Order Deny,Allow" or "Order Allow,Deny"...
1733 if (strncasecmp(value
, "deny", 4) == 0)
1734 loc
->order_type
= AUTH_ALLOW
;
1735 else if (strncasecmp(value
, "allow", 5) == 0)
1736 loc
->order_type
= AUTH_DENY
;
1738 LogMessage(L_ERROR
, "Unknown Order value %s on line %d.",
1741 else if (strcasecmp(name
, "Allow") == 0 ||
1742 strcasecmp(name
, "Deny") == 0)
1745 * Allow [From] host/ip...
1746 * Deny [From] host/ip...
1749 if (strncasecmp(value
, "from", 4) == 0)
1752 * Strip leading "from"...
1757 while (isspace(*value
))
1762 * Figure out what form the allow/deny address takes:
1773 * nnn.nnn.nnn.nnn/mm
1774 * nnn.nnn.nnn.nnn/mmm.mmm.mmm.mmm
1777 if (strcasecmp(value
, "all") == 0)
1783 if (strcasecmp(name
, "Allow") == 0)
1788 else if (strcasecmp(value
, "none") == 0)
1794 if (strcasecmp(name
, "Allow") == 0)
1795 AllowIP(loc
, ~0, 0);
1799 else if (value
[0] == '*' || value
[0] == '.' || !isdigit(value
[0]))
1802 * Host or domain name...
1805 if (value
[0] == '*')
1808 if (strcasecmp(name
, "Allow") == 0)
1809 AllowHost(loc
, value
);
1811 DenyHost(loc
, value
);
1816 * One of many IP address forms...
1819 memset(ip
, 0, sizeof(ip
));
1820 ipcount
= sscanf(value
, "%d.%d.%d.%d", ip
+ 0, ip
+ 1, ip
+ 2, ip
+ 3);
1821 address
= (((((ip
[0] << 8) | ip
[1]) << 8) | ip
[2]) << 8) | ip
[3];
1823 if ((value
= strchr(value
, '/')) != NULL
)
1826 memset(mask
, 0, sizeof(mask
));
1827 switch (sscanf(value
, "%d.%d.%d.%d", mask
+ 0, mask
+ 1,
1828 mask
+ 2, mask
+ 3))
1831 netmask
= (0xffffffff << (32 - mask
[0])) & 0xffffffff;
1834 netmask
= (((((mask
[0] << 8) | mask
[1]) << 8) |
1835 mask
[2]) << 8) | mask
[3];
1838 LogMessage(L_ERROR
, "Bad netmask value %s on line %d.",
1840 netmask
= 0xffffffff;
1845 netmask
= netmasks
[ipcount
- 1];
1847 if ((address
& ~netmask
) != 0)
1849 LogMessage(L_WARN
, "Discarding extra bits in %s address %08x for netmask %08x...",
1850 name
, address
, netmask
);
1854 if (strcasecmp(name
, "Allow") == 0)
1855 AllowIP(loc
, address
, netmask
);
1857 DenyIP(loc
, address
, netmask
);
1860 else if (strcasecmp(name
, "AuthType") == 0)
1863 * AuthType {none,basic,digest,basicdigest}
1866 if (strcasecmp(value
, "none") == 0)
1868 loc
->type
= AUTH_NONE
;
1869 loc
->level
= AUTH_ANON
;
1871 else if (strcasecmp(value
, "basic") == 0)
1873 loc
->type
= AUTH_BASIC
;
1875 if (loc
->level
== AUTH_ANON
)
1876 loc
->level
= AUTH_USER
;
1878 else if (strcasecmp(value
, "digest") == 0)
1880 loc
->type
= AUTH_DIGEST
;
1882 if (loc
->level
== AUTH_ANON
)
1883 loc
->level
= AUTH_USER
;
1885 else if (strcasecmp(value
, "basicdigest") == 0)
1887 loc
->type
= AUTH_BASICDIGEST
;
1889 if (loc
->level
== AUTH_ANON
)
1890 loc
->level
= AUTH_USER
;
1893 LogMessage(L_WARN
, "Unknown authorization type %s on line %d.",
1896 else if (strcasecmp(name
, "AuthClass") == 0)
1899 * AuthClass anonymous, user, system, group
1902 if (strcasecmp(value
, "anonymous") == 0)
1904 loc
->type
= AUTH_NONE
;
1905 loc
->level
= AUTH_ANON
;
1907 else if (strcasecmp(value
, "user") == 0)
1908 loc
->level
= AUTH_USER
;
1909 else if (strcasecmp(value
, "group") == 0)
1910 loc
->level
= AUTH_GROUP
;
1911 else if (strcasecmp(value
, "system") == 0)
1913 loc
->level
= AUTH_GROUP
;
1916 * Use the default system group if none is defined so far...
1919 if (NumSystemGroups
== 0)
1920 NumSystemGroups
= 1;
1922 for (i
= 0; i
< NumSystemGroups
; i
++)
1923 AddName(loc
, SystemGroups
[i
]);
1926 LogMessage(L_WARN
, "Unknown authorization class %s on line %d.",
1929 else if (strcasecmp(name
, "AuthGroupName") == 0)
1930 AddName(loc
, value
);
1931 else if (strcasecmp(name
, "Require") == 0)
1934 * Apache synonym for AuthClass and AuthGroupName...
1938 * Require valid-user
1939 * Require group names
1940 * Require user names
1943 for (valptr
= value
;
1944 !isspace(*valptr
) && *valptr
!= '>' && *valptr
;
1950 if (strcasecmp(value
, "valid-user") == 0 ||
1951 strcasecmp(value
, "user") == 0)
1952 loc
->level
= AUTH_USER
;
1953 else if (strcasecmp(value
, "group") == 0)
1954 loc
->level
= AUTH_GROUP
;
1957 LogMessage(L_WARN
, "Unknown Require type %s on line %d.",
1963 * Get the list of names from the line...
1966 for (value
= valptr
; *value
;)
1968 for (valptr
= value
; !isspace(*valptr
) && *valptr
; valptr
++);
1973 AddName(loc
, value
);
1975 for (value
= valptr
; isspace(*value
); value
++);
1978 else if (strcasecmp(name
, "Satisfy") == 0)
1980 if (strcasecmp(value
, "all") == 0)
1981 loc
->satisfy
= AUTH_SATISFY_ALL
;
1982 else if (strcasecmp(value
, "any") == 0)
1983 loc
->satisfy
= AUTH_SATISFY_ANY
;
1985 LogMessage(L_WARN
, "Unknown Satisfy value %s on line %d.", value
,
1989 LogMessage(L_ERROR
, "Unknown Location directive %s on line %d.",
1998 * 'get_address()' - Get an address + port number from a line.
2001 static int /* O - 1 if address good, 0 if bad */
2002 get_address(char *value
, /* I - Value string */
2003 unsigned defaddress
, /* I - Default address */
2004 int defport
, /* I - Default port */
2005 struct sockaddr_in
*address
) /* O - Socket address */
2007 char hostname
[256], /* Hostname or IP */
2008 portname
[256]; /* Port number or name */
2009 struct hostent
*host
; /* Host address */
2010 struct servent
*port
; /* Port number */
2014 * Initialize the socket address to the defaults...
2017 memset(address
, 0, sizeof(struct sockaddr_in
));
2018 address
->sin_family
= AF_INET
;
2019 address
->sin_addr
.s_addr
= htonl(defaddress
);
2020 address
->sin_port
= htons(defport
);
2023 * Try to grab a hostname and port number...
2026 switch (sscanf(value
, "%255[^:]:%255s", hostname
, portname
))
2029 if (strchr(hostname
, '.') == NULL
&& defaddress
== INADDR_ANY
)
2032 * Hostname is a port number...
2035 strlcpy(portname
, hostname
, sizeof(portname
));
2044 LogMessage(L_ERROR
, "Unable to decode address \"%s\"!", value
);
2049 * Decode the hostname and port number as needed...
2052 if (hostname
[0] && strcmp(hostname
, "*"))
2054 if ((host
= httpGetHostByName(hostname
)) == NULL
)
2056 LogMessage(L_ERROR
, "httpGetHostByName(\"%s\") failed - %s!", hostname
,
2057 hstrerror(h_errno
));
2061 memcpy(&(address
->sin_addr
), host
->h_addr
, host
->h_length
);
2062 address
->sin_port
= htons(defport
);
2065 if (portname
[0] != '\0')
2067 if (isdigit(portname
[0]))
2068 address
->sin_port
= htons(atoi(portname
));
2071 if ((port
= getservbyname(portname
, NULL
)) == NULL
)
2073 LogMessage(L_ERROR
, "getservbyname(\"%s\") failed - %s!", portname
,
2078 address
->sin_port
= htons(port
->s_port
);
2088 * 'CDSAGetServerCerts()' - Convert a keychain name into the CFArrayRef
2089 * required by SSLSetCertificate.
2091 * For now we assumes that there is exactly one SecIdentity in the
2092 * keychain - i.e. there is exactly one matching cert/private key pair.
2093 * In the future we will search a keychain for a SecIdentity matching a
2094 * specific criteria. We also skip the operation of adding additional
2095 * non-signing certs from the keychain to the CFArrayRef.
2097 * To create a self-signed certificate for testing use the certtool.
2098 * Executing the following as root will do it:
2100 * certtool c c v k=CUPS
2104 CDSAGetServerCerts(void)
2106 OSStatus err
; /* Error info */
2107 SecKeychainRef kcRef
; /* Keychain reference */
2108 SecIdentitySearchRef srchRef
; /* Search reference */
2109 SecIdentityRef identity
; /* Identity */
2110 CFArrayRef ca
; /* Certificate array */
2117 err
= SecKeychainOpen(ServerCertificate
, &kcRef
);
2120 LogMessage(L_ERROR
, "Cannot open keychain \"%s\", error %d.",
2121 ServerCertificate
, err
);
2125 * Search for "any" identity matching specified key use;
2126 * in this app, we expect there to be exactly one.
2129 err
= SecIdentitySearchCreate(kcRef
, CSSM_KEYUSE_SIGN
, &srchRef
);
2133 "Cannot find signing key in keychain \"%s\", error %d",
2134 ServerCertificate
, err
);
2137 err
= SecIdentitySearchCopyNext(srchRef
, &identity
);
2141 "Cannot find signing key in keychain \"%s\", error %d",
2142 ServerCertificate
, err
);
2145 if (CFGetTypeID(identity
) != SecIdentityGetTypeID())
2146 LogMessage(L_ERROR
, "SecIdentitySearchCopyNext CFTypeID failure!");
2150 * Found one. Place it in a CFArray.
2151 * TBD: snag other (non-identity) certs from keychain and add them
2155 ca
= CFArrayCreate(NULL
, (const void **)&identity
, 1, NULL
);
2158 LogMessage(L_ERROR
, "CFArrayCreate error");
2161 /*CFRelease(identity);*/
2164 /*CFRelease(srchRef);*/
2167 /*CFRelease(kcRef);*/
2172 #endif /* HAVE_CDSASSL */
2176 * End of "$Id: conf.c,v 1.142 2004/02/24 21:34:37 mike Exp $".