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 (the "License").
6  * You may not use this file except in compliance with the License.
7  *
8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9  * or https://opensource.org/licenses/CDDL-1.0.
10  * See the License for the specific language governing permissions
11  * and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL HEADER in each
14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15  * If applicable, add the following below this CDDL HEADER, with the
16  * fields enclosed by brackets "[]" replaced with your own identifying
17  * information: Portions Copyright [yyyy] [name of copyright owner]
18  *
19  * CDDL HEADER END
20  */
21 /*
22  * Copyright 2010 Sun Microsystems, Inc.  All rights reserved.
23  * Use is subject to license terms.
24  */
25 
26 #ifndef	_SYS_FS_ZFS_FUID_H
27 #define	_SYS_FS_ZFS_FUID_H
28 
29 #ifdef _KERNEL
30 #include <sys/sid.h>
31 #include <sys/dmu.h>
32 #include <sys/zfs_vfsops.h>
33 #endif
34 #include <sys/avl.h>
35 
36 #ifdef	__cplusplus
37 extern "C" {
38 #endif
39 
40 typedef enum {
41 	ZFS_OWNER,
42 	ZFS_GROUP,
43 	ZFS_ACE_USER,
44 	ZFS_ACE_GROUP
45 } zfs_fuid_type_t;
46 
47 /*
48  * Estimate space needed for one more fuid table entry.
49  * for now assume its current size + 1K
50  */
51 #define	FUID_SIZE_ESTIMATE(z) ((z)->z_fuid_size + (SPA_MINBLOCKSIZE << 1))
52 
53 #define	FUID_INDEX(x)	((x) >> 32)
54 #define	FUID_RID(x)	((x) & 0xffffffff)
55 #define	FUID_ENCODE(idx, rid) (((uint64_t)(idx) << 32) | (rid))
56 /*
57  * FUIDs cause problems for the intent log
58  * we need to replay the creation of the FUID,
59  * but we can't count on the idmapper to be around
60  * and during replay the FUID index may be different than
61  * before.  Also, if an ACL has 100 ACEs and 12 different
62  * domains we don't want to log 100 domain strings, but rather
63  * just the unique 12.
64  */
65 
66 /*
67  * The FUIDs in the log will index into
68  * domain string table and the bottom half will be the rid.
69  * Used for mapping ephemeral uid/gid during ACL setting to FUIDs
70  */
71 typedef struct zfs_fuid {
72 	list_node_t 	z_next;
73 	uint64_t 	z_id;		/* uid/gid being converted to fuid */
74 	uint64_t	z_domidx;	/* index in AVL domain table */
75 	uint64_t	z_logfuid;	/* index for domain in log */
76 } zfs_fuid_t;
77 
78 /* list of unique domains */
79 typedef struct zfs_fuid_domain {
80 	list_node_t	z_next;
81 	uint64_t	z_domidx;	/* AVL tree idx */
82 	const char	*z_domain;	/* domain string */
83 } zfs_fuid_domain_t;
84 
85 /*
86  * FUID information necessary for logging create, setattr, and setacl.
87  */
88 typedef struct zfs_fuid_info {
89 	list_t	z_fuids;
90 	list_t	z_domains;
91 	uint64_t z_fuid_owner;
92 	uint64_t z_fuid_group;
93 	char **z_domain_table;  /* Used during replay */
94 	uint32_t z_fuid_cnt;	/* How many fuids in z_fuids */
95 	uint32_t z_domain_cnt;	/* How many domains */
96 	size_t	z_domain_str_sz; /* len of domain strings z_domain list */
97 } zfs_fuid_info_t;
98 
99 #ifdef _KERNEL
100 struct znode;
101 extern uid_t zfs_fuid_map_id(zfsvfs_t *, uint64_t, cred_t *, zfs_fuid_type_t);
102 extern void zfs_fuid_node_add(zfs_fuid_info_t **, const char *, uint32_t,
103     uint64_t, uint64_t, zfs_fuid_type_t);
104 extern void zfs_fuid_destroy(zfsvfs_t *);
105 extern uint64_t zfs_fuid_create_cred(zfsvfs_t *, zfs_fuid_type_t,
106     cred_t *, zfs_fuid_info_t **);
107 extern uint64_t zfs_fuid_create(zfsvfs_t *, uint64_t, cred_t *, zfs_fuid_type_t,
108     zfs_fuid_info_t **);
109 extern void zfs_fuid_map_ids(struct znode *zp, cred_t *cr,
110     uid_t *uid, uid_t *gid);
111 extern zfs_fuid_info_t *zfs_fuid_info_alloc(void);
112 extern void zfs_fuid_info_free(zfs_fuid_info_t *);
113 extern boolean_t zfs_groupmember(zfsvfs_t *, uint64_t, cred_t *);
114 void zfs_fuid_sync(zfsvfs_t *, dmu_tx_t *);
115 extern const char *zfs_fuid_find_by_idx(zfsvfs_t *zfsvfs, uint32_t idx);
116 extern void zfs_fuid_txhold(zfsvfs_t *zfsvfs, dmu_tx_t *tx);
117 extern int zfs_id_to_fuidstr(zfsvfs_t *zfsvfs, const char *domain, uid_t rid,
118     char *buf, size_t len, boolean_t addok);
119 #endif
120 
121 const char *zfs_fuid_idx_domain(avl_tree_t *, uint32_t);
122 void zfs_fuid_avl_tree_create(avl_tree_t *, avl_tree_t *);
123 uint64_t zfs_fuid_table_load(objset_t *, uint64_t, avl_tree_t *, avl_tree_t *);
124 void zfs_fuid_table_destroy(avl_tree_t *, avl_tree_t *);
125 
126 #ifdef	__cplusplus
127 }
128 #endif
129 
130 #endif	/* _SYS_FS_ZFS_FUID_H */
131