Commit c3965be1 authored by Per Cederqvist's avatar Per Cederqvist

(access_perm_helper): New name for former plain_ol_access_perm. Get

	rid of call to GET_C_STAT by calling cached_get_conf_type
	instead.  Removed the victim_c argument from all calls to
	is_supervisor.
(plain_ol_fast_access_perm): Removed.
(access_perm): Removed the victim_c argument.
(copy_public_confs): Removed the victim_c argument from all calls
	to is_supervisor.  Removed the victim_c argument from all
	calls to access_perm.
(sub_member): Likewise.
(do_get_members): Likewise.
(get_unread_confs): Likewise.
(add_member_common): Likewise, and get rid of a call to GET_C_STAT.
(do_get_membership): Likewise, and get rid of a call to GET_C_STAT.
(set_membership_type): Likewise, and get rid of a call to GET_P_STAT.
parent 8f5323e9
/*
* $Id: membership.c,v 0.52 1999/07/04 13:10:49 ceder Exp $
* $Id: membership.c,v 0.53 1999/07/05 07:00:57 ceder Exp $
* Copyright (C) 1991-1999 Lysator Academic Computer Association.
*
* This file is part of the LysKOM server.
......@@ -38,7 +38,7 @@
#define DEBUG_MARK_AS_READ
static const char *
rcsid = "$Id: membership.c,v 0.52 1999/07/04 13:10:49 ceder Exp $";
rcsid = "$Id: membership.c,v 0.53 1999/07/05 07:00:57 ceder Exp $";
#include "rcs.h"
USE(rcsid);
......@@ -121,10 +121,10 @@ copy_public_confs (Connection * conn, /* The connection for which we copy */
for ( i = 0; i < orig_p->conferences.no_of_confs; i++, orig_m++ )
{
is_super = is_supervisor(orig_m->conf_no, NULL,
is_super = is_supervisor(orig_m->conf_no,
conn->pers_no, conn->person);
if ( access_perm(orig_m->conf_no, NULL, conn, read_protected) > none &&
if ( access_perm(orig_m->conf_no, conn, read_protected) > none &&
(copy_secret ||
!orig_m->type.secret ||
is_super ||
......@@ -716,15 +716,20 @@ do_sub_member(Conf_no conf_no, /* Conf to delete member from. */
* error: see kom_errno
*/
static
Access
plain_ol_\
access_perm(Conf_no victim,
Conference * victim_c, /* May be NULL */
Connection * conn)
static Access
access_perm_helper(Conf_no victim,
Connection *conn)
{
Pers_no viewer;
Person * viewer_p;
Conf_type victim_type;
if (!cached_conf_exists(victim))
{
kom_errno = KOM_UNDEF_CONF;
err_stat = victim;
return error;
}
viewer = conn->pers_no;
viewer_p = conn->person;
......@@ -732,98 +737,39 @@ access_perm(Conf_no victim,
if (victim == viewer)
return unlimited;
if (victim_c == NULL)
GET_C_STAT(victim_c, victim, error);
if (ENA_C(conn, admin, 2))
if (ENA_C(conn, admin, 2) || ENA_C(conn, wheel, 8))
return unlimited;
if (is_supervisor(victim, victim_c, viewer, viewer_p) ||
(ENA_C(conn, wheel, 8)))
if (is_supervisor(victim, viewer, viewer_p))
return unlimited;
if ( viewer != 0 )
{
/* FIXME: viewer_p is never NULL here. Log a warning
if the GET_P_STAT is ever executed. */
if ( viewer_p == NULL )
GET_P_STAT(viewer_p, viewer, error);
/* FIXME: no need to call the expensive locate_membership if
supervisor(victim) == victim. */
if ( locate_membership( victim, viewer_p ) != NULL )
return member;
}
if ( victim_c->type.secret )
victim_type = cached_get_conf_type(victim);
if ( victim_type.secret )
return none;
if ( victim_c->type.rd_prot )
if ( victim_type.rd_prot )
return read_protected;
return limited;
}
/*
* Fast version of access_perm. See comment in file server/manipulate.h
* where Access is defined.
*
* Check if viewer is allowed to look at victiom. viewer_p, if
* supplied, should be a pointer to the pers-stat of viewer.
*/
static
Access
plain_ol_\
fast_access_perm(Conf_no victim,
Connection *viewer_conn)
{
Conf_type conf_type;
Pers_no viewer;
Person * viewer_p;
if (viewer_conn == NULL)
{
assert(0);
kom_errno = KOM_LOGIN;
err_stat = 0;
return error;
}
if (!cached_conf_exists(victim))
{
kom_errno = KOM_UNDEF_CONF;
err_stat = victim;
return error;
}
viewer = viewer_conn->pers_no;
viewer_p = viewer_conn->person;
if (ENA_C(viewer_conn, admin, 2) ||
ENA_C(viewer_conn, wheel, 8) ||
viewer == victim)
{
return unlimited;
}
if ( viewer != 0 )
{
if ( viewer_p == NULL )
GET_P_STAT(viewer_p, viewer, error);
if ( locate_membership( victim, viewer_p ) != NULL )
return member;
}
/* Only read in conference struct when really necessary. */
conf_type = cached_get_conf_type (victim);
if ( conf_type.secret || conf_type.rd_prot )
return plain_ol_access_perm(victim, NULL, viewer_conn);
return limited;
}
Access
access_perm(Conf_no victim,
Conference *victim_c,
Connection *viewer_conn,
Access wanted_access)
{
......@@ -844,13 +790,7 @@ access_perm(Conf_no victim,
}
}
/* FIXME: implement something faster than this! This is just a quick
implementation to check if all edits outside this function are
performed correctly. */
if (wanted_access == unlimited)
result = plain_ol_access_perm(victim, victim_c, viewer_conn);
else
result = plain_ol_fast_access_perm(victim, viewer_conn);
result = access_perm_helper(victim, viewer_conn);
if (wanted_access < result)
return wanted_access;
......@@ -941,8 +881,8 @@ sub_member( Conf_no conf_no,
return FAILURE;
}
if ( !is_supervisor(conf_no, conf_c, ACTPERS, ACT_P) &&
!is_supervisor(pers_no, NULL, ACTPERS, ACT_P) &&
if ( !is_supervisor(conf_no, ACTPERS, ACT_P) &&
!is_supervisor(pers_no, ACTPERS, ACT_P) &&
!ENA(wheel,8) && /* OK -- In an RPC call */
!ENA(admin, 4) ) /* OK -- in an RPC call */
{
......@@ -986,7 +926,7 @@ add_member_common(Conf_no conf_no,
Bool fake_passive
)
{
Conference * conf_c, * pers_c;
Conference * conf_c;
Person * pers_p;
Membership * mship;
......@@ -994,11 +934,10 @@ add_member_common(Conf_no conf_no,
CHK_LOGIN(FAILURE);
GET_C_STAT(conf_c, conf_no, FAILURE);
GET_P_STAT(pers_p, pers_no, FAILURE);
GET_C_STAT(pers_c, pers_no, FAILURE);
/* Force invitation bit if not adding as admin or supervisor */
if (param.invite_by_default &&
!is_supervisor(pers_no, pers_c, ACTPERS, ACT_P) &&
!is_supervisor(pers_no, ACTPERS, ACT_P) &&
!ENA(admin, 2)) /* OK -- Guarded */
{
type->invitation = 1;
......@@ -1014,7 +953,7 @@ add_member_common(Conf_no conf_no,
}
/* Check access to the conference. We need limited access or more */
if (access_perm(conf_no, conf_c, active_connection, limited) < limited
if (access_perm(conf_no, active_connection, limited) < limited
&& !ENA(wheel, 8) ) /* OK -- Guarded */
{
err_stat = conf_no;
......@@ -1029,9 +968,8 @@ add_member_common(Conf_no conf_no,
Bool pers_supervisor;
Bool conf_supervisor;
GET_C_STAT(pers_c, pers_no, FAILURE);
pers_supervisor = is_supervisor(pers_no, pers_c, ACTPERS, ACT_P);
conf_supervisor = is_supervisor(conf_no, conf_c, ACTPERS, ACT_P);
pers_supervisor = is_supervisor(pers_no, ACTPERS, ACT_P);
conf_supervisor = is_supervisor(conf_no, ACTPERS, ACT_P);
/* Already a member, but a secret member? */
if (mship->type.secret &&
......@@ -1334,7 +1272,6 @@ do_get_membership (Pers_no pers_no,
{
Person * p_orig;
Person temp_pers;
Conference * pers_c;
Access acc;
int i;
......@@ -1342,9 +1279,8 @@ do_get_membership (Pers_no pers_no,
CHK_LOGIN (FAILURE);
GET_P_STAT (p_orig, pers_no, FAILURE);
GET_C_STAT (pers_c, pers_no, FAILURE);
acc = access_perm(pers_no, pers_c, active_connection, unlimited);
acc = access_perm(pers_no, active_connection, unlimited);
if (acc == error)
return FAILURE;
......@@ -1476,7 +1412,7 @@ do_get_members (Conf_no conf_no,
CHK_CONNECTION(FAILURE);
GET_C_STAT(conf_c, conf_no, FAILURE);
acc = access_perm(conf_no, conf_c, active_connection, read_protected);
acc = access_perm(conf_no, active_connection, read_protected);
if ( acc == error )
return FAILURE;
......@@ -1505,7 +1441,7 @@ do_get_members (Conf_no conf_no,
src = first;
dst = 0;
is_supervisor_of_conf = is_supervisor(conf_no, conf_c, ACTPERS, ACT_P);
is_supervisor_of_conf = is_supervisor(conf_no, ACTPERS, ACT_P);
while (dst < members->no_of_members)
{
if ((!(conf_c->members).members[src].type.secret ||
......@@ -1513,7 +1449,6 @@ do_get_members (Conf_no conf_no,
ENA(admin,2) ||
ENA(wheel,8) ||
is_supervisor((conf_c->members).members[src].member,
NULL,
ACTPERS,
ACT_P)))
{
......@@ -1592,7 +1527,7 @@ get_unread_confs(Pers_no pers_no,
if ((confs->type.passive == 0) &&
(confs->last_text_read <
cached_get_highest_local_no(confs->conf_no)) &&
(access_perm(confs->conf_no, NULL, active_connection, limited) >
(access_perm(confs->conf_no, active_connection, limited) >
read_protected))
{
result->conf_nos[ result->no_of_confs++ ] = confs->conf_no;
......@@ -1680,7 +1615,7 @@ extern Success set_membership_type(Pers_no pers_no,
Conf_no conf_no,
Membership_type *type)
{
Conference *conf_c, *pers_c;
Conference *conf_c;
Person *pers_p;
Membership *membership;
Member *mbr;
......@@ -1693,7 +1628,7 @@ extern Success set_membership_type(Pers_no pers_no,
/* Find the conference and person in question */
GET_C_STAT(conf_c, conf_no, FAILURE);
/* Make sure that ACTPERS may know about conf */
acc = access_perm(conf_no, conf_c, active_connection, read_protected);
acc = access_perm(conf_no, active_connection, read_protected);
if (acc == error)
{
return FAILURE;
......@@ -1706,10 +1641,9 @@ extern Success set_membership_type(Pers_no pers_no,
return FAILURE;
}
GET_C_STAT(pers_c, pers_no, FAILURE);
GET_P_STAT(pers_p, pers_no, FAILURE);
/* Check that ACTPERS may modify memberships of person */
acc = access_perm(pers_no, pers_c, active_connection, unlimited);
acc = access_perm(pers_no, active_connection, unlimited);
if (acc != unlimited &&
!ENA(wheel, 8) && /* OK -- In an RPC call */
!ENA(admin, 6)) /* OK -- In an RPC call */
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment