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