mirror of
https://github.com/MidnightCommander/mc
synced 2025-03-30 03:32:53 +03:00
* main.c: Remove extremely unsafe and poorly designed support
for /tmp/mc.$PID.control file. * util.c (my_putenv): Remove, it's unused now.
This commit is contained in:
parent
b9421d6927
commit
0d89dec899
@ -1,5 +1,9 @@
|
|||||||
2002-08-18 Pavel Roskin <proski@gnu.org>
|
2002-08-18 Pavel Roskin <proski@gnu.org>
|
||||||
|
|
||||||
|
* main.c: Remove extremely unsafe and poorly designed support
|
||||||
|
for /tmp/mc.$PID.control file.
|
||||||
|
* util.c (my_putenv): Remove, it's unused now.
|
||||||
|
|
||||||
* panel.h (struct format_e): Make string_fn return const char *.
|
* panel.h (struct format_e): Make string_fn return const char *.
|
||||||
Adjust all dependencies.
|
Adjust all dependencies.
|
||||||
* screen.c (string_file_mtime): Return empty string for "..".
|
* screen.c (string_file_mtime): Return empty string for "..".
|
||||||
|
154
src/main.c
154
src/main.c
@ -445,149 +445,6 @@ update_panels (int force_update, char *current_file)
|
|||||||
mc_chdir (panel->cwd);
|
mc_chdir (panel->cwd);
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef WANT_PARSE
|
|
||||||
static void select_by_index (WPanel *panel, int i);
|
|
||||||
|
|
||||||
/* Called by parse_control_file */
|
|
||||||
static int index_by_name (file_entry *list, int count)
|
|
||||||
{
|
|
||||||
char *name;
|
|
||||||
int i;
|
|
||||||
|
|
||||||
name = strtok (NULL, " \t\n");
|
|
||||||
if (!name || !*name)
|
|
||||||
return -1;
|
|
||||||
for (i = 0; i < count; i++){
|
|
||||||
if (strcmp (name, list[i].fname) == 0)
|
|
||||||
return i;
|
|
||||||
}
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Called by parse_control_file */
|
|
||||||
static void select_by_index (WPanel *panel, int i)
|
|
||||||
{
|
|
||||||
if (i >= panel->count)
|
|
||||||
return;
|
|
||||||
|
|
||||||
unselect_item (panel);
|
|
||||||
panel->selected = i;
|
|
||||||
|
|
||||||
while (panel->selected - panel->top_file >= ITEMS (panel)){
|
|
||||||
/* Scroll window half screen */
|
|
||||||
panel->top_file += ITEMS (panel)/2;
|
|
||||||
paint_dir (panel);
|
|
||||||
select_item (panel);
|
|
||||||
}
|
|
||||||
while (panel->selected < panel->top_file){
|
|
||||||
/* Scroll window half screen */
|
|
||||||
panel->top_file -= ITEMS (panel)/2;
|
|
||||||
if (panel->top_file < 0) panel->top_file = 0;
|
|
||||||
paint_dir (panel);
|
|
||||||
}
|
|
||||||
select_item (panel);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Called by my_system
|
|
||||||
No error reporting, just exits on the first sign of trouble */
|
|
||||||
static void parse_control_file (void)
|
|
||||||
{
|
|
||||||
char *data, *current;
|
|
||||||
WPanel *panel;
|
|
||||||
file_entry *list;
|
|
||||||
int i;
|
|
||||||
FILE *file;
|
|
||||||
struct stat s;
|
|
||||||
|
|
||||||
if ((file = fopen (control_file, "r")) == NULL){
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
/* Use of fstat prevents race conditions */
|
|
||||||
if (fstat (fileno (file), &s) != 0){
|
|
||||||
fclose (file);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
#ifndef OS2_NT
|
|
||||||
/* Security: Check that the user owns the control file and this file
|
|
||||||
is not group/world writable to prevent other users from playing tricks
|
|
||||||
on him/her. */
|
|
||||||
if (s.st_uid != getuid () || ((s.st_mode) & (S_IWGRP|S_IWOTH))) {
|
|
||||||
fclose (file);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
#endif /* !OS2_NT */
|
|
||||||
data = (char *) g_malloc (s.st_size+1);
|
|
||||||
if (!data){
|
|
||||||
fclose (file);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (s.st_size != fread (data, 1, s.st_size, file)){
|
|
||||||
g_free (data);
|
|
||||||
fclose (file);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
data [s.st_size] = 0;
|
|
||||||
fclose (file);
|
|
||||||
|
|
||||||
/* The Control file has now been loaded to memory -> start parsing. */
|
|
||||||
current = strtok (data, " \t\n");
|
|
||||||
while (current && *current){
|
|
||||||
if (isupper (*current)){
|
|
||||||
if (get_other_type () != view_listing)
|
|
||||||
break;
|
|
||||||
else
|
|
||||||
panel = other_panel;
|
|
||||||
} else
|
|
||||||
panel = cpanel;
|
|
||||||
|
|
||||||
list = panel->dir.list;
|
|
||||||
*current = tolower (*current);
|
|
||||||
|
|
||||||
if (strcmp (current, "clear_tags") == 0){
|
|
||||||
unmark_files (panel);
|
|
||||||
} else if (strcmp (current, "tag") == 0){
|
|
||||||
i = index_by_name (list, panel->count);
|
|
||||||
if (i >= 0) {
|
|
||||||
do_file_mark (panel, i, 1);
|
|
||||||
}
|
|
||||||
} else if (strcmp (current, "untag") == 0){
|
|
||||||
i = index_by_name (list, panel->count);
|
|
||||||
if (i >= 0){
|
|
||||||
do_file_mark (panel, i, 0);
|
|
||||||
}
|
|
||||||
} else if (strcmp (current, "select") == 0){
|
|
||||||
i = index_by_name (list, panel->count);
|
|
||||||
if (i >= 0){
|
|
||||||
select_by_index (panel, i);
|
|
||||||
}
|
|
||||||
} else if (strcmp (current, "change_panel") == 0){
|
|
||||||
change_panel ();
|
|
||||||
} else if (strcmp (current, "cd") == 0){
|
|
||||||
int change = 0;
|
|
||||||
current = strtok (NULL, " \t\n");
|
|
||||||
if (!current) break;
|
|
||||||
if (cpanel != panel){
|
|
||||||
change_panel ();
|
|
||||||
change = 1;
|
|
||||||
}
|
|
||||||
do_cd (current, cd_parse_command);
|
|
||||||
if (change)
|
|
||||||
change_panel ();
|
|
||||||
} else {
|
|
||||||
/* Unknown command -> let's give up */
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
current = strtok (NULL, " \t\n");
|
|
||||||
}
|
|
||||||
|
|
||||||
g_free (data);
|
|
||||||
paint_panel (cpanel);
|
|
||||||
paint_panel (opanel);
|
|
||||||
}
|
|
||||||
#else
|
|
||||||
#define parse_control_file()
|
|
||||||
#endif /* WANT_PARSE */
|
|
||||||
|
|
||||||
/* Sets up the terminal before executing a program */
|
/* Sets up the terminal before executing a program */
|
||||||
static void
|
static void
|
||||||
pre_exec (void)
|
pre_exec (void)
|
||||||
@ -662,7 +519,6 @@ do_execute (const char *shell, const char *command, int flags)
|
|||||||
if (console_flag)
|
if (console_flag)
|
||||||
restore_console ();
|
restore_console ();
|
||||||
|
|
||||||
unlink (control_file);
|
|
||||||
if (!use_subshell && !(flags & EXECUTE_INTERNAL && command)) {
|
if (!use_subshell && !(flags & EXECUTE_INTERNAL && command)) {
|
||||||
printf ("%s%s%s\n", last_paused ? "\r\n":"", prompt, command);
|
printf ("%s%s%s\n", last_paused ? "\r\n":"", prompt, command);
|
||||||
last_paused = 0;
|
last_paused = 0;
|
||||||
@ -723,8 +579,6 @@ do_execute (const char *shell, const char *command, int flags)
|
|||||||
|
|
||||||
update_panels (UP_OPTIMIZE, UP_KEEPSEL);
|
update_panels (UP_OPTIMIZE, UP_KEEPSEL);
|
||||||
|
|
||||||
parse_control_file ();
|
|
||||||
unlink (control_file);
|
|
||||||
do_refresh ();
|
do_refresh ();
|
||||||
use_dash (TRUE);
|
use_dash (TRUE);
|
||||||
}
|
}
|
||||||
@ -2083,8 +1937,6 @@ do_nc (void)
|
|||||||
|
|
||||||
#if defined (_OS_NT)
|
#if defined (_OS_NT)
|
||||||
/* Windows NT code */
|
/* Windows NT code */
|
||||||
#define CONTROL_FILE "\\mc.%d.control"
|
|
||||||
char control_file [sizeof (CONTROL_FILE) + 8];
|
|
||||||
|
|
||||||
void
|
void
|
||||||
OS_Setup (void)
|
OS_Setup (void)
|
||||||
@ -2123,9 +1975,6 @@ init_sigfatals (void)
|
|||||||
#else
|
#else
|
||||||
|
|
||||||
/* Unix version */
|
/* Unix version */
|
||||||
#define CONTROL_FILE "/tmp/mc.%d.control"
|
|
||||||
char control_file [sizeof (CONTROL_FILE) + 8];
|
|
||||||
|
|
||||||
static void
|
static void
|
||||||
OS_Setup (void)
|
OS_Setup (void)
|
||||||
{
|
{
|
||||||
@ -2136,9 +1985,6 @@ OS_Setup (void)
|
|||||||
if (!shell || !*shell)
|
if (!shell || !*shell)
|
||||||
shell = "/bin/sh";
|
shell = "/bin/sh";
|
||||||
|
|
||||||
g_snprintf (control_file, sizeof (control_file), CONTROL_FILE, getpid ());
|
|
||||||
my_putenv ("MC_CONTROL_FILE", control_file);
|
|
||||||
|
|
||||||
/* This is the directory, where MC was installed, on Unix this is LIBDIR */
|
/* This is the directory, where MC was installed, on Unix this is LIBDIR */
|
||||||
/* and can be overriden by the MC_LIBDIR environment variable */
|
/* and can be overriden by the MC_LIBDIR environment variable */
|
||||||
if ((mc_libdir = getenv ("MC_LIBDIR")) != NULL) {
|
if ((mc_libdir = getenv ("MC_LIBDIR")) != NULL) {
|
||||||
|
@ -131,7 +131,6 @@ void outrefresh_screen (void);
|
|||||||
void suspend_cmd (void);
|
void suspend_cmd (void);
|
||||||
void do_update_prompt (void);
|
void do_update_prompt (void);
|
||||||
|
|
||||||
extern char control_file [];
|
|
||||||
extern char *shell;
|
extern char *shell;
|
||||||
|
|
||||||
/* directory specified on command line for startup */
|
/* directory specified on command line for startup */
|
||||||
|
13
src/util.c
13
src/util.c
@ -727,19 +727,6 @@ char *x_basename (char *s)
|
|||||||
return ((where = strrchr (s, PATH_SEP))) ? where + 1 : s;
|
return ((where = strrchr (s, PATH_SEP))) ? where + 1 : s;
|
||||||
}
|
}
|
||||||
|
|
||||||
void my_putenv (char *name, char *data)
|
|
||||||
{
|
|
||||||
char *full;
|
|
||||||
|
|
||||||
full = malloc (strlen (name) + strlen (data) + 2);
|
|
||||||
strcpy (full, name);
|
|
||||||
strcat (full, "=");
|
|
||||||
strcat (full, data);
|
|
||||||
putenv (full);
|
|
||||||
|
|
||||||
/* WARNING: NEVER FREE THE full VARIABLE!!!!!!!!!!!!!!!!!!!!!!!! */
|
|
||||||
/* It is used by putenv. Freeing it will corrupt the environment */
|
|
||||||
}
|
|
||||||
#endif /* !VFS_STANDALONE */
|
#endif /* !VFS_STANDALONE */
|
||||||
|
|
||||||
char *unix_error_string (int error_num)
|
char *unix_error_string (int error_num)
|
||||||
|
@ -74,7 +74,6 @@ void check_error_pipe (void);
|
|||||||
int close_error_pipe (int error, char *text);
|
int close_error_pipe (int error, char *text);
|
||||||
|
|
||||||
/* Process spawning */
|
/* Process spawning */
|
||||||
void my_putenv (char*, char*);
|
|
||||||
#define EXECUTE_INTERNAL 1
|
#define EXECUTE_INTERNAL 1
|
||||||
#define EXECUTE_TEMPFILE 2
|
#define EXECUTE_TEMPFILE 2
|
||||||
#define EXECUTE_AS_SHELL 4
|
#define EXECUTE_AS_SHELL 4
|
||||||
|
Loading…
x
Reference in New Issue
Block a user