8327924db375ed492afb2489191703494ee897ab
[dragonfly.git] / sys / sys / caps.h
1 /*
2  * SYS/CAPS.H
3  *
4  *      Implements an architecture independant Capability Service API
5  * 
6  * $DragonFly: src/sys/sys/caps.h,v 1.1 2003/11/24 21:15:54 dillon Exp $
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
19 #define CAPS_USER       0x00000001
20 #define CAPS_GROUP      0x00000002
21 #define CAPS_WORLD      0x00000004
22 #define CAPS_EXCL       0x00000008
23 #define CAPS_ANYCLIENT  (CAPS_USER|CAPS_GROUP|CAPS_WORLD)
24 #define CAPS_WCRED      0x00000010      /* waiting for cred */
25
26 /*
27  * caps_type associated with caps_port:
28  *
29  *      CAPT_CLIENT     port returned to client representing connection to
30  *                      service.
31  *      CAPT_SERVICE    port returned to service representing namespace
32  *      CAPT_REMOTE     temporary port used by service to represent
33  *                      client connections to service (set as replyport for
34  *                      messages)
35  *
36  */
37 enum caps_type { CAPT_UNKNOWN, CAPT_CLIENT, CAPT_SERVICE, CAPT_REMOTE };
38
39 #define CAPS_MAXGROUPS  16
40
41 struct thread;
42 struct caps_port;
43
44 typedef struct caps_port *caps_port_t;
45
46 struct caps_cred {
47         pid_t                   pid;
48         uid_t                   uid;
49         uid_t                   euid;
50         gid_t                   gid;
51         int                     ngroups;
52         gid_t                   groups[CAPS_MAXGROUPS];
53 };
54
55 struct caps_port {
56         struct lwkt_port        lport;
57         caps_port_t             server; /* if CAPT_REMOTE, pointer to server */
58         enum caps_type          type;
59         int                     kqfd;   /* kqueue to collect active connects */
60         int                     lfd;    /* server: listening on (server) */
61         int                     cfd;    /* client/remote connection fd */
62         int                     flags;
63         TAILQ_HEAD(, caps_port) clist;  /* server: client client connections */
64         TAILQ_ENTRY(caps_port)  centry;
65         TAILQ_HEAD(, lwkt_msg)  wlist;  /* queue of outgoing messages */
66         TAILQ_HEAD(, lwkt_msg)  mlist;  /* written message waiting for reply */
67         struct lwkt_msg         rmsg_static;
68         lwkt_msg_t              rmsg;   /* read message in progress */
69         struct caps_cred        cred;   /* cred of owner of port */
70         int                     rbytes; /* read in progress byte count */
71         int                     wbytes; /* write in progress byte count */
72 };
73
74 #define CAPPF_WAITCRED          0x0001
75 #define CAPPF_ONLIST            0x0002
76 #define CAPPF_WREQUESTED        0x0004  /* write event requested */
77 #define CAPPF_SHUTDOWN          0x0008  /* terminated/failed */
78
79 #define CAPMSG_MAXSIZE          (1024+64*1024)
80
81 /*
82  * API
83  */
84 caps_port_t caps_service(const char *name, gid_t gid, mode_t modes, int flags);
85 caps_port_t caps_client(const char *name, uid_t uid, int flags);
86
87 /*
88  * Temporary hack until LWKT threading is integrated.
89  */
90 void *caps_client_waitreply(caps_port_t port, lwkt_msg_t msg);
91
92 #endif
93