2 * Copyright 2000, International Business Machines Corporation and others.
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
11 * osi_cred.c - Linux cred handling routines.
14 #include <afsconfig.h>
15 #include "afs/param.h"
20 #include "afs/sysincludes.h"
21 #include "afsincludes.h"
28 #if !defined(GFP_NOFS)
29 #define GFP_NOFS GFP_KERNEL
31 tmp = kmalloc(sizeof(cred_t), GFP_NOFS);
33 osi_Panic("crget: No more memory for creds!\n");
47 #if defined(AFS_LINUX26_ENV)
48 put_group_info(cr->cr_group_info);
55 /* Return a duplicate of the cred. */
59 cred_t *tmp = crget();
61 tmp->cr_uid = cr->cr_uid;
62 tmp->cr_ruid = cr->cr_ruid;
63 tmp->cr_gid = cr->cr_gid;
64 tmp->cr_rgid = cr->cr_rgid;
66 #if defined(AFS_LINUX26_ENV)
67 get_group_info(cr->cr_group_info);
68 tmp->cr_group_info = cr->cr_group_info;
70 memcpy(tmp->cr_groups, cr->cr_groups, NGROUPS * sizeof(gid_t));
71 tmp->cr_ngroups = cr->cr_ngroups;
82 cr->cr_uid = current_fsuid();
83 cr->cr_ruid = current_uid();
84 cr->cr_gid = current_fsgid();
85 cr->cr_rgid = current_gid();
87 #if defined(AFS_LINUX26_ENV)
89 get_group_info(current_group_info());
90 cr->cr_group_info = current_group_info();
93 memcpy(cr->cr_groups, current->groups, NGROUPS * sizeof(gid_t));
94 cr->cr_ngroups = current->ngroups;
100 /* Set the cred info into the current task */
104 #if defined(STRUCT_TASK_HAS_CRED)
105 struct cred *new_creds;
107 /* If our current task doesn't have identical real and effective
108 * credentials, commit_cred won't let us change them, so we just
111 if (current->cred != current->real_cred)
113 new_creds = prepare_creds();
114 new_creds->fsuid = cr->cr_uid;
115 new_creds->uid = cr->cr_ruid;
116 new_creds->fsgid = cr->cr_gid;
117 new_creds->gid = cr->cr_rgid;
119 current->fsuid = cr->cr_uid;
120 current->uid = cr->cr_ruid;
121 current->fsgid = cr->cr_gid;
122 current->gid = cr->cr_rgid;
124 #if defined(AFS_LINUX26_ENV)
126 struct group_info *old_info;
128 /* using set_current_groups() will sort the groups */
129 get_group_info(cr->cr_group_info);
132 #if defined(STRUCT_TASK_HAS_CRED)
133 old_info = current->cred->group_info;
134 new_creds->group_info = cr->cr_group_info;
135 commit_creds(new_creds);
137 old_info = current->group_info;
138 current->group_info = cr->cr_group_info;
140 task_unlock(current);
142 put_group_info(old_info);
145 memcpy(current->groups, cr->cr_groups, NGROUPS * sizeof(gid_t));
146 current->ngroups = cr->cr_ngroups;