/*
 * access.c
 *
$Author: dm3e $
$Date: 1992/12/01 23:39:07 $
$Revision: 1.1 $
$State: Exp $
$Locker:  $
 */

/***********************************************************
        Copyright 1991 by Carnegie Mellon University

                      All Rights Reserved

Permission to use, copy, modify, and distribute this software and its
documentation for any purpose and without fee is hereby granted,
provided that the above copyright notice appear in all copies and that
both that copyright notice and this permission notice appear in
supporting documentation, and that the name of CMU not be
used in advertising or publicity pertaining to distribution of the
software without specific, written prior permission.

CMU DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
CMU BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
SOFTWARE.
******************************************************************/

#include "emtd.h"

extern struct rx_connection *conn;

/***************************************************************************
 * [exported] emtd_AccessCommand
 *
 * Description:
 *
 * Arguments:
 *
 * Environment:
 *
 * History:
 *      Wed Oct 21 17:04:21 1992 - created by David Allen Markley
 *
 ***************************************************************************/
long emtd_AccessCommand(request, errstr)
struct comreq *request;
char **errstr;

{
    register long       code;
    char                buffer[MAXBUFSIZE], *sys;
    llist_t c_system;
    edb_sys_t c_sys;
    long common_done = 0;
    long lock = ((REQ_FLAGS & LOCK_ACCESS) ? LOCK_VOLUME : 0);

    IF_RTN(emtd_MakeGroups(request, errstr)); 
    IF_RTN(emtd_AddToGroups(request, errstr));
    if (REQ_FLAGS & DO_SOURCE) {
	IF_RTN(emtd_VolumeSetACL(request, request->tree->src_path,
				 SRC_VOL | lock, errstr));
    }
    if (REQ_FLAGS & DO_DESTS) {
	for (c_system = REQ_SYSTEMS; c_system; c_system = c_system->next) {
	    sys = c_system->buffA;
	    if (!strcasecmp (sys, "common")) continue;
	    if (NULL == (c_sys = get_system (request->tree->dest, sys))) {
		emtd_Broadcast(request, EMTD_LOGERR, "Unknown system: %s\n",
			       sys);
		continue;
	    }
	    IF_RTN(emtd_VolumeSetACL(request, c_sys->path, DEST_VOL | lock,
				     errstr));
	    if (! common_done) {
		code = emtd_VolumeSetACL(request, c_sys->path, DEST_VOL |
					 COMMON_VOL | lock, errstr);
		if (code && ENOENT != code) return code;
		common_done = TRUE;
	    }
	}
    }
    if (REQ_FLAGS & DO_OBJECTS) {
	for (c_system = REQ_SYSTEMS; c_system; c_system = c_system->next) {
	    sys = c_system->buffA;
	    if (!strcasecmp (sys, "common")) continue;
	    if (NULL == (c_sys = get_system (request->tree->obj, sys))) {
		emtd_Broadcast(request, EMTD_LOGERR, "Unknown system: %s\n",
			       sys);
		continue;
	    }
	    IF_RTN(emtd_VolumeSetACL(request, c_sys->path, OBJ_VOL | lock,
				     errstr));
	}
    }
    emtd_Broadcast(request, EMTD_LOGBASE, "Access setting complete.\n");
    return OK;
}

/***************************************************************************
 * [exported] emtd_TitleAccess
 *
 * Description:
 *
 * Arguments:
 *
 * Environment:
 *
 * History:
 *      Fri Nov 13 16:44:10 1992 - created by David Allen Markley
 *
 ***************************************************************************/
long emtd_TitleAccess(request, errstr)
struct comreq *request;
char **errstr;
{
    emtd_Broadcast(request, EMTD_LOGBASE, "Setting access for parts of %s.\n",
		   REQ_COLLECTION);
    return OK;
}
