xref: /illumos-gate/usr/src/uts/common/sys/session.h (revision bdfc6d18da790deeec2e0eb09c625902defe2498)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License, Version 1.0 only
6  * (the "License").  You may not use this file except in compliance
7  * with the License.
8  *
9  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10  * or http://www.opensolaris.org/os/licensing.
11  * See the License for the specific language governing permissions
12  * and limitations under the License.
13  *
14  * When distributing Covered Code, include this CDDL HEADER in each
15  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16  * If applicable, add the following below this CDDL HEADER, with the
17  * fields enclosed by brackets "[]" replaced with your own identifying
18  * information: Portions Copyright [yyyy] [name of copyright owner]
19  *
20  * CDDL HEADER END
21  */
22 /*
23  * Copyright 2004 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 /*	Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T	*/
28 /*	  All Rights Reserved  	*/
29 
30 
31 #ifndef _SYS_SESSION_H
32 #define	_SYS_SESSION_H
33 
34 #pragma ident	"%Z%%M%	%I%	%E% SMI"
35 
36 #ifdef	__cplusplus
37 extern "C" {
38 #endif
39 
40 typedef struct sess {
41 	uint_t s_ref; 			/* reference count */
42 	mode_t s_mode;			/* /sess current permissions */
43 	uid_t s_uid;			/* /sess current user ID */
44 	gid_t s_gid;			/* /sess current group ID */
45 	time_t s_ctime;			/* /sess change time */
46 	dev_t s_dev;			/* tty's device number */
47 	struct vnode *s_vp;		/* tty's vnode */
48 	struct pid *s_sidp;		/* session ID info */
49 	struct cred *s_cred;		/* allocation credentials */
50 	kmutex_t s_lock;		/* sync s_vp use with freectty */
51 	kcondvar_t s_wait_cv;		/* Condvar for sleeping */
52 	int s_cnt;			/* # of active users of this session */
53 	int s_flag;			/* session state flag see below */
54 } sess_t;
55 
56 #define	SESS_CLOSE	1		/* session about to close */
57 #define	s_sid s_sidp->pid_id
58 
59 /*
60  * Enumeration of the types of access that can be requested for a
61  * controlling terminal under job control.
62  */
63 
64 enum jcaccess {
65 	JCREAD,			/* read data on a ctty */
66 	JCWRITE,		/* write data to a ctty */
67 	JCSETP,			/* set ctty parameters */
68 	JCGETP			/* get ctty parameters */
69 };
70 
71 #if defined(_KERNEL)
72 
73 extern sess_t session0;
74 
75 #define	SESS_HOLD(sp)	(++(sp)->s_ref)
76 #define	SESS_RELE(sp)	sess_rele(sp)
77 
78 /*
79  * Used to synchronizing sessions vnode users with freectty
80  */
81 
82 #define	TTY_HOLD(sp)	{ \
83 	mutex_enter(&(sp)->s_lock); \
84 	(++(sp)->s_cnt); \
85 	mutex_exit(&(sp)->s_lock); \
86 }
87 
88 #define	TTY_RELE(sp)	{ \
89 	mutex_enter(&(sp)->s_lock); \
90 	if ((--(sp)->s_cnt) == 0) \
91 		cv_signal(&(sp)->s_wait_cv); \
92 	mutex_exit(&(sp)->s_lock); \
93 }
94 
95 /* forward referenced structure tags */
96 struct vnode;
97 struct cred;
98 struct proc;
99 
100 extern void sess_rele(sess_t *);
101 extern void sess_create(void);
102 extern void freectty(sess_t *);
103 extern void alloctty(struct proc *, struct vnode *);
104 extern dev_t cttydev(struct proc *);
105 extern int hascttyperm(sess_t *, struct cred *, mode_t);
106 
107 #endif /* defined(_KERNEL) */
108 
109 #ifdef	__cplusplus
110 }
111 #endif
112 
113 #endif	/* _SYS_SESSION_H */
114