Annotation of src/sys/sys/caps.h, revision 1.2

1.1       dillon      1: /*
                      2:  * SYS/CAPS.H
                      3:  *
                      4:  *     Implements an architecture independant Capability Service API
                      5:  * 
                      6:  * $DragonFly$
                      7:  */
                      8: 
                      9: #ifndef _SYS_CAPS_H_
                     10: #define _SYS_CAPS_H_
                     11: 
                     12: #ifndef _SYS_TYPES_H_
                     13: #include <sys/types.h>
                     14: #endif
                     15: #ifndef _SYS_MSGPORT_H_
                     16: #include <sys/msgport.h>
                     17: #endif
                     18: 
1.2     ! dillon     19: typedef enum caps_msg_state { 
        !            20:        CAPMS_REQUEST, 
        !            21:        CAPMS_REQUEST_RETRY,    /* internal / FUTURE */
        !            22:        CAPMS_REPLY, 
        !            23:        CAPMS_REPLY_RETRY,      /* internal / FUGURE */
        !            24:        CAPMS_DISPOSE
        !            25: } caps_msg_state_t;
        !            26: 
        !            27: typedef struct caps_msgid {
        !            28:        off_t                   c_id;
        !            29:        caps_msg_state_t        c_state;
        !            30:        int                     c_reserved01;
        !            31: } *caps_msgid_t;
1.1       dillon     32: 
                     33: /*
1.2     ! dillon     34:  * Note: upper 16 bits reserved for kernel use
        !            35:  */
        !            36: #define CAPF_UFLAGS    0xFFFF
        !            37: #define CAPF_USER      0x0001
        !            38: #define CAPF_GROUP     0x0002
        !            39: #define CAPF_WORLD     0x0004
        !            40: #define CAPF_EXCL      0x0008
        !            41: #define CAPF_ANYCLIENT (CAPF_USER|CAPF_GROUP|CAPF_WORLD)
        !            42: #define CAPF_WCRED     0x0010  /* waiting for cred */
        !            43: /* FUTURE: CAPF_ASYNC - support async services */
        !            44: /* FUTURE: CAPF_NOGROUPS - don't bother filling in the groups[] array */
        !            45: /* FUTURE: CAPF_TERM - send termination request to existing service */
        !            46: /* FUTURE: CAPF_TAKE - take over existing service's connections */
        !            47: /* FUTURE: CAPF_DISPOSE_IMM - need immediate dispose wakeups */
        !            48: 
        !            49: /*
        !            50:  * Abort codes
1.1       dillon     51:  */
1.2     ! dillon     52: #define CAPS_ABORT_NOTIMPL     0       /* abort not implemented, no action */
        !            53: #define CAPS_ABORT_RETURNED    1       /* already returned, no action */
        !            54: #define CAPS_ABORT_BEFORESERVER        2       /* caught before the server got it */
        !            55: #define CAPS_ABORT_ATSERVER    3       /* server had retrieved message */
        !            56: 
        !            57: #define CAPF_ABORT_HARD                0x0001  /* rip out from under server (3) */
1.1       dillon     58: 
                     59: #define CAPS_MAXGROUPS 16
1.2     ! dillon     60: #define CAPS_MAXNAMELEN        64
        !            61: #define CAPS_MAXINPROG 128
1.1       dillon     62: 
                     63: struct thread;
                     64: 
1.2     ! dillon     65: typedef struct caps_port {
        !            66:        struct lwkt_port        cp_lport;
        !            67:        int                     cp_portid;      /* caps port id */
        !            68:        int                     cp_upcallid;    /* upcall id */
        !            69: } *caps_port_t;
1.1       dillon     70: 
1.2     ! dillon     71: typedef struct caps_cred {
1.1       dillon     72:        pid_t                   pid;
                     73:        uid_t                   uid;
                     74:        uid_t                   euid;
                     75:        gid_t                   gid;
                     76:        int                     ngroups;
1.2     ! dillon     77:        int                     cacheid;
1.1       dillon     78:        gid_t                   groups[CAPS_MAXGROUPS];
1.2     ! dillon     79: } *caps_cred_t;
        !            80: 
        !            81: #if defined(_KERNEL) || defined(_KERNEL_STRUCTURES)
1.1       dillon     82: 
1.2     ! dillon     83: typedef enum caps_type { 
        !            84:        CAPT_UNKNOWN, CAPT_CLIENT, CAPT_SERVICE, CAPT_REMOTE 
        !            85: } caps_type_t;
        !            86: 
        !            87: struct caps_kmsg;
        !            88: 
        !            89: TAILQ_HEAD(caps_kmsg_queue, caps_kmsg);
        !            90: 
        !            91: /*
        !            92:  * caps_kinfo -        Holds a client or service registration
        !            93:  *
        !            94:  * ci_msgpendq: holds the kernel copy of the message after it has been
        !            95:  *             sent to the local port.  The message is matched up against
        !            96:  *             replies and automatically replied if the owner closes its 
        !            97:  *             connection.
1.1       dillon     98:  */
1.2     ! dillon     99: typedef struct caps_kinfo {
        !           100:        struct lwkt_port        ci_lport;       /* embedded local port */
        !           101:        struct caps_kinfo       *ci_tdnext;     /* per-process list */
        !           102:        struct caps_kinfo       *ci_hnext;      /* registration hash table */
        !           103:        struct thread           *ci_td;         /* owner */
        !           104:        struct caps_kmsg_queue  ci_msgpendq;    /* pending reply (just rcvd) */
        !           105:        struct caps_kmsg_queue  ci_msguserq;    /* pending reply (user holds) */
        !           106:        struct caps_kinfo       *ci_rcaps;      /* connected to remote */
        !           107:        int                     ci_cmsgcount;   /* client in-progress msgs */
        !           108:        int                     ci_id;
        !           109:        int                     ci_flags;
        !           110:        int                     ci_refs;
        !           111:        int                     ci_mrefs;       /* message (vmspace) refs */
        !           112:        caps_type_t             ci_type;
        !           113:        uid_t                   ci_uid;
        !           114:        gid_t                   ci_gid;
        !           115:        int                     ci_namelen;
        !           116:        char                    ci_name[4];     /* variable length */
        !           117:        /* ci_name must be last element */
        !           118: } *caps_kinfo_t;
        !           119: 
        !           120: /* note: user flags are held in the low 16 bits */
        !           121: #define CAPKF_TDLIST   0x00010000
        !           122: #define CAPKF_HLIST    0x00020000
        !           123: #define CAPKF_FLUSH    0x00040000
        !           124: #define CAPKF_RCAPS    0x00080000
        !           125: #define CAPKF_CLOSED   0x00100000
        !           126: #define CAPKF_MWAIT    0x00200000
1.1       dillon    127: 
                    128: /*
1.2     ! dillon    129:  * Kernel caps message.  The kernel keepps track of messagse received,
        !           130:  * undergoing processing by the service, and returned.  User-supplied data
        !           131:  * is copied on reception rather then transmission.
1.1       dillon    132:  */
1.2     ! dillon    133: typedef struct caps_kmsg {
        !           134:        TAILQ_ENTRY(caps_kmsg)  km_node;
        !           135:        caps_kinfo_t            km_mcaps;       /* message sender */
        !           136:        void                    *km_umsg;       /* mcaps vmspace */
        !           137:        int                     km_umsg_size;   /* mcaps vmspace */
        !           138:        struct caps_cred        km_ccr;         /* caps cred for msg */
        !           139:        struct caps_msgid       km_msgid;
        !           140:        int                     km_flags;
        !           141: } *caps_kmsg_t;
        !           142: 
        !           143: #define km_state       km_msgid.c_state
        !           144: 
        !           145: #define CAPKMF_ONUSERQ         0x0001
        !           146: #define CAPKMF_ONPENDQ         0x0002
        !           147: #define CAPKMF_REPLY           0x0004
        !           148: #define CAPKMF_CDONE           0x0008
        !           149: #define CAPKMF_PEEKED          0x0010
        !           150: #define CAPKMF_ABORTED         0x0020
        !           151: 
        !           152: #endif
        !           153: 
        !           154: #ifdef _KERNEL
        !           155: 
        !           156: /*
        !           157:  * kernel support
        !           158:  */
        !           159: void caps_exit(struct thread *td);
        !           160: void caps_fork(struct proc *p1, struct proc *p2);
        !           161: 
        !           162: #else
        !           163: 
        !           164: /*
        !           165:  * Userland API (libcaps)
        !           166:  */
        !           167: caps_port_t caps_service(const char *name, uid_t uid, gid_t gid, 
        !           168:                            mode_t modes, int flags);
        !           169: caps_port_t caps_client(const char *name, uid_t uid, gid_t gid, int flags);
        !           170: 
        !           171: /*
        !           172:  * Syscall API
        !           173:  */
        !           174: int caps_sys_service(const char *name, uid_t uid, gid_t gid, int upcid, int flags);
        !           175: int caps_sys_client(const char *name, uid_t uid, gid_t gid, int upcid, int flags);
        !           176: off_t caps_sys_put(int portid, void *msg, int msgsize);
        !           177: int caps_sys_reply(int portid, void *msg, int msgsize, off_t msgcid);
        !           178: int caps_sys_get(int portid, void *msg, int maxsize, caps_msgid_t msgid, caps_cred_t ccr);
        !           179: int caps_sys_wait(int portid, void *msg, int maxsize, caps_msgid_t msgid, caps_cred_t ccr);
        !           180: int caps_sys_abort(int portid, off_t msgcid, int flags);
        !           181: 
        !           182: #endif
1.1       dillon    183: 
                    184: #endif
                    185: