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"
21 /* Copy one credential structure to another, being careful about references */
23 afs_copy_creds(cred_t *to_cred, const cred_t *from_cred) {
24 afs_set_cr_uid(to_cred, afs_cr_uid(from_cred));
25 afs_set_cr_gid(to_cred, afs_cr_gid(from_cred));
26 afs_set_cr_ruid(to_cred, afs_cr_ruid(from_cred));
27 afs_set_cr_rgid(to_cred, afs_cr_rgid(from_cred));
28 get_group_info(afs_cr_group_info(from_cred));
29 afs_set_cr_group_info(to_cred, afs_cr_group_info(from_cred));
37 tmp = kmalloc(sizeof(cred_t), GFP_NOFS);
39 osi_Panic("crget: No more memory for creds!\n");
41 #if defined(STRUCT_TASK_STRUCT_HAS_CRED)
44 atomic_set(&tmp->cr_ref, 1);
52 #if defined(STRUCT_TASK_STRUCT_HAS_CRED)
55 if (atomic_dec_and_test(&cr->cr_ref)) {
56 put_group_info(afs_cr_group_info(cr));
63 /* Return a duplicate of the cred. */
67 cred_t *tmp = crget();
68 #if defined(STRUCT_TASK_STRUCT_HAS_CRED)
69 afs_copy_creds(tmp, cr);
71 afs_set_cr_uid(tmp, afs_cr_uid(cr));
72 afs_set_cr_ruid(tmp, afs_cr_ruid(cr));
73 afs_set_cr_gid(tmp, afs_cr_gid(cr));
74 afs_set_cr_rgid(tmp, afs_cr_rgid(cr));
76 get_group_info(afs_cr_group_info(cr));
77 afs_set_cr_group_info(tmp, afs_cr_group_info(cr));
85 #if defined(STRUCT_TASK_STRUCT_HAS_CRED)
86 return (cred_t *)get_current_cred();
90 afs_set_cr_uid(cr, current_fsuid());
91 afs_set_cr_ruid(cr, current_uid());
92 afs_set_cr_gid(cr, current_fsgid());
93 afs_set_cr_rgid(cr, current_gid());
96 get_group_info(current_group_info());
97 afs_set_cr_group_info(cr, current_group_info());
104 /* Set the cred info into the current task */
108 #if defined(STRUCT_TASK_STRUCT_HAS_CRED)
109 struct cred *new_creds;
111 /* If our current task doesn't have identical real and effective
112 * credentials, commit_cred won't let us change them, so we just
115 if (current->cred != current->real_cred)
117 new_creds = prepare_creds();
118 /* Drop the reference to group_info - we'll overwrite it in afs_copy_creds */
119 put_group_info(new_creds->group_info);
120 afs_copy_creds(new_creds, current_cred());
122 commit_creds(new_creds);
124 struct group_info *old_info;
126 current->fsuid = afs_cr_uid(cr);
127 current->uid = afs_cr_ruid(cr);
128 current->fsgid = afs_cr_gid(cr);
129 current->gid = afs_cr_rgid(cr);
131 get_group_info(afs_cr_group_info(cr));
133 old_info = current->group_info;
134 current->group_info = afs_cr_group_info(cr);
135 task_unlock(current);
136 put_group_info(old_info);