mirror of
https://github.com/MidnightCommander/mc
synced 2025-01-22 03:02:06 +03:00
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.
This commit is contained in:
parent
f2547b3cbd
commit
043e782496
@ -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>
|
||||
|
||||
* cmd.c (dirsizes_cmd): Don't cast st_size to long - use off_t
|
||||
|
@ -3177,8 +3177,8 @@ main (int argc, char *argv [])
|
||||
/* Virtual File System shutdown */
|
||||
vfs_shut ();
|
||||
|
||||
/* Delete list of all user groups*/
|
||||
delete_groups ();
|
||||
/* Delete list of all user groups */
|
||||
destroy_groups ();
|
||||
|
||||
flush_extension_file (); /* does only free memory */
|
||||
|
||||
|
@ -72,10 +72,6 @@ int permission_mode = 0;
|
||||
/* If 1 - then add per file type hilighting */
|
||||
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 */
|
||||
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;
|
||||
|
||||
l = get_user_rights (&fe->buf);
|
||||
l = get_user_permissions (&fe->buf);
|
||||
|
||||
if (is_octal){
|
||||
/* 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);
|
||||
old_char = format [pos];
|
||||
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;
|
||||
return 0;
|
||||
}
|
||||
|
@ -63,14 +63,9 @@ char *load_mc_home_file (const char *filename, char ** allocated_filename);
|
||||
#endif
|
||||
|
||||
/* uid/gid managing */
|
||||
typedef struct user_in_groups{
|
||||
struct user_in_groups *next;
|
||||
int gid;
|
||||
} user_in_groups;
|
||||
|
||||
void init_groups (void);
|
||||
void delete_groups (void);
|
||||
int get_user_rights (struct stat *buf);
|
||||
void destroy_groups (void);
|
||||
int get_user_permissions (struct stat *buf);
|
||||
|
||||
void init_uid_gid_cache (void);
|
||||
char *get_group (int);
|
||||
|
100
src/utilunix.c
100
src/utilunix.c
@ -70,9 +70,6 @@
|
||||
|
||||
struct sigaction startup_handler;
|
||||
|
||||
uid_t current_user_uid;
|
||||
user_in_groups *current_user_gid;
|
||||
|
||||
int
|
||||
max_open_files (void)
|
||||
{
|
||||
@ -94,63 +91,92 @@ max_open_files (void)
|
||||
}
|
||||
|
||||
#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)
|
||||
{
|
||||
int i;
|
||||
struct passwd *pwd;
|
||||
struct group *grp;
|
||||
user_in_groups *cug, *pug;
|
||||
|
||||
current_user_uid = getuid ();
|
||||
|
||||
pwd = getpwuid (current_user_uid=getuid ());
|
||||
pwd = getpwuid (current_user_uid);
|
||||
|
||||
g_return_if_fail (pwd != NULL);
|
||||
|
||||
grp = getgrgid (pwd->pw_gid);
|
||||
|
||||
g_return_if_fail (grp != NULL);
|
||||
|
||||
current_user_gid = g_tree_new (mc_gid_compare);
|
||||
|
||||
current_user_gid = (pug = g_new (user_in_groups, 1));
|
||||
current_user_gid->gid = getgid ();
|
||||
current_user_gid->next = NULL;
|
||||
|
||||
if (pwd == NULL)
|
||||
return;
|
||||
g_tree_insert (current_user_gid,
|
||||
GUINT_TO_POINTER(grp->gr_gid), g_strdup(grp->gr_name));
|
||||
|
||||
setgrent ();
|
||||
|
||||
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);
|
||||
cug->gid = grp->gr_gid;
|
||||
pug->next = cug;
|
||||
cug->next = NULL;
|
||||
pug = cug;
|
||||
break;
|
||||
}
|
||||
{
|
||||
for (i = 0; grp->gr_mem[i]; i++)
|
||||
{
|
||||
if (!strcmp (pwd->pw_name, grp->gr_mem[i]) &&
|
||||
!g_tree_lookup (current_user_gid, GUINT_TO_POINTER(grp->gr_gid)))
|
||||
{
|
||||
g_tree_insert (current_user_gid,
|
||||
GUINT_TO_POINTER(grp->gr_gid), g_strdup(grp->gr_name));
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
endgrent ();
|
||||
}
|
||||
|
||||
/* Return the index of permission triplet */
|
||||
/* Return the index of the permissions triplet */
|
||||
int
|
||||
get_user_rights (struct stat *buf)
|
||||
{
|
||||
user_in_groups *cug;
|
||||
get_user_permissions (struct stat *buf) {
|
||||
|
||||
if (buf->st_uid == current_user_uid || current_user_uid == 0)
|
||||
return 0;
|
||||
|
||||
for (cug = current_user_gid; cug; cug = cug->next)
|
||||
if (cug->gid == buf->st_gid) return 1;
|
||||
|
||||
if(current_user_gid && g_tree_lookup (current_user_gid, GUINT_TO_POINTER(buf->st_gid)))
|
||||
return 1;
|
||||
|
||||
return 2;
|
||||
}
|
||||
|
||||
|
||||
/* Completely destroys the gids tree */
|
||||
void
|
||||
delete_groups (void)
|
||||
destroy_groups (void)
|
||||
{
|
||||
user_in_groups *pug, *cug = current_user_gid;
|
||||
|
||||
while (cug){
|
||||
pug = cug->next;
|
||||
g_free (cug);
|
||||
cug = pug;
|
||||
}
|
||||
g_tree_traverse (current_user_gid, mc_gid_destroy, G_POST_ORDER, NULL);
|
||||
g_tree_destroy (current_user_gid);
|
||||
}
|
||||
|
||||
#define UID_CACHE_SIZE 200
|
||||
|
Loading…
Reference in New Issue
Block a user