Remove the RCSID macro
[openafs.git] / src / afs / LINUX / osi_cred.c
1 /*
2  * Copyright 2000, International Business Machines Corporation and others.
3  * All Rights Reserved.
4  * 
5  * This software has been released under the terms of the IBM Public
6  * License.  For details, see the LICENSE file in the top-level source
7  * directory or online at http://www.openafs.org/dl/license10.html
8  */
9
10 /*
11  * osi_cred.c - Linux cred handling routines.
12  *
13  */
14 #include <afsconfig.h>
15 #include "afs/param.h"
16
17
18 #include "afs/sysincludes.h"
19 #include "afsincludes.h"
20
21 cred_t *
22 crget(void)
23 {
24     cred_t *tmp;
25     
26 #if !defined(GFP_NOFS)
27 #define GFP_NOFS GFP_KERNEL
28 #endif
29     tmp = kmalloc(sizeof(cred_t), GFP_NOFS);
30     if (!tmp)
31         osi_Panic("crget: No more memory for creds!\n");
32     
33     tmp->cr_ref = 1;
34     return tmp;
35 }
36
37 void
38 crfree(cred_t * cr)
39 {
40     if (cr->cr_ref > 1) {
41         cr->cr_ref--;
42         return;
43     }
44
45 #if defined(AFS_LINUX26_ENV)
46     put_group_info(cr->cr_group_info);
47 #endif
48
49     kfree(cr);
50 }
51
52
53 /* Return a duplicate of the cred. */
54 cred_t *
55 crdup(cred_t * cr)
56 {
57     cred_t *tmp = crget();
58
59     tmp->cr_uid = cr->cr_uid;
60     tmp->cr_ruid = cr->cr_ruid;
61     tmp->cr_gid = cr->cr_gid;
62     tmp->cr_rgid = cr->cr_rgid;
63
64 #if defined(AFS_LINUX26_ENV)
65     get_group_info(cr->cr_group_info);
66     tmp->cr_group_info = cr->cr_group_info;
67 #else
68     memcpy(tmp->cr_groups, cr->cr_groups, NGROUPS * sizeof(gid_t));
69     tmp->cr_ngroups = cr->cr_ngroups;
70 #endif
71
72     return tmp;
73 }
74
75 cred_t *
76 crref(void)
77 {
78     cred_t *cr = crget();
79
80     cr->cr_uid = current_fsuid();
81     cr->cr_ruid = current_uid();
82     cr->cr_gid = current_fsgid();
83     cr->cr_rgid = current_gid();
84
85 #if defined(AFS_LINUX26_ENV)
86     task_lock(current);
87     get_group_info(current_group_info());
88     cr->cr_group_info = current_group_info();
89     task_unlock(current);
90 #else
91     memcpy(cr->cr_groups, current->groups, NGROUPS * sizeof(gid_t));
92     cr->cr_ngroups = current->ngroups;
93 #endif
94     return cr;
95 }
96
97
98 /* Set the cred info into the current task */
99 void
100 crset(cred_t * cr)
101 {
102 #if defined(STRUCT_TASK_HAS_CRED)
103     struct cred *new_creds;
104
105     /* If our current task doesn't have identical real and effective
106      * credentials, commit_cred won't let us change them, so we just
107      * bail here.
108      */
109     if (current->cred != current->real_cred)
110         return;
111     new_creds = prepare_creds();
112     new_creds->fsuid = cr->cr_uid;
113     new_creds->uid = cr->cr_ruid;
114     new_creds->fsgid = cr->cr_gid;
115     new_creds->gid = cr->cr_rgid;
116 #else
117     current->fsuid = cr->cr_uid;
118     current->uid = cr->cr_ruid;
119     current->fsgid = cr->cr_gid;
120     current->gid = cr->cr_rgid;
121 #endif
122 #if defined(AFS_LINUX26_ENV)
123 {
124     struct group_info *old_info;
125
126     /* using set_current_groups() will sort the groups */
127     get_group_info(cr->cr_group_info);
128
129     task_lock(current);
130 #if defined(STRUCT_TASK_HAS_CRED)
131     old_info = current->cred->group_info;
132     new_creds->group_info = cr->cr_group_info;
133     commit_creds(new_creds);
134 #else
135     old_info = current->group_info;
136     current->group_info = cr->cr_group_info;
137 #endif
138     task_unlock(current);
139
140     put_group_info(old_info);
141 }
142 #else
143     memcpy(current->groups, cr->cr_groups, NGROUPS * sizeof(gid_t));
144     current->ngroups = cr->cr_ngroups;
145 #endif
146 }