1
1

2001-08-31 23:14:21 Timur Bakeyev <mc@bat.ru>

* utilunix.c: init_groups(), destroy_groups(), get_user_permissions()
	rewritten to use GTree structure and functions. Add new static helper
	functions mc_gid_compare() and mc_gid_destroy().

	* util.h: Removed deprecated structure user_in_groups.

	* screen.c: Fixed typo in format report error string.

2001-08-31 23:14:21  Timur Bakeyev <mc@bat.ru>

	* utilunix.c: get_user_rights() renamed into get_user_permissions().
	delete_groups() renamed into destroy_groups().
	* util.h: Likewise.
	* screen.c: Likewise.
	* main.c: Likewise.
Этот коммит содержится в:
Timur Bakeyev 2001-09-01 13:47:34 +00:00
родитель f2547b3cbd
Коммит 043e782496
5 изменённых файлов: 87 добавлений и 52 удалений

Просмотреть файл

@ -1,3 +1,21 @@
2001-08-31 23:14:21 Timur Bakeyev <mc@bat.ru>
* utilunix.c: init_groups(), destroy_groups(), get_user_permissions()
rewritten to use GTree structure and functions. Add new static helper
functions mc_gid_compare() and mc_gid_destroy().
* util.h: Removed deprecated structure user_in_groups.
* screen.c: Fixed typo in format report error string.
2001-08-31 23:14:21 Timur Bakeyev <mc@bat.ru>
* utilunix.c: get_user_rights() renamed into get_user_permissions().
delete_groups() renamed into destroy_groups().
* util.h: Likewise.
* screen.c: Likewise.
* main.c: Likewise.
2001-08-27 Pavel Roskin <proski@gnu.org> 2001-08-27 Pavel Roskin <proski@gnu.org>
* cmd.c (dirsizes_cmd): Don't cast st_size to long - use off_t * cmd.c (dirsizes_cmd): Don't cast st_size to long - use off_t

Просмотреть файл

@ -3178,7 +3178,7 @@ main (int argc, char *argv [])
vfs_shut (); vfs_shut ();
/* Delete list of all user groups */ /* Delete list of all user groups */
delete_groups (); destroy_groups ();
flush_extension_file (); /* does only free memory */ flush_extension_file (); /* does only free memory */

Просмотреть файл

@ -72,10 +72,6 @@ int permission_mode = 0;
/* If 1 - then add per file type hilighting */ /* If 1 - then add per file type hilighting */
int filetype_mode = 1; int filetype_mode = 1;
/* This gives abilitiy to determine colored user priveleges */
extern user_in_groups *current_user_gid;
extern uid_t current_user_uid;
/* If we have an info panel, this points to it */ /* If we have an info panel, this points to it */
WPanel *the_info_panel = 0; WPanel *the_info_panel = 0;
@ -158,7 +154,7 @@ add_permission_string (char *dest, int width, file_entry *fe, int attr, int colo
{ {
int i, r, l; int i, r, l;
l = get_user_rights (&fe->buf); l = get_user_permissions (&fe->buf);
if (is_octal){ if (is_octal){
/* Place of the access bit in octal mode */ /* Place of the access bit in octal mode */
@ -1307,7 +1303,7 @@ parse_display_format (WPanel *panel, char *format, char **error, int isstatus, i
delete_format (home); delete_format (home);
old_char = format [pos]; old_char = format [pos];
format [pos] = 0; format [pos] = 0;
*error = g_strconcat (_("Unknow tag on display format: "), format, NULL); *error = g_strconcat (_("Unknown tag on display format: "), format, NULL);
format [pos] = old_char; format [pos] = old_char;
return 0; return 0;
} }

Просмотреть файл

@ -63,14 +63,9 @@ char *load_mc_home_file (const char *filename, char ** allocated_filename);
#endif #endif
/* uid/gid managing */ /* uid/gid managing */
typedef struct user_in_groups{
struct user_in_groups *next;
int gid;
} user_in_groups;
void init_groups (void); void init_groups (void);
void delete_groups (void); void destroy_groups (void);
int get_user_rights (struct stat *buf); int get_user_permissions (struct stat *buf);
void init_uid_gid_cache (void); void init_uid_gid_cache (void);
char *get_group (int); char *get_group (int);

Просмотреть файл

@ -70,9 +70,6 @@
struct sigaction startup_handler; struct sigaction startup_handler;
uid_t current_user_uid;
user_in_groups *current_user_gid;
int int
max_open_files (void) max_open_files (void)
{ {
@ -94,63 +91,92 @@ max_open_files (void)
} }
#ifndef VFS_STANDALONE #ifndef VFS_STANDALONE
/* uid of the MC user */
uid_t current_user_uid = -1;
/* List of the gids of the user */
GTree *current_user_gid = NULL;
/* Helper function to compare 2 gids */
static gint
mc_gid_compare (gconstpointer v, gconstpointer v2)
{
return ((GPOINTER_TO_UINT(v) > GPOINTER_TO_UINT(v2)) ? 1 :
(GPOINTER_TO_UINT(v) < GPOINTER_TO_UINT(v2)) ? -1 : 0);
}
/* Helper function to delete keys of the gids tree */
static gint
mc_gid_destroy (gpointer key, gpointer value, gpointer data)
{
g_free (value);
return FALSE;
}
/* This function initialize global GTree with the gids of groups,
to which user belongs. Tree also store corresponding string
with the name of the group.
FIXME: Do we need this names at all? If not, we can simplify
initialization by eliminating g_strdup's.
*/
void init_groups (void) void init_groups (void)
{ {
int i; int i;
struct passwd *pwd; struct passwd *pwd;
struct group *grp; struct group *grp;
user_in_groups *cug, *pug;
pwd = getpwuid (current_user_uid=getuid ()); current_user_uid = getuid ();
current_user_gid = (pug = g_new (user_in_groups, 1)); pwd = getpwuid (current_user_uid);
current_user_gid->gid = getgid ();
current_user_gid->next = NULL;
if (pwd == NULL) g_return_if_fail (pwd != NULL);
return;
grp = getgrgid (pwd->pw_gid);
g_return_if_fail (grp != NULL);
current_user_gid = g_tree_new (mc_gid_compare);
g_tree_insert (current_user_gid,
GUINT_TO_POINTER(grp->gr_gid), g_strdup(grp->gr_name));
setgrent (); setgrent ();
while ((grp = getgrent ())) while ((grp = getgrent ()))
for (i = 0; grp->gr_mem[i]; i++)
if (!strcmp (pwd->pw_name,grp->gr_mem[i]))
{ {
cug = g_new (user_in_groups, 1); for (i = 0; grp->gr_mem[i]; i++)
cug->gid = grp->gr_gid; {
pug->next = cug; if (!strcmp (pwd->pw_name, grp->gr_mem[i]) &&
cug->next = NULL; !g_tree_lookup (current_user_gid, GUINT_TO_POINTER(grp->gr_gid)))
pug = cug; {
g_tree_insert (current_user_gid,
GUINT_TO_POINTER(grp->gr_gid), g_strdup(grp->gr_name));
break; break;
} }
}
}
endgrent (); endgrent ();
} }
/* Return the index of permission triplet */ /* Return the index of the permissions triplet */
int int
get_user_rights (struct stat *buf) get_user_permissions (struct stat *buf) {
{
user_in_groups *cug;
if (buf->st_uid == current_user_uid || current_user_uid == 0) if (buf->st_uid == current_user_uid || current_user_uid == 0)
return 0; return 0;
for (cug = current_user_gid; cug; cug = cug->next) if(current_user_gid && g_tree_lookup (current_user_gid, GUINT_TO_POINTER(buf->st_gid)))
if (cug->gid == buf->st_gid) return 1; return 1;
return 2; return 2;
} }
/* Completely destroys the gids tree */
void void
delete_groups (void) destroy_groups (void)
{ {
user_in_groups *pug, *cug = current_user_gid; g_tree_traverse (current_user_gid, mc_gid_destroy, G_POST_ORDER, NULL);
g_tree_destroy (current_user_gid);
while (cug){
pug = cug->next;
g_free (cug);
cug = pug;
}
} }
#define UID_CACHE_SIZE 200 #define UID_CACHE_SIZE 200