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"
18 #include "afs/sysincludes.h"
19 #include "afsincludes.h"
26 #if !defined(GFP_NOFS)
27 #define GFP_NOFS GFP_KERNEL
29 tmp = kmalloc(sizeof(cred_t), GFP_NOFS);
31 osi_Panic("crget: No more memory for creds!\n");
45 #if defined(AFS_LINUX26_ENV)
46 put_group_info(cr->cr_group_info);
53 /* Return a duplicate of the cred. */
57 cred_t *tmp = crget();
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;
64 #if defined(AFS_LINUX26_ENV)
65 get_group_info(cr->cr_group_info);
66 tmp->cr_group_info = cr->cr_group_info;
68 memcpy(tmp->cr_groups, cr->cr_groups, NGROUPS * sizeof(gid_t));
69 tmp->cr_ngroups = cr->cr_ngroups;
80 cr->cr_uid = current_fsuid();
81 cr->cr_ruid = current_uid();
82 cr->cr_gid = current_fsgid();
83 cr->cr_rgid = current_gid();
85 #if defined(AFS_LINUX26_ENV)
87 get_group_info(current_group_info());
88 cr->cr_group_info = current_group_info();
91 memcpy(cr->cr_groups, current->groups, NGROUPS * sizeof(gid_t));
92 cr->cr_ngroups = current->ngroups;
98 /* Set the cred info into the current task */
102 #if defined(STRUCT_TASK_HAS_CRED)
103 struct cred *new_creds;
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
109 if (current->cred != current->real_cred)
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;
117 current->fsuid = cr->cr_uid;
118 current->uid = cr->cr_ruid;
119 current->fsgid = cr->cr_gid;
120 current->gid = cr->cr_rgid;
122 #if defined(AFS_LINUX26_ENV)
124 struct group_info *old_info;
126 /* using set_current_groups() will sort the groups */
127 get_group_info(cr->cr_group_info);
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);
135 old_info = current->group_info;
136 current->group_info = cr->cr_group_info;
138 task_unlock(current);
140 put_group_info(old_info);
143 memcpy(current->groups, cr->cr_groups, NGROUPS * sizeof(gid_t));
144 current->ngroups = cr->cr_ngroups;