direct-io.hg

changeset 5945:361d31028129

merge?
author cl349@firebug.cl.cam.ac.uk
date Tue Aug 02 17:13:11 2005 +0000 (2005-08-02)
parents 76794dad0aaf dcdcec634c2d
children f9a8f24dac67
files .hgignore linux-2.6-xen-sparse/arch/xen/i386/mm/fault.c linux-2.6-xen-sparse/arch/xen/kernel/reboot.c linux-2.6-xen-sparse/drivers/xen/balloon/balloon.c linux-2.6-xen-sparse/drivers/xen/xenbus/xenbus_comms.c linux-2.6-xen-sparse/drivers/xen/xenbus/xenbus_comms.h linux-2.6-xen-sparse/drivers/xen/xenbus/xenbus_probe.c linux-2.6-xen-sparse/include/asm-xen/xenbus.h linux-2.6-xen-sparse/kernel/irq/manage.c tools/Makefile tools/Rules.mk tools/consoled/Makefile tools/consoled/io.c tools/consoled/io.h tools/consoled/main.c tools/consoled/utils.c tools/consoled/utils.h tools/consoled/xc_console.c tools/libxc/xc.h tools/libxc/xc_ia64_stubs.c tools/libxc/xc_linux_restore.c tools/libxc/xc_linux_save.c tools/misc/policyprocessor/Makefile tools/misc/policyprocessor/XmlToBin.java tools/misc/policyprocessor/XmlToBinInterface.java tools/misc/policyprocessor/c2j_include.c tools/misc/policyprocessor/xen_sample_def.xml tools/pygrub/setup.py tools/pygrub/src/fsys/ext2/__init__.py tools/pygrub/src/fsys/ext2/ext2module.c tools/pygrub/src/pygrub tools/python/xen/util/blkif.py tools/python/xen/xend/XendCheckpoint.py tools/python/xen/xend/XendDomainInfo.py tools/security/Makefile tools/security/secpol_tool.c tools/xcutils/xc_restore.c xen/acm/acm_chinesewall_hooks.c xen/acm/acm_core.c xen/acm/acm_policy.c xen/acm/acm_simple_type_enforcement_hooks.c xen/arch/x86/shadow_public.c xen/arch/x86/x86_32/entry.S xen/arch/x86/x86_64/entry.S xen/common/acm_ops.c xen/include/acm/acm_core.h xen/include/public/acm.h xen/include/public/acm_ops.h xen/include/public/xen.h
line diff
     1.1 --- a/.hgignore	Tue Aug 02 17:12:36 2005 +0000
     1.2 +++ b/.hgignore	Tue Aug 02 17:13:11 2005 +0000
     1.3 @@ -86,6 +86,8 @@
     1.4  ^tools/check/\..*$
     1.5  ^tools/cmdline/.*$
     1.6  ^tools/cmdline/xen/.*$
     1.7 +^tools/consoled/consoled$
     1.8 +^tools/consoled/xc_console$
     1.9  ^tools/debugger/pdb/pdb$
    1.10  ^tools/debugger/pdb/linux-[0-9.]*-module/.*\.ko$
    1.11  ^tools/debugger/pdb/linux-[0-9.]*-module/.*\.mod.c$
    1.12 @@ -128,8 +130,8 @@
    1.13  ^tools/misc/xc_shadow$
    1.14  ^tools/misc/xen_cpuperf$
    1.15  ^tools/misc/xenperf$
    1.16 -^tools/policy/policy_tool$
    1.17 -^tools/policy/xen/.*$
    1.18 +^tools/security/secpol_tool$
    1.19 +^tools/security/xen/.*$
    1.20  ^tools/pygrub/build/.*$
    1.21  ^tools/python/build/.*$
    1.22  ^tools/tests/test_x86_emulator$
     2.1 --- a/linux-2.6-xen-sparse/arch/xen/i386/mm/fault.c	Tue Aug 02 17:12:36 2005 +0000
     2.2 +++ b/linux-2.6-xen-sparse/arch/xen/i386/mm/fault.c	Tue Aug 02 17:13:11 2005 +0000
     2.3 @@ -204,6 +204,63 @@ static inline int is_prefetch(struct pt_
     2.4  
     2.5  fastcall void do_invalid_op(struct pt_regs *, unsigned long);
     2.6  
     2.7 +#ifdef CONFIG_X86_PAE
     2.8 +static void dump_fault_path(unsigned long address)
     2.9 +{
    2.10 +	unsigned long *p, page;
    2.11 +
    2.12 +        page = __pa(per_cpu(cur_pgd, smp_processor_id()));
    2.13 +	p  = (unsigned long *)__va(page);
    2.14 +	p += (address >> 30) * 2;
    2.15 +	printk(KERN_ALERT "%08lx -> *pde = %08lx:%08lx\n", page, p[1], p[0]);
    2.16 +	if (p[0] & 1) {
    2.17 +		page = p[0] & PAGE_MASK;
    2.18 +		address &= 0x3fffffff;
    2.19 +		page = machine_to_phys(page);
    2.20 +		p  = (unsigned long *)__va(page);
    2.21 +		p += (address >> 21) * 2;
    2.22 +		printk(KERN_ALERT "%08lx -> *pme = %08lx:%08lx\n", page, p[1], p[0]);
    2.23 +#ifndef CONFIG_HIGHPTE
    2.24 +		if (p[0] & 1) {
    2.25 +			page = p[0] & PAGE_MASK;
    2.26 +			address &= 0x001fffff;
    2.27 +			page = machine_to_phys(page);
    2.28 +			p  = (unsigned long *) __va(page);
    2.29 +			p += (address >> 12) * 2;
    2.30 +			printk(KERN_ALERT "%08lx -> *pte = %08lx:%08lx\n", page, p[1], p[0]);
    2.31 +		}
    2.32 +#endif
    2.33 +	}
    2.34 +}
    2.35 +#else
    2.36 +static void dump_fault_path(unsigned long address)
    2.37 +{
    2.38 +	unsigned long page;
    2.39 +
    2.40 +	page = ((unsigned long *) per_cpu(cur_pgd, smp_processor_id()))
    2.41 +	    [address >> 22];
    2.42 +	printk(KERN_ALERT "*pde = ma %08lx pa %08lx\n", page,
    2.43 +	       machine_to_phys(page));
    2.44 +	/*
    2.45 +	 * We must not directly access the pte in the highpte
    2.46 +	 * case, the page table might be allocated in highmem.
    2.47 +	 * And lets rather not kmap-atomic the pte, just in case
    2.48 +	 * it's allocated already.
    2.49 +	 */
    2.50 +#ifndef CONFIG_HIGHPTE
    2.51 +	if (page & 1) {
    2.52 +		page &= PAGE_MASK;
    2.53 +		address &= 0x003ff000;
    2.54 +		page = machine_to_phys(page);
    2.55 +		page = ((unsigned long *) __va(page))[address >> PAGE_SHIFT];
    2.56 +		printk(KERN_ALERT "*pte = ma %08lx pa %08lx\n", page,
    2.57 +		       machine_to_phys(page));
    2.58 +	}
    2.59 +#endif
    2.60 +}
    2.61 +#endif
    2.62 +
    2.63 +
    2.64  /*
    2.65   * This routine handles page faults.  It determines the address,
    2.66   * and the problem, and then passes it off to one of the appropriate
    2.67 @@ -220,7 +277,6 @@ fastcall void do_page_fault(struct pt_re
    2.68  	struct task_struct *tsk;
    2.69  	struct mm_struct *mm;
    2.70  	struct vm_area_struct * vma;
    2.71 -	unsigned long page;
    2.72  	int write;
    2.73  	siginfo_t info;
    2.74  
    2.75 @@ -454,26 +510,7 @@ no_context:
    2.76  	printk(" at virtual address %08lx\n",address);
    2.77  	printk(KERN_ALERT " printing eip:\n");
    2.78  	printk("%08lx\n", regs->eip);
    2.79 -	page = ((unsigned long *) per_cpu(cur_pgd, smp_processor_id()))
    2.80 -	    [address >> 22];
    2.81 -	printk(KERN_ALERT "*pde = ma %08lx pa %08lx\n", page,
    2.82 -	       machine_to_phys(page));
    2.83 -	/*
    2.84 -	 * We must not directly access the pte in the highpte
    2.85 -	 * case, the page table might be allocated in highmem.
    2.86 -	 * And lets rather not kmap-atomic the pte, just in case
    2.87 -	 * it's allocated already.
    2.88 -	 */
    2.89 -#ifndef CONFIG_HIGHPTE
    2.90 -	if (page & 1) {
    2.91 -		page &= PAGE_MASK;
    2.92 -		address &= 0x003ff000;
    2.93 -		page = machine_to_phys(page);
    2.94 -		page = ((unsigned long *) __va(page))[address >> PAGE_SHIFT];
    2.95 -		printk(KERN_ALERT "*pte = ma %08lx pa %08lx\n", page,
    2.96 -		       machine_to_phys(page));
    2.97 -	}
    2.98 -#endif
    2.99 +	dump_fault_path(address);
   2.100  	die("Oops", regs, error_code);
   2.101  	bust_spinlocks(0);
   2.102  	do_exit(SIGKILL);
     4.1 --- a/linux-2.6-xen-sparse/drivers/xen/balloon/balloon.c	Tue Aug 02 17:12:36 2005 +0000
     4.2 +++ b/linux-2.6-xen-sparse/drivers/xen/balloon/balloon.c	Tue Aug 02 17:13:11 2005 +0000
     4.3 @@ -5,6 +5,7 @@
     4.4   *
     4.5   * Copyright (c) 2003, B Dragovic
     4.6   * Copyright (c) 2003-2004, M Williamson, K Fraser
     4.7 + * Copyright (c) 2005 Dan M. Smith, IBM Corporation
     4.8   * 
     4.9   * This file may be distributed separately from the Linux kernel, or
    4.10   * incorporated into other software packages, subject to the following license:
    4.11 @@ -42,7 +43,6 @@
    4.12  #include <linux/vmalloc.h>
    4.13  #include <asm-xen/xen_proc.h>
    4.14  #include <asm-xen/hypervisor.h>
    4.15 -#include <asm-xen/ctrl_if.h>
    4.16  #include <asm-xen/balloon.h>
    4.17  #include <asm/pgalloc.h>
    4.18  #include <asm/pgtable.h>
    4.19 @@ -50,6 +50,10 @@
    4.20  #include <asm/tlb.h>
    4.21  #include <linux/list.h>
    4.22  
    4.23 +#include<asm-xen/xenbus.h>
    4.24 +
    4.25 +#define PAGES2KB(_p) ((_p)<<(PAGE_SHIFT-10))
    4.26 +
    4.27  static struct proc_dir_entry *balloon_pde;
    4.28  
    4.29  static DECLARE_MUTEX(balloon_mutex);
    4.30 @@ -77,11 +81,17 @@ static void balloon_process(void *unused
    4.31  static DECLARE_WORK(balloon_worker, balloon_process, NULL);
    4.32  static struct timer_list balloon_timer;
    4.33  
    4.34 +/* Flag for dom0 xenstore workaround */
    4.35 +static int balloon_xenbus_init=0;
    4.36 +
    4.37 +/* Init Function */
    4.38 +void balloon_init_watcher(void);
    4.39 +
    4.40  #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
    4.41  /* Use the private and mapping fields of struct page as a list. */
    4.42  #define PAGE_TO_LIST(p) ( (struct list_head *)&p->private )
    4.43  #define LIST_TO_PAGE(l) ( list_entry( ((unsigned long *)l),   \
    4.44 -				      struct page, private ) )
    4.45 +                                      struct page, private ) )
    4.46  #define UNLIST_PAGE(p)  do { list_del(PAGE_TO_LIST(p));       \
    4.47                               p->mapping = NULL;               \
    4.48                               p->private = 0; } while(0)
    4.49 @@ -297,26 +307,97 @@ static void set_new_target(unsigned long
    4.50      schedule_work(&balloon_worker);
    4.51  }
    4.52  
    4.53 -static void balloon_ctrlif_rx(ctrl_msg_t *msg, unsigned long id)
    4.54 +static struct xenbus_watch xb_watch =
    4.55 +{
    4.56 +    .node = "memory"
    4.57 +};
    4.58 +
    4.59 +/* FIXME: This is part of a dom0 sequencing workaround */
    4.60 +static struct xenbus_watch root_watch =
    4.61  {
    4.62 -    switch ( msg->subtype )
    4.63 -    {
    4.64 -    case CMSG_MEM_REQUEST_SET:
    4.65 +    .node = "/"
    4.66 +};
    4.67 +
    4.68 +/* React to a change in the target key */
    4.69 +static void watch_target(struct xenbus_watch *watch, const char *node)
    4.70 +{
    4.71 +    unsigned long new_target;
    4.72 +    int err;
    4.73 +
    4.74 +    if(watch == &root_watch)
    4.75      {
    4.76 -        mem_request_t *req = (mem_request_t *)&msg->msg[0];
    4.77 -        set_new_target(req->target);
    4.78 -        req->status = 0;
    4.79 -    }
    4.80 -    break;        
    4.81 -
    4.82 -    default:
    4.83 -        msg->length = 0;
    4.84 -        break;
    4.85 +        /* FIXME: This is part of a dom0 sequencing workaround */
    4.86 +        if(register_xenbus_watch(&xb_watch) == 0)
    4.87 +        {
    4.88 +            /* 
    4.89 +               We successfully set a watch on memory/target:
    4.90 +               now we can stop watching root 
    4.91 +            */
    4.92 +            unregister_xenbus_watch(&root_watch);
    4.93 +            balloon_xenbus_init=1;
    4.94 +        } 
    4.95 +        else 
    4.96 +        {
    4.97 +            return;
    4.98 +        }
    4.99      }
   4.100  
   4.101 -    ctrl_if_send_response(msg);
   4.102 +    err = xenbus_scanf("memory", "target", "%lu", &new_target);
   4.103 +        
   4.104 +    if(err != 1) 
   4.105 +    {
   4.106 +        IPRINTK("Unable to read memory/target\n");
   4.107 +        return;
   4.108 +    } 
   4.109 +        
   4.110 +    set_new_target(new_target >> PAGE_SHIFT);
   4.111 +    
   4.112  }
   4.113  
   4.114 +/* 
   4.115 +   Try to set up our watcher, if not already set
   4.116 +   
   4.117 +*/
   4.118 +void balloon_init_watcher(void) 
   4.119 +{
   4.120 +    int err;
   4.121 +
   4.122 +    if(!xen_start_info.store_evtchn)
   4.123 +    {
   4.124 +        IPRINTK("Delaying watcher init until xenstore is available\n");
   4.125 +        return;
   4.126 +    }
   4.127 +
   4.128 +    down(&xenbus_lock);
   4.129 +
   4.130 +    if(! balloon_xenbus_init) 
   4.131 +    {
   4.132 +        err = register_xenbus_watch(&xb_watch);
   4.133 +        if(err) 
   4.134 +        {
   4.135 +            /* BIG FAT FIXME: dom0 sequencing workaround
   4.136 +             * dom0 can't set a watch on memory/target until
   4.137 +             * after the tools create it.  So, we have to watch
   4.138 +             * the whole store until that happens.
   4.139 +             *
   4.140 +             * This will go away when we have the ability to watch
   4.141 +             * non-existant keys
   4.142 +             */
   4.143 +            register_xenbus_watch(&root_watch);
   4.144 +        } 
   4.145 +        else
   4.146 +        {
   4.147 +            IPRINTK("Balloon xenbus watcher initialized\n");
   4.148 +            balloon_xenbus_init = 1;
   4.149 +        }
   4.150 +    }
   4.151 +
   4.152 +    up(&xenbus_lock);
   4.153 +
   4.154 +}
   4.155 +
   4.156 +EXPORT_SYMBOL(balloon_init_watcher);
   4.157 +
   4.158  static int balloon_write(struct file *file, const char __user *buffer,
   4.159                           unsigned long count, void *data)
   4.160  {
   4.161 @@ -346,7 +427,6 @@ static int balloon_read(char *page, char
   4.162  {
   4.163      int len;
   4.164  
   4.165 -#define K(_p) ((_p)<<(PAGE_SHIFT-10))
   4.166      len = sprintf(
   4.167          page,
   4.168          "Current allocation: %8lu kB\n"
   4.169 @@ -354,13 +434,14 @@ static int balloon_read(char *page, char
   4.170          "Low-mem balloon:    %8lu kB\n"
   4.171          "High-mem balloon:   %8lu kB\n"
   4.172          "Xen hard limit:     ",
   4.173 -        K(current_pages), K(target_pages), K(balloon_low), K(balloon_high));
   4.174 +        PAGES2KB(current_pages), PAGES2KB(target_pages), 
   4.175 +        PAGES2KB(balloon_low), PAGES2KB(balloon_high));
   4.176  
   4.177      if ( hard_limit != ~0UL )
   4.178          len += sprintf(
   4.179              page + len, 
   4.180              "%8lu kB (inc. %8lu kB driver headroom)\n",
   4.181 -            K(hard_limit), K(driver_pages));
   4.182 +            PAGES2KB(hard_limit), PAGES2KB(driver_pages));
   4.183      else
   4.184          len += sprintf(
   4.185              page + len,
   4.186 @@ -396,9 +477,7 @@ static int __init balloon_init(void)
   4.187  
   4.188      balloon_pde->read_proc  = balloon_read;
   4.189      balloon_pde->write_proc = balloon_write;
   4.190 -
   4.191 -    (void)ctrl_if_register_receiver(CMSG_MEM_REQUEST, balloon_ctrlif_rx, 0);
   4.192 -
   4.193 +    
   4.194      /* Initialise the balloon with excess memory space. */
   4.195      for ( pfn = xen_start_info.nr_pages; pfn < max_pfn; pfn++ )
   4.196      {
   4.197 @@ -407,6 +486,11 @@ static int __init balloon_init(void)
   4.198              balloon_append(page);
   4.199      }
   4.200  
   4.201 +    xb_watch.callback = watch_target;
   4.202 +    root_watch.callback = watch_target;
   4.203 +
   4.204 +    balloon_init_watcher();
   4.205 +
   4.206      return 0;
   4.207  }
   4.208  
     7.1 --- a/linux-2.6-xen-sparse/drivers/xen/xenbus/xenbus_probe.c	Tue Aug 02 17:12:36 2005 +0000
     7.2 +++ b/linux-2.6-xen-sparse/drivers/xen/xenbus/xenbus_probe.c	Tue Aug 02 17:13:11 2005 +0000
     7.3 @@ -322,6 +322,9 @@ int do_xenbus_probe(void *unused)
     7.4  		return err;
     7.5  	}
     7.6  
     7.7 +	/* Initialize non-xenbus drivers */
     7.8 +	balloon_init_watcher();
     7.9 +
    7.10  	down(&xenbus_lock);
    7.11  	/* Enumerate devices in xenstore. */
    7.12  	xenbus_probe_devices("device");
    10.1 --- a/tools/Makefile	Tue Aug 02 17:12:36 2005 +0000
    10.2 +++ b/tools/Makefile	Tue Aug 02 17:13:11 2005 +0000
    10.3 @@ -10,9 +10,10 @@ SUBDIRS += xentrace
    10.4  SUBDIRS += python
    10.5  SUBDIRS += xcs
    10.6  SUBDIRS += xcutils
    10.7 -SUBDIRS += pygrub
    10.8 +#SUBDIRS += pygrub
    10.9  SUBDIRS += firmware
   10.10 -SUBDIRS += policy
   10.11 +SUBDIRS += security
   10.12 +#SUBDIRS += consoled
   10.13  
   10.14  .PHONY: all install clean check check_clean ioemu eioemuinstall ioemuclean
   10.15  
    11.1 --- a/tools/Rules.mk	Tue Aug 02 17:12:36 2005 +0000
    11.2 +++ b/tools/Rules.mk	Tue Aug 02 17:13:11 2005 +0000
    11.3 @@ -4,6 +4,8 @@ include $(XEN_ROOT)/Config.mk
    11.4  
    11.5  XEN_XC             = $(XEN_ROOT)/tools/python/xen/lowlevel/xc
    11.6  XEN_LIBXC          = $(XEN_ROOT)/tools/libxc
    11.7 +XEN_XCS            = $(XEN_ROOT)/tools/xcs
    11.8 +XEN_XENSTORE       = $(XEN_ROOT)/tools/xenstore
    11.9  
   11.10  ifeq ($(XEN_TARGET_ARCH),x86_32)
   11.11  CFLAGS  += -m32 -march=i686
    12.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    12.2 +++ b/tools/consoled/Makefile	Tue Aug 02 17:13:11 2005 +0000
    12.3 @@ -0,0 +1,48 @@
    12.4 +# Makefile for consoled
    12.5 +# based on xcs Makefile
    12.6 +# Anthony Liguori 2005
    12.7 +
    12.8 +XEN_ROOT=../..
    12.9 +include $(XEN_ROOT)/tools/Rules.mk
   12.10 +
   12.11 +CONSOLED_INSTALL_DIR = /usr/sbin
   12.12 +XC_CONSOLE_INSTALL_DIR = /usr/libexec/xen
   12.13 +
   12.14 +INSTALL         = install
   12.15 +INSTALL_PROG    = $(INSTALL) -m0755
   12.16 +INSTALL_DIR     = $(INSTALL) -d -m0755
   12.17 +
   12.18 +CC       = gcc
   12.19 +CFLAGS   = -Wall -Werror -g3
   12.20 +
   12.21 +CFLAGS  += -I $(XEN_XCS)
   12.22 +CFLAGS  += -I $(XEN_LIBXC)
   12.23 +CFLAGS  += -I $(XEN_XENSTORE)
   12.24 +
   12.25 +SRCS    :=
   12.26 +SRCS    += main.c utils.c io.c
   12.27 +
   12.28 +HDRS     = $(wildcard *.h)
   12.29 +OBJS     = $(patsubst %.c,%.o,$(SRCS))
   12.30 +BIN      = consoled xc_console
   12.31 +
   12.32 +all: $(BIN)
   12.33 +
   12.34 +clean:
   12.35 +	$(RM) *.a *.so *.o *.rpm $(BIN)
   12.36 +
   12.37 +consoled: $(OBJS)
   12.38 +	$(CC) $(CFLAGS) $^ -o $@ -L$(XEN_LIBXC) -L$(XEN_XENSTORE) \
   12.39 +              -lxc -lxenstore
   12.40 +
   12.41 +xc_console: xc_console.o
   12.42 +	$(CC) $(CFLAGS) $^ -o $@ -L$(XEN_LIBXC) -L$(XEN_XENSTORE) \
   12.43 +	      -lxc -lxenstore
   12.44 +
   12.45 +$(OBJS): $(HDRS)
   12.46 +
   12.47 +install: $(BIN)
   12.48 +	$(INSTALL_DIR) -p $(DESTDIR)/$(CONSOLED_INSTALL_DIR)
   12.49 +	$(INSTALL_PROG) consoled $(DESTDIR)/$(CONSOLED_INSTALL_DIR)
   12.50 +	$(INSTALL_DIR) -p $(DESTDIR)/$(XC_CONSOLE_INSTALL_DIR)
   12.51 +	$(INSTALL_PROG) xc_console $(DESTDIR)/$(XC_CONSOLE_INSTALL_DIR)
    13.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    13.2 +++ b/tools/consoled/io.c	Tue Aug 02 17:13:11 2005 +0000
    13.3 @@ -0,0 +1,328 @@
    13.4 +/*\
    13.5 + *  Copyright (C) International Business Machines  Corp., 2005
    13.6 + *  Author(s): Anthony Liguori <aliguori@us.ibm.com>
    13.7 + *
    13.8 + *  Xen Console Daemon
    13.9 + *
   13.10 + *  This program is free software; you can redistribute it and/or modify
   13.11 + *  it under the terms of the GNU General Public License as published by
   13.12 + *  the Free Software Foundation; under version 2 of the License.
   13.13 + * 
   13.14 + *  This program is distributed in the hope that it will be useful,
   13.15 + *  but WITHOUT ANY WARRANTY; without even the implied warranty of
   13.16 + *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   13.17 + *  GNU General Public License for more details.
   13.18 + * 
   13.19 + *  You should have received a copy of the GNU General Public License
   13.20 + *  along with this program; if not, write to the Free Software
   13.21 + *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
   13.22 +\*/
   13.23 +
   13.24 +#define _GNU_SOURCE
   13.25 +
   13.26 +#include "utils.h"
   13.27 +#include "io.h"
   13.28 +
   13.29 +#include "xc.h"
   13.30 +#include "xs.h"
   13.31 +#include "xen/io/domain_controller.h"
   13.32 +#include "xcs_proto.h"
   13.33 +
   13.34 +#include <malloc.h>
   13.35 +#include <stdlib.h>
   13.36 +#include <errno.h>
   13.37 +#include <string.h>
   13.38 +#include <sys/select.h>
   13.39 +#include <fcntl.h>
   13.40 +#include <unistd.h>
   13.41 +#include <termios.h>
   13.42 +
   13.43 +#define MAX(a, b) (((a) > (b)) ? (a) : (b))
   13.44 +#define MIN(a, b) (((a) < (b)) ? (a) : (b))
   13.45 +
   13.46 +struct buffer
   13.47 +{
   13.48 +	char *data;
   13.49 +	size_t size;
   13.50 +	size_t capacity;
   13.51 +	size_t max_capacity;
   13.52 +};
   13.53 +
   13.54 +void buffer_append(struct buffer *buffer, const void *data, size_t size)
   13.55 +{
   13.56 +	if ((buffer->capacity - buffer->size) < size) {
   13.57 +		buffer->capacity += (size + 1024);
   13.58 +		buffer->data = realloc(buffer->data, buffer->capacity);
   13.59 +		if (buffer->data == NULL) {
   13.60 +			dolog(LOG_ERR, "Memory allocation failed");
   13.61 +			exit(ENOMEM);
   13.62 +		}
   13.63 +	}
   13.64 +
   13.65 +	memcpy(buffer->data + buffer->size, data, size);
   13.66 +	buffer->size += size;
   13.67 +
   13.68 +	if (buffer->max_capacity &&
   13.69 +	    buffer->size > buffer->max_capacity) {
   13.70 +		memmove(buffer->data + (buffer->size - buffer->max_capacity),
   13.71 +			buffer->data, buffer->max_capacity);
   13.72 +		buffer->data = realloc(buffer->data, buffer->max_capacity);
   13.73 +		buffer->capacity = buffer->max_capacity;
   13.74 +	}
   13.75 +}
   13.76 +
   13.77 +bool buffer_empty(struct buffer *buffer)
   13.78 +{
   13.79 +	return buffer->size == 0;
   13.80 +}
   13.81 +
   13.82 +void buffer_advance(struct buffer *buffer, size_t size)
   13.83 +{
   13.84 +	size = MIN(size, buffer->size);
   13.85 +	memmove(buffer->data, buffer + size, buffer->size - size);
   13.86 +	buffer->size -= size;
   13.87 +}
   13.88 +
   13.89 +struct domain
   13.90 +{
   13.91 +	int domid;
   13.92 +	int tty_fd;
   13.93 +	struct buffer buffer;
   13.94 +	struct domain *next;
   13.95 +};
   13.96 +
   13.97 +static struct domain *dom_head;
   13.98 +
   13.99 +bool domain_is_valid(int domid)
  13.100 +{
  13.101 +	bool ret;
  13.102 +	xc_dominfo_t info;
  13.103 +
  13.104 +	ret = (xc_domain_getinfo(xc, domid, 1, &info) == 1 &&
  13.105 +	       info.domid == domid);
  13.106 +		
  13.107 +	return ret;
  13.108 +}
  13.109 +
  13.110 +int domain_create_tty(int domid)
  13.111 +{
  13.112 +	char path[1024];
  13.113 +	int master;
  13.114 +
  13.115 +	if ((master = getpt()) == -1 ||
  13.116 +	    grantpt(master) == -1 || unlockpt(master) == -1) {
  13.117 +		dolog(LOG_ERR, "Failed to create tty for domain-%d", domid);
  13.118 +		master = -1;
  13.119 +	} else {
  13.120 +		const char *slave = ptsname(master);
  13.121 +		struct termios term;
  13.122 +
  13.123 +		if (tcgetattr(master, &term) != -1) {
  13.124 +			cfmakeraw(&term);
  13.125 +			tcsetattr(master, TCSAFLUSH, &term);
  13.126 +		}
  13.127 +
  13.128 +		xs_mkdir(xs, "/console");
  13.129 +		snprintf(path, sizeof(path), "/console/%d", domid);
  13.130 +		xs_mkdir(xs, path);
  13.131 +		strcat(path, "/tty");
  13.132 +
  13.133 +		xs_write(xs, path, slave, strlen(slave), O_CREAT);
  13.134 +	}
  13.135 +
  13.136 +	return master;
  13.137 +}
  13.138 +
  13.139 +struct domain *create_domain(int domid)
  13.140 +{
  13.141 +	struct domain *dom;
  13.142 +	char *data;
  13.143 +	unsigned int len;
  13.144 +	char path[1024];
  13.145 +
  13.146 +	dom = (struct domain *)malloc(sizeof(struct domain));
  13.147 +	if (dom == NULL) {
  13.148 +		dolog(LOG_ERR, "Out of memory %s:%s():L%d",
  13.149 +		      __FILE__, __FUNCTION__, __LINE__);
  13.150 +		exit(ENOMEM);
  13.151 +	}
  13.152 +
  13.153 +	dom->domid = domid;
  13.154 +	dom->tty_fd = domain_create_tty(domid);
  13.155 +	dom->buffer.data = 0;
  13.156 +	dom->buffer.size = 0;
  13.157 +	dom->buffer.capacity = 0;
  13.158 +	dom->buffer.max_capacity = 0;
  13.159 +
  13.160 +	snprintf(path, sizeof(path), "/console/%d/limit", domid);
  13.161 +	data = xs_read(xs, path, &len);
  13.162 +	if (data) {
  13.163 +		dom->buffer.max_capacity = strtoul(data, 0, 0);
  13.164 +		free(data);
  13.165 +	}
  13.166 +
  13.167 +	dolog(LOG_DEBUG, "New domain %d", domid);
  13.168 +
  13.169 +	return dom;
  13.170 +}
  13.171 +
  13.172 +struct domain *lookup_domain(int domid)
  13.173 +{
  13.174 +	struct domain **pp;
  13.175 +
  13.176 +	for (pp = &dom_head; *pp; pp = &(*pp)->next) {
  13.177 +		struct domain *dom = *pp;
  13.178 +
  13.179 +		if (dom->domid == domid) {
  13.180 +			return dom;
  13.181 +		} else if (dom->domid > domid) {
  13.182 +			*pp = create_domain(domid);
  13.183 +			(*pp)->next = dom;
  13.184 +			return *pp;
  13.185 +		}
  13.186 +	}
  13.187 +
  13.188 +	*pp = create_domain(domid);
  13.189 +	return *pp;
  13.190 +}
  13.191 +
  13.192 +void remove_domain(struct domain *dom)
  13.193 +{
  13.194 +	struct domain **pp;
  13.195 +
  13.196 +	dolog(LOG_DEBUG, "Removing domain-%d", dom->domid);
  13.197 +
  13.198 +	for (pp = &dom_head; *pp; pp = &(*pp)->next) {
  13.199 +		struct domain *d = *pp;
  13.200 +
  13.201 +		if (dom->domid == d->domid) {
  13.202 +			*pp = d->next;
  13.203 +			free(d);
  13.204 +			break;
  13.205 +		}
  13.206 +	}
  13.207 +}
  13.208 +
  13.209 +void handle_tty_read(struct domain *dom)
  13.210 +{
  13.211 +	ssize_t len;
  13.212 +	xcs_msg_t msg;
  13.213 +
  13.214 +	msg.type = XCS_REQUEST;
  13.215 +	msg.u.control.remote_dom = dom->domid;
  13.216 +	msg.u.control.msg.type = CMSG_CONSOLE;
  13.217 +	msg.u.control.msg.subtype = CMSG_CONSOLE_DATA;
  13.218 +	msg.u.control.msg.id = 1;
  13.219 +
  13.220 +	len = read(dom->tty_fd, msg.u.control.msg.msg, 60);
  13.221 +	if (len < 1) {
  13.222 +		close(dom->tty_fd);
  13.223 +
  13.224 +		if (domain_is_valid(dom->domid)) {
  13.225 +			dom->tty_fd = domain_create_tty(dom->domid);
  13.226 +		} else {
  13.227 +			remove_domain(dom);
  13.228 +		}
  13.229 +	} else if (domain_is_valid(dom->domid)) {
  13.230 +		msg.u.control.msg.length = len;
  13.231 +
  13.232 +		if (!write_sync(xcs_data_fd, &msg, sizeof(msg))) {
  13.233 +			dolog(LOG_ERR, "Write to xcs failed: %m");
  13.234 +		}
  13.235 +	} else {
  13.236 +		close(dom->tty_fd);
  13.237 +		remove_domain(dom);
  13.238 +	}
  13.239 +}
  13.240 +
  13.241 +void handle_tty_write(struct domain *dom)
  13.242 +{
  13.243 +	ssize_t len;
  13.244 +
  13.245 +	len = write(dom->tty_fd, dom->buffer.data, dom->buffer.size);
  13.246 +	if (len < 1) {
  13.247 +		close(dom->tty_fd);
  13.248 +
  13.249 +		if (domain_is_valid(dom->domid)) {
  13.250 +			dom->tty_fd = domain_create_tty(dom->domid);
  13.251 +		} else {
  13.252 +			remove_domain(dom);
  13.253 +		}
  13.254 +	} else {
  13.255 +		buffer_advance(&dom->buffer, len);
  13.256 +	}
  13.257 +}
  13.258 +
  13.259 +void handle_xcs_msg(int fd)
  13.260 +{
  13.261 +	xcs_msg_t msg;
  13.262 +
  13.263 +	if (!read_sync(fd, &msg, sizeof(msg))) {
  13.264 +		dolog(LOG_ERR, "read from xcs failed! %m");
  13.265 +	} else if (msg.type == XCS_REQUEST) {
  13.266 +		struct domain *dom;
  13.267 +
  13.268 +		dom = lookup_domain(msg.u.control.remote_dom);
  13.269 +		buffer_append(&dom->buffer,
  13.270 +			      msg.u.control.msg.msg,
  13.271 +			      msg.u.control.msg.length);
  13.272 +	}
  13.273 +}
  13.274 +
  13.275 +static void enum_domains(void)
  13.276 +{
  13.277 +	int domid = 0;
  13.278 +	xc_dominfo_t dominfo;
  13.279 +
  13.280 +	while (xc_domain_getinfo(xc, domid, 1, &dominfo) == 1) {
  13.281 +		lookup_domain(dominfo.domid);
  13.282 +		domid = dominfo.domid + 1;
  13.283 +	}
  13.284 +}
  13.285 +
  13.286 +void handle_io(void)
  13.287 +{
  13.288 +	fd_set readfds, writefds;
  13.289 +	int ret;
  13.290 +	int max_fd = -1;
  13.291 +
  13.292 +	do {
  13.293 +		struct domain *d;
  13.294 +		struct timeval tv = { 1, 0 };
  13.295 +
  13.296 +		FD_ZERO(&readfds);
  13.297 +		FD_ZERO(&writefds);
  13.298 +
  13.299 +		FD_SET(xcs_data_fd, &readfds);
  13.300 +		max_fd = MAX(xcs_data_fd, max_fd);
  13.301 +
  13.302 +		for (d = dom_head; d; d = d->next) {
  13.303 +			if (d->tty_fd != -1) {
  13.304 +				FD_SET(d->tty_fd, &readfds);
  13.305 +			}
  13.306 +
  13.307 +			if (d->tty_fd != -1 && !buffer_empty(&d->buffer)) {
  13.308 +				FD_SET(d->tty_fd, &writefds);
  13.309 +			}
  13.310 +
  13.311 +			max_fd = MAX(d->tty_fd, max_fd);
  13.312 +		}
  13.313 +
  13.314 +		ret = select(max_fd + 1, &readfds, &writefds, 0, &tv);
  13.315 +		enum_domains();
  13.316 +
  13.317 +		if (FD_ISSET(xcs_data_fd, &readfds)) {
  13.318 +			handle_xcs_msg(xcs_data_fd);
  13.319 +		}
  13.320 +
  13.321 +		for (d = dom_head; d; d = d->next) {
  13.322 +			if (FD_ISSET(d->tty_fd, &readfds)) {
  13.323 +				handle_tty_read(d);
  13.324 +			}
  13.325 +
  13.326 +			if (FD_ISSET(d->tty_fd, &writefds)) {
  13.327 +				handle_tty_write(d);
  13.328 +			}
  13.329 +		}
  13.330 +	} while (ret > -1);
  13.331 +}
    14.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    14.2 +++ b/tools/consoled/io.h	Tue Aug 02 17:13:11 2005 +0000
    14.3 @@ -0,0 +1,26 @@
    14.4 +/*\
    14.5 + *  Copyright (C) International Business Machines  Corp., 2005
    14.6 + *  Author(s): Anthony Liguori <aliguori@us.ibm.com>
    14.7 + *
    14.8 + *  Xen Console Daemon
    14.9 + *
   14.10 + *  This program is free software; you can redistribute it and/or modify
   14.11 + *  it under the terms of the GNU General Public License as published by
   14.12 + *  the Free Software Foundation; under version 2 of the License.
   14.13 + * 
   14.14 + *  This program is distributed in the hope that it will be useful,
   14.15 + *  but WITHOUT ANY WARRANTY; without even the implied warranty of
   14.16 + *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   14.17 + *  GNU General Public License for more details.
   14.18 + * 
   14.19 + *  You should have received a copy of the GNU General Public License
   14.20 + *  along with this program; if not, write to the Free Software
   14.21 + *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
   14.22 +\*/
   14.23 +
   14.24 +#ifndef CONSOLED_IO_H
   14.25 +#define CONSOLED_IO_H
   14.26 +
   14.27 +void handle_io(void);
   14.28 +
   14.29 +#endif
    15.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    15.2 +++ b/tools/consoled/main.c	Tue Aug 02 17:13:11 2005 +0000
    15.3 @@ -0,0 +1,93 @@
    15.4 +/*\
    15.5 + *  Copyright (C) International Business Machines  Corp., 2005
    15.6 + *  Author(s): Anthony Liguori <aliguori@us.ibm.com>
    15.7 + *
    15.8 + *  Xen Console Daemon
    15.9 + *
   15.10 + *  This program is free software; you can redistribute it and/or modify
   15.11 + *  it under the terms of the GNU General Public License as published by
   15.12 + *  the Free Software Foundation; under version 2 of the License.
   15.13 + * 
   15.14 + *  This program is distributed in the hope that it will be useful,
   15.15 + *  but WITHOUT ANY WARRANTY; without even the implied warranty of
   15.16 + *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   15.17 + *  GNU General Public License for more details.
   15.18 + * 
   15.19 + *  You should have received a copy of the GNU General Public License
   15.20 + *  along with this program; if not, write to the Free Software
   15.21 + *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
   15.22 +\*/
   15.23 +
   15.24 +#include <getopt.h>
   15.25 +#include <stdlib.h>
   15.26 +#include <stdio.h>
   15.27 +#include <errno.h>
   15.28 +#include <unistd.h>
   15.29 +#include <sys/types.h>
   15.30 +
   15.31 +#include "xc.h"
   15.32 +#include "xen/io/domain_controller.h"
   15.33 +#include "xcs_proto.h"
   15.34 +
   15.35 +#include "utils.h"
   15.36 +#include "io.h"
   15.37 +
   15.38 +int main(int argc, char **argv)
   15.39 +{
   15.40 +	const char *sopts = "hVvi";
   15.41 +	struct option lopts[] = {
   15.42 +		{ "help", 0, 0, 'h' },
   15.43 +		{ "version", 0, 0, 'V' },
   15.44 +		{ "verbose", 0, 0, 'v' },
   15.45 +		{ "interactive", 0, 0, 'i' },
   15.46 +		{ 0 },
   15.47 +	};
   15.48 +	bool is_interactive = false;
   15.49 +	int ch;
   15.50 +	int syslog_option = LOG_CONS;
   15.51 +	int syslog_mask = LOG_WARNING;
   15.52 +	int opt_ind = 0;
   15.53 +
   15.54 +	while ((ch = getopt_long(argc, argv, sopts, lopts, &opt_ind)) != -1) {
   15.55 +		switch (ch) {
   15.56 +		case 'h':
   15.57 +			//usage(argv[0]);
   15.58 +			exit(0);
   15.59 +		case 'V':
   15.60 +			//version(argv[0]);
   15.61 +			exit(0);
   15.62 +		case 'v':
   15.63 +			syslog_option |= LOG_PERROR;
   15.64 +			syslog_mask = LOG_DEBUG;
   15.65 +			break;
   15.66 +		case 'i':
   15.67 +			is_interactive = true;
   15.68 +			break;
   15.69 +		case '?':
   15.70 +			fprintf(stderr,
   15.71 +				"Try `%s --help' for more information\n",
   15.72 +				argv[0]);
   15.73 +			exit(EINVAL);
   15.74 +		}
   15.75 +	}
   15.76 +
   15.77 +	if (geteuid() != 0) {
   15.78 +		fprintf(stderr, "%s requires root to run.\n", argv[0]);
   15.79 +		exit(EPERM);
   15.80 +	}
   15.81 +
   15.82 +	openlog("consoled", syslog_option, LOG_DAEMON);
   15.83 +	setlogmask(syslog_mask);
   15.84 +
   15.85 +	if (!is_interactive) {
   15.86 +		daemonize("/var/run/consoled.pid");
   15.87 +	}
   15.88 +
   15.89 +	xen_setup();
   15.90 +
   15.91 +	handle_io();
   15.92 +
   15.93 +	closelog();
   15.94 +
   15.95 +	return 0;
   15.96 +}
    16.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    16.2 +++ b/tools/consoled/utils.c	Tue Aug 02 17:13:11 2005 +0000
    16.3 @@ -0,0 +1,251 @@
    16.4 +/*\
    16.5 + *  Copyright (C) International Business Machines  Corp., 2005
    16.6 + *  Author(s): Anthony Liguori <aliguori@us.ibm.com>
    16.7 + *
    16.8 + *  Xen Console Daemon
    16.9 + *
   16.10 + *  This program is free software; you can redistribute it and/or modify
   16.11 + *  it under the terms of the GNU General Public License as published by
   16.12 + *  the Free Software Foundation; under version 2 of the License.
   16.13 + * 
   16.14 + *  This program is distributed in the hope that it will be useful,
   16.15 + *  but WITHOUT ANY WARRANTY; without even the implied warranty of
   16.16 + *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   16.17 + *  GNU General Public License for more details.
   16.18 + * 
   16.19 + *  You should have received a copy of the GNU General Public License
   16.20 + *  along with this program; if not, write to the Free Software
   16.21 + *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
   16.22 +\*/
   16.23 +
   16.24 +#include <sys/types.h>
   16.25 +#include <sys/stat.h>
   16.26 +#include <sys/wait.h>
   16.27 +#include <unistd.h>
   16.28 +#include <stdlib.h>
   16.29 +#include <fcntl.h>
   16.30 +#include <err.h>
   16.31 +#include <errno.h>
   16.32 +#include <stdio.h>
   16.33 +#include <getopt.h>
   16.34 +#include <stdbool.h>
   16.35 +#include <sys/socket.h>
   16.36 +#include <sys/un.h>
   16.37 +#include <string.h>
   16.38 +
   16.39 +#include "xc.h"
   16.40 +#include "xen/io/domain_controller.h"
   16.41 +#include "xcs_proto.h"
   16.42 +
   16.43 +#include "utils.h"
   16.44 +
   16.45 +struct xs_handle *xs;
   16.46 +int xc;
   16.47 +
   16.48 +int xcs_ctrl_fd = -1;
   16.49 +int xcs_data_fd = -1;
   16.50 +
   16.51 +bool _read_write_sync(int fd, void *data, size_t size, bool do_read)
   16.52 +{
   16.53 +	size_t offset = 0;
   16.54 +	ssize_t len;
   16.55 +
   16.56 +	while (offset < size) {
   16.57 +		if (do_read) {
   16.58 +			len = read(fd, data + offset, size - offset);
   16.59 +		} else {
   16.60 +			len = write(fd, data + offset, size - offset);
   16.61 +		}
   16.62 +
   16.63 +		if (len < 1) {
   16.64 +			if (len == -1 && (errno == EAGAIN || errno == EINTR)) {
   16.65 +				return false;
   16.66 +			}
   16.67 +		} else {
   16.68 +			offset += len;
   16.69 +		}
   16.70 +	}
   16.71 +
   16.72 +	return true;
   16.73 +}
   16.74 +
   16.75 +static int open_domain_socket(const char *path)
   16.76 +{
   16.77 +	struct sockaddr_un addr;
   16.78 +	int sock;
   16.79 +	size_t addr_len;
   16.80 +
   16.81 +	if ((sock = socket(PF_UNIX, SOCK_STREAM, 0)) == -1) {
   16.82 +		goto out;
   16.83 +	}
   16.84 +
   16.85 +	addr.sun_family = AF_UNIX;
   16.86 +	strcpy(addr.sun_path, path);
   16.87 +	addr_len = sizeof(addr.sun_family) + strlen(XCS_SUN_PATH) + 1;
   16.88 +
   16.89 +	if (connect(sock, (struct sockaddr *)&addr, addr_len) == -1) {
   16.90 +		goto out_close_sock;
   16.91 +	}
   16.92 +
   16.93 +	return sock;
   16.94 +
   16.95 + out_close_sock:
   16.96 +	close(sock);
   16.97 + out:
   16.98 +	return -1;
   16.99 +}
  16.100 +
  16.101 +static void child_exit(int sig)
  16.102 +{
  16.103 +	while (waitpid(-1, NULL, WNOHANG) > 0);
  16.104 +}
  16.105 +
  16.106 +void daemonize(const char *pidfile)
  16.107 +{
  16.108 +	pid_t pid;
  16.109 +	int fd;
  16.110 +	int len;
  16.111 +	int i;
  16.112 +	char buf[100];
  16.113 +
  16.114 +	if (getppid() == 1) {
  16.115 +		return;
  16.116 +	}
  16.117 +
  16.118 +	if ((pid = fork()) > 0) {
  16.119 +		exit(0);
  16.120 +	} else if (pid == -1) {
  16.121 +		err(errno, "fork() failed");
  16.122 +	}
  16.123 +
  16.124 +	setsid();
  16.125 +
  16.126 +	/* redirect fd 0,1,2 to /dev/null */
  16.127 +	if ((fd = open("/dev/null",O_RDWR)) == -1) {
  16.128 +		exit(1);
  16.129 +	}
  16.130 +
  16.131 +	for (i = 0; i <= 2; i++) {
  16.132 +		close(i);
  16.133 +		dup2(fd, i);
  16.134 +	}
  16.135 +
  16.136 +	close(fd);
  16.137 +
  16.138 +	umask(027);
  16.139 +	chdir("/");
  16.140 +
  16.141 +	fd = open(pidfile, O_RDWR | O_CREAT);
  16.142 +	if (fd == -1) {
  16.143 +		exit(1);
  16.144 +	}
  16.145 +
  16.146 +	if (lockf(fd, F_TLOCK, 0) == -1) {
  16.147 +		exit(1);
  16.148 +	}
  16.149 +
  16.150 +	len = sprintf(buf, "%d\n", getpid());
  16.151 +	write(fd, buf, len);
  16.152 +
  16.153 +	signal(SIGCHLD, child_exit);
  16.154 +	signal(SIGTSTP, SIG_IGN);
  16.155 +	signal(SIGTTOU, SIG_IGN);
  16.156 +	signal(SIGTTIN, SIG_IGN);
  16.157 +}
  16.158 +
  16.159 +/* synchronized send/recv strictly for setting up xcs */
  16.160 +/* always use asychronize callbacks any other time */
  16.161 +static bool xcs_send_recv(int fd, xcs_msg_t *msg)
  16.162 +{
  16.163 +	bool ret = false;
  16.164 +
  16.165 +	if (!write_sync(fd, msg, sizeof(*msg))) {
  16.166 +		dolog(LOG_ERR, "Write failed at %s:%s():L%d?  Possible bug.",
  16.167 +		       __FILE__, __FUNCTION__, __LINE__);
  16.168 +		goto out;
  16.169 +	}
  16.170 +
  16.171 +	if (!read_sync(fd, msg, sizeof(*msg))) {
  16.172 +		dolog(LOG_ERR, "Read failed at %s:%s():L%d?  Possible bug.",
  16.173 +		       __FILE__, __FUNCTION__, __LINE__);
  16.174 +		goto out;
  16.175 +	}
  16.176 +
  16.177 +	ret = true;
  16.178 +
  16.179 + out:
  16.180 +	return ret;
  16.181 +}
  16.182 +
  16.183 +bool xen_setup(void)
  16.184 +{
  16.185 +	int sock;
  16.186 +	xcs_msg_t msg;
  16.187 +	
  16.188 +	xs = xs_daemon_open();
  16.189 +	if (xs == NULL) {
  16.190 +		dolog(LOG_ERR,
  16.191 +		      "Failed to contact xenstore (%m).  Is it running?");
  16.192 +		goto out;
  16.193 +	}
  16.194 +
  16.195 +	xc = xc_interface_open();
  16.196 +	if (xc == -1) {
  16.197 +		dolog(LOG_ERR, "Failed to contact hypervisor (%m)");
  16.198 +		goto out;
  16.199 +	}
  16.200 +
  16.201 +	sock = open_domain_socket(XCS_SUN_PATH);
  16.202 +	if (sock == -1) {
  16.203 +		dolog(LOG_ERR, "Failed to contact xcs (%m).  Is it running?");
  16.204 +		goto out_close_store;
  16.205 +	}
  16.206 +
  16.207 +	xcs_ctrl_fd = sock;
  16.208 +
  16.209 +	sock = open_domain_socket(XCS_SUN_PATH);
  16.210 +	if (sock == -1) {
  16.211 +		dolog(LOG_ERR, "Failed to contact xcs (%m).  Is it running?");
  16.212 +		goto out_close_ctrl;
  16.213 +	}
  16.214 +	
  16.215 +	xcs_data_fd = sock;
  16.216 +
  16.217 +	memset(&msg, 0, sizeof(msg));
  16.218 +	msg.type = XCS_CONNECT_CTRL;
  16.219 +	if (!xcs_send_recv(xcs_ctrl_fd, &msg) || msg.result != XCS_RSLT_OK) {
  16.220 +		dolog(LOG_ERR, "xcs control connect failed.  Possible bug.");
  16.221 +		goto out_close_data;
  16.222 +	}
  16.223 +
  16.224 +	msg.type = XCS_CONNECT_DATA;
  16.225 +	if (!xcs_send_recv(xcs_data_fd, &msg) || msg.result != XCS_RSLT_OK) {
  16.226 +		dolog(LOG_ERR, "xcs data connect failed.  Possible bug.");
  16.227 +		goto out_close_data;
  16.228 +	}
  16.229 +
  16.230 +	/* Since the vast majority of control messages are console messages
  16.231 +	   it's just easier to ignore other messages that try to bind to 
  16.232 +	   a specific type. */
  16.233 +	msg.type = XCS_MSG_BIND;
  16.234 +	msg.u.bind.port = PORT_WILDCARD;
  16.235 +	msg.u.bind.type = TYPE_WILDCARD;
  16.236 +	if (!xcs_send_recv(xcs_ctrl_fd, &msg) || msg.result != XCS_RSLT_OK) {
  16.237 +		dolog(LOG_ERR, "xcs vind failed.  Possible bug.");
  16.238 +		goto out_close_data;
  16.239 +	}
  16.240 +	
  16.241 +	return true;
  16.242 +
  16.243 + out_close_data:
  16.244 +	close(xcs_ctrl_fd);
  16.245 +	xcs_data_fd = -1;
  16.246 + out_close_ctrl:
  16.247 +	close(xcs_ctrl_fd);
  16.248 +	xcs_ctrl_fd = -1;
  16.249 + out_close_store:
  16.250 +	xs_daemon_close(xs);
  16.251 + out:
  16.252 +	return false;
  16.253 +}
  16.254 +
    17.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    17.2 +++ b/tools/consoled/utils.h	Tue Aug 02 17:13:11 2005 +0000
    17.3 @@ -0,0 +1,47 @@
    17.4 +/*\
    17.5 + *  Copyright (C) International Business Machines  Corp., 2005
    17.6 + *  Author(s): Anthony Liguori <aliguori@us.ibm.com>
    17.7 + *
    17.8 + *  Xen Console Daemon
    17.9 + *
   17.10 + *  This program is free software; you can redistribute it and/or modify
   17.11 + *  it under the terms of the GNU General Public License as published by
   17.12 + *  the Free Software Foundation; under version 2 of the License.
   17.13 + * 
   17.14 + *  This program is distributed in the hope that it will be useful,
   17.15 + *  but WITHOUT ANY WARRANTY; without even the implied warranty of
   17.16 + *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   17.17 + *  GNU General Public License for more details.
   17.18 + * 
   17.19 + *  You should have received a copy of the GNU General Public License
   17.20 + *  along with this program; if not, write to the Free Software
   17.21 + *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
   17.22 +\*/
   17.23 +
   17.24 +#ifndef CONSOLED_UTILS_H
   17.25 +#define CONSOLED_UTILS_H
   17.26 +
   17.27 +#include <stdbool.h>
   17.28 +#include <syslog.h>
   17.29 +#include <stdio.h>
   17.30 +
   17.31 +#include "xs.h"
   17.32 +
   17.33 +void daemonize(const char *pidfile);
   17.34 +bool xen_setup(void);
   17.35 +#define read_sync(fd, buffer, size) _read_write_sync(fd, buffer, size, true)
   17.36 +#define write_sync(fd, buffer, size) _read_write_sync(fd, buffer, size, false)
   17.37 +bool _read_write_sync(int fd, void *data, size_t size, bool do_read);
   17.38 +
   17.39 +extern int xcs_ctrl_fd;
   17.40 +extern int xcs_data_fd;
   17.41 +extern struct xs_handle *xs;
   17.42 +extern int xc;
   17.43 +
   17.44 +#if 1
   17.45 +#define dolog(val, fmt, ...) syslog(val, fmt, ## __VA_ARGS__)
   17.46 +#else
   17.47 +#define dolog(val, fmt, ...) fprintf(stderr, fmt "\n", ## __VA_ARGS__)
   17.48 +#endif
   17.49 +
   17.50 +#endif
    18.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    18.2 +++ b/tools/consoled/xc_console.c	Tue Aug 02 17:13:11 2005 +0000
    18.3 @@ -0,0 +1,236 @@
    18.4 +/*\
    18.5 + *  Copyright (C) International Business Machines  Corp., 2005
    18.6 + *  Author(s): Anthony Liguori <aliguori@us.ibm.com>
    18.7 + *
    18.8 + *  Xen Console Daemon
    18.9 + *
   18.10 + *  This program is free software; you can redistribute it and/or modify
   18.11 + *  it under the terms of the GNU General Public License as published by
   18.12 + *  the Free Software Foundation; under version 2 of the License.
   18.13 + * 
   18.14 + *  This program is distributed in the hope that it will be useful,
   18.15 + *  but WITHOUT ANY WARRANTY; without even the implied warranty of
   18.16 + *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   18.17 + *  GNU General Public License for more details.
   18.18 + * 
   18.19 + *  You should have received a copy of the GNU General Public License
   18.20 + *  along with this program; if not, write to the Free Software
   18.21 + *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
   18.22 +\*/
   18.23 +
   18.24 +#include <sys/types.h>
   18.25 +#include <sys/socket.h>
   18.26 +#include <sys/un.h>
   18.27 +#include <stdio.h>
   18.28 +#include <unistd.h>
   18.29 +#include <errno.h>
   18.30 +#include <stdlib.h>
   18.31 +#include <time.h>
   18.32 +#include <fcntl.h>
   18.33 +#include <sys/wait.h>
   18.34 +#include <termios.h>
   18.35 +#include <signal.h>
   18.36 +#include <getopt.h>
   18.37 +#include <sys/select.h>
   18.38 +#include <err.h>
   18.39 +#include <errno.h>
   18.40 +#include <pty.h>
   18.41 +
   18.42 +#include "xc.h"
   18.43 +#include "xs.h"
   18.44 +
   18.45 +#define ESCAPE_CHARACTER 0x1d
   18.46 +
   18.47 +static volatile sig_atomic_t received_signal = 0;
   18.48 +
   18.49 +static void sighandler(int signum)
   18.50 +{
   18.51 +	received_signal = 1;
   18.52 +}
   18.53 +
   18.54 +static bool write_sync(int fd, const void *data, size_t size)
   18.55 +{
   18.56 +	size_t offset = 0;
   18.57 +	ssize_t len;
   18.58 +
   18.59 +	while (offset < size) {
   18.60 +		len = write(fd, data + offset, size - offset);
   18.61 +		if (len < 1) {
   18.62 +			return false;
   18.63 +		}
   18.64 +		offset += len;
   18.65 +	}
   18.66 +
   18.67 +	return true;
   18.68 +}
   18.69 +
   18.70 +static void usage(const char *program) {
   18.71 +	printf("Usage: %s [OPTION] DOMID\n"
   18.72 +	       "Attaches to a virtual domain console\n"
   18.73 +	       "\n"
   18.74 +	       "  -h, --help       display this help and exit\n"
   18.75 +	       , program);
   18.76 +}
   18.77 +
   18.78 +/* don't worry too much if setting terminal attributes fail */
   18.79 +static void init_term(int fd, struct termios *old)
   18.80 +{
   18.81 +	struct termios new_term;
   18.82 +
   18.83 +	if (tcgetattr(fd, old) == -1) {
   18.84 +		perror("tcgetattr() failed");
   18.85 +		return;
   18.86 +	}
   18.87 +
   18.88 +	new_term = *old;
   18.89 +	cfmakeraw(&new_term);
   18.90 +
   18.91 +	if (tcsetattr(fd, TCSAFLUSH, &new_term) == -1) {
   18.92 +		perror("tcsetattr() failed");
   18.93 +	}
   18.94 +}
   18.95 +
   18.96 +static void restore_term(int fd, struct termios *old)
   18.97 +{
   18.98 +	if (tcsetattr(fd, TCSAFLUSH, old) == -1) {
   18.99 +		perror("tcsetattr() failed");
  18.100 +	}
  18.101 +}
  18.102 +
  18.103 +static int console_loop(int xc_handle, domid_t domid, int fd)
  18.104 +{
  18.105 +	int ret;
  18.106 +
  18.107 +	do {
  18.108 +		fd_set fds;
  18.109 +
  18.110 +		FD_ZERO(&fds);
  18.111 +		FD_SET(STDIN_FILENO, &fds);
  18.112 +		FD_SET(fd, &fds);
  18.113 +
  18.114 +		ret = select(fd + 1, &fds, NULL, NULL, NULL);
  18.115 +		if (ret == -1) {
  18.116 +			if (errno == EINTR || errno == EAGAIN) {
  18.117 +				continue;
  18.118 +			}
  18.119 +			perror("select() failed");
  18.120 +			return -1;
  18.121 +		}
  18.122 +
  18.123 +		if (FD_ISSET(STDIN_FILENO, &fds)) {
  18.124 +			ssize_t len;
  18.125 +			char msg[60];
  18.126 +
  18.127 +			len = read(STDIN_FILENO, msg, sizeof(msg));
  18.128 +			if (len == 1 && msg[0] == ESCAPE_CHARACTER) {
  18.129 +				return 0;
  18.130 +			} 
  18.131 +
  18.132 +			if (len == 0 && len == -1) {
  18.133 +				if (len == -1 &&
  18.134 +				    (errno == EINTR || errno == EAGAIN)) {
  18.135 +					continue;
  18.136 +				}
  18.137 +				perror("select() failed");
  18.138 +				return -1;
  18.139 +			}
  18.140 +
  18.141 +			if (!write_sync(fd, msg, len)) {
  18.142 +				perror("write() failed");
  18.143 +				return -1;
  18.144 +			}
  18.145 +		}
  18.146 +
  18.147 +		if (FD_ISSET(fd, &fds)) {
  18.148 +			ssize_t len;
  18.149 +			char msg[512];
  18.150 +
  18.151 +			len = read(fd, msg, sizeof(msg));
  18.152 +			if (len == 0 || len == -1) {
  18.153 +				if (len == -1 &&
  18.154 +				    (errno == EINTR || errno == EAGAIN)) {
  18.155 +					continue;
  18.156 +				}
  18.157 +				perror("select() failed");
  18.158 +				return -1;
  18.159 +			}
  18.160 +
  18.161 +			if (!write_sync(STDOUT_FILENO, msg, len)) {
  18.162 +				perror("write() failed");
  18.163 +				return -1;
  18.164 +			}
  18.165 +		}
  18.166 +	} while (received_signal == 0);
  18.167 +
  18.168 +	return 0;
  18.169 +}
  18.170 +
  18.171 +int main(int argc, char **argv)
  18.172 +{
  18.173 +	struct termios attr;
  18.174 +	int domid;
  18.175 +	int xc_handle;
  18.176 +	char *sopt = "hf:pc";
  18.177 +	int ch;
  18.178 +	int opt_ind=0;
  18.179 +	struct option lopt[] = {
  18.180 +		{ "help",    0, 0, 'h' },
  18.181 +		{ "file",    1, 0, 'f' },
  18.182 +		{ "pty",     0, 0, 'p' },
  18.183 +		{ "ctty",    0, 0, 'c' },
  18.184 +		{ 0 },
  18.185 +
  18.186 +	};
  18.187 +	char *str_pty;
  18.188 +	char path[1024];
  18.189 +	int spty;
  18.190 +	unsigned int len = 0;
  18.191 +	struct xs_handle *xs;
  18.192 +
  18.193 +	while((ch = getopt_long(argc, argv, sopt, lopt, &opt_ind)) != -1) {
  18.194 +		switch(ch) {
  18.195 +		case 'h':
  18.196 +			usage(argv[0]);
  18.197 +			exit(0);
  18.198 +			break;
  18.199 +		}
  18.200 +	}
  18.201 +	
  18.202 +	if ((argc - optind) != 1) {
  18.203 +		fprintf(stderr, "Invalid number of arguments\n");
  18.204 +		fprintf(stderr, "Try `%s --help' for more information.\n", 
  18.205 +			argv[0]);
  18.206 +		exit(EINVAL);
  18.207 +	}
  18.208 +	
  18.209 +	domid = atoi(argv[optind]);
  18.210 +
  18.211 +	xs = xs_daemon_open();
  18.212 +	if (xs == NULL) {
  18.213 +		err(errno, "Could not contact XenStore");
  18.214 +	}
  18.215 +
  18.216 +	xc_handle = xc_interface_open();
  18.217 +	if (xc_handle == -1) {
  18.218 +		err(errno, "xc_interface_open()");
  18.219 +	}
  18.220 +	
  18.221 +	signal(SIGTERM, sighandler);
  18.222 +
  18.223 +	snprintf(path, sizeof(path), "/console/%d/tty", domid);
  18.224 +	str_pty = xs_read(xs, path, &len);
  18.225 +	if (str_pty == NULL) {
  18.226 +		err(errno, "Could not read tty from store");
  18.227 +	}
  18.228 +	spty = open(str_pty, O_RDWR | O_NOCTTY);
  18.229 +	if (spty == -1) {
  18.230 +		err(errno, "Could not open tty `%s'", str_pty);
  18.231 +	}
  18.232 +	free(str_pty);
  18.233 +
  18.234 +	init_term(STDIN_FILENO, &attr);
  18.235 +	console_loop(xc_handle, domid, spty);
  18.236 +	restore_term(STDIN_FILENO, &attr);
  18.237 +
  18.238 +	return 0;
  18.239 + }
    20.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    20.2 +++ b/tools/libxc/xc_ia64_stubs.c	Tue Aug 02 17:13:11 2005 +0000
    20.3 @@ -0,0 +1,39 @@
    20.4 +#include "xc_private.h"
    20.5 +
    20.6 +int xc_linux_save(int xc_handle, int io_fd, u32 dom)
    20.7 +{
    20.8 +    PERROR("xc_linux_save not implemented\n");
    20.9 +    return -1;
   20.10 +}
   20.11 +
   20.12 +int xc_linux_restore(int xc_handle, int io_fd, u32 dom, unsigned long nr_pfns)
   20.13 +{
   20.14 +    PERROR("xc_linux_restore not implemented\n");
   20.15 +    return -1;
   20.16 +}
   20.17 +
   20.18 +int xc_vmx_build(int xc_handle,
   20.19 +                   u32 domid,
   20.20 +                   int memsize,
   20.21 +                   const char *image_name,
   20.22 +                   struct mem_map *mem_mapp,
   20.23 +                   const char *ramdisk_name,
   20.24 +                   const char *cmdline,
   20.25 +                   unsigned int control_evtchn,
   20.26 +                   unsigned long flags)
   20.27 +{
   20.28 +    PERROR("xc_vmx_build not implemented\n");
   20.29 +    return -1;
   20.30 +}
   20.31 +
   20.32 +int
   20.33 +xc_plan9_build(int xc_handle,
   20.34 +               u32 domid,
   20.35 +               const char *image_name,
   20.36 +               const char *cmdline,
   20.37 +               unsigned int control_evtchn, unsigned long flags)
   20.38 +{
   20.39 +    PERROR("xc_plan9_build not implemented\n");
   20.40 +    return -1;
   20.41 +}
   20.42 +
    23.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    23.2 +++ b/tools/misc/policyprocessor/Makefile	Tue Aug 02 17:13:11 2005 +0000
    23.3 @@ -0,0 +1,42 @@
    23.4 +XEN_ROOT = ../../..
    23.5 +include $(XEN_ROOT)/tools/Rules.mk
    23.6 +
    23.7 +CFLAGS   += -static
    23.8 +CFLAGS   += -Wall
    23.9 +CFLAGS   += -Werror
   23.10 +CFLAGS   += -O3
   23.11 +CFLAGS   += -fno-strict-aliasing
   23.12 +CFLAGS   += -I.
   23.13 +
   23.14 +all: build
   23.15 +
   23.16 +build: mk-symlinks
   23.17 +	$(MAKE) xml_to_bin
   23.18 +
   23.19 +default: all
   23.20 +
   23.21 +install: all
   23.22 +
   23.23 +xml_to_bin : make_include XmlToBin.java XmlToBinInterface.java SsidsEntry.java SecurityLabel.java myHandler.java
   23.24 +	javac XmlToBin.java
   23.25 +
   23.26 +make_include : c2j_include
   23.27 +	./c2j_include
   23.28 +
   23.29 +c2j_include: c2j_include.c
   23.30 +	$(CC) $(CPPFLAGS) $(CFLAGS) -o $@ $<
   23.31 +
   23.32 +clean:
   23.33 +	rm -rf *.class xen c2j_include policy_version.java *.bin
   23.34 +
   23.35 +
   23.36 +LINUX_ROOT := $(XEN_ROOT)/linux-2.6-xen-sparse
   23.37 +mk-symlinks:
   23.38 +	[ -e xen/linux ] || mkdir -p xen/linux
   23.39 +	[ -e xen/io ]    || mkdir -p xen/io
   23.40 +	( cd xen >/dev/null ; \
   23.41 +	  ln -sf ../$(XEN_ROOT)/xen/include/public/*.h . )
   23.42 +	( cd xen/io >/dev/null ; \
   23.43 +	  ln -sf ../../$(XEN_ROOT)/xen/include/public/io/*.h . )
   23.44 +	( cd xen/linux >/dev/null ; \
   23.45 +	  ln -sf ../../$(LINUX_ROOT)/include/asm-xen/linux-public/*.h . )
    24.1 --- a/tools/misc/policyprocessor/XmlToBin.java	Tue Aug 02 17:12:36 2005 +0000
    24.2 +++ b/tools/misc/policyprocessor/XmlToBin.java	Tue Aug 02 17:13:11 2005 +0000
    24.3 @@ -5,6 +5,9 @@
    24.4   *
    24.5   * Author: Ray Valdez
    24.6   *
    24.7 + * Contributors:
    24.8 + *         Reiner Sailer - adjust type-lengths
    24.9 + *
   24.10   * This program is free software; you can redistribute it and/or
   24.11   * modify it under the terms of the GNU General Public License as
   24.12   * published by the Free Software Foundation, version 2 of the
   24.13 @@ -490,175 +493,139 @@ public class XmlToBin
   24.14  	
   24.15  
   24.16    try {
   24.17 -	/* Write magic */
   24.18 -	writeIntToStream(binBuffer,ACM_MAGIC,index);
   24.19 -	index = u32Size;
   24.20 +	  index = 0;
   24.21 +	  /* fill in General Policy Version */
   24.22 +	  writeIntToStream(binBuffer, ACM_POLICY_VERSION, index);
   24.23 +	  index += u32Size;
   24.24  
   24.25 -	/* Write policy version */
   24.26 -	writeIntToStream(binBuffer,POLICY_INTERFACE_VERSION,index);
   24.27 -  	index = index + u32Size;
   24.28 +	  /* Write magic */
   24.29 +	  writeIntToStream(binBuffer, ACM_MAGIC, index);
   24.30 +	  index += u32Size;
   24.31  
   24.32 -	/* write len */
   24.33 -	writeIntToStream(binBuffer,binBuffer.length,index);
   24.34 -  	index = index + u32Size;
   24.35 +	  /* write len */
   24.36 +	  writeIntToStream(binBuffer, binBuffer.length, index);
   24.37 +	  index += u32Size;
   24.38  
   24.39    } catch (IOException ee) {
   24.40 -    	System.out.println(" GBPB:: got exception : " + ee); 
   24.41 -	return null;
   24.42 +	  System.out.println(" GBPB:: got exception : " + ee);
   24.43 +	  return null;
   24.44    }
   24.45  
   24.46    int offset, address;
   24.47    address = index;
   24.48  
   24.49    if (null != partMap) 
   24.50 -	offset = binaryBufferHeaderSz + resourceOffsetSz; 
   24.51 +	  offset = binaryBufferHeaderSz + resourceOffsetSz;
   24.52    else
   24.53 -	offset = binaryBufferHeaderSz; 
   24.54 +	  offset = binaryBufferHeaderSz;
   24.55  
   24.56    try {
   24.57 -
   24.58 -	if (null == chwPolicy || null == stePolicy) 
   24.59 -	{
   24.60 -	  writeShortToStream(binBuffer,ACM_NULL_POLICY,index);
   24.61 -  	  index = index + u16Size;
   24.62 -
   24.63 -	  writeShortToStream(binBuffer,(short) 0,index);
   24.64 -  	  index = index + u16Size;
   24.65 -
   24.66 -	  writeShortToStream(binBuffer,ACM_NULL_POLICY,index);
   24.67 -  	  index = index + u16Size;
   24.68 -
   24.69 -	  writeShortToStream(binBuffer,(short) 0,index);
   24.70 -  	  index = index + u16Size;
   24.71 +	  int skip = 0;
   24.72  
   24.73 -	}
   24.74 -    	index = address;
   24.75 -	if (null != chwPolicy) 
   24.76 -	{
   24.77 +	  /* init with NULL policy setting */
   24.78 +	  writeIntToStream(binBuffer, ACM_NULL_POLICY, index);
   24.79 +	  writeIntToStream(binBuffer, 0, index + u32Size);
   24.80 +	  writeIntToStream(binBuffer, ACM_NULL_POLICY, index + 2*u32Size);
   24.81 +	  writeIntToStream(binBuffer, 0, index + 3*u32Size);
   24.82  	  
   24.83 -	  /* Write policy name */
   24.84 -	  writeShortToStream(binBuffer,ACM_CHINESE_WALL_POLICY,index);
   24.85 -  	  index = index + u16Size;
   24.86 +	  index = address;
   24.87 +	  if (null != chwPolicy) {
   24.88 +	  
   24.89 +		  /* Write policy name */
   24.90 +		  writeIntToStream(binBuffer, ACM_CHINESE_WALL_POLICY, index);
   24.91 +		  index += u32Size;
   24.92  
   24.93 -	  /* Write offset */
   24.94 -	  writeShortToStream(binBuffer,(short) offset,index);
   24.95 -  	  index = index + u16Size;
   24.96 +		  /* Write offset */
   24.97 +		  writeIntToStream(binBuffer, offset, index);
   24.98 +		  index += u32Size;
   24.99  
  24.100 -	  /* Write payload. No need increment index */
  24.101 -	  address = offset;
  24.102 -	  System.arraycopy(chwPolicy, 0, binBuffer,address, chwPolicy.length);
  24.103 -	  address = address + chwPolicy.length;
  24.104 -	  
  24.105 +		  /* Write payload. No need increment index */
  24.106 +		  address = offset;
  24.107 +		  System.arraycopy(chwPolicy, 0, binBuffer,address, chwPolicy.length);
  24.108 +		  address = address + chwPolicy.length;
  24.109 +	  } else
  24.110 +		  skip += 2*u32Size;
  24.111 +
  24.112  	  if (null != stePolicy) 
  24.113  	  {	
  24.114  	  	/* Write policy name */
  24.115 -	  	writeShortToStream(binBuffer,ACM_SIMPLE_TYPE_ENFORCEMENT_POLICY,index);
  24.116 -  	  	index = index + u16Size;
  24.117 +	  	writeIntToStream(binBuffer, ACM_SIMPLE_TYPE_ENFORCEMENT_POLICY, index);
  24.118 +  	  	index += u32Size;
  24.119  
  24.120  	  	/* Write offset */
  24.121 -	  	writeShortToStream(binBuffer,(short) address,index);
  24.122 -  	  	index = index + u16Size;
  24.123 +	  	writeIntToStream(binBuffer, address, index);
  24.124 +  	  	index += u32Size;
  24.125  
  24.126  		/* Copy array */
  24.127  	  	System.arraycopy(stePolicy, 0, binBuffer,address, stePolicy.length);
  24.128  		/* Update address */
  24.129  		address = address + stePolicy.length;
  24.130 -	  } else {
  24.131 -	  	/* Skip writing policy name and offset */
  24.132 -  	  	index = index +  2 * u16Size;
  24.133 +	  } else
  24.134 +		 skip += 2*u32Size;
  24.135  
  24.136 -          }
  24.137 +	  /* Skip writing policy name and offset for each null policy*/
  24.138 +	  index +=  skip;
  24.139  
  24.140 -	} else {
  24.141 +	  int size;
  24.142 +	  /* Assumes that you will always have a partition defined in policy */
  24.143 +	  if ( 0 < partMap.length) {
  24.144 +		  writeIntToStream(binBuffer, address, index);
  24.145 +		  index = address;
  24.146  
  24.147 -	  if (null != stePolicy) 
  24.148 -	  {	
  24.149 -	  	/* Write policy name */
  24.150 -	  	writeShortToStream(binBuffer,ACM_SIMPLE_TYPE_ENFORCEMENT_POLICY,index);
  24.151 -  	  	index = index + u16Size;
  24.152 +		  /* Compute num of VMs */
  24.153 +		  size = partMap.length / (3 * u16Size);
  24.154  
  24.155 -	  	/* Write offset */
  24.156 -		address = offset;
  24.157 -	  	writeShortToStream(binBuffer, (short) offset,index);
  24.158 -  	  	index = index + u16Size;
  24.159 -		
  24.160 -		/* Copy array */
  24.161 -	  	System.arraycopy(stePolicy, 0, binBuffer,address, stePolicy.length);
  24.162 -		/* Update address */
  24.163 -		address = address + stePolicy.length;
  24.164 +		  writeShortToStream(binBuffer, (short)size,index);
  24.165 +		  index = index + u16Size;
  24.166  
  24.167 -		/* Increment index, since there is no secondary */
  24.168 -  	  	index = index + secondaryPolicyCodeSz + secondaryBufferOffsetSz;
  24.169 -		
  24.170 -	  } 
  24.171 +		  /* part, vlan and slot: each one consists of two entries */
  24.172 +		  offset = 3 * (2 * u16Size);
  24.173 +		  writeShortToStream(binBuffer, (short) offset,index);
  24.174  
  24.175 -	}
  24.176 -   	int size;
  24.177 -	/* Assumes that you will always have a partition defined in policy */ 
  24.178 -	if ( 0 < partMap.length)
  24.179 -	{
  24.180 -	  writeShortToStream(binBuffer, (short) address,index);
  24.181 -	  index = address;
  24.182 +		  /* Write partition array at offset */
  24.183 +		  System.arraycopy(partMap, 0, binBuffer,(offset + address), partMap.length);
  24.184 +		  index = index + u16Size;
  24.185 +		  offset = offset + partMap.length;
  24.186 +	  }
  24.187  
  24.188 -	  /* Compute num of VMs */
  24.189 -	  size = partMap.length / (3 * u16Size);
  24.190 -
  24.191 -	  writeShortToStream(binBuffer, (short)size,index);
  24.192 -  	  index = index + u16Size;
  24.193 -
  24.194 -	  /* part, vlan and slot: each one consists of two entries */
  24.195 -	  offset = 3 * (2 * u16Size); 
  24.196 -	  writeShortToStream(binBuffer, (short) offset,index);
  24.197 +	  if ( 0 < vlanMap.length) {
  24.198 +		  size = vlanMap.length / (2 * u16Size);
  24.199 +		  writeShortToStream(binBuffer, (short) size,index);
  24.200 +		  index = index + u16Size;
  24.201  
  24.202 -	  /* Write partition array at offset */
  24.203 -	  System.arraycopy(partMap, 0, binBuffer,(offset + address), partMap.length);
  24.204 -  	  index = index + u16Size;
  24.205 -	  offset = offset + partMap.length;
  24.206 -	}
  24.207 -
  24.208 -	if ( 0 < vlanMap.length)
  24.209 -	{
  24.210 -	  size = vlanMap.length / (2 * u16Size);
  24.211 -	  writeShortToStream(binBuffer, (short) size,index);
  24.212 -  	  index = index + u16Size;
  24.213 -
  24.214 -	  writeShortToStream(binBuffer, (short) offset,index);
  24.215 -  	  index = index + u16Size;
  24.216 -	  System.arraycopy(vlanMap, 0, binBuffer,(offset + address), vlanMap.length);
  24.217 -	} else {
  24.218 -	  /* Write vlan max */
  24.219 -	  writeShortToStream(binBuffer, (short) 0,index);
  24.220 -  	  index = index + u16Size;
  24.221 +		  writeShortToStream(binBuffer, (short) offset,index);
  24.222 +		  index = index + u16Size;
  24.223 +		  System.arraycopy(vlanMap, 0, binBuffer,(offset + address), vlanMap.length);
  24.224 +	  } else {
  24.225 +		  /* Write vlan max */
  24.226 +		  writeShortToStream(binBuffer, (short) 0,index);
  24.227 +		  index = index + u16Size;
  24.228   
  24.229 -	  /* Write vlan offset */
  24.230 -	  writeShortToStream(binBuffer, (short) 0,index);
  24.231 -  	  index = index + u16Size;
  24.232 -	  
  24.233 -   	}
  24.234 +		  /* Write vlan offset */
  24.235 +		  writeShortToStream(binBuffer, (short) 0,index);
  24.236 +		  index = index + u16Size;
  24.237 +	  }
  24.238  
  24.239 -	offset = offset + vlanMap.length;
  24.240 -	if ( 0 < slotMap.length)
  24.241 -	{
  24.242 -	  size = slotMap.length / (3 * u16Size);
  24.243 -	  writeShortToStream(binBuffer, (short) size,index);
  24.244 -  	  index = index + u16Size;
  24.245 +	  offset = offset + vlanMap.length;
  24.246 +	  if ( 0 < slotMap.length) {
  24.247 +		  size = slotMap.length / (3 * u16Size);
  24.248 +		  writeShortToStream(binBuffer, (short) size,index);
  24.249 +		  index = index + u16Size;
  24.250  
  24.251 -	  writeShortToStream(binBuffer, (short) offset,index);
  24.252 -  	  index = index + u16Size;
  24.253 -	  System.arraycopy(slotMap, 0, binBuffer,(offset + address), slotMap.length);
  24.254 -	}
  24.255 +		  writeShortToStream(binBuffer, (short) offset,index);
  24.256 +		  index = index + u16Size;
  24.257 +		  System.arraycopy(slotMap, 0, binBuffer,(offset + address), slotMap.length);
  24.258 +	  }
  24.259 +  } catch (IOException ee) {
  24.260 +	  System.out.println(" GBPB:: got exception : " + ee);
  24.261 +	  return null;
  24.262 +  }
  24.263  
  24.264 -     } catch (IOException ee)
  24.265 -    {
  24.266 -    	System.out.println(" GBPB:: got exception : " + ee); 
  24.267 -	return null; 
  24.268 -    }
  24.269 +  printDebug(" GBP:: Binary Policy ==> length " + binBuffer.length);
  24.270 +  if (debug)
  24.271 +	  printHex(binBuffer,binBuffer.length);
  24.272  
  24.273 -    printDebug(" GBP:: Binary Policy ==> length " + binBuffer.length); 
  24.274 -    if (debug) 
  24.275 -   	printHex(binBuffer,binBuffer.length);
  24.276 -
  24.277 -   return  binBuffer;   
  24.278 +  return  binBuffer;
  24.279   } 
  24.280  
  24.281   public  byte[] generateChwBuffer(Vector Ssids, Vector ConflictSsids, Vector ColorTypes)
  24.282 @@ -668,28 +635,20 @@ public class XmlToBin
  24.283    int position = 0;
  24.284  
  24.285    /* Get number of rTypes */
  24.286 -  short maxTypes = (short) ColorTypes.size();
  24.287 +  int maxTypes = ColorTypes.size();
  24.288  
  24.289    /* Get number of SSids entry */
  24.290 -  short maxSsids = (short) Ssids.size();
  24.291 +  int maxSsids = Ssids.size();
  24.292  
  24.293    /* Get number of conflict sets */
  24.294 -  short maxConflict = (short) ConflictSsids.size();
  24.295 +  int maxConflict = ConflictSsids.size();
  24.296  
  24.297     
  24.298    if (maxTypes * maxSsids == 0)
  24.299  	return null; 
  24.300    /*
  24.301 -     data structure acm_chwall_policy_buffer_t;
  24.302 -    
  24.303 -     uint16 policy_code;
  24.304 -     uint16 chwall_max_types;
  24.305 -     uint16 chwall_max_ssidrefs;
  24.306 -     uint16 chwall_max_conflictsets;
  24.307 -     uint16 chwall_ssid_offset;
  24.308 -     uint16 chwall_conflict_sets_offset;
  24.309 -     uint16 chwall_running_types_offset;
  24.310 -     uint16 chwall_conflict_aggregate_offset;
  24.311 +     data structure acm_chwall_policy_buffer
  24.312 +     se XmlToBinInterface.java
  24.313    */
  24.314    int totalBytes = chwHeaderSize  + u16Size *(maxTypes * (maxSsids + maxConflict)); 
  24.315  
  24.316 @@ -699,34 +658,38 @@ public class XmlToBin
  24.317    printDebug(" gCB:: chwall totalbytes : "+totalBytes); 
  24.318  
  24.319    try {
  24.320 -	index = 0;
  24.321 -	writeShortToStream(chwBuffer,ACM_CHINESE_WALL_POLICY,index);
  24.322 -	index = u16Size; 
  24.323 +	  index = 0;
  24.324 +	  /* fill in General Policy Version */
  24.325 +	  writeIntToStream(chwBuffer, ACM_CHWALL_VERSION, index);
  24.326 +	  index += u32Size;
  24.327  
  24.328 -	writeShortToStream(chwBuffer,maxTypes,index);
  24.329 -	index = index + u16Size; 
  24.330 +	  writeIntToStream(chwBuffer, ACM_CHINESE_WALL_POLICY, index);
  24.331 +	  index += u32Size;
  24.332  
  24.333 -	writeShortToStream(chwBuffer,maxSsids,index);
  24.334 -	index = index + u16Size; 
  24.335 +	  writeIntToStream(chwBuffer, maxTypes, index);
  24.336 +	  index += u32Size;
  24.337  
  24.338 -	writeShortToStream(chwBuffer,maxConflict,index);
  24.339 -	index = index + u16Size; 
  24.340 +	  writeIntToStream(chwBuffer, maxSsids, index);
  24.341 +	  index += u32Size;
  24.342  
  24.343 -        /*  Write chwall_ssid_offset */
  24.344 -	writeShortToStream(chwBuffer,chwHeaderSize,index);
  24.345 -	index = index + u16Size; 
  24.346 +	  writeIntToStream(chwBuffer, maxConflict, index);
  24.347 +	  index += u32Size;
  24.348  
  24.349 -	/* Write chwall_conflict_sets_offset */
  24.350 -	writeShortToStream(chwBuffer,(short) address,index);
  24.351 -	index = index + u16Size; 
  24.352 +	  /*  Write chwall_ssid_offset */
  24.353 +	  writeIntToStream(chwBuffer, chwHeaderSize, index);
  24.354 +	  index += u32Size;
  24.355  
  24.356 -	/*  Write chwall_running_types_offset */
  24.357 -	writeShortToStream(chwBuffer,(short) 0,index);
  24.358 -	index = index + u16Size; 
  24.359 +	  /* Write chwall_conflict_sets_offset */
  24.360 +	  writeIntToStream(chwBuffer, address, index);
  24.361 +	  index += u32Size;
  24.362  
  24.363 -	/*  Write chwall_conflict_aggregate_offset */
  24.364 -	writeShortToStream(chwBuffer,(short) 0,index);
  24.365 -	index = index + u16Size; 
  24.366 +	  /*  Write chwall_running_types_offset */
  24.367 +	  writeIntToStream(chwBuffer, 0, index);
  24.368 +	  index += u32Size;
  24.369 +
  24.370 +	  /*  Write chwall_conflict_aggregate_offset */
  24.371 +	  writeIntToStream(chwBuffer, 0, index);
  24.372 +	  index += u32Size;
  24.373  
  24.374    } catch (IOException ee) {
  24.375      	System.out.println(" gCB:: got exception : " + ee); 
  24.376 @@ -737,7 +700,6 @@ public class XmlToBin
  24.377    /* Create the SSids entry */
  24.378    for (int i = 0; i < maxSsids; i++)
  24.379    {
  24.380 -	
  24.381  	SecurityLabel ssidEntry = (SecurityLabel) Ssids.elementAt(i);
  24.382     	/* Get chwall types */
  24.383  	ssidEntry.chwSsidPosition = i;
  24.384 @@ -821,22 +783,16 @@ public class XmlToBin
  24.385    int position = 0;
  24.386  
  24.387    /* Get number of colorTypes */
  24.388 -  short numColorTypes = (short) ColorTypes.size();
  24.389 +  int numColorTypes = ColorTypes.size();
  24.390  
  24.391    /* Get number of SSids entry */
  24.392 -  short numSsids = (short) Ssids.size();
  24.393 +  int numSsids = Ssids.size();
  24.394     
  24.395    if (numColorTypes * numSsids == 0)
  24.396  	return null; 
  24.397  
  24.398 -  /* data structure: acm_ste_policy_buffer_t
  24.399 -   * 
  24.400 -   * policy code  (uint16)    >
  24.401 -   *  max_types    (uint16)    >
  24.402 -   * max_ssidrefs (uint16)    >  steHeaderSize
  24.403 -   * ssid_offset  (uint16)    >
  24.404 -   * DATA 	(colorTypes(size) * Ssids(size) *unit16)
  24.405 -   * 
  24.406 +  /* data structure: acm_ste_policy_buffer
  24.407 +   * see XmlToBinInterface.java
  24.408     * total bytes: steHeaderSize * 2B + colorTypes(size) * Ssids(size)
  24.409     * 
  24.410    */
  24.411 @@ -844,18 +800,22 @@ public class XmlToBin
  24.412  
  24.413    try {
  24.414  	
  24.415 -	index = 0;
  24.416 -	writeShortToStream(steBuffer,ACM_SIMPLE_TYPE_ENFORCEMENT_POLICY,index);
  24.417 -	index = u16Size; 
  24.418 +	  index = 0;
  24.419 +	  writeIntToStream(steBuffer, ACM_STE_VERSION, index);
  24.420 +	  index += u32Size;
  24.421 +
  24.422 +	  writeIntToStream(steBuffer, ACM_SIMPLE_TYPE_ENFORCEMENT_POLICY, index);
  24.423 +	  index += u32Size;
  24.424  
  24.425 -	writeShortToStream(steBuffer,numColorTypes,index);
  24.426 -	index = index + u16Size; 
  24.427 +	  writeIntToStream(steBuffer, numColorTypes, index);
  24.428 +	  index += u32Size;
  24.429  
  24.430 -	writeShortToStream(steBuffer,numSsids,index);
  24.431 -	index = index + u16Size; 
  24.432 +	  writeIntToStream(steBuffer, numSsids, index);
  24.433 +	  index += u32Size;
  24.434  
  24.435 -	writeShortToStream(steBuffer,(short)steHeaderSize,index);
  24.436 -	index = index + u16Size; 
  24.437 +	  writeIntToStream(steBuffer, steHeaderSize, index);
  24.438 +	  index += u32Size;
  24.439 +
  24.440  
  24.441    } catch (IOException ee) {
  24.442  	System.out.println(" gSB:: got exception : " + ee); 
  24.443 @@ -1469,6 +1429,17 @@ public class XmlToBin
  24.444  
  24.445    XmlToBin genObj = new XmlToBin(); 
  24.446  
  24.447 +  policy_version active_policy = new policy_version();
  24.448 +
  24.449 +  if ((active_policy.ACM_POLICY_VERSION != ACM_POLICY_VERSION) ||
  24.450 +      (active_policy.ACM_CHWALL_VERSION != ACM_CHWALL_VERSION) ||
  24.451 +      (active_policy.ACM_STE_VERSION != ACM_STE_VERSION)) {
  24.452 +	  System.out.println("ACM policy versions differ.");
  24.453 +	  System.out.println("Please verify that data structures are correct");
  24.454 +	  System.out.println("and then adjust the version numbers in XmlToBinInterface.java.");
  24.455 +	  return;
  24.456 +  }
  24.457 +
  24.458  
  24.459    for (int i = 0 ; i < args.length ; i++) {
  24.460  
    25.1 --- a/tools/misc/policyprocessor/XmlToBinInterface.java	Tue Aug 02 17:12:36 2005 +0000
    25.2 +++ b/tools/misc/policyprocessor/XmlToBinInterface.java	Tue Aug 02 17:13:11 2005 +0000
    25.3 @@ -19,37 +19,37 @@
    25.4   *
    25.5   *	policy binary structures
    25.6   *
    25.7 - *	typedef struct {
    25.8 - *        u32 magic;
    25.9 - *
   25.10 - *        u32 policyversion;
   25.11 - *        u32 len;
   25.12 + * struct acm_policy_buffer {
   25.13 + *	u32 policy_version; * ACM_POLICY_VERSION *
   25.14 + *      u32 magic;
   25.15 + *	u32 len;
   25.16 + *	u32 primary_policy_code;
   25.17 + *	u32 primary_buffer_offset;
   25.18 + *	u32 secondary_policy_code;
   25.19 + *	u32 secondary_buffer_offset;
   25.20 + *      +u32 resource offset (not used yet in Xen)
   25.21 + * };
   25.22   *
   25.23 - *        u16 primary_policy_code;
   25.24 - *        u16 primary_buffer_offset;
   25.25 - *        u16 secondary_policy_code;
   25.26 - *        u16 secondary_buffer_offset;
   25.27 - *	u16 resource_offset;
   25.28 - *
   25.29 - *	} acm_policy_buffer_t;
   25.30   *
   25.31 - *	typedef struct {
   25.32 - *        u16 policy_code;
   25.33 - *        u16 ste_max_types;
   25.34 - *        u16 ste_max_ssidrefs;
   25.35 - *        u16 ste_ssid_offset;
   25.36 - *	} acm_ste_policy_buffer_t;
   25.37 + * struct acm_ste_policy_buffer {
   25.38 + *	u32 policy_version; * ACM_STE_VERSION *
   25.39 + *	u32 policy_code;
   25.40 + *	u32 ste_max_types;
   25.41 + *	u32 ste_max_ssidrefs;
   25.42 + *	u32 ste_ssid_offset;
   25.43 + * };
   25.44   *
   25.45 - *  	typedef struct {
   25.46 - *        uint16 policy_code;
   25.47 - *        uint16 chwall_max_types;
   25.48 - *        uint16 chwall_max_ssidrefs;
   25.49 - *        uint16 chwall_max_conflictsets;
   25.50 - *        uint16 chwall_ssid_offset;
   25.51 - *        uint16 chwall_conflict_sets_offset;
   25.52 - *        uint16 chwall_running_types_offset;
   25.53 - *        uint16 chwall_conflict_aggregate_offset;
   25.54 - *	} acm_chwall_policy_buffer_t;
   25.55 + * struct acm_chwall_policy_buffer {
   25.56 + *	u32 policy_version; * ACM_CHWALL_VERSION *
   25.57 + *	u32 policy_code;
   25.58 + *	u32 chwall_max_types;
   25.59 + *	u32 chwall_max_ssidrefs;
   25.60 + *	u32 chwall_max_conflictsets;
   25.61 + *	u32 chwall_ssid_offset;
   25.62 + *	u32 chwall_conflict_sets_offset;
   25.63 + *	u32 chwall_running_types_offset;
   25.64 + *	u32 chwall_conflict_aggregate_offset;
   25.65 + * };
   25.66   *
   25.67   *	typedef struct {
   25.68   *	u16 partition_max;
   25.69 @@ -100,16 +100,17 @@ public interface XmlToBinInterface
   25.70    final int u16Size = 2;
   25.71  
   25.72    /* num of bytes for acm_ste_policy_buffer_t */
   25.73 -  final short steHeaderSize = (4 * u16Size); 
   25.74 +  final int steHeaderSize = (5 * u32Size);
   25.75 +
   25.76    /* byte for acm_chinese_wall_policy_buffer_t */
   25.77 -  final short chwHeaderSize = (8 * u16Size); 
   25.78 +  final int chwHeaderSize = (9 * u32Size);
   25.79  
   25.80 -  final short primaryPolicyCodeSize = u16Size;
   25.81 -  final short primaryBufferOffsetSize = u16Size ;
   25.82 +  final int primaryPolicyCodeSize = u32Size;
   25.83 +  final int primaryBufferOffsetSize = u32Size ;
   25.84  
   25.85 -  final int secondaryPolicyCodeSz = u16Size;
   25.86 -  final int secondaryBufferOffsetSz = u16Size;
   25.87 -  final short resourceOffsetSz = u16Size;
   25.88 +  final int secondaryPolicyCodeSz = u32Size;
   25.89 +  final int secondaryBufferOffsetSz = u32Size;
   25.90 +  final int resourceOffsetSz = u32Size;
   25.91  
   25.92    final short partitionBufferSz = (2 * u16Size);
   25.93    final short partitionEntrySz = (3 * u16Size);
   25.94 @@ -120,16 +121,18 @@ public interface XmlToBinInterface
   25.95    final short vlanBufferSz = (2 * u16Size);
   25.96    final short vlanEntrySz = (2 * u16Size);
   25.97  
   25.98 -  final short binaryBufferHeaderSz = (3 * u32Size + 4* u16Size);
   25.99 -
  25.100 -  /* copied directlty from policy_ops.h */
  25.101 -  final int POLICY_INTERFACE_VERSION = 0xAAAA0003;
  25.102 +  final int binaryBufferHeaderSz = (8 * u32Size); /* 8th not used in Xen */
  25.103  
  25.104    /* copied directly from acm.h */
  25.105    final int ACM_MAGIC  =  0x0001debc;
  25.106 -  final short ACM_NULL_POLICY = 0;
  25.107 -  final short ACM_CHINESE_WALL_POLICY = 1;
  25.108 -  final short ACM_SIMPLE_TYPE_ENFORCEMENT_POLICY = 2;
  25.109 -  final short ACM_CHINESE_WALL_AND_SIMPLE_TYPE_ENFORCEMENT_POLICY = 3;
  25.110 -  final short ACM_EMPTY_POLICY = 4;
  25.111 +  final int ACM_NULL_POLICY = 0;
  25.112 +  final int ACM_CHINESE_WALL_POLICY = 1;
  25.113 +  final int ACM_SIMPLE_TYPE_ENFORCEMENT_POLICY = 2;
  25.114 +  final int ACM_CHINESE_WALL_AND_SIMPLE_TYPE_ENFORCEMENT_POLICY = 3;
  25.115 +  final int ACM_EMPTY_POLICY = 4;
  25.116 +
  25.117 +  /* version for compatibility check */
  25.118 +  final int ACM_POLICY_VERSION = 1;
  25.119 +  final int ACM_STE_VERSION    = 1;
  25.120 +  final int ACM_CHWALL_VERSION = 1;
  25.121  }
    26.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    26.2 +++ b/tools/misc/policyprocessor/c2j_include.c	Tue Aug 02 17:13:11 2005 +0000
    26.3 @@ -0,0 +1,57 @@
    26.4 +/****************************************************************
    26.5 + * c2j_include.c
    26.6 + *
    26.7 + * Copyright (C) 2005 IBM Corporation
    26.8 + *
    26.9 + * Authors:
   26.10 + * Reiner Sailer <sailer@watson.ibm.com>
   26.11 + *
   26.12 + * This program is free software; you can redistribute it and/or
   26.13 + * modify it under the terms of the GNU General Public License as
   26.14 + * published by the Free Software Foundation, version 2 of the
   26.15 + * License.
   26.16 + *
   26.17 + * This tool makes some constants from acm.h available to the
   26.18 + * java policyprocessor for version checking.
   26.19 + */
   26.20 +#include <stdio.h>
   26.21 +#include <errno.h>
   26.22 +#include <stdlib.h>
   26.23 +#include <stdint.h>
   26.24 +
   26.25 +typedef uint8_t  u8;
   26.26 +typedef uint16_t u16;
   26.27 +typedef uint32_t u32;
   26.28 +typedef uint64_t u64;
   26.29 +typedef int8_t   s8;
   26.30 +typedef int16_t  s16;
   26.31 +typedef int32_t  s32;
   26.32 +typedef int64_t  s64;
   26.33 +
   26.34 +#include <xen/acm.h>
   26.35 +
   26.36 +char *filename = "policy_version.java";
   26.37 +
   26.38 +int main(int argc, char **argv)
   26.39 +{
   26.40 +
   26.41 +    FILE *fd;
   26.42 +    if ((fd = fopen(filename, "w")) <= 0)
   26.43 +    {
   26.44 +        printf("File %s not found.\n", filename);
   26.45 +        exit(-ENOENT);
   26.46 +    }
   26.47 +
   26.48 +    fprintf(fd, "/*\n * This file was automatically generated\n");
   26.49 +    fprintf(fd, " * Do not change it manually!\n */\n");
   26.50 +    fprintf(fd, "public class policy_version {\n");
   26.51 +    fprintf(fd, "	final int ACM_POLICY_VERSION = %x;\n",
   26.52 +            ACM_POLICY_VERSION);
   26.53 +    fprintf(fd, "	final int ACM_CHWALL_VERSION = %x;\n",
   26.54 +            ACM_CHWALL_VERSION);
   26.55 +    fprintf(fd, "	final int ACM_STE_VERSION = %x;\n",
   26.56 +            ACM_STE_VERSION);
   26.57 +    fprintf(fd, "}\n");
   26.58 +    fclose(fd);
   26.59 +    return 0;
   26.60 +}
    27.1 --- a/tools/misc/policyprocessor/xen_sample_def.xml	Tue Aug 02 17:12:36 2005 +0000
    27.2 +++ b/tools/misc/policyprocessor/xen_sample_def.xml	Tue Aug 02 17:13:11 2005 +0000
    27.3 @@ -37,7 +37,7 @@ xsi:schemaLocation="http://www.ibm.com S
    27.4     </ConflictSet>
    27.5  
    27.6     <ConflictSet>
    27.7 -		 <ChWall>Q-Company</ChWall>
    27.8 +		 <ChWall>R-Company</ChWall>
    27.9  		 <ChWall>V-Company</ChWall>
   27.10  		 <ChWall>W-Company</ChWall>
   27.11     </ConflictSet>
    28.1 --- a/tools/policy/Makefile	Tue Aug 02 17:12:36 2005 +0000
    28.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    28.3 @@ -1,36 +0,0 @@
    28.4 -XEN_ROOT = ../..
    28.5 -include $(XEN_ROOT)/tools/Rules.mk
    28.6 -
    28.7 -SRCS     = policy_tool.c
    28.8 -CFLAGS   += -static
    28.9 -CFLAGS   += -Wall
   28.10 -CFLAGS   += -Werror
   28.11 -CFLAGS   += -O3
   28.12 -CFLAGS   += -fno-strict-aliasing
   28.13 -CFLAGS   += -I.
   28.14 -
   28.15 -all: build
   28.16 -build: mk-symlinks
   28.17 -	$(MAKE) policy_tool
   28.18 -
   28.19 -default: all
   28.20 -
   28.21 -install: all
   28.22 -
   28.23 -policy_tool : policy_tool.c
   28.24 -	$(CC) $(CPPFLAGS) $(CFLAGS) -o $@ $<
   28.25 -
   28.26 -clean:
   28.27 -	rm -rf policy_tool xen
   28.28 -
   28.29 -
   28.30 -LINUX_ROOT := $(XEN_ROOT)/linux-2.6-xen-sparse
   28.31 -mk-symlinks:
   28.32 -	[ -e xen/linux ] || mkdir -p xen/linux
   28.33 -	[ -e xen/io ]    || mkdir -p xen/io
   28.34 -	( cd xen >/dev/null ; \
   28.35 -	  ln -sf ../$(XEN_ROOT)/xen/include/public/*.h . )
   28.36 -	( cd xen/io >/dev/null ; \
   28.37 -	  ln -sf ../../$(XEN_ROOT)/xen/include/public/io/*.h . )
   28.38 -	( cd xen/linux >/dev/null ; \
   28.39 -	  ln -sf ../../$(LINUX_ROOT)/include/asm-xen/linux-public/*.h . )
    29.1 --- a/tools/policy/policy_tool.c	Tue Aug 02 17:12:36 2005 +0000
    29.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    29.3 @@ -1,552 +0,0 @@
    29.4 -/****************************************************************
    29.5 - * policy_tool.c
    29.6 - * 
    29.7 - * Copyright (C) 2005 IBM Corporation
    29.8 - *
    29.9 - * Authors:
   29.10 - * Reiner Sailer <sailer@watson.ibm.com>
   29.11 - * Stefan Berger <stefanb@watson.ibm.com>
   29.12 - *
   29.13 - * This program is free software; you can redistribute it and/or
   29.14 - * modify it under the terms of the GNU General Public License as
   29.15 - * published by the Free Software Foundation, version 2 of the
   29.16 - * License. 
   29.17 - *
   29.18 - * sHype policy management tool. This code runs in a domain and
   29.19 - *     manages the Xen security policy by interacting with the
   29.20 - *     Xen access control module via a /proc/xen/privcmd proc-ioctl, 
   29.21 - *     which is translated into a policy_op hypercall into Xen.
   29.22 - * 
   29.23 - * todo: implement setpolicy to dynamically set a policy cache.
   29.24 - */
   29.25 -#include <unistd.h>
   29.26 -#include <stdio.h>
   29.27 -#include <errno.h>
   29.28 -#include <fcntl.h>
   29.29 -#include <sys/mman.h>
   29.30 -#include <sys/types.h>
   29.31 -#include <sys/stat.h>
   29.32 -#include <stdlib.h>
   29.33 -#include <sys/ioctl.h>
   29.34 -#include <string.h>
   29.35 -#include <stdint.h>
   29.36 -#include <netinet/in.h>
   29.37 -
   29.38 -typedef uint8_t            u8;
   29.39 -typedef uint16_t           u16;
   29.40 -typedef uint32_t           u32;
   29.41 -typedef uint64_t           u64;
   29.42 -typedef int8_t             s8;
   29.43 -typedef int16_t            s16;
   29.44 -typedef int32_t            s32;
   29.45 -typedef int64_t            s64;
   29.46 -
   29.47 -#include <xen/acm.h>
   29.48 -
   29.49 -#include <xen/policy_ops.h>
   29.50 -
   29.51 -#include <xen/linux/privcmd.h>
   29.52 -
   29.53 -#define ERROR(_m, _a...)	\
   29.54 -	fprintf(stderr, "ERROR: " _m "\n" , ## _a )
   29.55 -
   29.56 -#define PERROR(_m, _a...) \
   29.57 -	fprintf(stderr, "ERROR: " _m " (%d = %s)\n" , ## _a ,	\
   29.58 -            errno, strerror(errno))
   29.59 -
   29.60 -static inline int do_policycmd(int xc_handle,
   29.61 -                             unsigned int cmd, 
   29.62 -                             unsigned long data)
   29.63 -{
   29.64 -    return ioctl(xc_handle, cmd, data);
   29.65 -}
   29.66 -
   29.67 -static inline int do_xen_hypercall(int xc_handle,
   29.68 -                                   privcmd_hypercall_t *hypercall)
   29.69 -{
   29.70 -    return do_policycmd(xc_handle,
   29.71 -                      IOCTL_PRIVCMD_HYPERCALL, 
   29.72 -                      (unsigned long)hypercall);
   29.73 -}
   29.74 -
   29.75 -static inline int do_policy_op(int xc_handle, policy_op_t *op)
   29.76 -{
   29.77 -    int ret = -1;
   29.78 -    privcmd_hypercall_t hypercall;
   29.79 -
   29.80 -    op->interface_version = POLICY_INTERFACE_VERSION;
   29.81 -
   29.82 -    hypercall.op     = __HYPERVISOR_policy_op;
   29.83 -    hypercall.arg[0] = (unsigned long)op;
   29.84 -
   29.85 -    if ( mlock(op, sizeof(*op)) != 0 )
   29.86 -    {
   29.87 -        PERROR("Could not lock memory for Xen policy hypercall");
   29.88 -        goto out1;
   29.89 -    }
   29.90 -
   29.91 -    if ( (ret = do_xen_hypercall(xc_handle, &hypercall)) < 0 )
   29.92 -    {
   29.93 -        if ( errno == EACCES )
   29.94 -            fprintf(stderr, "POLICY operation failed -- need to"
   29.95 -                    " rebuild the user-space tool set?\n");
   29.96 -        goto out2;
   29.97 -    }
   29.98 -
   29.99 - out2: (void)munlock(op, sizeof(*op));
  29.100 - out1: return ret;
  29.101 -}
  29.102 -
  29.103 -/*************************** DUMPS *******************************/
  29.104 -
  29.105 -void acm_dump_chinesewall_buffer(void *buf, int buflen) {
  29.106 -
  29.107 -	struct acm_chwall_policy_buffer *cwbuf = (struct acm_chwall_policy_buffer *)buf;
  29.108 -	domaintype_t *ssids, *conflicts, *running_types, *conflict_aggregate;
  29.109 -	int i,j;
  29.110 -
  29.111 -       
  29.112 -	if (htons(cwbuf->policy_code) != ACM_CHINESE_WALL_POLICY) {
  29.113 -		printf("CHINESE WALL POLICY CODE not found ERROR!!\n");
  29.114 -		return;
  29.115 -	}
  29.116 -	printf("\n\nChinese Wall policy:\n");
  29.117 -	printf("====================\n");
  29.118 -	printf("Max Types     = %x.\n", ntohs(cwbuf->chwall_max_types));
  29.119 -	printf("Max Ssidrefs  = %x.\n", ntohs(cwbuf->chwall_max_ssidrefs));
  29.120 -	printf("Max ConfSets  = %x.\n", ntohs(cwbuf->chwall_max_conflictsets));
  29.121 -	printf("Ssidrefs Off  = %x.\n", ntohs(cwbuf->chwall_ssid_offset));
  29.122 -	printf("Conflicts Off = %x.\n", ntohs(cwbuf->chwall_conflict_sets_offset));
  29.123 -	printf("Runing T. Off = %x.\n", ntohs(cwbuf->chwall_running_types_offset));
  29.124 -	printf("C. Agg. Off   = %x.\n", ntohs(cwbuf->chwall_conflict_aggregate_offset));
  29.125 -	printf("\nSSID To CHWALL-Type matrix:\n");
  29.126 -
  29.127 -	ssids = (domaintype_t *)(buf + ntohs(cwbuf->chwall_ssid_offset));
  29.128 -	for(i=0; i< ntohs(cwbuf->chwall_max_ssidrefs); i++) {
  29.129 -		printf("\n   ssidref%2x:  ", i);
  29.130 -		for(j=0; j< ntohs(cwbuf->chwall_max_types); j++)
  29.131 -			printf("%02x ", ntohs(ssids[i*ntohs(cwbuf->chwall_max_types) + j]));
  29.132 -	}
  29.133 -	printf("\n\nConfict Sets:\n");
  29.134 -	conflicts = (domaintype_t *)(buf + ntohs(cwbuf->chwall_conflict_sets_offset));
  29.135 -	for(i=0; i< ntohs(cwbuf->chwall_max_conflictsets); i++) {
  29.136 -		printf("\n   c-set%2x:    ", i);
  29.137 -		for(j=0; j< ntohs(cwbuf->chwall_max_types); j++)
  29.138 -			printf("%02x ", ntohs(conflicts[i*ntohs(cwbuf->chwall_max_types) +j]));
  29.139 -	}
  29.140 -	printf("\n");
  29.141 -
  29.142 -	printf("\nRunning\nTypes:         ");
  29.143 -	if (ntohs(cwbuf->chwall_running_types_offset)) {
  29.144 -		running_types = (domaintype_t *)(buf + ntohs(cwbuf->chwall_running_types_offset));
  29.145 -		for(i=0; i< ntohs(cwbuf->chwall_max_types); i++) {
  29.146 -			printf("%02x ", ntohs(running_types[i]));
  29.147 -		}
  29.148 -		printf("\n");
  29.149 -	} else {
  29.150 -		printf("Not Reported!\n");
  29.151 -	}
  29.152 -	printf("\nConflict\nAggregate Set: ");
  29.153 -	if (ntohs(cwbuf->chwall_conflict_aggregate_offset)) {
  29.154 -		conflict_aggregate = (domaintype_t *)(buf + ntohs(cwbuf->chwall_conflict_aggregate_offset));
  29.155 -		for(i=0; i< ntohs(cwbuf->chwall_max_types); i++) {
  29.156 -			printf("%02x ", ntohs(conflict_aggregate[i]));
  29.157 -		}
  29.158 -		printf("\n\n");
  29.159 -	} else {
  29.160 -		printf("Not Reported!\n");
  29.161 -	}
  29.162 -}
  29.163 -
  29.164 -void acm_dump_ste_buffer(void *buf, int buflen) {
  29.165 -
  29.166 -	struct acm_ste_policy_buffer *stebuf = (struct acm_ste_policy_buffer *)buf;
  29.167 -	domaintype_t *ssids;
  29.168 -	int i,j;
  29.169 -
  29.170 -       
  29.171 -	if (ntohs(stebuf->policy_code) != ACM_SIMPLE_TYPE_ENFORCEMENT_POLICY) {
  29.172 -		printf("SIMPLE TYPE ENFORCEMENT POLICY CODE not found ERROR!!\n");
  29.173 -		return;
  29.174 -	}
  29.175 -	printf("\nSimple Type Enforcement policy:\n");
  29.176 -	printf("===============================\n");
  29.177 -	printf("Max Types     = %x.\n", ntohs(stebuf->ste_max_types));
  29.178 -	printf("Max Ssidrefs  = %x.\n", ntohs(stebuf->ste_max_ssidrefs));
  29.179 -	printf("Ssidrefs Off  = %x.\n", ntohs(stebuf->ste_ssid_offset));
  29.180 -	printf("\nSSID To STE-Type matrix:\n");
  29.181 -	
  29.182 -	ssids = (domaintype_t *)(buf + ntohs(stebuf->ste_ssid_offset));
  29.183 -	for(i=0; i< ntohs(stebuf->ste_max_ssidrefs); i++) {
  29.184 -		printf("\n   ssidref%2x: ", i);
  29.185 -		for(j=0; j< ntohs(stebuf->ste_max_types); j++)
  29.186 -			printf("%02x ", ntohs(ssids[i*ntohs(stebuf->ste_max_types) +j]));
  29.187 -	}
  29.188 -	printf("\n\n");
  29.189 -}
  29.190 -
  29.191 -void acm_dump_policy_buffer(void *buf, int buflen) {
  29.192 -	struct acm_policy_buffer *pol = (struct acm_policy_buffer *)buf;
  29.193 -
  29.194 -	printf("\nPolicy dump:\n");
  29.195 -	printf("============\n");
  29.196 -	printf("Magic     = %x.\n", ntohl(pol->magic));
  29.197 -	printf("PolVer    = %x.\n", ntohl(pol->policyversion));
  29.198 -	printf("Len       = %x.\n", ntohl(pol->len));
  29.199 -	printf("Primary   = %s (c=%x, off=%x).\n",
  29.200 -	       ACM_POLICY_NAME(ntohs(pol->primary_policy_code)),
  29.201 -	       ntohs(pol->primary_policy_code), ntohs(pol->primary_buffer_offset));
  29.202 -	printf("Secondary = %s (c=%x, off=%x).\n",
  29.203 -	       ACM_POLICY_NAME(ntohs(pol->secondary_policy_code)),
  29.204 -	       ntohs(pol->secondary_policy_code), ntohs(pol->secondary_buffer_offset));
  29.205 -	switch (ntohs(pol->primary_policy_code)) {
  29.206 -	case ACM_CHINESE_WALL_POLICY:
  29.207 -		acm_dump_chinesewall_buffer(buf+ntohs(pol->primary_buffer_offset), 
  29.208 -					     ntohl(pol->len) - ntohs(pol->primary_buffer_offset));
  29.209 -		break;
  29.210 -	case ACM_SIMPLE_TYPE_ENFORCEMENT_POLICY:
  29.211 -		acm_dump_ste_buffer(buf+ntohs(pol->primary_buffer_offset), 
  29.212 -				    ntohl(pol->len) - ntohs(pol->primary_buffer_offset));
  29.213 -		break;
  29.214 -	case ACM_NULL_POLICY:
  29.215 -		printf("Primary policy is NULL Policy (n/a).\n");
  29.216 -		break;
  29.217 -	default:
  29.218 -		printf("UNKNOWN POLICY!\n");
  29.219 -	}
  29.220 -	switch (ntohs(pol->secondary_policy_code)) {
  29.221 -	case ACM_CHINESE_WALL_POLICY:
  29.222 -		acm_dump_chinesewall_buffer(buf+ntohs(pol->secondary_buffer_offset), 
  29.223 -					     ntohl(pol->len) - ntohs(pol->secondary_buffer_offset));
  29.224 -		break;
  29.225 -	case ACM_SIMPLE_TYPE_ENFORCEMENT_POLICY:
  29.226 -		acm_dump_ste_buffer(buf+ntohs(pol->secondary_buffer_offset), 
  29.227 -				    ntohl(pol->len) - ntohs(pol->secondary_buffer_offset));
  29.228 -		break;
  29.229 -	case ACM_NULL_POLICY:
  29.230 -		printf("Secondary policy is NULL Policy (n/a).\n");
  29.231 -		break;
  29.232 -	default:
  29.233 -		printf("UNKNOWN POLICY!\n");
  29.234 -	}
  29.235 -}
  29.236 -
  29.237 -/*************************** set policy ****************************/
  29.238 -
  29.239 -int acm_domain_set_chwallpolicy(void *bufstart, int buflen) {
  29.240 -#define CWALL_MAX_SSIDREFS      	6
  29.241 -#define CWALL_MAX_TYPES  		10
  29.242 -#define CWALL_MAX_CONFLICTSETS		2
  29.243 -
  29.244 -     struct acm_chwall_policy_buffer *chwall_bin_pol = (struct acm_chwall_policy_buffer *)bufstart;
  29.245 -     domaintype_t *ssidrefs, *conflicts;
  29.246 -     int ret = 0;
  29.247 -     int j;
  29.248 -
  29.249 -     chwall_bin_pol->chwall_max_types = htons(CWALL_MAX_TYPES);
  29.250 -     chwall_bin_pol->chwall_max_ssidrefs = htons(CWALL_MAX_SSIDREFS);
  29.251 -     chwall_bin_pol->policy_code = htons(ACM_CHINESE_WALL_POLICY);
  29.252 -     chwall_bin_pol->chwall_ssid_offset = htons(sizeof(struct acm_chwall_policy_buffer));
  29.253 -     chwall_bin_pol->chwall_max_conflictsets = htons(CWALL_MAX_CONFLICTSETS);
  29.254 -     chwall_bin_pol->chwall_conflict_sets_offset =
  29.255 -	 htons(
  29.256 -	     ntohs(chwall_bin_pol->chwall_ssid_offset) + 
  29.257 -	     sizeof(domaintype_t)*CWALL_MAX_SSIDREFS*CWALL_MAX_TYPES);
  29.258 -     chwall_bin_pol->chwall_running_types_offset = 0; /* not set */
  29.259 -     chwall_bin_pol->chwall_conflict_aggregate_offset = 0; /* not set */
  29.260 -     ret += sizeof(struct acm_chwall_policy_buffer);
  29.261 -     /* now push example ssids into the buffer (max_ssidrefs x max_types entries) */
  29.262 -     /* check buffer size */
  29.263 -     if ((buflen - ret) < (CWALL_MAX_TYPES*CWALL_MAX_SSIDREFS*sizeof(domaintype_t)))
  29.264 -			   return -1; /* not enough space */
  29.265 -
  29.266 -     ssidrefs = (domaintype_t *)(bufstart+ntohs(chwall_bin_pol->chwall_ssid_offset));
  29.267 -     memset(ssidrefs, 0, CWALL_MAX_TYPES*CWALL_MAX_SSIDREFS*sizeof(domaintype_t));
  29.268 -
  29.269 -     /* now set type j-1 for ssidref i+1 */
  29.270 -     for(j=0; j<= CWALL_MAX_SSIDREFS; j++)
  29.271 -         if ((0 < j) &&( j <= CWALL_MAX_TYPES))
  29.272 -             ssidrefs[j*CWALL_MAX_TYPES + j - 1] = htons(1);
  29.273 -
  29.274 -     ret += CWALL_MAX_TYPES*CWALL_MAX_SSIDREFS*sizeof(domaintype_t);
  29.275 -     if ((buflen - ret) < (CWALL_MAX_CONFLICTSETS*CWALL_MAX_TYPES*sizeof(domaintype_t)))
  29.276 -			   return -1; /* not enough space */
  29.277 -
  29.278 -     /* now the chinese wall policy conflict sets*/
  29.279 -     conflicts = (domaintype_t *)(bufstart + 
  29.280 -				  ntohs(chwall_bin_pol->chwall_conflict_sets_offset));
  29.281 -     memset((void *)conflicts, 0, CWALL_MAX_CONFLICTSETS*CWALL_MAX_TYPES*sizeof(domaintype_t));
  29.282 -     /* just 1 conflict set [0]={2,3}, [1]={1,5,6} */
  29.283 -     if (CWALL_MAX_TYPES > 3) {
  29.284 -	     conflicts[2] = htons(1); conflicts[3] = htons(1); /* {2,3} */
  29.285 -	     conflicts[CWALL_MAX_TYPES+1] = htons(1); conflicts[CWALL_MAX_TYPES+5] = htons(1); 
  29.286 -	     conflicts[CWALL_MAX_TYPES+6] = htons(1);/* {0,5,6} */
  29.287 -     }
  29.288 -     ret += sizeof(domaintype_t)*CWALL_MAX_CONFLICTSETS*CWALL_MAX_TYPES;
  29.289 -     return ret;
  29.290 -}
  29.291 -
  29.292 -int acm_domain_set_stepolicy(void *bufstart, int buflen) {
  29.293 -#define STE_MAX_SSIDREFS        6
  29.294 -#define STE_MAX_TYPES  	        5
  29.295 -	
  29.296 -    struct acm_ste_policy_buffer *ste_bin_pol = (struct acm_ste_policy_buffer *)bufstart;
  29.297 -    domaintype_t *ssidrefs;
  29.298 -    int j, ret = 0;
  29.299 -
  29.300 -    ste_bin_pol->ste_max_types = htons(STE_MAX_TYPES);
  29.301 -    ste_bin_pol->ste_max_ssidrefs = htons(STE_MAX_SSIDREFS);
  29.302 -    ste_bin_pol->policy_code = htons(ACM_SIMPLE_TYPE_ENFORCEMENT_POLICY);
  29.303 -    ste_bin_pol->ste_ssid_offset = htons(sizeof(struct acm_ste_policy_buffer));
  29.304 -    ret += sizeof(struct acm_ste_policy_buffer);
  29.305 -    /* check buffer size */
  29.306 -    if ((buflen - ret) < (STE_MAX_TYPES*STE_MAX_SSIDREFS*sizeof(domaintype_t)))
  29.307 -	    return -1; /* not enough space */
  29.308 -
  29.309 -     ssidrefs = (domaintype_t *)(bufstart+ntohs(ste_bin_pol->ste_ssid_offset));
  29.310 -     memset(ssidrefs, 0, STE_MAX_TYPES*STE_MAX_SSIDREFS*sizeof(domaintype_t));
  29.311 -     /* all types 1 for ssidref 1 */
  29.312 -     for(j=0; j< STE_MAX_TYPES; j++)
  29.313 -	 ssidrefs[1*STE_MAX_TYPES +j] = htons(1);
  29.314 -     /* now set type j-1 for ssidref j */
  29.315 -     for(j=0; j< STE_MAX_SSIDREFS; j++)
  29.316 -	     if ((0 < j) &&( j <= STE_MAX_TYPES))
  29.317 -		     ssidrefs[j*STE_MAX_TYPES + j - 1] = htons(1);
  29.318 -     ret += STE_MAX_TYPES*STE_MAX_SSIDREFS*sizeof(domaintype_t);
  29.319 -     return ret;
  29.320 -}
  29.321 -
  29.322 -#define MAX_PUSH_BUFFER 	16384
  29.323 -u8 push_buffer[MAX_PUSH_BUFFER];
  29.324 -
  29.325 -int acm_domain_setpolicy(int xc_handle)
  29.326 -{
  29.327 -     int ret;
  29.328 -     struct acm_policy_buffer *bin_pol;
  29.329 -     policy_op_t op;
  29.330 -
  29.331 -     /* future: read policy from file and set it */
  29.332 -     bin_pol = (struct acm_policy_buffer *)push_buffer;
  29.333 -     bin_pol->magic = htonl(ACM_MAGIC);
  29.334 -     bin_pol->policyversion = htonl(POLICY_INTERFACE_VERSION);
  29.335 -     bin_pol->primary_policy_code = htons(ACM_CHINESE_WALL_POLICY);
  29.336 -     bin_pol->secondary_policy_code = htons(ACM_SIMPLE_TYPE_ENFORCEMENT_POLICY);
  29.337 -
  29.338 -     bin_pol->len = htonl(sizeof(struct acm_policy_buffer));
  29.339 -     bin_pol->primary_buffer_offset = htons(ntohl(bin_pol->len));
  29.340 -     ret = acm_domain_set_chwallpolicy(push_buffer + ntohs(bin_pol->primary_buffer_offset), 
  29.341 -				       MAX_PUSH_BUFFER - ntohs(bin_pol->primary_buffer_offset));
  29.342 -     if (ret < 0) {
  29.343 -	     printf("ERROR creating chwallpolicy buffer.\n");
  29.344 -	     return -1;
  29.345 -     }
  29.346 -     bin_pol->len = htonl(ntohl(bin_pol->len) + ret);
  29.347 -     bin_pol->secondary_buffer_offset = htons(ntohl(bin_pol->len));
  29.348 -     ret = acm_domain_set_stepolicy(push_buffer + ntohs(bin_pol->secondary_buffer_offset), 
  29.349 -				    MAX_PUSH_BUFFER - ntohs(bin_pol->secondary_buffer_offset));
  29.350 -     if (ret < 0) {
  29.351 -	     printf("ERROR creating chwallpolicy buffer.\n");
  29.352 -	     return -1;
  29.353 -     }
  29.354 -     bin_pol->len = htonl(ntohl(bin_pol->len) + ret);
  29.355 -
  29.356 -     /* dump it and then push it down into xen/acm */
  29.357 -     acm_dump_policy_buffer(push_buffer, ntohl(bin_pol->len));
  29.358 -     op.cmd = POLICY_SETPOLICY;
  29.359 -     op.u.setpolicy.pushcache = (void *)push_buffer;
  29.360 -     op.u.setpolicy.pushcache_size = ntohl(bin_pol->len);
  29.361 -     op.u.setpolicy.policy_type = ACM_CHINESE_WALL_AND_SIMPLE_TYPE_ENFORCEMENT_POLICY;
  29.362 -     ret = do_policy_op(xc_handle, &op);
  29.363 -
  29.364 -     if (ret)
  29.365 -	     printf("ERROR setting policy. Use 'xm dmesg' to see details.\n");
  29.366 -     else
  29.367 -	     printf("Successfully changed policy.\n");
  29.368 -     return ret;
  29.369 -}
  29.370 -
  29.371 -/******************************* get policy ******************************/
  29.372 -
  29.373 -#define PULL_CACHE_SIZE		8192
  29.374 -u8 pull_buffer[PULL_CACHE_SIZE];
  29.375 -int acm_domain_getpolicy(int xc_handle)
  29.376 -{
  29.377 -     policy_op_t op;
  29.378 -     int ret;
  29.379 -
  29.380 -     memset(pull_buffer, 0x00, sizeof(pull_buffer));
  29.381 -     op.cmd = POLICY_GETPOLICY;
  29.382 -     op.u.getpolicy.pullcache = (void *)pull_buffer;
  29.383 -     op.u.getpolicy.pullcache_size = sizeof(pull_buffer);
  29.384 -     ret = do_policy_op(xc_handle, &op);
  29.385 -     /* dump policy  */
  29.386 -     acm_dump_policy_buffer(pull_buffer, sizeof(pull_buffer));
  29.387 -     return ret;
  29.388 -}
  29.389 -
  29.390 -/************************ load binary policy ******************************/
  29.391 -
  29.392 -int acm_domain_loadpolicy(int xc_handle,
  29.393 -                          const char *filename)
  29.394 -{
  29.395 -     struct stat mystat;
  29.396 -     int ret, fd;
  29.397 -     off_t len;
  29.398 -     u8 *buffer;
  29.399 -
  29.400 -     if ((ret = stat(filename, &mystat))) {
  29.401 -	     printf("File %s not found.\n",filename);
  29.402 -	     goto out;
  29.403 -     }
  29.404 -
  29.405 -     len = mystat.st_size;
  29.406 -     if ((buffer = malloc(len)) == NULL) {
  29.407 -	     ret = -ENOMEM;
  29.408 -	     goto out;
  29.409 -     }
  29.410 -     if ((fd = open(filename, O_RDONLY)) <= 0) {
  29.411 -	     ret = -ENOENT;
  29.412 -	     printf("File %s not found.\n",filename);
  29.413 -	     goto free_out;
  29.414 -     }
  29.415 -     if (len == read(fd, buffer, len)) {
  29.416 -	     policy_op_t op;
  29.417 -	     /* dump it and then push it down into xen/acm */
  29.418 -	     acm_dump_policy_buffer(buffer, len);
  29.419 -	     op.cmd = POLICY_SETPOLICY;
  29.420 -	     op.u.setpolicy.pushcache = (void *)buffer;
  29.421 -	     op.u.setpolicy.pushcache_size = len;
  29.422 -	     op.u.setpolicy.policy_type = ACM_CHINESE_WALL_AND_SIMPLE_TYPE_ENFORCEMENT_POLICY;
  29.423 -	     ret = do_policy_op(xc_handle, &op);
  29.424 -                     
  29.425 -	     if (ret)
  29.426 -		     printf("ERROR setting policy. Use 'xm dmesg' to see details.\n");
  29.427 -	     else
  29.428 -		     printf("Successfully changed policy.\n");
  29.429 -                     
  29.430 -     } else {
  29.431 -	     ret = -1;
  29.432 -     }
  29.433 -     close(fd);
  29.434 - free_out:
  29.435 -     free(buffer);
  29.436 - out:
  29.437 -     return ret;
  29.438 -}
  29.439 -
  29.440 -/************************ dump hook statistics ******************************/
  29.441 -void 
  29.442 -dump_ste_stats(struct acm_ste_stats_buffer *ste_stats)
  29.443 -{
  29.444 -    printf("STE-Policy Security Hook Statistics:\n");
  29.445 -    printf("ste: event_channel eval_count      = %d\n", ntohl(ste_stats->ec_eval_count));
  29.446 -    printf("ste: event_channel denied_count    = %d\n", ntohl(ste_stats->ec_denied_count)); 
  29.447 -    printf("ste: event_channel cache_hit_count = %d\n", ntohl(ste_stats->ec_cachehit_count));
  29.448 -    printf("ste:\n");
  29.449 -    printf("ste: grant_table   eval_count      = %d\n", ntohl(ste_stats->gt_eval_count));
  29.450 -    printf("ste: grant_table   denied_count    = %d\n", ntohl(ste_stats->gt_denied_count)); 
  29.451 -    printf("ste: grant_table   cache_hit_count = %d\n", ntohl(ste_stats->gt_cachehit_count));
  29.452 -}
  29.453 -
  29.454 -#define PULL_STATS_SIZE		8192
  29.455 -int acm_domain_dumpstats(int xc_handle)
  29.456 -{
  29.457 -    u8 stats_buffer[PULL_STATS_SIZE];
  29.458 -    policy_op_t op;
  29.459 -    int ret;
  29.460 -    struct acm_stats_buffer *stats;
  29.461 -
  29.462 -    memset(stats_buffer, 0x00, sizeof(stats_buffer));
  29.463 -    op.cmd = POLICY_DUMPSTATS;
  29.464 -    op.u.dumpstats.pullcache = (void *)stats_buffer;
  29.465 -    op.u.dumpstats.pullcache_size = sizeof(stats_buffer);
  29.466 -    ret = do_policy_op(xc_handle, &op);
  29.467 -
  29.468 -    if (ret < 0) {
  29.469 -	printf("ERROR dumping policy stats. Use 'xm dmesg' to see details.\n"); 
  29.470 -	return ret;
  29.471 -    }
  29.472 -    stats = (struct acm_stats_buffer *)stats_buffer;
  29.473 -
  29.474 -    printf("\nPolicy dump:\n");
  29.475 -    printf("============\n");
  29.476 -    printf("Magic     = %x.\n", ntohl(stats->magic));
  29.477 -    printf("PolVer    = %x.\n", ntohl(stats->policyversion));
  29.478 -    printf("Len       = %x.\n", ntohl(stats->len));
  29.479 -
  29.480 -    switch(ntohs(stats->primary_policy_code)) {
  29.481 -    case ACM_NULL_POLICY:
  29.482 -	    printf("NULL Policy: No statistics apply.\n");
  29.483 -	    break;
  29.484 -    case ACM_CHINESE_WALL_POLICY:
  29.485 -	    printf("Chinese Wall Policy: No statistics apply.\n");
  29.486 -	    break;
  29.487 -    case ACM_SIMPLE_TYPE_ENFORCEMENT_POLICY:
  29.488 -	    dump_ste_stats((struct acm_ste_stats_buffer *)(stats_buffer + ntohs(stats->primary_stats_offset)));
  29.489 -	    break;
  29.490 -    default:
  29.491 -	    printf("UNKNOWN PRIMARY POLICY ERROR!\n");
  29.492 -    }
  29.493 -    switch(ntohs(stats->secondary_policy_code)) {
  29.494 -    case ACM_NULL_POLICY:
  29.495 -	    printf("NULL Policy: No statistics apply.\n");
  29.496 -	    break;
  29.497 -    case ACM_CHINESE_WALL_POLICY:
  29.498 -	    printf("Chinese Wall Policy: No statistics apply.\n");
  29.499 -	    break;
  29.500 -    case ACM_SIMPLE_TYPE_ENFORCEMENT_POLICY:
  29.501 -	    dump_ste_stats((struct acm_ste_stats_buffer *)(stats_buffer + ntohs(stats->secondary_stats_offset)));
  29.502 -	    break;
  29.503 -    default:
  29.504 -	    printf("UNKNOWN SECONDARY POLICY ERROR!\n");
  29.505 -    }                
  29.506 -    return ret;
  29.507 -}
  29.508 -
  29.509 -/***************************** main **************************************/
  29.510 -
  29.511 -void
  29.512 -usage(char *progname){
  29.513 -	printf("Use: %s \n"
  29.514 -	       "\t setpolicy\n"
  29.515 -	       "\t getpolicy\n"
  29.516 -	       "\t dumpstats\n"
  29.517 -	       "\t loadpolicy <binary policy file>\n", progname);
  29.518 -	exit(-1);
  29.519 -}
  29.520 -
  29.521 -int
  29.522 -main(int argc, char **argv) {
  29.523 -
  29.524 -	int policycmd_fd, ret;
  29.525 -
  29.526 -	if (argc < 2) 
  29.527 -		usage(argv[0]);
  29.528 -		
  29.529 -	if ((policycmd_fd = open("/proc/xen/privcmd", O_RDONLY)) <= 0) {
  29.530 -		    printf("ERROR: Could not open xen privcmd device!\n");
  29.531 -		    exit(-1);
  29.532 -	}
  29.533 -	    
  29.534 -	if (!strcmp(argv[1], "setpolicy")) {
  29.535 -		if (argc != 2)
  29.536 -			usage(argv[0]);
  29.537 -		ret = acm_domain_setpolicy(policycmd_fd);
  29.538 -	} else if (!strcmp(argv[1], "getpolicy")) {
  29.539 -		if (argc != 2)
  29.540 -			usage(argv[0]);
  29.541 -		ret = acm_domain_getpolicy(policycmd_fd);
  29.542 -	} else if (!strcmp(argv[1], "loadpolicy")) {
  29.543 -		if (argc != 3) 
  29.544 -			usage(argv[0]);
  29.545 -		ret = acm_domain_loadpolicy(policycmd_fd, argv[2]);
  29.546 -	} else if (!strcmp(argv[1], "dumpstats")) {
  29.547 -		if (argc != 2) 
  29.548 -			usage(argv[0]);
  29.549 -		ret = acm_domain_dumpstats(policycmd_fd);
  29.550 -	} else
  29.551 -		usage(argv[0]);
  29.552 -
  29.553 -	close(policycmd_fd);
  29.554 -	return ret;
  29.555 -}
    30.1 --- a/tools/pygrub/setup.py	Tue Aug 02 17:12:36 2005 +0000
    30.2 +++ b/tools/pygrub/setup.py	Tue Aug 02 17:13:11 2005 +0000
    30.3 @@ -23,7 +23,7 @@ if os.path.exists("/usr/include/reiserfs
    30.4      fsys_pkgs.append("grub.fsys.reiser")
    30.5  
    30.6  setup(name='pygrub',
    30.7 -      version='0.2',
    30.8 +      version='0.3',
    30.9        description='Boot loader that looks a lot like grub for Xen',
   30.10        author='Jeremy Katz',
   30.11        author_email='katzj@redhat.com',
    31.1 --- a/tools/pygrub/src/fsys/ext2/__init__.py	Tue Aug 02 17:12:36 2005 +0000
    31.2 +++ b/tools/pygrub/src/fsys/ext2/__init__.py	Tue Aug 02 17:13:11 2005 +0000
    31.3 @@ -32,7 +32,7 @@ class Ext2FileSystemType(FileSystemType)
    31.4      def open_fs(self, fn, offset = 0):
    31.5          if not self.sniff_magic(fn, offset):
    31.6              raise ValueError, "Not an ext2 filesystem"
    31.7 -        return Ext2Fs(fn)
    31.8 +        return Ext2Fs(fn, offset = offset)
    31.9  
   31.10  register_fstype(Ext2FileSystemType())
   31.11  
    32.1 --- a/tools/pygrub/src/fsys/ext2/ext2module.c	Tue Aug 02 17:12:36 2005 +0000
    32.2 +++ b/tools/pygrub/src/fsys/ext2/ext2module.c	Tue Aug 02 17:13:11 2005 +0000
    32.3 @@ -208,23 +208,29 @@ static PyObject *
    32.4  ext2_fs_open (Ext2Fs *fs, PyObject *args, PyObject *kwargs)
    32.5  {
    32.6      static char *kwlist[] = { "name", "flags", "superblock", 
    32.7 -                              "block_size", NULL };
    32.8 +                              "block_size", "offset", NULL };
    32.9      char * name;
   32.10 -    int flags = 0, superblock = 0, err;
   32.11 +    int flags = 0, superblock = 0, offset = 0, err;
   32.12      unsigned int block_size = 0;
   32.13      ext2_filsys efs;
   32.14 +    char offsetopt[30];
   32.15  
   32.16 -    if (!PyArg_ParseTupleAndKeywords(args, kwargs, "s|iii", kwlist, 
   32.17 -                                     &name, &flags, &superblock, &block_size))
   32.18 -                                     return NULL;
   32.19 +    if (!PyArg_ParseTupleAndKeywords(args, kwargs, "s|iiii", kwlist, 
   32.20 +                                     &name, &flags, &superblock, 
   32.21 +                                     &block_size, &offset))
   32.22 +        return NULL;
   32.23  
   32.24      if (fs->fs != NULL) {
   32.25          PyErr_SetString(PyExc_ValueError, "already have an fs object");
   32.26          return NULL;
   32.27      }
   32.28  
   32.29 -    err = ext2fs_open(name, flags, superblock, block_size, 
   32.30 -                      unix_io_manager, &efs);
   32.31 +    if (offset != 0) {
   32.32 +        snprintf(offsetopt, 29, "offset=%d", offset);
   32.33 +    }
   32.34 +
   32.35 +    err = ext2fs_open2(name, offsetopt, flags, superblock, block_size, 
   32.36 +                       unix_io_manager, &efs);
   32.37      if (err) {
   32.38          PyErr_SetString(PyExc_ValueError, "unable to open file");
   32.39          return NULL;
   32.40 @@ -323,14 +329,15 @@ static PyObject *
   32.41  ext2_fs_new(PyObject *o, PyObject *args, PyObject *kwargs) 
   32.42  {
   32.43      static char *kwlist[] = { "name", "flags", "superblock", 
   32.44 -                              "block_size", NULL };
   32.45 +                              "block_size", "offset", NULL };
   32.46      char * name;
   32.47 -    int flags = 0, superblock = 0;
   32.48 +    int flags = 0, superblock = 0, offset;
   32.49      unsigned int block_size = 0;
   32.50      Ext2Fs *pfs;
   32.51  
   32.52 -    if (!PyArg_ParseTupleAndKeywords(args, kwargs, "s|iii", kwlist, 
   32.53 -                                     &name, &flags, &superblock, &block_size))
   32.54 +    if (!PyArg_ParseTupleAndKeywords(args, kwargs, "s|iiii", kwlist, 
   32.55 +                                     &name, &flags, &superblock, &block_size,
   32.56 +                                     &offset))
   32.57          return NULL;
   32.58  
   32.59      pfs = (Ext2Fs *) PyObject_NEW(Ext2Fs, &Ext2FsType);
   32.60 @@ -339,8 +346,8 @@ ext2_fs_new(PyObject *o, PyObject *args,
   32.61      pfs->fs = NULL;
   32.62  
   32.63      if (!ext2_fs_open(pfs, 
   32.64 -                      Py_BuildValue("siii", name, flags, superblock, block_size),
   32.65 -                      NULL))
   32.66 +                      Py_BuildValue("siiii", name, flags, superblock, 
   32.67 +                                    block_size, offset), NULL))
   32.68          return NULL;
   32.69  
   32.70      return (PyObject *)pfs;
    33.1 --- a/tools/pygrub/src/pygrub	Tue Aug 02 17:12:36 2005 +0000
    33.2 +++ b/tools/pygrub/src/pygrub	Tue Aug 02 17:13:11 2005 +0000
    33.3 @@ -24,7 +24,7 @@ sys.path = [ '/usr/lib/python' ] + sys.p
    33.4  import grub.GrubConf
    33.5  import grub.fsys
    33.6  
    33.7 -PYGRUB_VER = 0.02
    33.8 +PYGRUB_VER = 0.3
    33.9  
   33.10  
   33.11  def draw_window():
   33.12 @@ -77,24 +77,39 @@ def is_disk_image(file):
   33.13      buf = os.read(fd, 512)
   33.14      os.close(fd)
   33.15  
   33.16 -    if len(buf) >= 512 and struct.unpack("H", buf[0x1fe: 0x200]) == (0xaaff):
   33.17 +    if len(buf) >= 512 and struct.unpack("H", buf[0x1fe: 0x200]) == (0xaa55,):
   33.18          return True
   33.19      return False
   33.20  
   33.21 +SECTOR_SIZE=512
   33.22 +def get_active_offset(file):
   33.23 +    """Find the offset for the start of the first active partition in the
   33.24 +    disk image file."""
   33.25 +    fd = os.open(file, os.O_RDONLY)
   33.26 +    buf = os.read(fd, 512)
   33.27 +    for poff in (446, 462, 478, 494): # partition offsets
   33.28 +        # active partition has 0x80 as the first byte
   33.29 +        if struct.unpack("<c", buf[p:p+1]) == ('\x80',):
   33.30 +            return struct.unpack("<", buf[p+8:p+12])[0] * SECTOR_SIZE
   33.31 +    return -1
   33.32 +
   33.33  def get_config(fn):
   33.34      if not os.access(fn, os.R_OK):
   33.35          raise RuntimeError, "Unable to access %s" %(fn,)
   33.36  
   33.37      cf = grub.GrubConf.GrubConfigFile()
   33.38  
   33.39 +    offset = 0
   33.40      if is_disk_image(fn):
   33.41 -        raise RuntimeError, "appears to be a full disk image... unable to handle this yet"
   33.42 +        offset = get_active_offset(fn)
   33.43 +        if offset == -1:
   33.44 +            raise RuntimeError, "Unable to find active partition on disk"
   33.45  
   33.46      # open the image and read the grub config
   33.47      fs = None
   33.48      for fstype in grub.fsys.fstypes.values():
   33.49 -        if fstype.sniff_magic(fn):
   33.50 -            fs = fstype.open_fs(fn)
   33.51 +        if fstype.sniff_magic(fn, offset):
   33.52 +            fs = fstype.open_fs(fn, offset)
   33.53              break
   33.54  
   33.55      if fs is not None:
   33.56 @@ -244,14 +259,17 @@ if __name__ == "__main__":
   33.57      if img.initrd:
   33.58          print "  initrd: %s" %(img.initrd[1],)
   33.59  
   33.60 +    offset = 0
   33.61      if is_disk_image(file):
   33.62 -        raise RuntimeError, "unable to handle full disk images yet"
   33.63 +        offset = get_active_offset(fn)
   33.64 +        if offset == -1:
   33.65 +            raise RuntimeError, "Unable to find active partition on disk"
   33.66  
   33.67      # read the kernel and initrd onto the hostfs
   33.68      fs = None
   33.69      for fstype in grub.fsys.fstypes.values():
   33.70 -        if fstype.sniff_magic(file):
   33.71 -            fs = fstype.open_fs(file)
   33.72 +        if fstype.sniff_magic(file, offset):
   33.73 +            fs = fstype.open_fs(file, offset)
   33.74              break
   33.75  
   33.76      if fs is None:
    34.1 --- a/tools/python/xen/util/blkif.py	Tue Aug 02 17:12:36 2005 +0000
    34.2 +++ b/tools/python/xen/util/blkif.py	Tue Aug 02 17:13:11 2005 +0000
    34.3 @@ -24,8 +24,8 @@ def blkdev_name_to_number(name):
    34.4          log.debug("exception looking up device number for %s: %s", name, ex)
    34.5          pass
    34.6  
    34.7 -    if re.match( '/dev/sd[a-p]([0-9]|1[0-5])', n):
    34.8 -        return 8 * 256 + 16 * (ord(n[7:8]) - ord('a')) + int(n[8:])
    34.9 +    if re.match( '/dev/sd[a-p]([1-9]|1[0-5])?', n):
   34.10 +        return 8 * 256 + 16 * (ord(n[7:8]) - ord('a')) + int(n[8:] or 0)
   34.11  
   34.12      if re.match( '/dev/hd[a-t]([1-9]|[1-5][0-9]|6[0-3])?', n):
   34.13          ide_majors = [ 3, 22, 33, 34, 56, 57, 88, 89, 90, 91 ]
   34.14 @@ -33,6 +33,9 @@ def blkdev_name_to_number(name):
   34.15          minor = ((ord(n[7:8]) - ord('a')) % 2) * 64 + int(n[8:] or 0)
   34.16          return major * 256 + minor
   34.17  
   34.18 +    if re.match( '/dev/xvd[a-p]([1-9]|1[0-5])?', n):
   34.19 +        return 202 * 256 + 16 * (ord(n[8:9]) - ord('a')) + int(n[9:] or 0)
   34.20 +
   34.21      # see if this is a hex device number
   34.22      if re.match( '^(0x)?[0-9a-fA-F]+$', name ):
   34.23          return string.atoi(name,16)
    36.1 --- a/tools/python/xen/xend/XendDomainInfo.py	Tue Aug 02 17:12:36 2005 +0000
    36.2 +++ b/tools/python/xen/xend/XendDomainInfo.py	Tue Aug 02 17:13:11 2005 +0000
    36.3 @@ -152,6 +152,9 @@ class XendDomainInfo:
    36.4          vm = cls(db)
    36.5          vm.construct(config)
    36.6          vm.saveToDB(sync=True)
    36.7 +        # Flush info to xenstore immediately
    36.8 +        vm.exportToDB()
    36.9 +
   36.10          return vm
   36.11  
   36.12      create = classmethod(create)
   36.13 @@ -172,6 +175,7 @@ class XendDomainInfo:
   36.14          log.debug('config=' + prettyprintstring(config))
   36.15  
   36.16          vm.memory = info['mem_kb']/1024
   36.17 +        vm.target = info['mem_kb'] * 1024
   36.18  
   36.19          if config:
   36.20              try:
   36.21 @@ -222,6 +226,7 @@ class XendDomainInfo:
   36.22          DBVar('restart_state', ty='str'),
   36.23          DBVar('restart_time',  ty='float'),
   36.24          DBVar('restart_count', ty='int'),
   36.25 +        DBVar('target',        ty='long', path="memory/target"),
   36.26          ]
   36.27      
   36.28      def __init__(self, db):
   36.29 @@ -240,6 +245,8 @@ class XendDomainInfo:
   36.30          self.ssidref = None
   36.31          self.image = None
   36.32  
   36.33 +        self.target = None
   36.34 +
   36.35          self.channel = None
   36.36          self.store_channel = None
   36.37          self.store_mfn = None
   36.38 @@ -315,6 +322,7 @@ class XendDomainInfo:
   36.39          self.info = info
   36.40          self.memory = self.info['mem_kb'] / 1024
   36.41          self.ssidref = self.info['ssidref']
   36.42 +        self.target = self.info['mem_kb'] * 1024
   36.43  
   36.44      def state_set(self, state):
   36.45          self.state_updated.acquire()
   36.46 @@ -399,7 +407,8 @@ class XendDomainInfo:
   36.47                  ['id', self.id],
   36.48                  ['name', self.name],
   36.49                  ['memory', self.memory],
   36.50 -                ['ssidref', self.ssidref] ]
   36.51 +                ['ssidref', self.ssidref],
   36.52 +                ['target', self.target] ]
   36.53          if self.uuid:
   36.54              sxpr.append(['uuid', self.uuid])
   36.55          if self.info:
   36.56 @@ -536,6 +545,7 @@ class XendDomainInfo:
   36.57          self.memory = int(sxp.child_value(config, 'memory'))
   36.58          if self.memory is None:
   36.59              raise VmError('missing memory size')
   36.60 +        self.target = self.memory * (1 << 20)
   36.61          self.ssidref = int(sxp.child_value(config, 'ssidref'))
   36.62          cpu = sxp.child_value(config, 'cpu')
   36.63          if self.recreate and self.id and cpu is not None and int(cpu) >= 0:
   36.64 @@ -947,11 +957,12 @@ class XendDomainInfo:
   36.65              index[field_name] = field_index + 1
   36.66  
   36.67      def mem_target_set(self, target):
   36.68 -        """Set domain memory target in pages.
   36.69 +        """Set domain memory target in bytes.
   36.70          """
   36.71 -        if self.channel:
   36.72 -            msg = messages.packMsg('mem_request_t', { 'target' : target * (1 << 8)} )
   36.73 -            self.channel.writeRequest(msg)
   36.74 +        if target:
   36.75 +            self.target = target * (1 << 20)
   36.76 +            # Commit to XenStore immediately
   36.77 +            self.exportToDB()
   36.78  
   36.79      def vcpu_hotplug(self, vcpu, state):
   36.80          """Disable or enable VCPU in domain.
    37.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    37.2 +++ b/tools/security/Makefile	Tue Aug 02 17:13:11 2005 +0000
    37.3 @@ -0,0 +1,36 @@
    37.4 +XEN_ROOT = ../..
    37.5 +include $(XEN_ROOT)/tools/Rules.mk
    37.6 +
    37.7 +SRCS     = secpol_tool.c
    37.8 +CFLAGS   += -static
    37.9 +CFLAGS   += -Wall
   37.10 +CFLAGS   += -Werror
   37.11 +CFLAGS   += -O3
   37.12 +CFLAGS   += -fno-strict-aliasing
   37.13 +CFLAGS   += -I.
   37.14 +
   37.15 +all: build
   37.16 +build: mk-symlinks
   37.17 +	$(MAKE) secpol_tool
   37.18 +
   37.19 +default: all
   37.20 +
   37.21 +install: all
   37.22 +
   37.23 +secpol_tool : secpol_tool.c
   37.24 +	$(CC) $(CPPFLAGS) $(CFLAGS) -o $@ $<
   37.25 +
   37.26 +clean:
   37.27 +	rm -rf secpol_tool xen
   37.28 +
   37.29 +
   37.30 +LINUX_ROOT := $(XEN_ROOT)/linux-2.6-xen-sparse
   37.31 +mk-symlinks:
   37.32 +	[ -e xen/linux ] || mkdir -p xen/linux
   37.33 +	[ -e xen/io ]    || mkdir -p xen/io
   37.34 +	( cd xen >/dev/null ; \
   37.35 +	  ln -sf ../$(XEN_ROOT)/xen/include/public/*.h . )
   37.36 +	( cd xen/io >/dev/null ; \
   37.37 +	  ln -sf ../../$(XEN_ROOT)/xen/include/public/io/*.h . )
   37.38 +	( cd xen/linux >/dev/null ; \
   37.39 +	  ln -sf ../../$(LINUX_ROOT)/include/asm-xen/linux-public/*.h . )
    38.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    38.2 +++ b/tools/security/secpol_tool.c	Tue Aug 02 17:13:11 2005 +0000
    38.3 @@ -0,0 +1,648 @@
    38.4 +/****************************************************************
    38.5 + * secpol_tool.c
    38.6 + *
    38.7 + * Copyright (C) 2005 IBM Corporation
    38.8 + *
    38.9 + * Authors:
   38.10 + * Reiner Sailer <sailer@watson.ibm.com>
   38.11 + * Stefan Berger <stefanb@watson.ibm.com>
   38.12 + *
   38.13 + * This program is free software; you can redistribute it and/or
   38.14 + * modify it under the terms of the GNU General Public License as
   38.15 + * published by the Free Software Foundation, version 2 of the
   38.16 + * License.
   38.17 + *
   38.18 + * sHype policy management tool. This code runs in a domain and
   38.19 + *     manages the Xen security policy by interacting with the
   38.20 + *     Xen access control module via a /proc/xen/privcmd proc-ioctl,
   38.21 + *     which is translated into a acm_op hypercall into Xen.
   38.22 + *
   38.23 + * indent -i4 -kr -nut
   38.24 + */
   38.25 +
   38.26 +
   38.27 +#include <unistd.h>
   38.28 +#include <stdio.h>
   38.29 +#include <errno.h>
   38.30 +#include <fcntl.h>
   38.31 +#include <sys/mman.h>
   38.32 +#include <sys/types.h>
   38.33 +#include <sys/stat.h>
   38.34 +#include <stdlib.h>
   38.35 +#include <sys/ioctl.h>
   38.36 +#include <string.h>
   38.37 +#include <stdint.h>
   38.38 +#include <netinet/in.h>
   38.39 +
   38.40 +typedef uint8_t u8;
   38.41 +typedef uint16_t u16;
   38.42 +typedef uint32_t u32;
   38.43 +typedef uint64_t u64;
   38.44 +typedef int8_t s8;
   38.45 +typedef int16_t s16;
   38.46 +typedef int32_t s32;
   38.47 +typedef int64_t s64;
   38.48 +
   38.49 +#include <xen/acm.h>
   38.50 +#include <xen/acm_ops.h>
   38.51 +#include <xen/linux/privcmd.h>
   38.52 +
   38.53 +#define PERROR(_m, _a...) \
   38.54 +fprintf(stderr, "ERROR: " _m " (%d = %s)\n" , ## _a ,	\
   38.55 +                errno, strerror(errno))
   38.56 +
   38.57 +static inline int do_policycmd(int xc_handle, unsigned int cmd,
   38.58 +                               unsigned long data)
   38.59 +{
   38.60 +    return ioctl(xc_handle, cmd, data);
   38.61 +}
   38.62 +
   38.63 +static inline int do_xen_hypercall(int xc_handle,
   38.64 +                                   privcmd_hypercall_t * hypercall)
   38.65 +{
   38.66 +    return do_policycmd(xc_handle,
   38.67 +                        IOCTL_PRIVCMD_HYPERCALL,
   38.68 +                        (unsigned long) hypercall);
   38.69 +}
   38.70 +
   38.71 +static inline int do_acm_op(int xc_handle, acm_op_t * op)
   38.72 +{
   38.73 +    int ret = -1;
   38.74 +    privcmd_hypercall_t hypercall;
   38.75 +
   38.76 +    op->interface_version = ACM_INTERFACE_VERSION;
   38.77 +
   38.78 +    hypercall.op = __HYPERVISOR_acm_op;
   38.79 +    hypercall.arg[0] = (unsigned long) op;
   38.80 +
   38.81 +    if (mlock(op, sizeof(*op)) != 0)
   38.82 +    {
   38.83 +        PERROR("Could not lock memory for Xen policy hypercall");
   38.84 +        goto out1;
   38.85 +    }
   38.86 +
   38.87 +    if ((ret = do_xen_hypercall(xc_handle, &hypercall)) < 0)
   38.88 +    {
   38.89 +        if (errno == EACCES)
   38.90 +            fprintf(stderr, "ACM operation failed -- need to"
   38.91 +                    " rebuild the user-space tool set?\n");
   38.92 +        goto out2;
   38.93 +    }
   38.94 +
   38.95 +  out2:(void) munlock(op, sizeof(*op));
   38.96 +  out1:return ret;
   38.97 +}
   38.98 +
   38.99 +/*************************** DUMPS *******************************/
  38.100 +
  38.101 +void acm_dump_chinesewall_buffer(void *buf, int buflen)
  38.102 +{
  38.103 +
  38.104 +    struct acm_chwall_policy_buffer *cwbuf =
  38.105 +        (struct acm_chwall_policy_buffer *) buf;
  38.106 +    domaintype_t *ssids, *conflicts, *running_types, *conflict_aggregate;
  38.107 +    int i, j;
  38.108 +
  38.109 +
  38.110 +    if (htonl(cwbuf->policy_code) != ACM_CHINESE_WALL_POLICY)
  38.111 +    {
  38.112 +        printf("CHINESE WALL POLICY CODE not found ERROR!!\n");
  38.113 +        return;
  38.114 +    }
  38.115 +    printf("\n\nChinese Wall policy:\n");
  38.116 +    printf("====================\n");
  38.117 +    printf("Policy version= %x.\n", ntohl(cwbuf->policy_version));
  38.118 +    printf("Max Types     = %x.\n", ntohl(cwbuf->chwall_max_types));
  38.119 +    printf("Max Ssidrefs  = %x.\n", ntohl(cwbuf->chwall_max_ssidrefs));
  38.120 +    printf("Max ConfSets  = %x.\n", ntohl(cwbuf->chwall_max_conflictsets));
  38.121 +    printf("Ssidrefs Off  = %x.\n", ntohl(cwbuf->chwall_ssid_offset));
  38.122 +    printf("Conflicts Off = %x.\n",
  38.123 +           ntohl(cwbuf->chwall_conflict_sets_offset));
  38.124 +    printf("Runing T. Off = %x.\n",
  38.125 +           ntohl(cwbuf->chwall_running_types_offset));
  38.126 +    printf("C. Agg. Off   = %x.\n",
  38.127 +           ntohl(cwbuf->chwall_conflict_aggregate_offset));
  38.128 +    printf("\nSSID To CHWALL-Type matrix:\n");
  38.129 +
  38.130 +    ssids = (domaintype_t *) (buf + ntohl(cwbuf->chwall_ssid_offset));
  38.131 +    for (i = 0; i < ntohl(cwbuf->chwall_max_ssidrefs); i++)
  38.132 +    {
  38.133 +        printf("\n   ssidref%2x:  ", i);
  38.134 +        for (j = 0; j < ntohl(cwbuf->chwall_max_types); j++)
  38.135 +            printf("%02x ",
  38.136 +                   ntohs(ssids[i * ntohl(cwbuf->chwall_max_types) + j]));
  38.137 +    }
  38.138 +    printf("\n\nConfict Sets:\n");
  38.139 +    conflicts =
  38.140 +        (domaintype_t *) (buf + ntohl(cwbuf->chwall_conflict_sets_offset));
  38.141 +    for (i = 0; i < ntohl(cwbuf->chwall_max_conflictsets); i++)
  38.142 +    {
  38.143 +        printf("\n   c-set%2x:    ", i);
  38.144 +        for (j = 0; j < ntohl(cwbuf->chwall_max_types); j++)
  38.145 +            printf("%02x ",
  38.146 +                   ntohs(conflicts
  38.147 +                         [i * ntohl(cwbuf->chwall_max_types) + j]));
  38.148 +    }
  38.149 +    printf("\n");
  38.150 +
  38.151 +    printf("\nRunning\nTypes:         ");
  38.152 +    if (ntohl(cwbuf->chwall_running_types_offset))
  38.153 +    {
  38.154 +        running_types =
  38.155 +            (domaintype_t *) (buf +
  38.156 +                              ntohl(cwbuf->chwall_running_types_offset));
  38.157 +        for (i = 0; i < ntohl(cwbuf->chwall_max_types); i++)
  38.158 +        {
  38.159 +            printf("%02x ", ntohs(running_types[i]));
  38.160 +        }
  38.161 +        printf("\n");
  38.162 +    } else {
  38.163 +        printf("Not Reported!\n");
  38.164 +    }
  38.165 +    printf("\nConflict\nAggregate Set: ");
  38.166 +    if (ntohl(cwbuf->chwall_conflict_aggregate_offset))
  38.167 +    {
  38.168 +        conflict_aggregate =
  38.169 +            (domaintype_t *) (buf +
  38.170 +                              ntohl(cwbuf->chwall_conflict_aggregate_offset));
  38.171 +        for (i = 0; i < ntohl(cwbuf->chwall_max_types); i++)
  38.172 +        {
  38.173 +            printf("%02x ", ntohs(conflict_aggregate[i]));
  38.174 +        }
  38.175 +        printf("\n\n");
  38.176 +    } else {
  38.177 +        printf("Not Reported!\n");
  38.178 +    }
  38.179 +}
  38.180 +
  38.181 +void acm_dump_ste_buffer(void *buf, int buflen)
  38.182 +{
  38.183 +
  38.184 +    struct acm_ste_policy_buffer *stebuf =
  38.185 +        (struct acm_ste_policy_buffer *) buf;
  38.186 +    domaintype_t *ssids;
  38.187 +    int i, j;
  38.188 +
  38.189 +
  38.190 +    if (ntohl(stebuf->policy_code) != ACM_SIMPLE_TYPE_ENFORCEMENT_POLICY) {
  38.191 +        printf("SIMPLE TYPE ENFORCEMENT POLICY CODE not found ERROR!!\n");
  38.192 +        return;
  38.193 +    }
  38.194 +    printf("\nSimple Type Enforcement policy:\n");
  38.195 +    printf("===============================\n");
  38.196 +    printf("Policy version= %x.\n", ntohl(stebuf->policy_version));
  38.197 +    printf("Max Types     = %x.\n", ntohl(stebuf->ste_max_types));
  38.198 +    printf("Max Ssidrefs  = %x.\n", ntohl(stebuf->ste_max_ssidrefs));
  38.199 +    printf("Ssidrefs Off  = %x.\n", ntohl(stebuf->ste_ssid_offset));
  38.200 +    printf("\nSSID To STE-Type matrix:\n");
  38.201 +
  38.202 +    ssids = (domaintype_t *) (buf + ntohl(stebuf->ste_ssid_offset));
  38.203 +    for (i = 0; i < ntohl(stebuf->ste_max_ssidrefs); i++)
  38.204 +    {
  38.205 +        printf("\n   ssidref%2x: ", i);
  38.206 +        for (j = 0; j < ntohl(stebuf->ste_max_types); j++)
  38.207 +            printf("%02x ", ntohs(ssids[i * ntohl(stebuf->ste_max_types) + j]));
  38.208 +    }
  38.209 +    printf("\n\n");
  38.210 +}
  38.211 +
  38.212 +void acm_dump_policy_buffer(void *buf, int buflen)
  38.213 +{
  38.214 +    struct acm_policy_buffer *pol = (struct acm_policy_buffer *) buf;
  38.215 +
  38.216 +    printf("\nPolicy dump:\n");
  38.217 +    printf("============\n");
  38.218 +    printf("PolicyVer = %x.\n", ntohl(pol->policy_version));
  38.219 +    printf("Magic     = %x.\n", ntohl(pol->magic));
  38.220 +    printf("Len       = %x.\n", ntohl(pol->len));
  38.221 +    printf("Primary   = %s (c=%x, off=%x).\n",
  38.222 +           ACM_POLICY_NAME(ntohl(pol->primary_policy_code)),
  38.223 +           ntohl(pol->primary_policy_code),
  38.224 +           ntohl(pol->primary_buffer_offset));
  38.225 +    printf("Secondary = %s (c=%x, off=%x).\n",
  38.226 +           ACM_POLICY_NAME(ntohl(pol->secondary_policy_code)),
  38.227 +           ntohl(pol->secondary_policy_code),
  38.228 +           ntohl(pol->secondary_buffer_offset));
  38.229 +    switch (ntohl(pol->primary_policy_code))
  38.230 +    {
  38.231 +    case ACM_CHINESE_WALL_POLICY:
  38.232 +        acm_dump_chinesewall_buffer(buf +
  38.233 +                                    ntohl(pol->primary_buffer_offset),
  38.234 +                                    ntohl(pol->len) -
  38.235 +                                    ntohl(pol->primary_buffer_offset));
  38.236 +        break;
  38.237 +
  38.238 +    case ACM_SIMPLE_TYPE_ENFORCEMENT_POLICY:
  38.239 +        acm_dump_ste_buffer(buf + ntohl(pol->primary_buffer_offset),
  38.240 +                            ntohl(pol->len) -
  38.241 +                            ntohl(pol->primary_buffer_offset));
  38.242 +        break;
  38.243 +
  38.244 +    case ACM_NULL_POLICY:
  38.245 +        printf("Primary policy is NULL Policy (n/a).\n");
  38.246 +        break;
  38.247 +
  38.248 +    default:
  38.249 +        printf("UNKNOWN POLICY!\n");
  38.250 +    }
  38.251 +
  38.252 +    switch (ntohl(pol->secondary_policy_code))
  38.253 +    {
  38.254 +    case ACM_CHINESE_WALL_POLICY:
  38.255 +        acm_dump_chinesewall_buffer(buf +
  38.256 +                                    ntohl(pol->secondary_buffer_offset),
  38.257 +                                    ntohl(pol->len) -
  38.258 +                                    ntohl(pol->secondary_buffer_offset));
  38.259 +        break;
  38.260 +
  38.261 +    case ACM_SIMPLE_TYPE_ENFORCEMENT_POLICY:
  38.262 +        acm_dump_ste_buffer(buf + ntohl(pol->secondary_buffer_offset),
  38.263 +                            ntohl(pol->len) -
  38.264 +                            ntohl(pol->secondary_buffer_offset));
  38.265 +        break;
  38.266 +
  38.267 +    case ACM_NULL_POLICY:
  38.268 +        printf("Secondary policy is NULL Policy (n/a).\n");
  38.269 +        break;
  38.270 +
  38.271 +    default:
  38.272 +        printf("UNKNOWN POLICY!\n");
  38.273 +    }
  38.274 +}
  38.275 +
  38.276 +/*************************** set policy ****************************/
  38.277 +
  38.278 +int acm_domain_set_chwallpolicy(void *bufstart, int buflen)
  38.279 +{
  38.280 +#define CWALL_MAX_SSIDREFS      	6
  38.281 +#define CWALL_MAX_TYPES             10
  38.282 +#define CWALL_MAX_CONFLICTSETS		2
  38.283 +
  38.284 +    struct acm_chwall_policy_buffer *chwall_bin_pol =
  38.285 +        (struct acm_chwall_policy_buffer *) bufstart;
  38.286 +    domaintype_t *ssidrefs, *conflicts;
  38.287 +    int ret = 0;
  38.288 +    int j;
  38.289 +
  38.290 +    chwall_bin_pol->chwall_max_types = htonl(CWALL_MAX_TYPES);
  38.291 +    chwall_bin_pol->chwall_max_ssidrefs = htonl(CWALL_MAX_SSIDREFS);
  38.292 +    chwall_bin_pol->policy_code = htonl(ACM_CHINESE_WALL_POLICY);
  38.293 +    chwall_bin_pol->policy_version = htonl(ACM_CHWALL_VERSION);
  38.294 +    chwall_bin_pol->chwall_ssid_offset =
  38.295 +        htonl(sizeof(struct acm_chwall_policy_buffer));
  38.296 +    chwall_bin_pol->chwall_max_conflictsets =
  38.297 +        htonl(CWALL_MAX_CONFLICTSETS);
  38.298 +    chwall_bin_pol->chwall_conflict_sets_offset =
  38.299 +        htonl(ntohl(chwall_bin_pol->chwall_ssid_offset) +
  38.300 +              sizeof(domaintype_t) * CWALL_MAX_SSIDREFS * CWALL_MAX_TYPES);
  38.301 +    chwall_bin_pol->chwall_running_types_offset = 0;    /* not set */
  38.302 +    chwall_bin_pol->chwall_conflict_aggregate_offset = 0;       /* not set */
  38.303 +    ret += sizeof(struct acm_chwall_policy_buffer);
  38.304 +    /* now push example ssids into the buffer (max_ssidrefs x max_types entries) */
  38.305 +    /* check buffer size */
  38.306 +    if ((buflen - ret) <
  38.307 +        (CWALL_MAX_TYPES * CWALL_MAX_SSIDREFS * sizeof(domaintype_t)))
  38.308 +        return -1;              /* not enough space */
  38.309 +
  38.310 +    ssidrefs = (domaintype_t *) (bufstart +
  38.311 +                          ntohl(chwall_bin_pol->chwall_ssid_offset));
  38.312 +    memset(ssidrefs, 0,
  38.313 +           CWALL_MAX_TYPES * CWALL_MAX_SSIDREFS * sizeof(domaintype_t));
  38.314 +
  38.315 +    /* now set type j-1 for ssidref i+1 */
  38.316 +    for (j = 0; j <= CWALL_MAX_SSIDREFS; j++)
  38.317 +        if ((0 < j) && (j <= CWALL_MAX_TYPES))
  38.318 +            ssidrefs[j * CWALL_MAX_TYPES + j - 1] = htons(1);
  38.319 +
  38.320 +    ret += CWALL_MAX_TYPES * CWALL_MAX_SSIDREFS * sizeof(domaintype_t);
  38.321 +    if ((buflen - ret) <
  38.322 +        (CWALL_MAX_CONFLICTSETS * CWALL_MAX_TYPES * sizeof(domaintype_t)))
  38.323 +        return -1;              /* not enough space */
  38.324 +
  38.325 +    /* now the chinese wall policy conflict sets */
  38.326 +    conflicts = (domaintype_t *) (bufstart +
  38.327 +                                  ntohl(chwall_bin_pol->
  38.328 +                                        chwall_conflict_sets_offset));
  38.329 +    memset((void *) conflicts, 0,
  38.330 +           CWALL_MAX_CONFLICTSETS * CWALL_MAX_TYPES *
  38.331 +           sizeof(domaintype_t));
  38.332 +    /* just 1 conflict set [0]={2,3}, [1]={1,5,6} */
  38.333 +    if (CWALL_MAX_TYPES > 3)
  38.334 +    {
  38.335 +        conflicts[2] = htons(1);
  38.336 +        conflicts[3] = htons(1);        /* {2,3} */
  38.337 +        conflicts[CWALL_MAX_TYPES + 1] = htons(1);
  38.338 +        conflicts[CWALL_MAX_TYPES + 5] = htons(1);
  38.339 +        conflicts[CWALL_MAX_TYPES + 6] = htons(1);      /* {0,5,6} */
  38.340 +    }
  38.341 +    ret += sizeof(domaintype_t) * CWALL_MAX_CONFLICTSETS * CWALL_MAX_TYPES;
  38.342 +    return ret;
  38.343 +}
  38.344 +
  38.345 +int acm_domain_set_stepolicy(void *bufstart, int buflen)
  38.346 +{
  38.347 +#define STE_MAX_SSIDREFS        6
  38.348 +#define STE_MAX_TYPES  	        5
  38.349 +
  38.350 +    struct acm_ste_policy_buffer *ste_bin_pol =
  38.351 +        (struct acm_ste_policy_buffer *) bufstart;
  38.352 +    domaintype_t *ssidrefs;
  38.353 +    int j, ret = 0;
  38.354 +
  38.355 +    ste_bin_pol->ste_max_types = htonl(STE_MAX_TYPES);
  38.356 +    ste_bin_pol->ste_max_ssidrefs = htonl(STE_MAX_SSIDREFS);
  38.357 +    ste_bin_pol->policy_code = htonl(ACM_SIMPLE_TYPE_ENFORCEMENT_POLICY);
  38.358 +    ste_bin_pol->policy_version = htonl(ACM_STE_VERSION);
  38.359 +    ste_bin_pol->ste_ssid_offset =
  38.360 +        htonl(sizeof(struct acm_ste_policy_buffer));
  38.361 +    ret += sizeof(struct acm_ste_policy_buffer);
  38.362 +    /* check buffer size */
  38.363 +    if ((buflen - ret) <
  38.364 +        (STE_MAX_TYPES * STE_MAX_SSIDREFS * sizeof(domaintype_t)))
  38.365 +        return -1;              /* not enough space */
  38.366 +
  38.367 +    ssidrefs =
  38.368 +        (domaintype_t *) (bufstart + ntohl(ste_bin_pol->ste_ssid_offset));
  38.369 +    memset(ssidrefs, 0,
  38.370 +           STE_MAX_TYPES * STE_MAX_SSIDREFS * sizeof(domaintype_t));
  38.371 +    /* all types 1 for ssidref 1 */
  38.372 +    for (j = 0; j < STE_MAX_TYPES; j++)
  38.373 +        ssidrefs[1 * STE_MAX_TYPES + j] = htons(1);
  38.374 +    /* now set type j-1 for ssidref j */
  38.375 +    for (j = 0; j < STE_MAX_SSIDREFS; j++)
  38.376 +        if ((0 < j) && (j <= STE_MAX_TYPES))
  38.377 +            ssidrefs[j * STE_MAX_TYPES + j - 1] = htons(1);
  38.378 +    ret += STE_MAX_TYPES * STE_MAX_SSIDREFS * sizeof(domaintype_t);
  38.379 +    return ret;
  38.380 +}
  38.381 +
  38.382 +#define MAX_PUSH_BUFFER 	16384
  38.383 +u8 push_buffer[MAX_PUSH_BUFFER];
  38.384 +
  38.385 +int acm_domain_setpolicy(int xc_handle)
  38.386 +{
  38.387 +    int ret;
  38.388 +    struct acm_policy_buffer *bin_pol;
  38.389 +    acm_op_t op;
  38.390 +
  38.391 +    /* future: read policy from file and set it */
  38.392 +    bin_pol = (struct acm_policy_buffer *) push_buffer;
  38.393 +    bin_pol->policy_version = htonl(ACM_POLICY_VERSION);
  38.394 +    bin_pol->magic = htonl(ACM_MAGIC);
  38.395 +    bin_pol->primary_policy_code = htonl(ACM_CHINESE_WALL_POLICY);
  38.396 +    bin_pol->secondary_policy_code =
  38.397 +        htonl(ACM_SIMPLE_TYPE_ENFORCEMENT_POLICY);
  38.398 +
  38.399 +    bin_pol->len = htonl(sizeof(struct acm_policy_buffer));
  38.400 +    bin_pol->primary_buffer_offset = htonl(ntohl(bin_pol->len));
  38.401 +    ret =
  38.402 +        acm_domain_set_chwallpolicy(push_buffer +
  38.403 +                                    ntohl(bin_pol->primary_buffer_offset),
  38.404 +                                    MAX_PUSH_BUFFER -
  38.405 +                                    ntohl(bin_pol->primary_buffer_offset));
  38.406 +    if (ret < 0)
  38.407 +    {
  38.408 +        printf("ERROR creating chwallpolicy buffer.\n");
  38.409 +        return -1;
  38.410 +    }
  38.411 +    bin_pol->len = htonl(ntohl(bin_pol->len) + ret);
  38.412 +    bin_pol->secondary_buffer_offset = htonl(ntohl(bin_pol->len));
  38.413 +    ret = acm_domain_set_stepolicy(push_buffer +
  38.414 +                                 ntohl(bin_pol->secondary_buffer_offset),
  38.415 +                                 MAX_PUSH_BUFFER -
  38.416 +                                 ntohl(bin_pol->secondary_buffer_offset));
  38.417 +    if (ret < 0)
  38.418 +    {
  38.419 +        printf("ERROR creating chwallpolicy buffer.\n");
  38.420 +        return -1;
  38.421 +    }
  38.422 +    bin_pol->len = htonl(ntohl(bin_pol->len) + ret);
  38.423 +
  38.424 +    /* dump it and then push it down into xen/acm */
  38.425 +    acm_dump_policy_buffer(push_buffer, ntohl(bin_pol->len));
  38.426 +
  38.427 +    op.cmd = ACM_SETPOLICY;
  38.428 +    op.interface_version = ACM_INTERFACE_VERSION;
  38.429 +    op.u.setpolicy.pushcache = (void *) push_buffer;
  38.430 +    op.u.setpolicy.pushcache_size = ntohl(bin_pol->len);
  38.431 +    ret = do_acm_op(xc_handle, &op);
  38.432 +
  38.433 +    if (ret)
  38.434 +        printf("ERROR setting policy. Use 'xm dmesg' to see details.\n");
  38.435 +    else
  38.436 +        printf("Successfully changed policy.\n");
  38.437 +
  38.438 +    return ret;
  38.439 +}
  38.440 +
  38.441 +/******************************* get policy ******************************/
  38.442 +
  38.443 +#define PULL_CACHE_SIZE		8192
  38.444 +u8 pull_buffer[PULL_CACHE_SIZE];
  38.445 +int acm_domain_getpolicy(int xc_handle)
  38.446 +{
  38.447 +    acm_op_t op;
  38.448 +    int ret;
  38.449 +
  38.450 +    memset(pull_buffer, 0x00, sizeof(pull_buffer));
  38.451 +    op.cmd = ACM_GETPOLICY;
  38.452 +    op.interface_version = ACM_INTERFACE_VERSION;
  38.453 +    op.u.getpolicy.pullcache = (void *) pull_buffer;
  38.454 +    op.u.getpolicy.pullcache_size = sizeof(pull_buffer);
  38.455 +    ret = do_acm_op(xc_handle, &op);
  38.456 +    /* dump policy  */
  38.457 +    acm_dump_policy_buffer(pull_buffer, sizeof(pull_buffer));
  38.458 +    return ret;
  38.459 +}
  38.460 +
  38.461 +/************************ load binary policy ******************************/
  38.462 +
  38.463 +int acm_domain_loadpolicy(int xc_handle, const char *filename)
  38.464 +{
  38.465 +    struct stat mystat;
  38.466 +    int ret, fd;
  38.467 +    off_t len;
  38.468 +    u8 *buffer;
  38.469 +
  38.470 +    if ((ret = stat(filename, &mystat)))
  38.471 +    {
  38.472 +        printf("File %s not found.\n", filename);
  38.473 +        goto out;
  38.474 +    }
  38.475 +
  38.476 +    len = mystat.st_size;
  38.477 +    if ((buffer = malloc(len)) == NULL)
  38.478 +    {
  38.479 +        ret = -ENOMEM;
  38.480 +        goto out;
  38.481 +    }
  38.482 +    if ((fd = open(filename, O_RDONLY)) <= 0)
  38.483 +    {
  38.484 +        ret = -ENOENT;
  38.485 +        printf("File %s not found.\n", filename);
  38.486 +        goto free_out;
  38.487 +    }
  38.488 +    if (len == read(fd, buffer, len))
  38.489 +    {
  38.490 +        acm_op_t op;
  38.491 +        /* dump it and then push it down into xen/acm */
  38.492 +        acm_dump_policy_buffer(buffer, len);
  38.493 +        op.cmd = ACM_SETPOLICY;
  38.494 +        op.interface_version = ACM_INTERFACE_VERSION;
  38.495 +        op.u.setpolicy.pushcache = (void *) buffer;
  38.496 +        op.u.setpolicy.pushcache_size = len;
  38.497 +        ret = do_acm_op(xc_handle, &op);
  38.498 +
  38.499 +        if (ret)
  38.500 +            printf
  38.501 +                ("ERROR setting policy. Use 'xm dmesg' to see details.\n");
  38.502 +        else
  38.503 +            printf("Successfully changed policy.\n");
  38.504 +
  38.505 +    } else {
  38.506 +        ret = -1;
  38.507 +    }
  38.508 +    close(fd);
  38.509 +  free_out:
  38.510 +    free(buffer);
  38.511 +  out:
  38.512 +    return ret;
  38.513 +}
  38.514 +
  38.515 +/************************ dump hook statistics ******************************/
  38.516 +void dump_ste_stats(struct acm_ste_stats_buffer *ste_stats)
  38.517 +{
  38.518 +    printf("STE-Policy Security Hook Statistics:\n");
  38.519 +    printf("ste: event_channel eval_count      = %d\n",
  38.520 +           ntohl(ste_stats->ec_eval_count));
  38.521 +    printf("ste: event_channel denied_count    = %d\n",
  38.522 +           ntohl(ste_stats->ec_denied_count));
  38.523 +    printf("ste: event_channel cache_hit_count = %d\n",
  38.524 +           ntohl(ste_stats->ec_cachehit_count));
  38.525 +    printf("ste:\n");
  38.526 +    printf("ste: grant_table   eval_count      = %d\n",
  38.527 +           ntohl(ste_stats->gt_eval_count));
  38.528 +    printf("ste: grant_table   denied_count    = %d\n",
  38.529 +           ntohl(ste_stats->gt_denied_count));
  38.530 +    printf("ste: grant_table   cache_hit_count = %d\n",
  38.531 +           ntohl(ste_stats->gt_cachehit_count));
  38.532 +}
  38.533 +
  38.534 +#define PULL_STATS_SIZE		8192
  38.535 +int acm_domain_dumpstats(int xc_handle)
  38.536 +{
  38.537 +    u8 stats_buffer[PULL_STATS_SIZE];
  38.538 +    acm_op_t op;
  38.539 +    int ret;
  38.540 +    struct acm_stats_buffer *stats;
  38.541 +
  38.542 +    memset(stats_buffer, 0x00, sizeof(stats_buffer));
  38.543 +    op.cmd = ACM_DUMPSTATS;
  38.544 +    op.interface_version = ACM_INTERFACE_VERSION;
  38.545 +    op.u.dumpstats.pullcache = (void *) stats_buffer;
  38.546 +    op.u.dumpstats.pullcache_size = sizeof(stats_buffer);
  38.547 +    ret = do_acm_op(xc_handle, &op);
  38.548 +
  38.549 +    if (ret < 0)
  38.550 +    {
  38.551 +        printf("ERROR dumping policy stats. Use 'xm dmesg' to see details.\n");
  38.552 +        return ret;
  38.553 +    }
  38.554 +    stats = (struct acm_stats_buffer *) stats_buffer;
  38.555 +
  38.556 +    printf("\nPolicy dump:\n");
  38.557 +    printf("============\n");
  38.558 +    printf("Magic     = %x.\n", ntohl(stats->magic));
  38.559 +    printf("Len       = %x.\n", ntohl(stats->len));
  38.560 +
  38.561 +    switch (ntohl(stats->primary_policy_code))
  38.562 +    {
  38.563 +    case ACM_NULL_POLICY:
  38.564 +        printf("NULL Policy: No statistics apply.\n");
  38.565 +        break;
  38.566 +
  38.567 +    case ACM_CHINESE_WALL_POLICY:
  38.568 +        printf("Chinese Wall Policy: No statistics apply.\n");
  38.569 +        break;
  38.570 +
  38.571 +    case ACM_SIMPLE_TYPE_ENFORCEMENT_POLICY:
  38.572 +        dump_ste_stats((struct acm_ste_stats_buffer *) (stats_buffer +
  38.573 +                                                        ntohl(stats->
  38.574 +                                                              primary_stats_offset)));
  38.575 +        break;
  38.576 +
  38.577 +    default:
  38.578 +        printf("UNKNOWN PRIMARY POLICY ERROR!\n");
  38.579 +    }
  38.580 +
  38.581 +    switch (ntohl(stats->secondary_policy_code))
  38.582 +    {
  38.583 +    case ACM_NULL_POLICY:
  38.584 +        printf("NULL Policy: No statistics apply.\n");
  38.585 +        break;
  38.586 +
  38.587 +    case ACM_CHINESE_WALL_POLICY:
  38.588 +        printf("Chinese Wall Policy: No statistics apply.\n");
  38.589 +        break;
  38.590 +
  38.591 +    case ACM_SIMPLE_TYPE_ENFORCEMENT_POLICY:
  38.592 +        dump_ste_stats((struct acm_ste_stats_buffer *) (stats_buffer +
  38.593 +                                                        ntohl(stats->
  38.594 +                                                              secondary_stats_offset)));
  38.595 +        break;
  38.596 +
  38.597 +    default:
  38.598 +        printf("UNKNOWN SECONDARY POLICY ERROR!\n");
  38.599 +    }
  38.600 +    return ret;
  38.601 +}
  38.602 +
  38.603 +/***************************** main **************************************/
  38.604 +
  38.605 +void usage(char *progname)
  38.606 +{
  38.607 +    printf("Use: %s \n"
  38.608 +           "\t setpolicy\n"
  38.609 +           "\t getpolicy\n"
  38.610 +           "\t dumpstats\n"
  38.611 +           "\t loadpolicy <binary policy file>\n", progname);
  38.612 +    exit(-1);
  38.613 +}
  38.614 +
  38.615 +int main(int argc, char **argv)
  38.616 +{
  38.617 +
  38.618 +    int acm_cmd_fd, ret;
  38.619 +
  38.620 +    if (argc < 2)
  38.621 +        usage(argv[0]);
  38.622 +
  38.623 +    if ((acm_cmd_fd = open("/proc/xen/privcmd", O_RDONLY)) <= 0)
  38.624 +    {
  38.625 +        printf("ERROR: Could not open xen privcmd device!\n");
  38.626 +        exit(-1);
  38.627 +    }
  38.628 +
  38.629 +    if (!strcmp(argv[1], "setpolicy"))
  38.630 +    {
  38.631 +        if (argc != 2)
  38.632 +            usage(argv[0]);
  38.633 +        ret = acm_domain_setpolicy(acm_cmd_fd);
  38.634 +    } else if (!strcmp(argv[1], "getpolicy")) {
  38.635 +        if (argc != 2)
  38.636 +            usage(argv[0]);
  38.637 +        ret = acm_domain_getpolicy(acm_cmd_fd);
  38.638 +    } else if (!strcmp(argv[1], "loadpolicy")) {
  38.639 +        if (argc != 3)
  38.640 +            usage(argv[0]);
  38.641 +        ret = acm_domain_loadpolicy(acm_cmd_fd, argv[2]);
  38.642 +    } else if (!strcmp(argv[1], "dumpstats")) {
  38.643 +        if (argc != 2)
  38.644 +            usage(argv[0]);
  38.645 +        ret = acm_domain_dumpstats(acm_cmd_fd);
  38.646 +    } else
  38.647 +        usage(argv[0]);
  38.648 +
  38.649 +    close(acm_cmd_fd);
  38.650 +    return ret;
  38.651 +}
    40.1 --- a/xen/acm/acm_chinesewall_hooks.c	Tue Aug 02 17:12:36 2005 +0000
    40.2 +++ b/xen/acm/acm_chinesewall_hooks.c	Tue Aug 02 17:13:11 2005 +0000
    40.3 @@ -110,45 +110,45 @@ chwall_dump_policy(u8 *buf, u16 buf_size
    40.4       struct acm_chwall_policy_buffer *chwall_buf = (struct acm_chwall_policy_buffer *)buf;
    40.5       int ret = 0;
    40.6  
    40.7 -     chwall_buf->chwall_max_types = htons(chwall_bin_pol.max_types);
    40.8 -     chwall_buf->chwall_max_ssidrefs = htons(chwall_bin_pol.max_ssidrefs);
    40.9 -     chwall_buf->policy_code = htons(ACM_CHINESE_WALL_POLICY);
   40.10 -     chwall_buf->chwall_ssid_offset = htons(sizeof(struct acm_chwall_policy_buffer));
   40.11 -     chwall_buf->chwall_max_conflictsets = htons(chwall_bin_pol.max_conflictsets);
   40.12 +     chwall_buf->chwall_max_types = htonl(chwall_bin_pol.max_types);
   40.13 +     chwall_buf->chwall_max_ssidrefs = htonl(chwall_bin_pol.max_ssidrefs);
   40.14 +     chwall_buf->policy_code = htonl(ACM_CHINESE_WALL_POLICY);
   40.15 +     chwall_buf->chwall_ssid_offset = htonl(sizeof(struct acm_chwall_policy_buffer));
   40.16 +     chwall_buf->chwall_max_conflictsets = htonl(chwall_bin_pol.max_conflictsets);
   40.17       chwall_buf->chwall_conflict_sets_offset =
   40.18 -	     htons(
   40.19 -		   ntohs(chwall_buf->chwall_ssid_offset) + 
   40.20 +	     htonl(
   40.21 +		   ntohl(chwall_buf->chwall_ssid_offset) +
   40.22  		   sizeof(domaintype_t) * chwall_bin_pol.max_ssidrefs * 
   40.23  		   chwall_bin_pol.max_types);
   40.24  
   40.25       chwall_buf->chwall_running_types_offset = 
   40.26 -	     htons(
   40.27 -		   ntohs(chwall_buf->chwall_conflict_sets_offset) +
   40.28 +	     htonl(
   40.29 +		   ntohl(chwall_buf->chwall_conflict_sets_offset) +
   40.30  		   sizeof(domaintype_t) * chwall_bin_pol.max_conflictsets *
   40.31  		   chwall_bin_pol.max_types);
   40.32  
   40.33       chwall_buf->chwall_conflict_aggregate_offset =
   40.34 -	     htons(
   40.35 -		   ntohs(chwall_buf->chwall_running_types_offset) +
   40.36 +	     htonl(
   40.37 +		   ntohl(chwall_buf->chwall_running_types_offset) +
   40.38  		   sizeof(domaintype_t) * chwall_bin_pol.max_types);
   40.39  
   40.40 -     ret = ntohs(chwall_buf->chwall_conflict_aggregate_offset) +
   40.41 +     ret = ntohl(chwall_buf->chwall_conflict_aggregate_offset) +
   40.42  	     sizeof(domaintype_t) * chwall_bin_pol.max_types;
   40.43  
   40.44       /* now copy buffers over */
   40.45 -     arrcpy16((u16 *)(buf + ntohs(chwall_buf->chwall_ssid_offset)),
   40.46 +     arrcpy16((u16 *)(buf + ntohl(chwall_buf->chwall_ssid_offset)),
   40.47  	      chwall_bin_pol.ssidrefs,
   40.48  	      chwall_bin_pol.max_ssidrefs * chwall_bin_pol.max_types);
   40.49  
   40.50 -     arrcpy16((u16 *)(buf + ntohs(chwall_buf->chwall_conflict_sets_offset)),
   40.51 +     arrcpy16((u16 *)(buf + ntohl(chwall_buf->chwall_conflict_sets_offset)),
   40.52  	      chwall_bin_pol.conflict_sets,
   40.53  	      chwall_bin_pol.max_conflictsets * chwall_bin_pol.max_types);
   40.54  
   40.55 -     arrcpy16((u16 *)(buf + ntohs(chwall_buf->chwall_running_types_offset)),
   40.56 +     arrcpy16((u16 *)(buf + ntohl(chwall_buf->chwall_running_types_offset)),
   40.57  	      chwall_bin_pol.running_types,
   40.58  	      chwall_bin_pol.max_types);
   40.59  
   40.60 -     arrcpy16((u16 *)(buf + ntohs(chwall_buf->chwall_conflict_aggregate_offset)),
   40.61 +     arrcpy16((u16 *)(buf + ntohl(chwall_buf->chwall_conflict_aggregate_offset)),
   40.62  	      chwall_bin_pol.conflict_aggregate_set,
   40.63  	      chwall_bin_pol.max_types);
   40.64       return ret;
   40.65 @@ -226,14 +226,20 @@ chwall_set_policy(u8 *buf, u16 buf_size)
   40.66  	void *ssids = NULL, *conflict_sets = NULL, *running_types = NULL, *conflict_aggregate_set = NULL;	
   40.67  
   40.68          /* rewrite the policy due to endianess */
   40.69 -        chwall_buf->policy_code                      = ntohs(chwall_buf->policy_code);
   40.70 -        chwall_buf->chwall_max_types                 = ntohs(chwall_buf->chwall_max_types);
   40.71 -        chwall_buf->chwall_max_ssidrefs              = ntohs(chwall_buf->chwall_max_ssidrefs);
   40.72 -        chwall_buf->chwall_max_conflictsets          = ntohs(chwall_buf->chwall_max_conflictsets);
   40.73 -        chwall_buf->chwall_ssid_offset               = ntohs(chwall_buf->chwall_ssid_offset);
   40.74 -        chwall_buf->chwall_conflict_sets_offset      = ntohs(chwall_buf->chwall_conflict_sets_offset);
   40.75 -        chwall_buf->chwall_running_types_offset      = ntohs(chwall_buf->chwall_running_types_offset);
   40.76 -        chwall_buf->chwall_conflict_aggregate_offset = ntohs(chwall_buf->chwall_conflict_aggregate_offset);
   40.77 +        chwall_buf->policy_code                      = ntohl(chwall_buf->policy_code);
   40.78 +        chwall_buf->policy_version                   = ntohl(chwall_buf->policy_version);
   40.79 +        chwall_buf->chwall_max_types                 = ntohl(chwall_buf->chwall_max_types);
   40.80 +        chwall_buf->chwall_max_ssidrefs              = ntohl(chwall_buf->chwall_max_ssidrefs);
   40.81 +        chwall_buf->chwall_max_conflictsets          = ntohl(chwall_buf->chwall_max_conflictsets);
   40.82 +        chwall_buf->chwall_ssid_offset               = ntohl(chwall_buf->chwall_ssid_offset);
   40.83 +        chwall_buf->chwall_conflict_sets_offset      = ntohl(chwall_buf->chwall_conflict_sets_offset);
   40.84 +        chwall_buf->chwall_running_types_offset      = ntohl(chwall_buf->chwall_running_types_offset);
   40.85 +        chwall_buf->chwall_conflict_aggregate_offset = ntohl(chwall_buf->chwall_conflict_aggregate_offset);
   40.86 +
   40.87 +	/* policy type and version checks */
   40.88 +	if ((chwall_buf->policy_code != ACM_CHINESE_WALL_POLICY) ||
   40.89 +	    (chwall_buf->policy_version != ACM_CHWALL_VERSION))
   40.90 +		return -EINVAL;
   40.91  
   40.92  	/* 1. allocate new buffers */
   40.93  	ssids = xmalloc_array(domaintype_t, chwall_buf->chwall_max_types*chwall_buf->chwall_max_ssidrefs);
    41.1 --- a/xen/acm/acm_core.c	Tue Aug 02 17:12:36 2005 +0000
    41.2 +++ b/xen/acm/acm_core.c	Tue Aug 02 17:13:11 2005 +0000
    41.3 @@ -120,7 +120,6 @@ acm_setup(unsigned int *initrdidx,
    41.4          if (ntohl(pol->magic) == ACM_MAGIC) {
    41.5              rc = acm_set_policy((void *)_policy_start,
    41.6                                  (u16)_policy_len,
    41.7 -                                ACM_USE_SECURITY_POLICY,
    41.8                                  0);
    41.9              if (rc == ACM_OK) {
   41.10                  printf("Policy len  0x%lx, start at %p.\n",_policy_len,_policy_start);
    42.1 --- a/xen/acm/acm_policy.c	Tue Aug 02 17:12:36 2005 +0000
    42.2 +++ b/xen/acm/acm_policy.c	Tue Aug 02 17:13:11 2005 +0000
    42.3 @@ -6,9 +6,8 @@
    42.4   * Author:
    42.5   * Reiner Sailer <sailer@watson.ibm.com>
    42.6   *
    42.7 - * Contributions:
    42.8 + * Contributors:
    42.9   * Stefan Berger <stefanb@watson.ibm.com>
   42.10 - *	support for network-byte-order binary policies
   42.11   *
   42.12   * This program is free software; you can redistribute it and/or
   42.13   * modify it under the terms of the GNU General Public License as
   42.14 @@ -27,29 +26,20 @@
   42.15  #include <xen/lib.h>
   42.16  #include <xen/delay.h>
   42.17  #include <xen/sched.h>
   42.18 -#include <public/policy_ops.h>
   42.19 +#include <public/acm_ops.h>
   42.20  #include <acm/acm_core.h>
   42.21  #include <acm/acm_hooks.h>
   42.22  #include <acm/acm_endian.h>
   42.23  
   42.24  int
   42.25 -acm_set_policy(void *buf, u16 buf_size, u16 policy, int isuserbuffer)
   42.26 +acm_set_policy(void *buf, u16 buf_size, int isuserbuffer)
   42.27  {
   42.28  	u8 *policy_buffer = NULL;
   42.29  	struct acm_policy_buffer *pol;
   42.30  	
   42.31 -	if (policy != ACM_USE_SECURITY_POLICY) {
   42.32 -		printk("%s: Loading incompatible policy (running: %s).\n", __func__,
   42.33 -		       ACM_POLICY_NAME(ACM_USE_SECURITY_POLICY));
   42.34 -		return -EFAULT;
   42.35 -	}
   42.36 -	/* now check correct buffer sizes for policy combinations */
   42.37 -	if (policy == ACM_NULL_POLICY) {
   42.38 -		printkd("%s: NULL Policy, no policy needed.\n", __func__);
   42.39 -		goto out;
   42.40 -	}
   42.41       	if (buf_size < sizeof(struct acm_policy_buffer))
   42.42  		return -EFAULT;
   42.43 +
   42.44  	/* 1. copy buffer from domain */
   42.45  	if ((policy_buffer = xmalloc_array(u8, buf_size)) == NULL)
   42.46  	    goto error_free;
   42.47 @@ -58,17 +48,17 @@ acm_set_policy(void *buf, u16 buf_size, 
   42.48  			printk("%s: Error copying!\n",__func__);
   42.49  			goto error_free;
   42.50  		}
   42.51 -	} else {
   42.52 +	} else
   42.53  		memcpy(policy_buffer, buf, buf_size);
   42.54 -	}
   42.55 +
   42.56  	/* 2. some sanity checking */
   42.57  	pol = (struct acm_policy_buffer *)policy_buffer;
   42.58  
   42.59  	if ((ntohl(pol->magic) != ACM_MAGIC) || 
   42.60 -	    (ntohs(pol->primary_policy_code) != acm_bin_pol.primary_policy_code) ||
   42.61 -	    (ntohs(pol->secondary_policy_code) != acm_bin_pol.secondary_policy_code) ||
   42.62 -	    (ntohl(pol->policyversion) != POLICY_INTERFACE_VERSION)) {
   42.63 -		printkd("%s: Wrong policy magics!\n", __func__);
   42.64 +	    (ntohl(pol->policy_version) != ACM_POLICY_VERSION) ||
   42.65 +	    (ntohl(pol->primary_policy_code) != acm_bin_pol.primary_policy_code) ||
   42.66 +	    (ntohl(pol->secondary_policy_code) != acm_bin_pol.secondary_policy_code)) {
   42.67 +		printkd("%s: Wrong policy magics or versions!\n", __func__);
   42.68  		goto error_free;
   42.69  	}
   42.70  	if (buf_size != ntohl(pol->len)) {
   42.71 @@ -79,21 +69,19 @@ acm_set_policy(void *buf, u16 buf_size, 
   42.72  	/* get bin_policy lock and rewrite policy (release old one) */
   42.73  	write_lock(&acm_bin_pol_rwlock);
   42.74  
   42.75 -	/* 3. now get/set primary policy data */
   42.76 -	if (acm_primary_ops->set_binary_policy(buf + ntohs(pol->primary_buffer_offset), 
   42.77 -                                               ntohs(pol->secondary_buffer_offset) -
   42.78 -					       ntohs(pol->primary_buffer_offset))) {
   42.79 +	/* 3. set primary policy data */
   42.80 +	if (acm_primary_ops->set_binary_policy(buf + ntohl(pol->primary_buffer_offset),
   42.81 +                                               ntohl(pol->secondary_buffer_offset) -
   42.82 +					       ntohl(pol->primary_buffer_offset))) {
   42.83  		goto error_lock_free;
   42.84  	}
   42.85 -	/* 4. now get/set secondary policy data */
   42.86 -	if (acm_secondary_ops->set_binary_policy(buf + ntohs(pol->secondary_buffer_offset),
   42.87 +	/* 4. set secondary policy data */
   42.88 +	if (acm_secondary_ops->set_binary_policy(buf + ntohl(pol->secondary_buffer_offset),
   42.89  						 ntohl(pol->len) - 
   42.90 -						 ntohs(pol->secondary_buffer_offset))) {
   42.91 +						 ntohl(pol->secondary_buffer_offset))) {
   42.92  		goto error_lock_free;
   42.93  	}
   42.94  	write_unlock(&acm_bin_pol_rwlock);
   42.95 - out:
   42.96 -	printk("%s: Done .\n", __func__);
   42.97  	if (policy_buffer != NULL)
   42.98  		xfree(policy_buffer);
   42.99  	return ACM_OK;
  42.100 @@ -121,26 +109,25 @@ acm_get_policy(void *buf, u16 buf_size)
  42.101       /* future: read policy from file and set it */
  42.102       bin_pol = (struct acm_policy_buffer *)policy_buffer;
  42.103       bin_pol->magic = htonl(ACM_MAGIC);
  42.104 -     bin_pol->policyversion = htonl(POLICY_INTERFACE_VERSION);
  42.105 -     bin_pol->primary_policy_code = htons(acm_bin_pol.primary_policy_code);
  42.106 -     bin_pol->secondary_policy_code = htons(acm_bin_pol.secondary_policy_code);
  42.107 +     bin_pol->primary_policy_code = htonl(acm_bin_pol.primary_policy_code);
  42.108 +     bin_pol->secondary_policy_code = htonl(acm_bin_pol.secondary_policy_code);
  42.109  
  42.110       bin_pol->len = htonl(sizeof(struct acm_policy_buffer));
  42.111 -     bin_pol->primary_buffer_offset = htons(ntohl(bin_pol->len));
  42.112 -     bin_pol->secondary_buffer_offset = htons(ntohl(bin_pol->len));
  42.113 +     bin_pol->primary_buffer_offset = htonl(ntohl(bin_pol->len));
  42.114 +     bin_pol->secondary_buffer_offset = htonl(ntohl(bin_pol->len));
  42.115       
  42.116 -     ret = acm_primary_ops->dump_binary_policy (policy_buffer + ntohs(bin_pol->primary_buffer_offset),
  42.117 -				       buf_size - ntohs(bin_pol->primary_buffer_offset));
  42.118 +     ret = acm_primary_ops->dump_binary_policy (policy_buffer + ntohl(bin_pol->primary_buffer_offset),
  42.119 +				       buf_size - ntohl(bin_pol->primary_buffer_offset));
  42.120       if (ret < 0) {
  42.121  	     printk("%s: ERROR creating chwallpolicy buffer.\n", __func__);
  42.122  	     read_unlock(&acm_bin_pol_rwlock);
  42.123  	     return -1;
  42.124       }
  42.125       bin_pol->len = htonl(ntohl(bin_pol->len) + ret);
  42.126 -     bin_pol->secondary_buffer_offset = htons(ntohl(bin_pol->len));
  42.127 +     bin_pol->secondary_buffer_offset = htonl(ntohl(bin_pol->len));
  42.128  
  42.129 -     ret = acm_secondary_ops->dump_binary_policy(policy_buffer + ntohs(bin_pol->secondary_buffer_offset), 
  42.130 -				    buf_size - ntohs(bin_pol->secondary_buffer_offset));
  42.131 +     ret = acm_secondary_ops->dump_binary_policy(policy_buffer + ntohl(bin_pol->secondary_buffer_offset),
  42.132 +				    buf_size - ntohl(bin_pol->secondary_buffer_offset));
  42.133       if (ret < 0) {
  42.134  	     printk("%s: ERROR creating chwallpolicy buffer.\n", __func__);
  42.135  	     read_unlock(&acm_bin_pol_rwlock);
  42.136 @@ -178,11 +165,10 @@ acm_dump_statistics(void *buf, u16 buf_s
  42.137  	     goto error_lock_free;
  42.138  
  42.139       acm_stats.magic = htonl(ACM_MAGIC);
  42.140 -     acm_stats.policyversion = htonl(POLICY_INTERFACE_VERSION);
  42.141 -     acm_stats.primary_policy_code = htons(acm_bin_pol.primary_policy_code);
  42.142 -     acm_stats.secondary_policy_code = htons(acm_bin_pol.secondary_policy_code);
  42.143 -     acm_stats.primary_stats_offset = htons(sizeof(struct acm_stats_buffer));
  42.144 -     acm_stats.secondary_stats_offset = htons(sizeof(struct acm_stats_buffer) + len1);
  42.145 +     acm_stats.primary_policy_code = htonl(acm_bin_pol.primary_policy_code);
  42.146 +     acm_stats.secondary_policy_code = htonl(acm_bin_pol.secondary_policy_code);
  42.147 +     acm_stats.primary_stats_offset = htonl(sizeof(struct acm_stats_buffer));
  42.148 +     acm_stats.secondary_stats_offset = htonl(sizeof(struct acm_stats_buffer) + len1);
  42.149       acm_stats.len = htonl(sizeof(struct acm_stats_buffer) + len1 + len2);
  42.150       memcpy(stats_buffer, &acm_stats, sizeof(struct acm_stats_buffer));
  42.151  
    43.1 --- a/xen/acm/acm_simple_type_enforcement_hooks.c	Tue Aug 02 17:12:36 2005 +0000
    43.2 +++ b/xen/acm/acm_simple_type_enforcement_hooks.c	Tue Aug 02 17:13:11 2005 +0000
    43.3 @@ -140,15 +140,15 @@ ste_dump_policy(u8 *buf, u16 buf_size) {
    43.4       struct acm_ste_policy_buffer *ste_buf = (struct acm_ste_policy_buffer *)buf;
    43.5       int ret = 0;
    43.6  
    43.7 -     ste_buf->ste_max_types = htons(ste_bin_pol.max_types);
    43.8 -     ste_buf->ste_max_ssidrefs = htons(ste_bin_pol.max_ssidrefs);
    43.9 -     ste_buf->policy_code = htons(ACM_SIMPLE_TYPE_ENFORCEMENT_POLICY);
   43.10 -     ste_buf->ste_ssid_offset = htons(sizeof(struct acm_ste_policy_buffer));
   43.11 -     ret = ntohs(ste_buf->ste_ssid_offset) +
   43.12 +     ste_buf->ste_max_types = htonl(ste_bin_pol.max_types);
   43.13 +     ste_buf->ste_max_ssidrefs = htonl(ste_bin_pol.max_ssidrefs);
   43.14 +     ste_buf->policy_code = htonl(ACM_SIMPLE_TYPE_ENFORCEMENT_POLICY);
   43.15 +     ste_buf->ste_ssid_offset = htonl(sizeof(struct acm_ste_policy_buffer));
   43.16 +     ret = ntohl(ste_buf->ste_ssid_offset) +
   43.17  	     sizeof(domaintype_t)*ste_bin_pol.max_ssidrefs*ste_bin_pol.max_types;
   43.18  
   43.19       /* now copy buffer over */
   43.20 -     arrcpy(buf + ntohs(ste_buf->ste_ssid_offset),
   43.21 +     arrcpy(buf + ntohl(ste_buf->ste_ssid_offset),
   43.22  	    ste_bin_pol.ssidrefs,
   43.23  	    sizeof(domaintype_t),
   43.24               ste_bin_pol.max_ssidrefs*ste_bin_pol.max_types);
   43.25 @@ -276,10 +276,16 @@ ste_set_policy(u8 *buf, u16 buf_size)
   43.26       int i;
   43.27  
   43.28       /* Convert endianess of policy */
   43.29 -     ste_buf->policy_code = ntohs(ste_buf->policy_code);
   43.30 -     ste_buf->ste_max_types = ntohs(ste_buf->ste_max_types);
   43.31 -     ste_buf->ste_max_ssidrefs = ntohs(ste_buf->ste_max_ssidrefs);
   43.32 -     ste_buf->ste_ssid_offset = ntohs(ste_buf->ste_ssid_offset);
   43.33 +     ste_buf->policy_code = ntohl(ste_buf->policy_code);
   43.34 +     ste_buf->policy_version = ntohl(ste_buf->policy_version);
   43.35 +     ste_buf->ste_max_types = ntohl(ste_buf->ste_max_types);
   43.36 +     ste_buf->ste_max_ssidrefs = ntohl(ste_buf->ste_max_ssidrefs);
   43.37 +     ste_buf->ste_ssid_offset = ntohl(ste_buf->ste_ssid_offset);
   43.38 +
   43.39 +     /* policy type and version checks */
   43.40 +     if ((ste_buf->policy_code != ACM_SIMPLE_TYPE_ENFORCEMENT_POLICY) ||
   43.41 +	 (ste_buf->policy_version != ACM_STE_VERSION))
   43.42 +	     return -EINVAL;
   43.43  
   43.44       /* 1. create and copy-in new ssidrefs buffer */
   43.45       ssidrefsbuf = xmalloc_array(u8, sizeof(domaintype_t)*ste_buf->ste_max_types*ste_buf->ste_max_ssidrefs);
    44.1 --- a/xen/arch/x86/shadow_public.c	Tue Aug 02 17:12:36 2005 +0000
    44.2 +++ b/xen/arch/x86/shadow_public.c	Tue Aug 02 17:13:11 2005 +0000
    44.3 @@ -30,7 +30,7 @@
    44.4  #include <xen/sched.h>
    44.5  #include <xen/trace.h>
    44.6  
    44.7 -#if CONFIG_PAGING_LEVELS >= 4 
    44.8 +#if CONFIG_PAGING_LEVELS >= 3
    44.9  #include <asm/shadow_64.h>
   44.10  
   44.11  extern struct shadow_ops MODE_F_HANDLER;
   44.12 @@ -233,7 +233,20 @@ void free_monitor_pagetable(struct vcpu 
   44.13      v->arch.monitor_vtable = 0;
   44.14  }
   44.15  
   44.16 +#elif CONFIG_PAGING_LEVELS == 3
   44.17 +
   44.18 +static void alloc_monitor_pagetable(struct vcpu *v)
   44.19 +{
   44.20 +    BUG(); /* PAE not implemented yet */
   44.21 +}
   44.22 +
   44.23 +void free_monitor_pagetable(struct vcpu *v)
   44.24 +{
   44.25 +    BUG(); /* PAE not implemented yet */
   44.26 +}
   44.27 +
   44.28  #elif CONFIG_PAGING_LEVELS == 2
   44.29 +
   44.30  static void alloc_monitor_pagetable(struct vcpu *v)
   44.31  {
   44.32      unsigned long mmfn;
    45.1 --- a/xen/arch/x86/x86_32/entry.S	Tue Aug 02 17:12:36 2005 +0000
    45.2 +++ b/xen/arch/x86/x86_32/entry.S	Tue Aug 02 17:13:11 2005 +0000
    45.3 @@ -751,7 +751,7 @@ ENTRY(hypercall_table)
    45.4          .long do_boot_vcpu
    45.5          .long do_ni_hypercall       /* 25 */
    45.6          .long do_mmuext_op
    45.7 -	 .long do_policy_op          /* 27 */
    45.8 +        .long do_acm_op             /* 27 */
    45.9          .rept NR_hypercalls-((.-hypercall_table)/4)
   45.10          .long do_ni_hypercall
   45.11          .endr
    46.1 --- a/xen/arch/x86/x86_64/entry.S	Tue Aug 02 17:12:36 2005 +0000
    46.2 +++ b/xen/arch/x86/x86_64/entry.S	Tue Aug 02 17:13:11 2005 +0000
    46.3 @@ -587,7 +587,7 @@ ENTRY(hypercall_table)
    46.4          .quad do_boot_vcpu
    46.5          .quad do_set_segment_base   /* 25 */
    46.6          .quad do_mmuext_op
    46.7 -        .quad do_policy_op
    46.8 +        .quad do_acm_op
    46.9          .rept NR_hypercalls-((.-hypercall_table)/4)
   46.10          .quad do_ni_hypercall
   46.11          .endr
    47.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    47.2 +++ b/xen/common/acm_ops.c	Tue Aug 02 17:13:11 2005 +0000
    47.3 @@ -0,0 +1,127 @@
    47.4 +/******************************************************************************
    47.5 + * acm_ops.c
    47.6 + *
    47.7 + * Copyright (C) 2005 IBM Corporation
    47.8 + *
    47.9 + * Author:
   47.10 + * Reiner Sailer <sailer@watson.ibm.com>
   47.11 + *
   47.12 + * This program is free software; you can redistribute it and/or
   47.13 + * modify it under the terms of the GNU General Public License as
   47.14 + * published by the Free Software Foundation, version 2 of the
   47.15 + * License.
   47.16 + *
   47.17 + * Process acm command requests from guest OS.
   47.18 + *
   47.19 + */
   47.20 +
   47.21 +#include <xen/config.h>
   47.22 +#include <xen/types.h>
   47.23 +#include <xen/lib.h>
   47.24 +#include <xen/mm.h>
   47.25 +#include <public/acm_ops.h>
   47.26 +#include <xen/sched.h>
   47.27 +#include <xen/event.h>
   47.28 +#include <xen/trace.h>
   47.29 +#include <xen/console.h>
   47.30 +#include <asm/shadow.h>
   47.31 +#include <public/sched_ctl.h>
   47.32 +#include <acm/acm_hooks.h>
   47.33 +
   47.34 +#if (ACM_USE_SECURITY_POLICY == ACM_NULL_POLICY)
   47.35 +
   47.36 +long do_acm_op(acm_op_t * u_acm_op)
   47.37 +{
   47.38 +    return -ENOSYS;
   47.39 +}
   47.40 +
   47.41 +#else
   47.42 +
   47.43 +typedef enum acm_operation {
   47.44 +    POLICY,                     /* access to policy interface (early drop) */
   47.45 +    GETPOLICY,                  /* dump policy cache */
   47.46 +    SETPOLICY,                  /* set policy cache (controls security) */
   47.47 +    DUMPSTATS                   /* dump policy statistics */
   47.48 +} acm_operation_t;
   47.49 +
   47.50 +int acm_authorize_acm_ops(struct domain *d, acm_operation_t pops)
   47.51 +{
   47.52 +    /* all policy management functions are restricted to privileged domains,
   47.53 +     * soon we will introduce finer-grained privileges for policy operations
   47.54 +     */
   47.55 +    if (!IS_PRIV(d))
   47.56 +    {
   47.57 +        printk("%s: ACM management authorization denied ERROR!\n", __func__);
   47.58 +        return ACM_ACCESS_DENIED;
   47.59 +    }
   47.60 +    return ACM_ACCESS_PERMITTED;
   47.61 +}
   47.62 +
   47.63 +long do_acm_op(acm_op_t * u_acm_op)
   47.64 +{
   47.65 +    long ret = 0;
   47.66 +    acm_op_t curop, *op = &curop;
   47.67 +
   47.68 +    /* check here policy decision for policy commands */
   47.69 +    /* for now allow DOM0 only, later indepedently    */
   47.70 +    if (acm_authorize_acm_ops(current->domain, POLICY))
   47.71 +        return -EACCES;
   47.72 +
   47.73 +    if (copy_from_user(op, u_acm_op, sizeof(*op)))
   47.74 +        return -EFAULT;
   47.75 +
   47.76 +    if (op->interface_version != ACM_INTERFACE_VERSION)
   47.77 +        return -EACCES;
   47.78 +
   47.79 +    switch (op->cmd)
   47.80 +    {
   47.81 +    case ACM_SETPOLICY:
   47.82 +        {
   47.83 +            if (acm_authorize_acm_ops(current->domain, SETPOLICY))
   47.84 +                return -EACCES;
   47.85 +            printkd("%s: setting policy.\n", __func__);
   47.86 +            ret = acm_set_policy(op->u.setpolicy.pushcache,
   47.87 +                                 op->u.setpolicy.pushcache_size, 1);
   47.88 +            if (ret == ACM_OK)
   47.89 +                ret = 0;
   47.90 +            else
   47.91 +                ret = -ESRCH;
   47.92 +        }
   47.93 +        break;
   47.94 +
   47.95 +    case ACM_GETPOLICY:
   47.96 +        {
   47.97 +            if (acm_authorize_acm_ops(current->domain, GETPOLICY))
   47.98 +                return -EACCES;
   47.99 +            printkd("%s: getting policy.\n", __func__);
  47.100 +            ret = acm_get_policy(op->u.getpolicy.pullcache,
  47.101 +                                 op->u.getpolicy.pullcache_size);
  47.102 +            if (ret == ACM_OK)
  47.103 +                ret = 0;
  47.104 +            else
  47.105 +                ret = -ESRCH;
  47.106 +        }
  47.107 +        break;
  47.108 +
  47.109 +    case ACM_DUMPSTATS:
  47.110 +        {
  47.111 +            if (acm_authorize_acm_ops(current->domain, DUMPSTATS))
  47.112 +                return -EACCES;
  47.113 +            printkd("%s: dumping statistics.\n", __func__);
  47.114 +            ret = acm_dump_statistics(op->u.dumpstats.pullcache,
  47.115 +                                      op->u.dumpstats.pullcache_size);
  47.116 +            if (ret == ACM_OK)
  47.117 +                ret = 0;
  47.118 +            else
  47.119 +                ret = -ESRCH;
  47.120 +        }
  47.121 +        break;
  47.122 +
  47.123 +    default:
  47.124 +        ret = -ESRCH;
  47.125 +
  47.126 +    }
  47.127 +    return ret;
  47.128 +}
  47.129 +
  47.130 +#endif
    48.1 --- a/xen/common/policy_ops.c	Tue Aug 02 17:12:36 2005 +0000
    48.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    48.3 @@ -1,133 +0,0 @@
    48.4 -/******************************************************************************
    48.5 - * policy_ops.c
    48.6 - * 
    48.7 - * Copyright (C) 2005 IBM Corporation
    48.8 - *
    48.9 - * Author:
   48.10 - * Reiner Sailer <sailer@watson.ibm.com>
   48.11 - *
   48.12 - * This program is free software; you can redistribute it and/or
   48.13 - * modify it under the terms of the GNU General Public License as
   48.14 - * published by the Free Software Foundation, version 2 of the
   48.15 - * License.
   48.16 - *
   48.17 - * Process policy command requests from guest OS.
   48.18 - *
   48.19 - */
   48.20 -
   48.21 -#include <xen/config.h>
   48.22 -#include <xen/types.h>
   48.23 -#include <xen/lib.h>
   48.24 -#include <xen/mm.h>
   48.25 -#include <public/policy_ops.h>
   48.26 -#include <xen/sched.h>
   48.27 -#include <xen/event.h>
   48.28 -#include <xen/trace.h>
   48.29 -#include <xen/console.h>
   48.30 -#include <asm/shadow.h>
   48.31 -#include <public/sched_ctl.h>
   48.32 -#include <acm/acm_hooks.h>
   48.33 -
   48.34 -#if (ACM_USE_SECURITY_POLICY == ACM_NULL_POLICY)
   48.35 -
   48.36 -long do_policy_op(policy_op_t *u_policy_op)
   48.37 -{
   48.38 -    return -ENOSYS;
   48.39 -}
   48.40 -
   48.41 -#else
   48.42 -
   48.43 -typedef enum policyoperation {
   48.44 -    POLICY,     /* access to policy interface (early drop) */
   48.45 -    GETPOLICY,  /* dump policy cache */
   48.46 -    SETPOLICY,  /* set policy cache (controls security) */
   48.47 -    DUMPSTATS   /* dump policy statistics */
   48.48 -} policyoperation_t;
   48.49 -
   48.50 -int
   48.51 -acm_authorize_policyops(struct domain *d, policyoperation_t pops)
   48.52 -{
   48.53 -    /* all policy management functions are restricted to privileged domains,
   48.54 -     * soon we will introduce finer-grained privileges for policy operations 
   48.55 -     */
   48.56 -    if (!IS_PRIV(d)) {
   48.57 -        printk("%s: Policy management authorization denied ERROR!\n",
   48.58 -               __func__);
   48.59 -        return ACM_ACCESS_DENIED;
   48.60 -    }
   48.61 -    return ACM_ACCESS_PERMITTED;
   48.62 -}
   48.63 -
   48.64 -long do_policy_op(policy_op_t *u_policy_op)
   48.65 -{
   48.66 -    long ret = 0;
   48.67 -    policy_op_t curop, *op = &curop;
   48.68 -
   48.69 -    /* check here policy decision for policy commands */
   48.70 -    /* for now allow DOM0 only, later indepedently    */
   48.71 -    if (acm_authorize_policyops(current->domain, POLICY))
   48.72 -        return -EACCES;
   48.73 -
   48.74 -    if ( copy_from_user(op, u_policy_op, sizeof(*op)) )
   48.75 -        return -EFAULT;
   48.76 -
   48.77 -    if ( op->interface_version != POLICY_INTERFACE_VERSION )
   48.78 -        return -EACCES;
   48.79 -
   48.80 -    switch ( op->cmd )
   48.81 -    {
   48.82 -    case POLICY_SETPOLICY:
   48.83 -    {
   48.84 -        if (acm_authorize_policyops(current->domain, SETPOLICY))
   48.85 -            return -EACCES;
   48.86 -        printkd("%s: setting policy.\n", __func__);
   48.87 -        ret = acm_set_policy(
   48.88 -            op->u.setpolicy.pushcache, 
   48.89 -            op->u.setpolicy.pushcache_size, 
   48.90 -            op->u.setpolicy.policy_type,
   48.91 -            1);
   48.92 -        if (ret == ACM_OK)
   48.93 -            ret = 0;
   48.94 -        else
   48.95 -            ret = -ESRCH;
   48.96 -    }
   48.97 -    break;
   48.98 -
   48.99 -    case POLICY_GETPOLICY:
  48.100 -    {
  48.101 -        if (acm_authorize_policyops(current->domain, GETPOLICY))
  48.102 -            return -EACCES;
  48.103 -        printkd("%s: getting policy.\n", __func__);
  48.104 -        ret = acm_get_policy(
  48.105 -            op->u.getpolicy.pullcache, 
  48.106 -            op->u.getpolicy.pullcache_size);
  48.107 -        if (ret == ACM_OK)
  48.108 -            ret = 0;
  48.109 -        else
  48.110 -            ret = -ESRCH;
  48.111 -    }
  48.112 -    break;
  48.113 -
  48.114 -    case POLICY_DUMPSTATS:
  48.115 -    {
  48.116 -        if (acm_authorize_policyops(current->domain, DUMPSTATS))
  48.117 -            return -EACCES;
  48.118 -        printkd("%s: dumping statistics.\n", __func__);
  48.119 -        ret = acm_dump_statistics(
  48.120 -            op->u.dumpstats.pullcache, 
  48.121 -            op->u.dumpstats.pullcache_size);
  48.122 -        if (ret == ACM_OK)
  48.123 -            ret = 0;
  48.124 -        else
  48.125 -            ret = -ESRCH;
  48.126 -    }
  48.127 -    break;
  48.128 -
  48.129 -    default:
  48.130 -        ret = -ESRCH;
  48.131 -
  48.132 -    }
  48.133 -    return ret;
  48.134 -}
  48.135 -
  48.136 -#endif
    49.1 --- a/xen/include/acm/acm_core.h	Tue Aug 02 17:12:36 2005 +0000
    49.2 +++ b/xen/include/acm/acm_core.h	Tue Aug 02 17:13:11 2005 +0000
    49.3 @@ -21,7 +21,7 @@
    49.4  #include <xen/spinlock.h>
    49.5  #include <public/acm.h>
    49.6  #include <xen/acm_policy.h>
    49.7 -#include <public/policy_ops.h>
    49.8 +#include <public/acm_ops.h>
    49.9  
   49.10  /* Xen-internal representation of the binary policy */
   49.11  struct acm_binary_policy {
   49.12 @@ -113,7 +113,7 @@ struct ste_ssid {
   49.13  /* protos */
   49.14  int acm_init_domain_ssid(domid_t id, ssidref_t ssidref);
   49.15  int acm_free_domain_ssid(struct acm_ssid_domain *ssid);
   49.16 -int acm_set_policy(void *buf, u16 buf_size, u16 policy, int isuserbuffer);
   49.17 +int acm_set_policy(void *buf, u16 buf_size, int isuserbuffer);
   49.18  int acm_get_policy(void *buf, u16 buf_size);
   49.19  int acm_dump_statistics(void *buf, u16 buf_size);
   49.20  
    50.1 --- a/xen/include/public/acm.h	Tue Aug 02 17:12:36 2005 +0000
    50.2 +++ b/xen/include/public/acm.h	Tue Aug 02 17:13:11 2005 +0000
    50.3 @@ -71,6 +71,14 @@
    50.4  	(X == ACM_CHINESE_WALL_AND_SIMPLE_TYPE_ENFORCEMENT_POLICY) ? "CHINESE WALL AND SIMPLE TYPE ENFORCEMENT policy" : \
    50.5  	"UNDEFINED policy"
    50.6  
    50.7 +/* the following policy versions must be increased
    50.8 + * whenever the interpretation of the related
    50.9 + * policy's data structure changes
   50.10 + */
   50.11 +#define ACM_POLICY_VERSION	1
   50.12 +#define ACM_CHWALL_VERSION	1
   50.13 +#define ACM_STE_VERSION		1
   50.14 +
   50.15  /* defines a ssid reference used by xen */
   50.16  typedef u32 ssidref_t;
   50.17  
   50.18 @@ -102,46 +110,53 @@ typedef u16 domaintype_t;
   50.19  #define ACM_MAGIC		0x0001debc
   50.20  
   50.21  /* each offset in bytes from start of the struct they
   50.22 - *   the are part of */
   50.23 + * are part of */
   50.24 +
   50.25  /* each buffer consists of all policy information for
   50.26   * the respective policy given in the policy code
   50.27 + *
   50.28 + * acm_policy_buffer, acm_chwall_policy_buffer,
   50.29 + * and acm_ste_policy_buffer need to stay 32-bit aligned
   50.30 + * because we create binary policies also with external
   50.31 + * tools that assume packed representations (e.g. the java tool)
   50.32   */
   50.33  struct acm_policy_buffer {
   50.34 +	u32 policy_version; /* ACM_POLICY_VERSION */
   50.35          u32 magic;
   50.36 -	u32 policyversion;
   50.37  	u32 len;
   50.38 -	u16 primary_policy_code;
   50.39 -	u16 primary_buffer_offset;
   50.40 -	u16 secondary_policy_code;
   50.41 -	u16 secondary_buffer_offset;
   50.42 +	u32 primary_policy_code;
   50.43 +	u32 primary_buffer_offset;
   50.44 +	u32 secondary_policy_code;
   50.45 +	u32 secondary_buffer_offset;
   50.46  };
   50.47  
   50.48  struct acm_chwall_policy_buffer {
   50.49 -	u16 policy_code;
   50.50 -	u16 chwall_max_types;
   50.51 -	u16 chwall_max_ssidrefs;
   50.52 -	u16 chwall_max_conflictsets;
   50.53 -	u16 chwall_ssid_offset;
   50.54 -	u16 chwall_conflict_sets_offset;
   50.55 -	u16 chwall_running_types_offset;
   50.56 -	u16 chwall_conflict_aggregate_offset;
   50.57 +	u32 policy_version; /* ACM_CHWALL_VERSION */
   50.58 +	u32 policy_code;
   50.59 +	u32 chwall_max_types;
   50.60 +	u32 chwall_max_ssidrefs;
   50.61 +	u32 chwall_max_conflictsets;
   50.62 +	u32 chwall_ssid_offset;
   50.63 +	u32 chwall_conflict_sets_offset;
   50.64 +	u32 chwall_running_types_offset;
   50.65 +	u32 chwall_conflict_aggregate_offset;
   50.66  };
   50.67  
   50.68  struct acm_ste_policy_buffer {
   50.69 -	u16 policy_code;
   50.70 -	u16 ste_max_types;
   50.71 -	u16 ste_max_ssidrefs;
   50.72 -	u16 ste_ssid_offset;
   50.73 +	u32 policy_version; /* ACM_STE_VERSION */
   50.74 +	u32 policy_code;
   50.75 +	u32 ste_max_types;
   50.76 +	u32 ste_max_ssidrefs;
   50.77 +	u32 ste_ssid_offset;
   50.78  };
   50.79  
   50.80  struct acm_stats_buffer {
   50.81          u32 magic;
   50.82 -	u32 policyversion;
   50.83  	u32 len;
   50.84 -	u16 primary_policy_code;
   50.85 -	u16 primary_stats_offset;
   50.86 -	u16 secondary_policy_code;
   50.87 -	u16 secondary_stats_offset;
   50.88 +	u32 primary_policy_code;
   50.89 +	u32 primary_stats_offset;
   50.90 +	u32 secondary_policy_code;
   50.91 +	u32 secondary_stats_offset;
   50.92  };
   50.93  
   50.94  struct acm_ste_stats_buffer {
    51.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    51.2 +++ b/xen/include/public/acm_ops.h	Tue Aug 02 17:13:11 2005 +0000
    51.3 @@ -0,0 +1,66 @@
    51.4 +/******************************************************************************
    51.5 + * acm_ops.h
    51.6 + *
    51.7 + * Copyright (C) 2005 IBM Corporation
    51.8 + *
    51.9 + * Author:
   51.10 + * Reiner Sailer <sailer@watson.ibm.com>
   51.11 + *
   51.12 + * This program is free software; you can redistribute it and/or
   51.13 + * modify it under the terms of the GNU General Public License as
   51.14 + * published by the Free Software Foundation, version 2 of the
   51.15 + * License.
   51.16 + *
   51.17 + * Process acm policy command requests from guest OS.
   51.18 + * access checked by policy; not restricted to DOM0
   51.19 + *
   51.20 + */
   51.21 +
   51.22 +#ifndef __XEN_PUBLIC_ACM_OPS_H__
   51.23 +#define __XEN_PUBLIC_ACM_OPS_H__
   51.24 +
   51.25 +#include "xen.h"
   51.26 +#include "sched_ctl.h"
   51.27 +
   51.28 +/*
   51.29 + * Make sure you increment the interface version whenever you modify this file!
   51.30 + * This makes sure that old versions of acm tools will stop working in a
   51.31 + * well-defined way (rather than crashing the machine, for instance).
   51.32 + */
   51.33 +#define ACM_INTERFACE_VERSION   0xAAAA0003
   51.34 +
   51.35 +/************************************************************************/
   51.36 +
   51.37 +#define ACM_SETPOLICY        	4
   51.38 +typedef struct acm_setpolicy {
   51.39 +    /* OUT variables */
   51.40 +    void *pushcache;
   51.41 +    u16 pushcache_size;
   51.42 +} acm_setpolicy_t;
   51.43 +
   51.44 +
   51.45 +#define ACM_GETPOLICY        	5
   51.46 +typedef struct acm_getpolicy {
   51.47 +    /* OUT variables */
   51.48 +    void *pullcache;
   51.49 +    u16 pullcache_size;
   51.50 +} acm_getpolicy_t;
   51.51 +
   51.52 +#define ACM_DUMPSTATS        	6
   51.53 +typedef struct acm_dumpstats {
   51.54 +    void *pullcache;
   51.55 +    u16 pullcache_size;
   51.56 +} acm_dumpstats_t;
   51.57 +
   51.58 +
   51.59 +typedef struct acm_op {
   51.60 +    u32 cmd;
   51.61 +    u32 interface_version;      /* ACM_INTERFACE_VERSION */
   51.62 +    union {
   51.63 +        acm_setpolicy_t setpolicy;
   51.64 +        acm_getpolicy_t getpolicy;
   51.65 +        acm_dumpstats_t dumpstats;
   51.66 +    } u;
   51.67 +} acm_op_t;
   51.68 +
   51.69 +#endif                          /* __XEN_PUBLIC_ACM_OPS_H__ */
    52.1 --- a/xen/include/public/policy_ops.h	Tue Aug 02 17:12:36 2005 +0000
    52.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    52.3 @@ -1,70 +0,0 @@
    52.4 -/******************************************************************************
    52.5 - * policy_ops.h
    52.6 - * 
    52.7 - * Copyright (C) 2005 IBM Corporation
    52.8 - *
    52.9 - * Author:
   52.10 - * Reiner Sailer <sailer@watson.ibm.com>
   52.11 - *
   52.12 - * This program is free software; you can redistribute it and/or
   52.13 - * modify it under the terms of the GNU General Public License as
   52.14 - * published by the Free Software Foundation, version 2 of the
   52.15 - * License. 
   52.16 - *
   52.17 - * Process policy command requests from guest OS.
   52.18 - * access checked by policy; not restricted to DOM0
   52.19 - * 
   52.20 - */
   52.21 -
   52.22 -#ifndef __XEN_PUBLIC_POLICY_OPS_H__
   52.23 -#define __XEN_PUBLIC_POLICY_OPS_H__
   52.24 -
   52.25 -#include "xen.h"
   52.26 -#include "sched_ctl.h"
   52.27 -
   52.28 -/*
   52.29 - * Make sure you increment the interface version whenever you modify this file!
   52.30 - * This makes sure that old versions of policy tools will stop working in a
   52.31 - * well-defined way (rather than crashing the machine, for instance).
   52.32 - */
   52.33 -#define POLICY_INTERFACE_VERSION   0xAAAA0003
   52.34 -
   52.35 -/************************************************************************/
   52.36 -
   52.37 -#define POLICY_SETPOLICY        	4
   52.38 -typedef struct policy_setpolicy {
   52.39 -    /* IN variables. */
   52.40 -    u16           policy_type;
   52.41 -    /* OUT variables */
   52.42 -    void  	  *pushcache;
   52.43 -    u16           pushcache_size;
   52.44 -} policy_setpolicy_t;          
   52.45 -
   52.46 -
   52.47 -#define POLICY_GETPOLICY        	5
   52.48 -typedef struct policy_getpolicy {
   52.49 -    /* IN variables. */
   52.50 -    u16           policy_type;
   52.51 -    /* OUT variables */
   52.52 -    void  	  *pullcache;
   52.53 -    u16           pullcache_size;
   52.54 -} policy_getpolicy_t;       
   52.55 -
   52.56 -#define POLICY_DUMPSTATS        	6
   52.57 -typedef struct policy_dumpstats {
   52.58 -    void  	  *pullcache;
   52.59 -    u16           pullcache_size;
   52.60 -} policy_dumpstats_t;            
   52.61 - 
   52.62 -
   52.63 -typedef struct policy_op {
   52.64 -    u32 cmd;
   52.65 -    u32 interface_version;       /* POLICY_INTERFACE_VERSION */
   52.66 -    union {
   52.67 -	policy_setpolicy_t       setpolicy;
   52.68 -        policy_getpolicy_t       getpolicy;
   52.69 -	policy_dumpstats_t	 dumpstats;
   52.70 -    } u;
   52.71 -} policy_op_t;
   52.72 -
   52.73 -#endif /* __XEN_PUBLIC_POLICY_OPS_H__ */
    53.1 --- a/xen/include/public/xen.h	Tue Aug 02 17:12:36 2005 +0000
    53.2 +++ b/xen/include/public/xen.h	Tue Aug 02 17:13:11 2005 +0000
    53.3 @@ -58,7 +58,7 @@
    53.4  #define __HYPERVISOR_boot_vcpu            24
    53.5  #define __HYPERVISOR_set_segment_base     25 /* x86/64 only */
    53.6  #define __HYPERVISOR_mmuext_op            26
    53.7 -#define __HYPERVISOR_policy_op            27
    53.8 +#define __HYPERVISOR_acm_op               27
    53.9  
   53.10  /* 
   53.11   * VIRTUAL INTERRUPTS