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