1
|
1 /*****************************************************************************/
|
|
2 /* config_file.c - config file routines */
|
|
3 /* Copyright (C) 1998-2002 Brian Masney <masneyb@gftp.org> */
|
|
4 /* */
|
|
5 /* This program is free software; you can redistribute it and/or modify */
|
|
6 /* it under the terms of the GNU General Public License as published by */
|
|
7 /* the Free Software Foundation; either version 2 of the License, or */
|
|
8 /* (at your option) any later version. */
|
|
9 /* */
|
|
10 /* This program is distributed in the hope that it will be useful, */
|
|
11 /* but WITHOUT ANY WARRANTY; without even the implied warranty of */
|
|
12 /* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
|
|
13 /* GNU General Public License for more details. */
|
|
14 /* */
|
|
15 /* You should have received a copy of the GNU General Public License */
|
|
16 /* along with this program; if not, write to the Free Software */
|
|
17 /* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111 USA */
|
|
18 /*****************************************************************************/
|
|
19
|
|
20 #include "gftp.h"
|
33
|
21 static const char cvsid[] = "$Id$";
|
1
|
22
|
|
23 static void write_comment ( FILE * fd,
|
|
24 const char *comment );
|
|
25 static int parse_args ( char *str,
|
|
26 int numargs,
|
|
27 int lineno,
|
|
28 char **first,
|
|
29 ... );
|
|
30
|
|
31 gftp_config_vars config_file_vars[] =
|
|
32 {
|
|
33 {"", N_("General"), (void *) 0x1, CONFIG_NOTEBOOK, 1, ""},
|
|
34 {"", "", (void *) 0x1, CONFIG_TABLE, 1, ""},
|
|
35 {"email", N_("Email address:"), &emailaddr, CONFIG_CHARTEXT, 1,
|
|
36 N_("Enter your email address here")},
|
|
37 {"view_program", N_("View program:"), &view_program, CONFIG_CHARTEXT, 1,
|
|
38 N_("The default program used to view files. If this is blank, the internal file viewer will be used")},
|
|
39 {"edit_program", N_("Edit program:"), &edit_program, CONFIG_CHARTEXT, 1,
|
|
40 N_("The default program used to edit files.")},
|
|
41 {"startup_directory", N_("Startup Directory:"), &startup_directory,
|
|
42 CONFIG_CHARTEXT, 1,
|
|
43 N_("The default directory gFTP will go to on startup")},
|
|
44 {"max_log_window_size", N_("Max Log Window Size:"), &max_log_window_size, CONFIG_UINTTEXT,
|
|
45 1, N_("The maximum size of the log window in bytes for the GTK+ port")},
|
|
46 {"", "", (void *) 0x1, CONFIG_TABLE, 1, ""},
|
|
47 {"append_transfers", N_("Append file transfers"), &append_file_transfers,
|
|
48 CONFIG_CHECKBOX, 1,
|
|
49 N_("Append new file transfers onto existing ones")},
|
|
50 {"one_transfer", N_("Do one transfer at a time"), &do_one_transfer_at_a_time, CONFIG_CHECKBOX, 1, N_("Do only one transfer at a time?")},
|
|
51 {"overwrite_default", N_("Overwrite by Default"), &overwrite_by_default,
|
|
52 CONFIG_CHECKBOX, 1,
|
|
53 N_("Overwrite files by default or set to resume file transfers")},
|
|
54 {"refresh_files", N_("Refresh after each file transfer"), &refresh_files,
|
|
55 CONFIG_CHECKBOX, 1,
|
|
56 N_("Refresh the listbox after each file is transfered")},
|
|
57 {"sort_dirs_first", N_("Sort directories first"), &sort_dirs_first,
|
|
58 CONFIG_CHECKBOX, 1, N_("Put the directories first then the files")},
|
|
59 {"start_transfers", N_("Start file transfers"), &start_file_transfers,
|
|
60 CONFIG_CHECKBOX, 1,
|
|
61 N_("Automatically start the file transfers when they get queued?")},
|
|
62 {"show_hidden_files", N_("Show hidden files"), &show_hidden_files,
|
|
63 CONFIG_CHECKBOX, 1, N_("Show hidden files in the listboxes")},
|
|
64
|
|
65 {"", N_("Network"), (void *) 0x1, CONFIG_NOTEBOOK, 1, ""},
|
|
66 {"", "", (void *) 0x1, CONFIG_TABLE, 1, ""},
|
|
67 {"network_timeout", N_("Network timeout:"), &network_timeout, CONFIG_INTTEXT,
|
|
68 1, N_("The timeout waiting for network input/output. This is NOT an idle timeout.")},
|
|
69 {"retries", N_("Connect retries:"), &retries, CONFIG_INTTEXT, 1,
|
|
70 N_("The number of auto-retries to do. Set this to 0 to retry indefinately")},
|
|
71 {"sleep_time", N_("Retry sleep time:"), &sleep_time, CONFIG_INTTEXT, 1,
|
|
72 N_("The number of seconds to wait between retries")},
|
|
73 {"maxkbs", N_("Max KB/S:"), &maxkbs, CONFIG_FLOATTEXT, 1,
|
|
74 N_("The maximum KB/s a file transfer can get. (Set to 0 to disable)")},
|
|
75 {"", N_("Default Protocol"), (void *) 0x1, CONFIG_COMBO, 1, "DP"},
|
|
76 {"default_protocol", N_("Default Protocol"), &default_protocol,
|
|
77 CONFIG_CHARTEXT, 0, N_("This specifies the default protocol to use")},
|
|
78
|
|
79 {"", N_("FTP"), (void *) 0x1, CONFIG_NOTEBOOK, 1, ""},
|
|
80 {"", "", (void *) 0x1, CONFIG_TABLE, 1, ""},
|
|
81 {"firewall_host", N_("Proxy hostname:"), &firewall_host, CONFIG_CHARTEXT, 1,
|
|
82 N_("Firewall hostname")},
|
|
83 {"firewall_port", N_("Proxy port:"), &firewall_port, CONFIG_INTTEXT, 1,
|
|
84 N_("Port to connect to on the firewall")},
|
|
85 {"firewall_username", N_("Proxy username:"), &firewall_username,
|
|
86 CONFIG_CHARTEXT, 1, N_("Your firewall username")},
|
|
87 {"firewall_password", N_("Proxy password:"), &firewall_password,
|
|
88 CONFIG_CHARPASS, 1, N_("Your firewall password")},
|
|
89 {"firewall_account", N_("Proxy account:"), &firewall_account, CONFIG_CHARTEXT, 1, N_("Your firewall account (optional)")},
|
|
90 {"", "", (void *) 0x1, CONFIG_TABLE, 1, ""},
|
|
91
|
|
92 {"passive_transfer", N_("Passive file transfers"), &passive_transfer,
|
|
93 CONFIG_CHECKBOX, 1,
|
|
94 N_("Send PASV command or PORT command for data transfers")},
|
|
95 {"resolve_symlinks", N_("Resolve Remote Symlinks (LIST -L)"), &resolve_symlinks,
|
|
96 CONFIG_CHECKBOX, 1,
|
|
97 N_("If you disable this feature, then gFTP will only send LIST to the remote server instead of LIST -L")},
|
|
98
|
|
99 {"", "", (void *) 0x1, CONFIG_TABLE, 1, ""},
|
|
100 {"", N_("Proxy server type"), (void *) 0x1, CONFIG_COMBO, 1, "PS"},
|
|
101 {"proxy_config", N_("Proxy config"), &proxy_config, CONFIG_TEXT, 1,
|
|
102 N_("This specifies how your proxy server expects us to log in")},
|
|
103 {"", N_("%pu = proxy user"), (void *) 0x1, CONFIG_LABEL, 1, ""},
|
|
104 {"", N_("%hu = host user"), (void *) 0x1, CONFIG_LABEL, 1, ""},
|
|
105 {"", N_("%pp = proxy pass"), (void *) 0x1, CONFIG_LABEL, 1, ""},
|
|
106 {"", N_("%hp = host pass"), (void *) 0x1, CONFIG_LABEL, 1, ""},
|
|
107 {"", N_("%ph = proxy host"), (void *) 0x1, CONFIG_LABEL, 1, ""},
|
|
108 {"", N_("%hh = host"), (void *) 0x1, CONFIG_LABEL, 1, ""},
|
|
109 {"", N_("%po = proxy port"), (void *) 0x1, CONFIG_LABEL, 1, ""},
|
|
110 {"", N_("%ho = host port"), (void *) 0x1, CONFIG_LABEL, 1, ""},
|
|
111 {"", N_("%pa = proxy account"), (void *) 0x1, CONFIG_LABEL, 1, ""},
|
|
112 {"", N_("%ha = host account"), (void *) 0x1, CONFIG_LABEL, 1, ""},
|
|
113
|
|
114 {"", N_("HTTP"), (void *) 0x1, CONFIG_NOTEBOOK, 1, ""},
|
|
115 {"", "", (void *) 0x1, CONFIG_TABLE, 1, ""},
|
|
116 {"http_proxy_host", N_("Proxy hostname:"), &http_proxy_host, CONFIG_CHARTEXT,
|
|
117 1, N_("Firewall hostname")},
|
|
118 {"http_proxy_port", N_("Proxy port:"), &http_proxy_port, CONFIG_INTTEXT, 1,
|
|
119 N_("Port to connect to on the firewall")},
|
|
120 {"http_proxy_username", N_("Proxy username:"), &http_proxy_username,
|
|
121 CONFIG_CHARTEXT, 1, N_("Your firewall username")},
|
|
122 {"http_proxy_password", N_("Proxy password:"), &http_proxy_password,
|
|
123 CONFIG_CHARPASS, 1, N_("Your firewall password")},
|
|
124 {"", "", (void *) 0x1, CONFIG_TABLE, 1, ""},
|
|
125 {"use_http11", N_("Use HTTP/1.1"), &use_http11, CONFIG_CHECKBOX, 1,
|
|
126 N_("Do you want to use HTTP/1.1 or HTTP/1.0")},
|
|
127
|
|
128 {"", N_("SSH"), (void *) 0x1, CONFIG_NOTEBOOK, 1, ""},
|
|
129 {"", "", (void *) 0x1, CONFIG_TABLE, 1, ""},
|
|
130 {"ssh_prog_name", N_("SSH Prog Name:"), &ssh_prog_name, CONFIG_CHARTEXT, 1,
|
|
131 N_("The path to the SSH executable")},
|
|
132 {"ssh_extra_params", N_("SSH Extra Params:"), &ssh_extra_params,
|
|
133 CONFIG_CHARTEXT, 1, N_("Extra parameters to pass to the SSH program")},
|
|
134 {"ssh1_sftp_path", N_("SSH sftpserv path:"), &ssh1_sftp_path,
|
|
135 CONFIG_CHARTEXT, 1, N_("Default remote SSH sftpserv path")},
|
|
136 {"ssh2_sftp_path", N_("SSH2 sftp-server path:"), &ssh2_sftp_path,
|
|
137 CONFIG_CHARTEXT, 1, N_("Default remote SSH2 sftp-server path")},
|
|
138 {"", "", (void *) 0x1, CONFIG_TABLE, 1, ""},
|
|
139 {"ssh_need_userpass", N_("Need SSH User/Pass"), &ssh_need_userpass,
|
|
140 CONFIG_CHECKBOX, 1,
|
|
141 N_("Require a username/password for SSH connections")},
|
|
142 {"ssh_use_askpass", N_("Use ssh-askpass util"), &ssh_use_askpass,
|
|
143 CONFIG_CHECKBOX, 1,
|
|
144 N_("Use the ssh-askpass utility to grab the users password")},
|
|
145 {"sshv2_use_sftp_subsys", N_("Use SSH2 SFTP subsys"),
|
|
146 &sshv2_use_sftp_subsys, CONFIG_CHECKBOX, 1,
|
|
147 N_("Call ssh with the -s sftp flag. This is helpful because you won't have to know the remote path to the remote sftp-server")},
|
|
148 {"enable_old_ssh", N_("Enable old SSH protocol"), &enable_old_ssh,
|
|
149 CONFIG_CHECKBOX, 0,
|
|
150 N_("Enable the old SSH protocol. You will need to download the sftp server from http:///www.xbill.org/sftp")},
|
|
151
|
|
152 {"list_dblclk_action", "", &listbox_dblclick_action, CONFIG_HIDEINT, 0,
|
|
153 N_("This defines what will happen when you double click a file in the file listboxes. 0=View file 1=Edit file 2=Transfer file")},
|
|
154 {"use_default_dl_types", "", &use_default_dl_types, CONFIG_HIDEINT, 0,
|
|
155 N_("(*) If this is set, and there is a ext= line below for the file extension, it will download the file as specified below")},
|
|
156 {"listbox_local_width", "", &listbox_local_width, CONFIG_HIDEINT, 0,
|
|
157 N_("The default width of the local files listbox")},
|
|
158 {"listbox_remote_width", "", &listbox_remote_width, CONFIG_HIDEINT, 0,
|
|
159 N_("The default width of the remote files listbox")},
|
|
160 {"listbox_file_height", "", &listbox_file_height, CONFIG_HIDEINT, 0,
|
|
161 N_("The default height of the local/remote files listboxes")},
|
|
162 {"transfer_height", "", &transfer_height, CONFIG_HIDEINT, 0,
|
|
163 N_("The default height of the transfer listbox")},
|
|
164 {"log_height", "", &log_height, CONFIG_HIDEINT, 0,
|
|
165 N_("The default height of the logging window")},
|
|
166 {"file_trans_column", "", &file_trans_column, CONFIG_HIDEINT, 0,
|
|
167 N_("The width of the filename column in the transfer window. Set this to 0 to have this column automagically resize.")},
|
|
168 {"local_file_width", "", &local_columns[0], CONFIG_HIDEINT, 0,
|
|
169 N_("The width of the filename column in the file listboxes. Set this to 0 to have this column automagically resize. Set this to -1 to disable this column")},
|
|
170 {"local_size_width", "", &local_columns[1], CONFIG_HIDEINT, 0,
|
|
171 N_("The width of the size column in the file listboxes. Set this to 0 to have this column automagically resize. Set this to -1 to disable this column")},
|
|
172 {"local_user_width", "", &local_columns[2], CONFIG_HIDEINT, 0,
|
|
173 N_("The width of the user column in the file listboxes. Set this to 0 to have this column automagically resize. Set this to -1 to disable this column")},
|
|
174 {"local_group_width", "", &local_columns[3], CONFIG_HIDEINT, 0,
|
|
175 N_("The width of the group column in the file listboxes. Set this to 0 to have this column automagically resize. Set this to -1 to disable this column")},
|
|
176 {"local_date_width", "", &local_columns[4], CONFIG_HIDEINT, 0,
|
|
177 N_("The width of the date column in the file listboxes. Set this to 0 to have this column automagically resize. Set this to -1 to disable this column")},
|
|
178 {"local_attribs_width", "", &local_columns[5], CONFIG_HIDEINT, 0,
|
|
179 N_("The width of the attribs column in the file listboxes. Set this to 0 to have this column automagically resize. Set this to -1 to disable this column")},
|
|
180 {"remote_file_width", "", &remote_columns[0], CONFIG_HIDEINT, 0,
|
|
181 N_("The width of the filename column in the file listboxes. Set this to 0 to have this column automagically resize. Set this to -1 to disable this column")},
|
|
182 {"remote_size_width", "", &remote_columns[1], CONFIG_HIDEINT, 0,
|
|
183 N_("The width of the size column in the file listboxes. Set this to 0 to have this column automagically resize. Set this to -1 to disable this column")},
|
|
184 {"remote_user_width", "", &remote_columns[2], CONFIG_HIDEINT, 0,
|
|
185 N_("The width of the user column in the file listboxes. Set this to 0 to have this column automagically resize. Set this to -1 to disable this column")},
|
|
186 {"remote_group_width", "", &remote_columns[3], CONFIG_HIDEINT, 0,
|
|
187 N_("The width of the group column in the file listboxes. Set this to 0 to have this column automagically resize. Set this to -1 to disable this column")},
|
|
188 {"remote_date_width", "", &remote_columns[4], CONFIG_HIDEINT, 0,
|
|
189 N_("The width of the date column in the file listboxes. Set this to 0 to have this column automagically resize. Set this to -1 to disable this column")},
|
|
190 {"remote_attribs_width", "", &remote_columns[5], CONFIG_HIDEINT, 0,
|
|
191 N_("The width of the attribs column in the file listboxes. Set this to 0 to have this column automagically resize. Set this to -1 to disable this column")},
|
|
192 {"send_color", "", &send_color, CONFIG_COLOR, 0,
|
|
193 N_("The color of the commands that are sent to the server")},
|
|
194 {"recv_color", "", &recv_color, CONFIG_COLOR, 0,
|
|
195 N_("The color of the commands that are received from the server")},
|
|
196 {"error_color", "", &error_color, CONFIG_COLOR, 0,
|
|
197 N_("The color of the error messages")},
|
|
198 {"misc_color", "", &misc_color, CONFIG_COLOR, 0,
|
|
199 N_("The color of the rest of the log messages")},
|
|
200 {NULL, NULL, NULL, 0, 0, ""}
|
|
201 };
|
|
202
|
|
203
|
|
204 void
|
|
205 gftp_read_config_file (char **argv, int get_xpms)
|
|
206 {
|
|
207 char *tempstr, *temp1str, *curpos, *endpos, buf[255], *str, *red, *green,
|
|
208 *blue;
|
|
209 gftp_file_extensions * tempext;
|
|
210 gftp_bookmarks * newentry;
|
|
211 gftp_proxy_hosts * host;
|
|
212 unsigned int nums[4];
|
|
213 struct hostent *hent;
|
|
214 struct utsname unme;
|
|
215 gftp_color * color;
|
|
216 struct passwd *pw;
|
|
217 FILE *conffile;
|
|
218 uid_t my_uid;
|
|
219 gid_t my_gid;
|
|
220 int line, i;
|
|
221 size_t len;
|
|
222 void *ptr;
|
|
223
|
|
224 memset (&send_color, 0, sizeof (send_color));
|
|
225 memset (&recv_color, 0, sizeof (recv_color));
|
|
226 memset (&error_color, 0, sizeof (error_color));
|
|
227 memset (&misc_color, 0, sizeof (misc_color));
|
|
228 send_color.green = 0x8600;
|
|
229 recv_color.blue = 0xffff;
|
|
230 error_color.red = 0xffff;
|
|
231 misc_color.red = 0xffff;
|
|
232
|
|
233 line = 0;
|
|
234 bookmarks = g_malloc0 (sizeof (*bookmarks));
|
|
235 bookmarks->isfolder = 1;
|
|
236 bookmarks->path = g_malloc0 (1);
|
|
237 bookmarks_htable = g_hash_table_new (string_hash_function, string_hash_compare);
|
|
238 config_htable = g_hash_table_new (string_hash_function, string_hash_compare);
|
|
239
|
|
240 if ((tempstr = expand_path (CONFIG_FILE)) == NULL)
|
|
241 {
|
|
242 printf (_("gFTP Error: Bad config file name %s\n"), CONFIG_FILE);
|
|
243 exit (0);
|
|
244 }
|
|
245
|
|
246 if (access (tempstr, F_OK) == -1)
|
|
247 {
|
|
248 temp1str = expand_path (BASE_CONF_DIR);
|
|
249 if (access (temp1str, F_OK) == -1)
|
|
250 {
|
|
251 if (mkdir (temp1str, 0700) != 0)
|
|
252 {
|
|
253 printf (_("gFTP Error: Could not make directory %s: %s\n"),
|
|
254 temp1str, g_strerror (errno));
|
|
255 exit (-1);
|
|
256 }
|
|
257 }
|
|
258 g_free (temp1str);
|
|
259
|
|
260 temp1str = g_strdup_printf ("%s/gftprc", SHARE_DIR);
|
|
261 if (access (temp1str, F_OK) == -1)
|
|
262 {
|
|
263 printf (_("gFTP Error: Cannot find master config file %s\n"),
|
|
264 temp1str);
|
|
265 printf (_("Did you do a make install?\n"));
|
|
266 exit (-1);
|
|
267 }
|
|
268 copyfile (temp1str, tempstr);
|
|
269 g_free (temp1str);
|
|
270 }
|
|
271 chmod (tempstr, S_IRUSR | S_IWUSR);
|
|
272 if ((conffile = fopen (tempstr, "r")) == NULL)
|
|
273 {
|
|
274 printf (_("gFTP Error: Cannot open config file %s: %s\n"), CONFIG_FILE,
|
|
275 g_strerror (errno));
|
|
276 exit (0);
|
|
277 }
|
|
278 g_free (tempstr);
|
|
279
|
|
280 for (i = 0; config_file_vars[i].var != NULL; i++)
|
|
281 {
|
|
282 g_hash_table_insert (config_htable, config_file_vars[i].key,
|
|
283 GINT_TO_POINTER(i));
|
|
284 }
|
|
285
|
|
286 while (fgets (buf, sizeof (buf), conffile))
|
|
287 {
|
|
288 len = strlen (buf);
|
|
289 if (buf[len - 1] == '\n')
|
|
290 buf[--len] = '\0';
|
|
291 if (buf[len - 1] == '\r')
|
|
292 buf[--len] = '\0';
|
|
293 line++;
|
|
294
|
|
295 if (*buf == '#' || *buf == '\0')
|
|
296 continue;
|
|
297
|
|
298 if ((curpos = strchr (buf, '=')) != NULL)
|
|
299 *curpos = '\0';
|
|
300
|
|
301 if ((ptr = g_hash_table_lookup (config_htable, buf)) != NULL)
|
|
302 {
|
|
303 i = GPOINTER_TO_INT(ptr);
|
|
304 curpos = buf + strlen (buf) + 1;
|
|
305 if (config_file_vars[i].type == CONFIG_CHARTEXT ||
|
|
306 config_file_vars[i].type == CONFIG_CHARPASS ||
|
|
307 config_file_vars[i].type == CONFIG_TEXT)
|
|
308 {
|
|
309 *(char **) config_file_vars[i].var = g_malloc (strlen (curpos) + 1);
|
|
310 strcpy (*(char **) config_file_vars[i].var, curpos);
|
|
311 }
|
|
312 else if (config_file_vars[i].type == CONFIG_FLOATTEXT)
|
|
313 *(double *) config_file_vars[i].var = strtod (curpos, NULL);
|
|
314 else if (config_file_vars[i].type == CONFIG_COLOR)
|
|
315 {
|
|
316 color = config_file_vars[i].var;
|
|
317 parse_args (curpos, 3, line, &red, &green, &blue);
|
|
318 color->red = strtol (red, NULL, 16);
|
|
319 color->green = strtol (green, NULL, 16);
|
|
320 color->blue = strtol (blue, NULL, 16);
|
|
321 g_free (red);
|
|
322 g_free (green);
|
|
323 g_free (blue);
|
|
324 }
|
|
325 else
|
|
326 *(int *) config_file_vars[i].var = strtol (curpos, NULL, 10);
|
|
327 }
|
|
328 else if (strcmp (buf, "host") == 0)
|
|
329 {
|
|
330 /* This is just here for compatibility with old versions of gftp */
|
|
331 curpos = buf + 5;
|
|
332 while (*curpos == '/')
|
|
333 curpos++;
|
|
334 newentry = g_malloc0 (sizeof (*newentry));
|
|
335 newentry->isfolder = 0;
|
|
336 parse_args (curpos, 8, line, &newentry->path, &newentry->hostname,
|
|
337 &temp1str, &newentry->remote_dir, &newentry->user,
|
|
338 &newentry->pass, &tempstr, &newentry->acct);
|
|
339 newentry->port = strtol (temp1str, NULL, 10);
|
|
340 g_free (temp1str);
|
|
341 newentry->save_password = *newentry->pass != '\0';
|
|
342 add_to_bookmark (newentry);
|
|
343 }
|
|
344 else if (strcmp (buf, "dont_use_proxy") == 0)
|
|
345 {
|
|
346 curpos = buf + 15;
|
|
347 host = g_malloc0 (sizeof (*host));
|
|
348 if ((tempstr = strchr (curpos, '/')) == NULL)
|
|
349 {
|
|
350 host->domain = g_malloc (strlen (curpos) + 1);
|
|
351 strcpy (host->domain, curpos);
|
|
352 }
|
|
353 else
|
|
354 {
|
|
355 *tempstr = '\0';
|
|
356 sscanf (curpos, "%u.%u.%u.%u", &nums[0], &nums[1], &nums[2],
|
|
357 &nums[3]);
|
|
358 host->ipv4_network_address =
|
|
359 nums[0] << 24 | nums[1] << 16 | nums[2] << 8 | nums[3];
|
|
360
|
|
361 if (strchr (tempstr + 1, '.') == NULL)
|
|
362 host->ipv4_netmask =
|
|
363 0xffffffff << (32 - strtol (tempstr + 1, NULL, 10));
|
|
364 else
|
|
365 {
|
|
366 sscanf (tempstr + 1, "%u.%u.%u.%u", &nums[0], &nums[1],
|
|
367 &nums[2], &nums[3]);
|
|
368 host->ipv4_netmask =
|
|
369 nums[0] << 24 | nums[1] << 16 | nums[2] << 8 | nums[3];
|
|
370 }
|
|
371 }
|
|
372 proxy_hosts = g_list_append (proxy_hosts, host);
|
|
373 }
|
|
374 else if (strcmp (buf, "ext") == 0)
|
|
375 {
|
|
376 if (get_xpms)
|
|
377 {
|
|
378 curpos = buf + 4;
|
|
379 tempext = g_malloc (sizeof (*tempext));
|
|
380 parse_args (curpos, 4, line, &tempext->ext, &tempext->filename,
|
|
381 &tempext->ascii_binary, &tempext->view_program);
|
|
382
|
|
383 if ((tempstr = get_xpm_path (tempext->filename, 1)) != NULL)
|
|
384 g_free (tempstr);
|
|
385
|
|
386 tempext->stlen = strlen (tempext->ext);
|
|
387 registered_exts = g_list_append (registered_exts, tempext);
|
|
388 }
|
|
389 }
|
|
390 else if (strcmp (buf, "localhistory") == 0)
|
|
391 {
|
|
392 curpos = buf + 13;
|
|
393 str = g_malloc (strlen (curpos) + 1);
|
|
394 strcpy (str, curpos);
|
|
395 localhistory = g_list_append (localhistory, str);
|
|
396 localhistlen++;
|
|
397 }
|
|
398 else if (strcmp (buf, "remotehistory") == 0)
|
|
399 {
|
|
400 curpos = buf + 14;
|
|
401 str = g_malloc (strlen (curpos) + 1);
|
|
402 strcpy (str, curpos);
|
|
403 remotehistory = g_list_append (remotehistory, str);
|
|
404 remotehistlen++;
|
|
405 }
|
|
406 else if (strcmp (buf, "hosthistory") == 0)
|
|
407 {
|
|
408 curpos = buf + 12;
|
|
409 str = g_malloc (strlen (curpos) + 1);
|
|
410 strcpy (str, curpos);
|
|
411 host_history = g_list_append (host_history, str);
|
|
412 host_len++;
|
|
413 }
|
|
414 else if (strcmp (buf, "porthistory") == 0)
|
|
415 {
|
|
416 curpos = buf + 12;
|
|
417 str = g_malloc (strlen (curpos) + 1);
|
|
418 strcpy (str, curpos);
|
|
419 port_history = g_list_append (port_history, str);
|
|
420 port_len++;
|
|
421 }
|
|
422 else if (strcmp (buf, "userhistory") == 0)
|
|
423 {
|
|
424 curpos = buf + 12;
|
|
425 str = g_malloc (strlen (curpos) + 1);
|
|
426 strcpy (str, curpos);
|
|
427 user_history = g_list_append (user_history, str);
|
|
428 user_len++;
|
|
429 }
|
|
430 else
|
|
431 {
|
|
432 printf (_("gFTP Warning: Skipping line %d in config file: %s\n"),
|
|
433 line, buf);
|
|
434 }
|
|
435 }
|
|
436
|
|
437 if (default_protocol == NULL)
|
|
438 {
|
|
439 default_protocol = g_malloc (4);
|
|
440 strcpy (default_protocol, "FTP");
|
|
441 }
|
|
442
|
|
443 if (!enable_old_ssh)
|
|
444 {
|
|
445 gftp_protocols[GFTP_SSH_NUM].name = NULL;
|
|
446 gftp_protocols[GFTP_SSH_NUM].init = NULL;
|
|
447 gftp_protocols[GFTP_SSH_NUM].url_prefix = NULL;
|
|
448 gftp_protocols[GFTP_SSH_NUM].shown = 0;
|
|
449 }
|
|
450
|
|
451 if ((tempstr = expand_path (LOG_FILE)) == NULL)
|
|
452 {
|
|
453 printf (_("gFTP Error: Bad log file name %s\n"), LOG_FILE);
|
|
454 exit (0);
|
|
455 }
|
|
456
|
|
457 if ((logfd = fopen (tempstr, "w")) == NULL)
|
|
458 {
|
|
459 printf (_("gFTP Warning: Cannot open %s for writing: %s\n"),
|
|
460 tempstr, g_strerror (errno));
|
|
461 }
|
|
462 g_free (tempstr);
|
|
463
|
|
464 gftp_read_bookmarks ();
|
|
465
|
|
466 if (ssh_extra_params != NULL)
|
|
467 {
|
|
468 num_ssh_extra_params = 0;
|
|
469 curpos = ssh_extra_params;
|
|
470 while ((endpos = strchr (curpos, ' ')) != NULL)
|
|
471 {
|
|
472 *endpos = '\0';
|
|
473 num_ssh_extra_params++;
|
|
474 ssh_extra_params_list = g_realloc (ssh_extra_params_list,
|
|
475 (num_ssh_extra_params + 1) *
|
|
476 sizeof (char *));
|
|
477 ssh_extra_params_list[num_ssh_extra_params - 1] =
|
|
478 g_strconcat (curpos, NULL);
|
|
479 ssh_extra_params_list[num_ssh_extra_params] = NULL;
|
|
480 *endpos = ' ';
|
|
481 curpos = endpos + 1;
|
|
482 }
|
|
483
|
|
484 if (*curpos != '\0')
|
|
485 {
|
|
486 num_ssh_extra_params++;
|
|
487 ssh_extra_params_list = g_realloc (ssh_extra_params_list,
|
|
488 (num_ssh_extra_params + 1) *
|
|
489 sizeof (char *));
|
|
490 ssh_extra_params_list[num_ssh_extra_params - 1] =
|
|
491 g_strconcat (curpos, NULL);
|
|
492 ssh_extra_params_list[num_ssh_extra_params] = NULL;
|
|
493 }
|
|
494 }
|
|
495
|
|
496 make_nonnull (&proxy_config);
|
|
497 make_nonnull (&firewall_host);
|
|
498 make_nonnull (&firewall_username);
|
|
499 make_nonnull (&firewall_password);
|
|
500 make_nonnull (&firewall_account);
|
|
501 make_nonnull (&http_proxy_host);
|
|
502 make_nonnull (&http_proxy_username);
|
|
503 make_nonnull (&http_proxy_password);
|
|
504 make_nonnull (&view_program);
|
|
505 make_nonnull (&edit_program);
|
|
506
|
|
507 my_uid = geteuid ();
|
|
508 my_gid = getegid ();
|
|
509 pw = getpwuid (my_uid);
|
|
510 if (emailaddr == NULL || *emailaddr == '\0')
|
|
511 {
|
|
512 /* If there is no email address specified, then we'll just use the
|
|
513 currentuser@currenthost */
|
|
514 if (emailaddr)
|
|
515 g_free (emailaddr);
|
|
516 uname (&unme);
|
|
517 hent = gethostbyname (unme.nodename);
|
|
518 if (strchr (unme.nodename, '.') == NULL && hent != NULL)
|
|
519 emailaddr = g_strconcat (pw->pw_name, "@", hent->h_name, NULL);
|
|
520 else
|
|
521 emailaddr = g_strconcat (pw->pw_name, "@", unme.nodename, NULL);
|
|
522 gftp_write_config_file ();
|
|
523 }
|
|
524
|
|
525 if ((tempstr = getenv ("TMP")) != NULL && *tempstr != '\0')
|
|
526 tmp_directory = g_strconcat (tempstr, NULL);
|
|
527 else
|
|
528 tmp_directory = g_strconcat ("/tmp", NULL);
|
|
529 }
|
|
530
|
|
531
|
|
532 void
|
|
533 gftp_read_bookmarks (void)
|
|
534 {
|
|
535 char *tempstr, *temp1str, buf[255], *curpos;
|
|
536 gftp_bookmarks *newentry;
|
|
537 FILE *bmfile;
|
|
538 size_t len;
|
|
539 int line;
|
|
540
|
|
541 if ((tempstr = expand_path (BOOKMARKS_FILE)) == NULL)
|
|
542 {
|
|
543 printf (_("gFTP Error: Bad bookmarks file name %s\n"), BOOKMARKS_FILE);
|
|
544 exit (0);
|
|
545 }
|
|
546
|
|
547 if (access (tempstr, F_OK) == -1)
|
|
548 {
|
|
549 temp1str = expand_path (BASE_CONF_DIR);
|
|
550 if (access (temp1str, F_OK) == -1)
|
|
551 {
|
|
552 if (mkdir (temp1str, 0700) != 0)
|
|
553 {
|
|
554 printf (_("gFTP Error: Could not make directory %s: %s\n"),
|
|
555 temp1str, g_strerror (errno));
|
|
556 exit (-1);
|
|
557 }
|
|
558 }
|
|
559 g_free (temp1str);
|
|
560
|
|
561 temp1str = g_strdup_printf ("%s/bookmarks", SHARE_DIR);
|
|
562 if (access (temp1str, F_OK) == -1)
|
|
563 {
|
|
564 printf (_("Warning: Cannot find master bookmark file %s\n"),
|
|
565 temp1str);
|
|
566 g_free (temp1str);
|
|
567 return;
|
|
568 }
|
|
569 copyfile (temp1str, tempstr);
|
|
570 g_free (temp1str);
|
|
571 }
|
|
572 chmod (tempstr, S_IRUSR | S_IWUSR);
|
|
573 if ((bmfile = fopen (tempstr, "r")) == NULL)
|
|
574 {
|
|
575 printf (_("gFTP Error: Cannot open bookmarks file %s: %s\n"), tempstr,
|
|
576 g_strerror (errno));
|
|
577 exit (0);
|
|
578 }
|
|
579 g_free (tempstr);
|
|
580
|
|
581 line = 0;
|
|
582 newentry = NULL;
|
|
583 while (fgets (buf, sizeof (buf), bmfile))
|
|
584 {
|
|
585 len = strlen (buf);
|
|
586 if (buf[len - 1] == '\n')
|
|
587 buf[--len] = '\0';
|
|
588 if (buf[len - 1] == '\r')
|
|
589 buf[--len] = '\0';
|
|
590 line++;
|
|
591
|
|
592 if (*buf == '[')
|
|
593 {
|
|
594 newentry = g_malloc0 (sizeof (*newentry));
|
|
595 for (; buf[len - 1] == ' ' || buf[len - 1] == ']'; buf[--len] = '\0');
|
|
596 newentry->path = g_malloc (len);
|
|
597 strcpy (newentry->path, buf + 1);
|
|
598 newentry->isfolder = 0;
|
|
599 add_to_bookmark (newentry);
|
|
600 }
|
|
601 else if (strncmp (buf, "hostname", 8) == 0 && newentry)
|
|
602 {
|
|
603 curpos = buf + 9;
|
|
604 if (newentry->hostname)
|
|
605 g_free (newentry->hostname);
|
|
606 newentry->hostname = g_malloc (strlen (curpos) + 1);
|
|
607 strcpy (newentry->hostname, curpos);
|
|
608 }
|
|
609 else if (strncmp (buf, "port", 4) == 0 && newentry)
|
|
610 newentry->port = strtol (buf + 5, NULL, 10);
|
|
611 else if (strncmp (buf, "protocol", 8) == 0 && newentry)
|
|
612 {
|
|
613 curpos = buf + 9;
|
|
614 if (newentry->protocol)
|
|
615 g_free (newentry->protocol);
|
|
616 newentry->protocol = g_malloc (strlen (curpos) + 1);
|
|
617 strcpy (newentry->protocol, curpos);
|
|
618 }
|
|
619 else if (strncmp (buf, "remote directory", 16) == 0 && newentry)
|
|
620 {
|
|
621 curpos = buf + 17;
|
|
622 if (newentry->remote_dir)
|
|
623 g_free (newentry->remote_dir);
|
|
624 newentry->remote_dir = g_malloc (strlen (curpos) + 1);
|
|
625 strcpy (newentry->remote_dir, curpos);
|
|
626 }
|
|
627 else if (strncmp (buf, "local directory", 15) == 0 && newentry)
|
|
628 {
|
|
629 curpos = buf + 16;
|
|
630 if (newentry->local_dir)
|
|
631 g_free (newentry->local_dir);
|
|
632 newentry->local_dir = g_malloc (strlen (curpos) + 1);
|
|
633 strcpy (newentry->local_dir, curpos);
|
|
634 }
|
|
635 else if (strncmp (buf, "username", 8) == 0 && newentry)
|
|
636 {
|
|
637 curpos = buf + 9;
|
|
638 if (newentry->user)
|
|
639 g_free (newentry->user);
|
|
640 newentry->user = g_malloc (strlen (curpos) + 1);
|
|
641 strcpy (newentry->user, curpos);
|
|
642 }
|
|
643 else if (strncmp (buf, "password", 8) == 0 && newentry)
|
|
644 {
|
|
645 curpos = buf + 9;
|
|
646 if (newentry->pass)
|
|
647 g_free (newentry->pass);
|
|
648 newentry->pass = g_malloc (strlen (curpos) + 1);
|
|
649 strcpy (newentry->pass, curpos);
|
|
650 newentry->save_password = *newentry->pass != '\0';
|
|
651 }
|
|
652 else if (strncmp (buf, "account", 7) == 0 && newentry)
|
|
653 {
|
|
654 curpos = buf + 8;
|
|
655 if (newentry->acct)
|
|
656 g_free (newentry->acct);
|
|
657 newentry->acct = g_malloc (strlen (curpos) + 1);
|
|
658 strcpy (newentry->acct, curpos);
|
|
659 }
|
|
660 else if (strncmp (buf, "sftpserv_path", 13) == 0 && newentry)
|
|
661 {
|
|
662 curpos = buf + 14;
|
|
663 if (newentry->sftpserv_path)
|
|
664 g_free (newentry->sftpserv_path);
|
|
665 newentry->sftpserv_path = g_malloc (strlen (curpos) + 1);
|
|
666 strcpy (newentry->sftpserv_path, curpos);
|
|
667 }
|
|
668 else if (*buf != '#' && *buf != '\0')
|
|
669 printf (_("gFTP Warning: Skipping line %d in bookmarks file: %s\n"),
|
|
670 line, buf);
|
|
671 }
|
|
672 }
|
|
673
|
|
674
|
|
675 void
|
|
676 add_to_bookmark (gftp_bookmarks * newentry)
|
|
677 {
|
|
678 gftp_bookmarks *preventry, *folderentry, *endentry;
|
|
679 char *curpos;
|
|
680
|
|
681 if (!newentry->protocol)
|
|
682 {
|
|
683 newentry->protocol = g_malloc (4);
|
|
684 strcpy (newentry->protocol, "FTP");
|
|
685 }
|
|
686
|
|
687 /* We have to create the folders. For example, if we have
|
|
688 Debian Sites/Debian, we have to create a Debian Sites entry */
|
|
689 preventry = bookmarks;
|
|
690 if (preventry->children != NULL)
|
|
691 {
|
|
692 endentry = preventry->children;
|
|
693 while (endentry->next != NULL)
|
|
694 endentry = endentry->next;
|
|
695 }
|
|
696 else
|
|
697 endentry = NULL;
|
|
698 curpos = newentry->path;
|
|
699 while ((curpos = strchr (curpos, '/')) != NULL)
|
|
700 {
|
|
701 *curpos = '\0';
|
|
702 /* See if we already made this folder */
|
|
703 if ((folderentry = (gftp_bookmarks *)
|
|
704 g_hash_table_lookup (bookmarks_htable, newentry->path)) == NULL)
|
|
705 {
|
|
706 /* Allocate the individual folder. We have to do this for the edit
|
|
707 bookmarks feature */
|
|
708 folderentry = g_malloc0 (sizeof (*folderentry));
|
|
709 folderentry->path = g_malloc (strlen (newentry->path) + 1);
|
|
710 strcpy (folderentry->path, newentry->path);
|
|
711 folderentry->prev = preventry;
|
|
712 folderentry->isfolder = 1;
|
|
713 g_hash_table_insert (bookmarks_htable, folderentry->path,
|
|
714 folderentry);
|
|
715 if (preventry->children == NULL)
|
|
716 preventry->children = folderentry;
|
|
717 else
|
|
718 endentry->next = folderentry;
|
|
719 preventry = folderentry;
|
|
720 endentry = NULL;
|
|
721 }
|
|
722 else
|
|
723 {
|
|
724 preventry = folderentry;
|
|
725 if (preventry->children != NULL)
|
|
726 {
|
|
727 endentry = preventry->children;
|
|
728 while (endentry->next != NULL)
|
|
729 endentry = endentry->next;
|
|
730 }
|
|
731 else
|
|
732 endentry = NULL;
|
|
733 }
|
|
734 *curpos = '/';
|
|
735 curpos++;
|
|
736 }
|
|
737
|
|
738 /* Get the parent node */
|
|
739 if ((curpos = strrchr (newentry->path, '/')) == NULL)
|
|
740 preventry = bookmarks;
|
|
741 else
|
|
742 {
|
|
743 *curpos = '\0';
|
|
744 preventry = (gftp_bookmarks *)
|
|
745 g_hash_table_lookup (bookmarks_htable, newentry->path);
|
|
746 *curpos = '/';
|
|
747 }
|
|
748
|
|
749 if (preventry->children != NULL)
|
|
750 {
|
|
751 endentry = preventry->children;
|
|
752 while (endentry->next != NULL)
|
|
753 endentry = endentry->next;
|
|
754 endentry->next = newentry;
|
|
755 }
|
|
756 else
|
|
757 preventry->children = newentry;
|
|
758 newentry->prev = preventry;
|
|
759 newentry->next = NULL;
|
|
760 g_hash_table_insert (bookmarks_htable, newentry->path, newentry);
|
|
761 }
|
|
762
|
|
763
|
|
764 void
|
|
765 gftp_write_config_file (void)
|
|
766 {
|
26
|
767 char *hdr, *proxyhdr, *exthdr, *histhdr;
|
1
|
768 gftp_file_extensions *tempext;
|
|
769 gftp_proxy_hosts *hosts;
|
|
770 gftp_color *color;
|
|
771 GList *templist;
|
26
|
772 FILE *conffile;
|
|
773 char *tempstr;
|
1
|
774 int pos;
|
|
775
|
|
776 hdr = N_("Config file for gFTP. Copyright (C) 1998-2002 Brian Masney <masneyb@gftp.org>. Warning: Any comments that you add to this file WILL be overwritten. If a entry has a (*) in it's comment, you can't change it inside gFTP");
|
|
777 proxyhdr = N_("This section specifies which hosts are on the local subnet and won't need to go out the proxy server (if available). Syntax: dont_use_proxy=.domain or dont_use_proxy=network number/netmask");
|
|
778 exthdr = N_("ext=file extenstion:XPM file:Ascii or Binary (A or B):viewer program. Note: All arguments except the file extension are optional");
|
|
779 histhdr = N_("This section contains the data that is in the history");
|
|
780
|
|
781 if ((tempstr = expand_path (CONFIG_FILE)) == NULL)
|
|
782 {
|
|
783 printf (_("gFTP Error: Bad config file name %s\n"), CONFIG_FILE);
|
|
784 exit (0);
|
|
785 }
|
26
|
786
|
1
|
787 if ((conffile = fopen (tempstr, "w+")) == NULL)
|
|
788 {
|
|
789 printf (_("gFTP Error: Cannot open config file %s: %s\n"), CONFIG_FILE,
|
|
790 g_strerror (errno));
|
|
791 exit (0);
|
|
792 }
|
26
|
793
|
1
|
794 g_free (tempstr);
|
|
795
|
|
796 write_comment (conffile, _(hdr));
|
|
797 fwrite ("\n", 1, 1, conffile);
|
|
798
|
|
799 for (pos = 0; config_file_vars[pos].var != NULL; pos++)
|
|
800 {
|
|
801 if (config_file_vars[pos].type == CONFIG_CHARTEXT ||
|
|
802 config_file_vars[pos].type == CONFIG_CHARPASS ||
|
|
803 config_file_vars[pos].type == CONFIG_TEXT)
|
|
804 {
|
|
805 if (*config_file_vars[pos].comment != '\0')
|
|
806 write_comment (conffile, _(config_file_vars[pos].comment));
|
|
807
|
|
808 fprintf (conffile, "%s=%s\n\n", config_file_vars[pos].key,
|
|
809 *(char **) config_file_vars[pos].var == NULL ? "" :
|
|
810 *(char **) config_file_vars[pos].var);
|
|
811 }
|
|
812 else if (config_file_vars[pos].type == CONFIG_FLOATTEXT)
|
|
813 {
|
|
814 if (*config_file_vars[pos].comment != '\0')
|
|
815 write_comment (conffile, _(config_file_vars[pos].comment));
|
|
816
|
|
817 fprintf (conffile, "%s=%.2f\n\n", config_file_vars[pos].key,
|
|
818 *(double *) config_file_vars[pos].var);
|
|
819 }
|
|
820 else if (config_file_vars[pos].type == CONFIG_INTTEXT ||
|
|
821 config_file_vars[pos].type == CONFIG_UINTTEXT ||
|
|
822 config_file_vars[pos].type == CONFIG_CHECKBOX ||
|
|
823 config_file_vars[pos].type == CONFIG_HIDEINT)
|
|
824 {
|
|
825 if (*config_file_vars[pos].comment != '\0')
|
|
826 write_comment (conffile, _(config_file_vars[pos].comment));
|
|
827
|
|
828 fprintf (conffile, "%s=%d\n\n", config_file_vars[pos].key,
|
|
829 *(int *) config_file_vars[pos].var);
|
|
830 }
|
|
831 else if (config_file_vars[pos].type == CONFIG_COLOR)
|
|
832 {
|
|
833 if (*config_file_vars[pos].comment != '\0')
|
|
834 write_comment (conffile, _(config_file_vars[pos].comment));
|
|
835
|
|
836 color = config_file_vars[pos].var;
|
|
837 fprintf (conffile, "%s=%x:%x:%x\n\n", config_file_vars[pos].key,
|
|
838 color->red, color->green, color->blue);
|
|
839 }
|
|
840 }
|
|
841
|
|
842 write_comment (conffile, _(proxyhdr));
|
|
843 templist = proxy_hosts;
|
|
844 while (templist != NULL)
|
|
845 {
|
|
846 hosts = templist->data;
|
|
847 if (hosts->domain)
|
|
848 fprintf (conffile, "dont_use_proxy=%s\n", hosts->domain);
|
|
849 else
|
|
850 fprintf (conffile, "dont_use_proxy=%d.%d.%d.%d/%d.%d.%d.%d\n",
|
|
851 hosts->ipv4_network_address >> 24 & 0xff,
|
|
852 hosts->ipv4_network_address >> 16 & 0xff,
|
|
853 hosts->ipv4_network_address >> 8 & 0xff,
|
|
854 hosts->ipv4_network_address & 0xff,
|
|
855 hosts->ipv4_netmask >> 24 & 0xff,
|
|
856 hosts->ipv4_netmask >> 16 & 0xff,
|
|
857 hosts->ipv4_netmask >> 8 & 0xff, hosts->ipv4_netmask & 0xff);
|
|
858 templist = templist->next;
|
|
859 }
|
|
860
|
|
861 fwrite ("\n", 1, 1, conffile);
|
|
862 write_comment (conffile, _(exthdr));
|
|
863 templist = registered_exts;
|
|
864 while (templist != NULL)
|
|
865 {
|
|
866 tempext = templist->data;
|
|
867 fprintf (conffile, "ext=%s:%s:%c:%s\n", tempext->ext, tempext->filename,
|
|
868 *tempext->ascii_binary == '\0' ? ' ' : *tempext->ascii_binary,
|
|
869 tempext->view_program);
|
|
870 templist = templist->next;
|
|
871 }
|
|
872
|
|
873 fwrite ("\n", 1, 1, conffile);
|
|
874 write_comment (conffile, _(histhdr));
|
|
875 for (templist = localhistory; templist != NULL; templist = templist->next)
|
|
876 fprintf (conffile, "localhistory=%s\n", (char *) templist->data);
|
|
877
|
|
878 for (templist = remotehistory; templist != NULL; templist = templist->next)
|
|
879 fprintf (conffile, "remotehistory=%s\n", (char *) templist->data);
|
|
880
|
|
881 for (templist = host_history; templist != NULL; templist = templist->next)
|
|
882 fprintf (conffile, "hosthistory=%s\n", (char *) templist->data);
|
|
883
|
|
884 for (templist = port_history; templist != NULL; templist = templist->next)
|
|
885 fprintf (conffile, "porthistory=%s\n", (char *) templist->data);
|
|
886
|
|
887 for (templist = user_history; templist != NULL; templist = templist->next)
|
|
888 fprintf (conffile, "userhistory=%s\n", (char *) templist->data);
|
|
889
|
|
890 fclose (conffile);
|
26
|
891 }
|
|
892
|
|
893
|
|
894 void
|
|
895 gftp_write_bookmarks_file (void)
|
|
896 {
|
|
897 gftp_bookmarks *tempentry;
|
|
898 char *bmhdr, *tempstr;
|
|
899 FILE * bmfile;
|
|
900
|
|
901 bmhdr = N_("Bookmarks file for gFTP. Copyright (C) 1998-2002 Brian Masney <masneyb@gftp.org>. Warning: Any comments that you add to this file WILL be overwritten");
|
|
902
|
|
903 if ((tempstr = expand_path (BOOKMARKS_FILE)) == NULL)
|
|
904 {
|
|
905 printf (_("gFTP Error: Bad bookmarks file name %s\n"), CONFIG_FILE);
|
|
906 exit (0);
|
|
907 }
|
|
908
|
|
909 if ((bmfile = fopen (tempstr, "w+")) == NULL)
|
|
910 {
|
|
911 printf (_("gFTP Error: Cannot open bookmarks file %s: %s\n"),
|
|
912 CONFIG_FILE, g_strerror (errno));
|
|
913 exit (0);
|
|
914 }
|
|
915
|
|
916 g_free (tempstr);
|
|
917
|
|
918 write_comment (bmfile, _(bmhdr));
|
|
919 fwrite ("\n", 1, 1, bmfile);
|
|
920
|
|
921 tempentry = bookmarks->children;
|
|
922 while (tempentry != NULL)
|
|
923 {
|
|
924 if (tempentry->children != NULL)
|
|
925 {
|
|
926 tempentry = tempentry->children;
|
|
927 continue;
|
|
928 }
|
|
929 tempstr = tempentry->path;
|
|
930 while (*tempstr == '/')
|
|
931 tempstr++;
|
|
932 fprintf (bmfile,
|
|
933 "[%s]\nhostname=%s\nport=%d\nprotocol=%s\nremote directory=%s\nlocal directory=%s\nusername=%s\npassword=%s\naccount=%s\n",
|
|
934 tempstr, tempentry->hostname == NULL ? "" : tempentry->hostname,
|
|
935 tempentry->port, tempentry->protocol == NULL
|
|
936 || *tempentry->protocol ==
|
|
937 '\0' ? gftp_protocols[0].name : tempentry->protocol,
|
|
938 tempentry->remote_dir == NULL ? "" : tempentry->remote_dir,
|
|
939 tempentry->local_dir == NULL ? "" : tempentry->local_dir,
|
|
940 tempentry->user == NULL ? "" : tempentry->user,
|
|
941 !tempentry->save_password
|
|
942 || tempentry->pass == NULL ? "" : tempentry->pass,
|
|
943 tempentry->acct == NULL ? "" : tempentry->acct);
|
|
944
|
|
945 if (tempentry->sftpserv_path)
|
|
946 fprintf (bmfile, "sftpserv_path=%s\n", tempentry->sftpserv_path);
|
|
947
|
|
948 fprintf (bmfile, "\n");
|
|
949
|
|
950 if (tempentry->next == NULL)
|
|
951 {
|
|
952 tempentry = tempentry->prev;
|
|
953 while (tempentry->next == NULL && tempentry->prev != NULL)
|
|
954 tempentry = tempentry->prev;
|
|
955 tempentry = tempentry->next;
|
|
956 }
|
|
957 else
|
|
958 tempentry = tempentry->next;
|
|
959 }
|
|
960
|
1
|
961 fclose (bmfile);
|
|
962 }
|
|
963
|
|
964
|
|
965 static void
|
|
966 write_comment (FILE * fd, const char *comment)
|
|
967 {
|
|
968 const char *pos, *endpos;
|
|
969
|
|
970 /* FIXME - need to use UTF functions here. I need to check to see how
|
|
971 portable they are before I do this though */
|
|
972
|
|
973 fwrite ("# ", 1, 2, fd);
|
|
974 pos = comment;
|
|
975 while (strlen (pos) > 76)
|
|
976 {
|
|
977 for (endpos = pos + 76; *endpos != ' ' && endpos > pos; endpos--);
|
|
978 if (endpos == pos)
|
|
979 {
|
|
980 for (endpos = pos + 76; *endpos != ' ' && *endpos != '\0';
|
|
981 endpos++);
|
|
982 }
|
|
983 fwrite (pos, 1, endpos - pos, fd);
|
|
984 fwrite ("\n# ", 1, 3, fd);
|
|
985 if (*endpos == '\0')
|
|
986 {
|
|
987 pos = endpos;
|
|
988 break;
|
|
989 }
|
|
990 else
|
|
991 pos = endpos + 1;
|
|
992 }
|
|
993 if (strlen (pos) > 1)
|
|
994 {
|
|
995 fwrite (pos, 1, strlen (pos), fd);
|
|
996 fwrite ("\n", 1, 1, fd);
|
|
997 }
|
|
998 }
|
|
999
|
|
1000
|
|
1001 static int
|
|
1002 parse_args (char *str, int numargs, int lineno, char **first, ...)
|
|
1003 {
|
|
1004 char *curpos, *endpos, *pos, **dest, tempchar;
|
|
1005 int ret, has_colon;
|
|
1006 va_list argp;
|
|
1007
|
|
1008 ret = 1;
|
|
1009 va_start (argp, first);
|
|
1010 curpos = str;
|
|
1011 dest = first;
|
|
1012 *dest = NULL;
|
|
1013 while (numargs > 0)
|
|
1014 {
|
|
1015 has_colon = 0;
|
|
1016 if (numargs > 1)
|
|
1017 {
|
|
1018 if ((endpos = strchr (curpos, ':')) == NULL)
|
|
1019 {
|
|
1020 printf (_("gFTP Warning: Line %d doesn't have enough arguments\n"),
|
|
1021 lineno);
|
|
1022 ret = 0;
|
|
1023 endpos = curpos + strlen (curpos);
|
|
1024 }
|
|
1025 else
|
|
1026 {
|
|
1027 /* Allow colons inside the fields. If you want a colon inside a
|
|
1028 field, just put 2 colons in there */
|
|
1029 while (endpos != NULL && *(endpos - 1) == '\\')
|
|
1030 {
|
|
1031 endpos = strchr (endpos + 1, ':');
|
|
1032 has_colon = 1;
|
|
1033 }
|
|
1034 }
|
|
1035 }
|
|
1036 else
|
|
1037 endpos = curpos + strlen (curpos);
|
|
1038
|
|
1039 *dest = g_malloc (endpos - curpos + 1);
|
|
1040 tempchar = *endpos;
|
|
1041 *endpos = '\0';
|
|
1042 strcpy (*dest, curpos);
|
|
1043 *endpos = tempchar;
|
|
1044 if (has_colon)
|
|
1045 {
|
|
1046 pos = *dest;
|
|
1047 curpos = *dest;
|
|
1048 while (*pos != '\0')
|
|
1049 {
|
|
1050 if (*pos != '\\' && *(pos + 1) != ':')
|
|
1051 *curpos++ = *pos++;
|
|
1052 else
|
|
1053 pos++;
|
|
1054 }
|
|
1055 *curpos = '\0';
|
|
1056 }
|
|
1057 if (*endpos == '\0')
|
|
1058 break;
|
|
1059 curpos = endpos + 1;
|
|
1060 if (numargs > 1)
|
|
1061 {
|
|
1062 dest = va_arg (argp, char **);
|
|
1063 *dest = NULL;
|
|
1064 }
|
|
1065 numargs--;
|
|
1066 }
|
|
1067
|
|
1068 while (numargs > 1)
|
|
1069 {
|
|
1070 dest = va_arg (argp, char **);
|
|
1071 *dest = g_malloc (1);
|
|
1072 **dest = '\0';
|
|
1073 numargs--;
|
|
1074 }
|
|
1075 va_end (argp);
|
|
1076 return (1);
|
|
1077 }
|
|
1078
|
|
1079
|
|
1080 GHashTable *
|
|
1081 build_bookmarks_hash_table (gftp_bookmarks * entry)
|
|
1082 {
|
|
1083 gftp_bookmarks * tempentry;
|
|
1084 GHashTable * htable;
|
|
1085
|
|
1086 htable = g_hash_table_new (string_hash_function, string_hash_compare);
|
|
1087 tempentry = entry;
|
|
1088 while (tempentry != NULL)
|
|
1089 {
|
|
1090 g_hash_table_insert (htable, tempentry->path, tempentry);
|
|
1091 if (tempentry->children != NULL)
|
|
1092 {
|
|
1093 tempentry = tempentry->children;
|
|
1094 continue;
|
|
1095 }
|
|
1096 while (tempentry->next == NULL && tempentry->prev != NULL)
|
|
1097 tempentry = tempentry->prev;
|
|
1098 tempentry = tempentry->next;
|
|
1099 }
|
|
1100 return (htable);
|
|
1101 }
|
|
1102
|
|
1103
|
|
1104 void
|
|
1105 print_bookmarks (gftp_bookmarks * bookmarks)
|
|
1106 {
|
|
1107 gftp_bookmarks * tempentry;
|
|
1108
|
|
1109 tempentry = bookmarks->children;
|
|
1110 while (tempentry != NULL)
|
|
1111 {
|
|
1112 printf ("Path: %s (%d)\n", tempentry->path, tempentry->children != NULL);
|
|
1113 if (tempentry->children != NULL)
|
|
1114 {
|
|
1115 tempentry = tempentry->children;
|
|
1116 continue;
|
|
1117 }
|
|
1118
|
|
1119 if (tempentry->next == NULL)
|
|
1120 {
|
|
1121 while (tempentry->next == NULL && tempentry->prev != NULL)
|
|
1122 tempentry = tempentry->prev;
|
|
1123 tempentry = tempentry->next;
|
|
1124 }
|
|
1125 else
|
|
1126 tempentry = tempentry->next;
|
|
1127 }
|
|
1128 }
|
|
1129
|