summaryrefslogtreecommitdiff
path: root/sys/miscfs/tcfs/tcfs_keytab.h
blob: e5a286080f13c33631db4e866cdf59e547c2845a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
/*	$OpenBSD: tcfs_keytab.h,v 1.4 2000/06/18 16:23:10 provos Exp $	*/
/*
 * Copyright 2000 The TCFS Project at http://tcfs.dia.unisa.it/
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 * 3. The name of the authors may not be used to endorse or promote products
 *    derived from this software without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS OR
 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
 * IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY DIRECT, INDIRECT,
 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */
#ifndef _TCFS_KEYTAB_H_
#define _TCFS_KEYTAB_H_

#include <sys/types.h>
struct tcfs_mount;

#define	KEYTABSIZE	20
#define KEYSIZE		32
#define KEYPARTSIZE	(KEYSIZE+KEYSIZE/8)

#define CLEAN		0x00
#define	PID_BIT		0x01
#define UID_KEY		0x02
#define GID_KEY		0x04
#define PID_KEY		(PID_BIT|UID_KEY)

#define IS_GID_NODE(np)	(((np)->kn_type)&GID_KEY)
#define IS_UID_NODE(np)	(((np)->kn_type)&UID_KEY)
#define IS_PID_NODE(np)	((((np)->kn_type)&PID_BIT)&&(IS_UID_NODE((np))))

#ifndef TCFS_OK
#define TCFS_OK 0
#endif

#define MAXUSRPERGRP	10

typedef struct {
	unsigned char gui_flag;
	uid_t gui_uid;
	unsigned char gui_tcfskey[KEYPARTSIZE];
} tcfs_grp_uinfo;

#define	GUI_CLEAN	0
#define GUI_SET		1
#define IS_SET_GUI(gui)	((gui).gui_flag==GUI_SET)

typedef struct _grp_data {
	int gd_flag;
	int gd_n;
	int gd_k;
	tcfs_grp_uinfo gd_part[MAXUSRPERGRP];
} tcfs_grp_data;

#define IS_CLEAN_GD(gd)	((gd)->gd_n==0)
#define IS_FULL_GD(gd)	((gd)->gd_n==MAXUSRPERGRP)
#define IS_READY_GD(gd)	(((gd)->gd_n)>=((gd)->gd_k))

typedef struct _kn {
	pid_t 		 kn_pid;
	uid_t 		 kn_uid;
	gid_t		 kn_gid;
	unsigned int	 kn_type;

	void *kn_key;
	tcfs_grp_data *kn_data;

	struct _kn *kn_n;
	struct _kn *kn_p;
}	tcfs_keytab_node;

typedef struct 	_kt {
	unsigned int cnt;
	tcfs_keytab_node* node[KEYTABSIZE]; 
} tcfs_keytab;

#define	NIL	((tcfs_keytab_node*)0)

#ifdef _HAVE_HASH_
int		_tcfs_keytab_hash __P(unsigned int));
#define		tcfs_keytab_hash(x)	_tcfs_keytab_hash((unsigned int)(x))
#else
#define		tcfs_keytab_hash(u)	((u)%KEYTABSIZE)
#endif

tcfs_keytab_node	*tcfs_keytab_newnode __P((void));
tcfs_keytab_node	*tcfs_keytab_newgidnode __P((void));
void			 tcfs_keytab_dispnode __P((tcfs_keytab_node*));
tcfs_keytab		*tcfs_keytab_init __P((void));
void			 tcfs_keytab_dispose __P((tcfs_keytab*));
tcfs_keytab_node	*tcfs_keytab_fetch_uid __P((tcfs_keytab *, uid_t));
int			 tcfs_keytab_push_gidpart __P((struct tcfs_mount *,tcfs_keytab_node *,uid_t, gid_t,int,char*));
tcfs_keytab_node	*tcfs_keytab_fetch_gid __P((tcfs_keytab *, gid_t));
tcfs_keytab_node	*tcfs_keytab_fetch_pid __P((tcfs_keytab *, uid_t, pid_t));
int			 tcfs_keytab_push_uid __P((tcfs_keytab*, uid_t, void* ));
int			 tcfs_keytab_push_pid __P((tcfs_keytab*, uid_t, pid_t, void *));
int			 tcfs_keytab_push_gid __P((struct tcfs_mount *,tcfs_keytab *, uid_t, gid_t, int, char *));
int			 tcfs_keytab_rm_uid __P((tcfs_keytab *, uid_t));
int			 tcfs_keytab_rm_pid __P((tcfs_keytab *, uid_t, pid_t));
int			 tcfs_keytab_rm_gidpart __P((tcfs_keytab_node *,uid_t, gid_t));
int			 tcfs_keytab_rm_gid __P((tcfs_keytab*, uid_t, gid_t));
int			 tcfs_interp __P((struct tcfs_mount *, tcfs_keytab_node*));
int			 tcfs_keytab_check_uid __P((tcfs_keytab *, uid_t));
int			 tcfs_keytab_check_pid __P((tcfs_keytab *, uid_t, pid_t));
int			 tcfs_keytab_check_gid __P((tcfs_keytab *, gid_t));
#endif /* _TCFS_KEYTAB_H_ */