| 94 if ((stat(filename, &st)) == -1) { |
94 if ((stat(filename, &st)) == -1) { |
| 95 /* If dir doesn't exist */ |
95 /* If dir doesn't exist */ |
| 96 if (errno == ENOENT) { |
96 if (errno == ENOENT) { |
| 97 if (pw->pw_uid == geteuid()) { |
97 if (pw->pw_uid == geteuid()) { |
| 98 if ((mkdir(filename, 0755)) == -1) { |
98 if ((mkdir(filename, 0755)) == -1) { |
| 99 fprintf(stderr, "Couldn't create `%s' directory\n", filename); |
99 gaim_debug_error("silc", "Couldn't create '%s' directory\n", filename); |
| 100 return FALSE; |
100 return FALSE; |
| 101 } |
101 } |
| 102 } else { |
102 } else { |
| 103 fprintf(stderr, "Couldn't create `%s' directory due to a wrong uid!\n", |
103 gaim_debug_error("silc", "Couldn't create '%s' directory due to a wrong uid!\n", |
| 104 filename); |
104 filename); |
| 105 return FALSE; |
105 return FALSE; |
| 106 } |
106 } |
| 107 } else { |
107 } else { |
| 108 fprintf(stderr, "%s\n", strerror(errno)); |
108 gaim_debug_error("silc", "Couldn't stat '%s' directory, error: %s\n", filename, strerror(errno)); |
| 109 return FALSE; |
109 return FALSE; |
| 110 } |
110 } |
| 111 } else { |
111 } else { |
| 112 /* Check the owner of the dir */ |
112 /* Check the owner of the dir */ |
| 113 if (st.st_uid != 0 && st.st_uid != pw->pw_uid) { |
113 if (st.st_uid != 0 && st.st_uid != pw->pw_uid) { |
| 114 fprintf(stderr, "You don't seem to own `%s' directory\n", |
114 gaim_debug_error("silc", "You don't seem to own '%s' directory\n", |
| 115 filename); |
115 filename); |
| 116 return FALSE; |
116 return FALSE; |
| 117 } |
117 } |
| 118 } |
118 } |
| 119 |
119 |
| 123 if ((stat(servfilename, &st)) == -1) { |
123 if ((stat(servfilename, &st)) == -1) { |
| 124 /* If dir doesn't exist */ |
124 /* If dir doesn't exist */ |
| 125 if (errno == ENOENT) { |
125 if (errno == ENOENT) { |
| 126 if (pw->pw_uid == geteuid()) { |
126 if (pw->pw_uid == geteuid()) { |
| 127 if ((mkdir(servfilename, 0755)) == -1) { |
127 if ((mkdir(servfilename, 0755)) == -1) { |
| 128 fprintf(stderr, "Couldn't create `%s' directory\n", servfilename); |
128 gaim_debug_error("silc", "Couldn't create '%s' directory\n", servfilename); |
| 129 return FALSE; |
129 return FALSE; |
| 130 } |
130 } |
| 131 } else { |
131 } else { |
| 132 fprintf(stderr, "Couldn't create `%s' directory due to a wrong uid!\n", |
132 gaim_debug_error("silc", "Couldn't create '%s' directory due to a wrong uid!\n", |
| 133 servfilename); |
133 servfilename); |
| 134 return FALSE; |
134 return FALSE; |
| 135 } |
135 } |
| 136 } else { |
136 } else { |
| 137 fprintf(stderr, "%s\n", strerror(errno)); |
137 gaim_debug_error("silc", "Couldn't stat '%s' directory, error: %s\n", |
| |
138 servfilename, strerror(errno)); |
| 138 return FALSE; |
139 return FALSE; |
| 139 } |
140 } |
| 140 } |
141 } |
| 141 |
142 |
| 142 /* |
143 /* |
| 145 if ((stat(clientfilename, &st)) == -1) { |
146 if ((stat(clientfilename, &st)) == -1) { |
| 146 /* If dir doesn't exist */ |
147 /* If dir doesn't exist */ |
| 147 if (errno == ENOENT) { |
148 if (errno == ENOENT) { |
| 148 if (pw->pw_uid == geteuid()) { |
149 if (pw->pw_uid == geteuid()) { |
| 149 if ((mkdir(clientfilename, 0755)) == -1) { |
150 if ((mkdir(clientfilename, 0755)) == -1) { |
| 150 fprintf(stderr, "Couldn't create `%s' directory\n", clientfilename); |
151 gaim_debug_error("silc", "Couldn't create '%s' directory\n", clientfilename); |
| 151 return FALSE; |
152 return FALSE; |
| 152 } |
153 } |
| 153 } else { |
154 } else { |
| 154 fprintf(stderr, "Couldn't create `%s' directory due to a wrong uid!\n", |
155 gaim_debug_error("silc", "Couldn't create '%s' directory due to a wrong uid!\n", |
| 155 clientfilename); |
156 clientfilename); |
| 156 return FALSE; |
157 return FALSE; |
| 157 } |
158 } |
| 158 } else { |
159 } else { |
| 159 fprintf(stderr, "%s\n", strerror(errno)); |
160 gaim_debug_error("silc", "Couldn't stat '%s' directory, error: %s\n", |
| |
161 clientfilename, strerror(errno)); |
| 160 return FALSE; |
162 return FALSE; |
| 161 } |
163 } |
| 162 } |
164 } |
| 163 |
165 |
| 164 /* |
166 /* |
| 167 if ((stat(friendsfilename, &st)) == -1) { |
169 if ((stat(friendsfilename, &st)) == -1) { |
| 168 /* If dir doesn't exist */ |
170 /* If dir doesn't exist */ |
| 169 if (errno == ENOENT) { |
171 if (errno == ENOENT) { |
| 170 if (pw->pw_uid == geteuid()) { |
172 if (pw->pw_uid == geteuid()) { |
| 171 if ((mkdir(friendsfilename, 0755)) == -1) { |
173 if ((mkdir(friendsfilename, 0755)) == -1) { |
| 172 fprintf(stderr, "Couldn't create `%s' directory\n", friendsfilename); |
174 gaim_debug_error("silc", "Couldn't create '%s' directory\n", friendsfilename); |
| 173 return FALSE; |
175 return FALSE; |
| 174 } |
176 } |
| 175 } else { |
177 } else { |
| 176 fprintf(stderr, "Couldn't create `%s' directory due to a wrong uid!\n", |
178 gaim_debug_error("silc", "Couldn't create '%s' directory due to a wrong uid!\n", |
| 177 friendsfilename); |
179 friendsfilename); |
| 178 return FALSE; |
180 return FALSE; |
| 179 } |
181 } |
| 180 } else { |
182 } else { |
| 181 fprintf(stderr, "%s\n", strerror(errno)); |
183 gaim_debug_error("silc", "Couldn't stat '%s' directory, error: %s\n", |
| |
184 friendsfilename, strerror(errno)); |
| 182 return FALSE; |
185 return FALSE; |
| 183 } |
186 } |
| 184 } |
187 } |
| 185 |
188 |
| 186 /* |
189 /* |
| 196 if (errno == ENOENT) { |
199 if (errno == ENOENT) { |
| 197 gaim_connection_update_progress(gc, _("Creating SILC key pair..."), 1, 5); |
200 gaim_connection_update_progress(gc, _("Creating SILC key pair..."), 1, 5); |
| 198 silc_create_key_pair(SILCGAIM_DEF_PKCS, |
201 silc_create_key_pair(SILCGAIM_DEF_PKCS, |
| 199 SILCGAIM_DEF_PKCS_LEN, |
202 SILCGAIM_DEF_PKCS_LEN, |
| 200 file_public_key, file_private_key, NULL, |
203 file_public_key, file_private_key, NULL, |
| 201 "", NULL, NULL, NULL, FALSE); |
204 (gc->account->password == NULL) ? "" : gc->account->password, |
| 202 } else { |
205 NULL, NULL, NULL, FALSE); |
| 203 fprintf(stderr, "%s\n", strerror(errno)); |
206 stat(file_public_key, &st); |
| |
207 } else { |
| |
208 gaim_debug_error("silc", "Couldn't stat '%s' public key, error: %s\n", |
| |
209 file_public_key, strerror(errno)); |
| 204 return FALSE; |
210 return FALSE; |
| 205 } |
211 } |
| 206 } |
212 } |
| 207 |
213 |
| 208 /* Check the owner of the public key */ |
214 /* Check the owner of the public key */ |
| 209 if (st.st_uid != 0 && st.st_uid != pw->pw_uid) { |
215 if (st.st_uid != 0 && st.st_uid != pw->pw_uid) { |
| 210 fprintf(stderr, "You don't seem to own your public key!?\n"); |
216 gaim_debug_error("silc", "You don't seem to own your public key!?\n"); |
| 211 return FALSE; |
217 return FALSE; |
| 212 } |
218 } |
| 213 |
219 |
| 214 if ((stat(file_private_key, &st)) == -1) { |
220 if ((stat(file_private_key, &st)) == -1) { |
| 215 /* If file doesn't exist */ |
221 /* If file doesn't exist */ |
| 216 if (errno == ENOENT) { |
222 if (errno == ENOENT) { |
| 217 gaim_connection_update_progress(gc, _("Creating SILC key pair..."), 1, 5); |
223 gaim_connection_update_progress(gc, _("Creating SILC key pair..."), 1, 5); |
| 218 silc_create_key_pair(SILCGAIM_DEF_PKCS, |
224 silc_create_key_pair(SILCGAIM_DEF_PKCS, |
| 219 SILCGAIM_DEF_PKCS_LEN, |
225 SILCGAIM_DEF_PKCS_LEN, |
| 220 file_public_key, file_private_key, NULL, |
226 file_public_key, file_private_key, NULL, |
| 221 "", NULL, NULL, NULL, FALSE); |
227 (gc->account->password == NULL) ? "" : gc->account->password, |
| 222 } else { |
228 NULL, NULL, NULL, FALSE); |
| 223 fprintf(stderr, "%s\n", strerror(errno)); |
229 stat(file_private_key, &st); |
| |
230 } else { |
| |
231 gaim_debug_error("silc", "Couldn't stat '%s' private key, error: %s\n", |
| |
232 file_private_key, strerror(errno)); |
| 224 return FALSE; |
233 return FALSE; |
| 225 } |
234 } |
| 226 } |
235 } |
| 227 |
236 |
| 228 /* Check the owner of the private key */ |
237 /* Check the owner of the private key */ |
| 229 if (st.st_uid != 0 && st.st_uid != pw->pw_uid) { |
238 if (st.st_uid != 0 && st.st_uid != pw->pw_uid) { |
| 230 fprintf(stderr, "You don't seem to own your private key!?\n"); |
239 gaim_debug_error("silc", "You don't seem to own your private key!?\n"); |
| 231 return FALSE; |
240 return FALSE; |
| 232 } |
241 } |
| 233 |
242 |
| 234 /* Check the permissions for the private key */ |
243 /* Check the permissions for the private key */ |
| 235 if ((st.st_mode & 0777) != 0600) { |
244 if ((st.st_mode & 0777) != 0600) { |
| 236 fprintf(stderr, "Wrong permissions in your private key file `%s'!\n" |
245 gaim_debug_warning("silc", "Wrong permissions in your private key file `%s'!\n" |
| 237 "Trying to change them ... ", file_private_key); |
246 "Trying to change them ... ", file_private_key); |
| 238 if ((chmod(file_private_key, 0600)) == -1) { |
247 if ((chmod(file_private_key, 0600)) == -1) { |
| 239 fprintf(stderr, |
248 gaim_debug_error("silc", |
| 240 "Failed to change permissions for private key file!\n" |
249 "Failed to change permissions for private key file!\n" |
| 241 "Permissions for your private key file must be 0600.\n"); |
250 "Permissions for your private key file must be 0600.\n"); |
| 242 return FALSE; |
251 return FALSE; |
| 243 } |
252 } |
| 244 fprintf(stderr, "Done.\n\n"); |
253 gaim_debug_warning("silc", "Done.\n\n"); |
| 245 } |
254 } |
| 246 |
255 |
| 247 return TRUE; |
256 return TRUE; |
| 248 } |
257 } |
| 249 |
258 |