]>
Commit | Line | Data |
---|---|---|
89db771d | 1 | /* |
bcf61448 | 2 | * "$Id: server.c,v 1.2.2.4 2003/01/15 04:25:56 mike Exp $" |
89db771d | 3 | * |
4 | * Server start/stop routines for the Common UNIX Printing System (CUPS). | |
5 | * | |
1d9595ab | 6 | * Copyright 1997-2003 by Easy Software Products, all rights reserved. |
89db771d | 7 | * |
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 | |
13 | * at: | |
14 | * | |
15 | * Attn: CUPS Licensing Information | |
16 | * Easy Software Products | |
17 | * 44141 Airport View Drive, Suite 204 | |
18 | * Hollywood, Maryland 20636-3111 USA | |
19 | * | |
20 | * Voice: (301) 373-9603 | |
21 | * EMail: cups-info@cups.org | |
22 | * WWW: http://www.cups.org | |
23 | * | |
24 | * Contents: | |
25 | * | |
26 | * StartServer() - Start the server. | |
27 | * StopServer() - Stop the server. | |
28 | */ | |
29 | ||
30 | /* | |
31 | * Include necessary headers... | |
32 | */ | |
33 | ||
34 | #include "cupsd.h" | |
35 | ||
7a91f14b | 36 | #include <grp.h> |
37 | ||
bcf61448 | 38 | #if defined HAVE_LIBSSL |
89db771d | 39 | # include <openssl/ssl.h> |
40 | # include <openssl/rand.h> | |
bcf61448 | 41 | #elif defined HAVE_GNUTLS |
42 | # include <gnutls/gnutls.h> | |
89db771d | 43 | #endif /* HAVE_LIBSSL */ |
44 | ||
45 | ||
46 | /* | |
47 | * 'StartServer()' - Start the server. | |
48 | */ | |
49 | ||
50 | void | |
51 | StartServer(void) | |
52 | { | |
53 | #ifdef HAVE_LIBSSL | |
54 | int i; /* Looping var */ | |
55 | struct timeval curtime; /* Current time in microseconds */ | |
56 | unsigned char data[1024]; /* Seed data */ | |
57 | #endif /* HAVE_LIBSSL */ | |
58 | ||
59 | ||
bcf61448 | 60 | #if defined HAVE_LIBSSL |
89db771d | 61 | /* |
62 | * Initialize the encryption libraries... | |
63 | */ | |
64 | ||
65 | SSL_library_init(); | |
66 | SSL_load_error_strings(); | |
67 | ||
68 | /* | |
69 | * Using the current time is a dubious random seed, but on some systems | |
70 | * it is the best we can do (on others, this seed isn't even used...) | |
71 | */ | |
72 | ||
73 | gettimeofday(&curtime, NULL); | |
74 | srand(curtime.tv_sec + curtime.tv_usec); | |
75 | ||
76 | for (i = 0; i < sizeof(data); i ++) | |
77 | data[i] = rand(); /* Yes, this is a poor source of random data... */ | |
78 | ||
79 | RAND_seed(&data, sizeof(data)); | |
bcf61448 | 80 | #elif defined HAVE_GNUTLS |
81 | /* | |
82 | * Initialize the encryption libraries... | |
83 | */ | |
84 | ||
85 | gnutls_global_init(); | |
89db771d | 86 | #endif /* HAVE_LIBSSL */ |
87 | ||
88 | /* | |
89 | * Startup all the networking stuff... | |
90 | */ | |
91 | ||
92 | StartListening(); | |
93 | StartBrowsing(); | |
94 | StartPolling(); | |
89db771d | 95 | } |
96 | ||
97 | ||
98 | /* | |
99 | * 'StopServer()' - Stop the server. | |
100 | */ | |
101 | ||
102 | void | |
103 | StopServer(void) | |
104 | { | |
105 | /* | |
106 | * Close all network clients and stop all jobs... | |
107 | */ | |
108 | ||
109 | CloseAllClients(); | |
110 | StopListening(); | |
111 | StopPolling(); | |
112 | StopBrowsing(); | |
113 | ||
114 | if (Clients != NULL) | |
115 | { | |
116 | free(Clients); | |
117 | Clients = NULL; | |
118 | } | |
119 | ||
120 | StopAllJobs(); | |
121 | ||
122 | /* | |
123 | * Close all log files... | |
124 | */ | |
125 | ||
126 | if (AccessFile != NULL) | |
127 | { | |
128 | fclose(AccessFile); | |
129 | ||
130 | AccessFile = NULL; | |
131 | } | |
132 | ||
133 | if (ErrorFile != NULL) | |
134 | { | |
135 | fclose(ErrorFile); | |
136 | ||
137 | ErrorFile = NULL; | |
138 | } | |
139 | ||
140 | if (PageFile != NULL) | |
141 | { | |
142 | fclose(PageFile); | |
143 | ||
144 | PageFile = NULL; | |
145 | } | |
146 | ||
147 | /* | |
148 | * Clear the input and output sets... | |
149 | */ | |
150 | ||
151 | FD_ZERO(&InputSet); | |
152 | FD_ZERO(&OutputSet); | |
153 | } | |
154 | ||
155 | ||
156 | /* | |
bcf61448 | 157 | * End of "$Id: server.c,v 1.2.2.4 2003/01/15 04:25:56 mike Exp $". |
89db771d | 158 | */ |