#include "afs/nfsclient.h"
#include "osi_compat.h"
-#include <linux/smp_lock.h>
-
-#if defined(LINUX_KEYRING_SUPPORT)
-# include <linux/rwsem.h>
-# include <linux/key.h>
-# if defined(HAVE_LINUX_KEY_TYPE_H)
-# include <linux/key-type.h>
-# endif
-# ifndef KEY_ALLOC_IN_QUOTA
-/* Before these flags were added in Linux commit v2.6.18-rc1~816,
- * key_alloc just took a boolean not_in_quota */
-# define KEY_ALLOC_IN_QUOTA 0
-# define KEY_ALLOC_NOT_IN_QUOTA 1
-# endif
-#endif
-
#ifdef AFS_LINUX26_ONEGROUP_ENV
# define NUMPAGGROUPS 1
int
__setpag(cred_t **cr, afs_uint32 pagvalue, afs_uint32 *newpag,
- int change_parent)
+ int change_parent, struct group_info **old_groups)
{
struct group_info *group_info;
struct group_info *tmp;
*newpag = (pagvalue == -1 ? genpag() : pagvalue);
afs_linux_pag_to_groups(*newpag, group_info, &tmp);
- put_group_info(group_info);
- group_info = tmp;
+ if (old_groups) {
+ *old_groups = group_info;
+ } else {
+ put_group_info(group_info);
+ group_info = NULL;
+ }
- afs_setgroups(cr, group_info, change_parent);
+ afs_setgroups(cr, tmp, change_parent);
- put_group_info(group_info);
+ put_group_info(tmp);
return 0;
}
extern struct key_type key_type_keyring __attribute__((weak));
static struct key_type *__key_type_keyring = &key_type_keyring;
+/* install_session_keyring returns negative error values */
static int
install_session_keyring(struct key *keyring)
{
}
#endif /* LINUX_KEYRING_SUPPORT */
+/* Error codes from setpag must be positive, otherwise they don't
+ * make it back into userspace properly. Error codes from the
+ * Linux keyring utilities, and from install_session_keyring()
+ * are negative. So we need to be careful to convert them correctly
+ * here
+ */
int
setpag(cred_t **cr, afs_uint32 pagvalue, afs_uint32 *newpag,
int change_parent)
{
int code;
+ struct group_info *old_groups = NULL;
AFS_STATCNT(setpag);
- code = __setpag(cr, pagvalue, newpag, change_parent);
+ code = __setpag(cr, pagvalue, newpag, change_parent, &old_groups);
#ifdef LINUX_KEYRING_SUPPORT
if (code == 0 && afs_cr_rgid(*cr) != NFSXLATOR_CRED) {
code = PTR_ERR(key);
}
}
+ if (code)
+ code = -code;
}
#endif /* LINUX_KEYRING_SUPPORT */
+ if (code) {
+ if (old_groups) {
+ afs_setgroups(cr, old_groups, change_parent);
+ put_group_info(old_groups);
+ old_groups = NULL;
+ }
+ if (*newpag > -1) {
+ afs_MarkUserExpired(*newpag);
+ *newpag = -1;
+ }
+ }
+
return code;
}
cr = crref();
if (old_pag != NOPAG && PagInCred(cr) == NOPAG) {
/* re-install old pag if there's room. */
- code = __setpag(&cr, old_pag, &junk, 0);
+ code = __setpag(&cr, old_pag, &junk, 0, NULL);
}
crfree(cr);
cr = crref();
if (old_pag != NOPAG && PagInCred(cr) == NOPAG) {
/* re-install old pag if there's room. */
- code = __setpag(&cr, old_pag, &junk, 0);
+ code = __setpag(&cr, old_pag, &junk, 0, NULL);
}
crfree(cr);
cr = crref();
if (old_pag != NOPAG && PagInCred(cr) == NOPAG) {
/* re-install old pag if there's room. */
- code = __setpag(&cr, old_pag, &junk, 0);
+ code = __setpag(&cr, old_pag, &junk, 0, NULL);
}
crfree(cr);
cr = crref();
if (old_pag != NOPAG && PagInCred(cr) == NOPAG) {
/* re-install old pag if there's room. */
- code = __setpag(&cr, old_pag, &junk, 0);
+ code = __setpag(&cr, old_pag, &junk, 0, NULL);
}
crfree(cr);
cr = crref();
if (old_pag != NOPAG && PagInCred(cr) == NOPAG) {
/* re-install old pag if there's room. */
- code = __setpag(&cr, old_pag, &junk, 0);
+ code = __setpag(&cr, old_pag, &junk, 0, NULL);
}
crfree(cr);
if (afs_linux_cred_is_current(cred) &&
((keyring_pag >> 24) & 0xff) == 'A' &&
keyring_pag != afs_linux_pag_from_groups(current_group_info())) {
- __setpag(&cred, keyring_pag, &newpag, 0);
+ __setpag(&cred, keyring_pag, &newpag, 0, NULL);
}
}
key_put(key);