2011-09-08 18:49:54 +02:00
|
|
|
|
|
|
|
#include <minix/vfsif.h>
|
|
|
|
#include <minix/type.h>
|
2011-11-14 11:07:49 +01:00
|
|
|
#include <minix/syslib.h>
|
2011-09-08 18:49:54 +02:00
|
|
|
#include <assert.h>
|
2011-11-14 11:07:49 +01:00
|
|
|
#include <string.h>
|
2011-09-08 18:49:54 +02:00
|
|
|
|
|
|
|
#include "minixfs.h"
|
|
|
|
|
|
|
|
int fs_lookup_credentials(vfs_ucred_t *credentials,
|
|
|
|
uid_t *caller_uid, gid_t *caller_gid, cp_grant_id_t grant2, size_t cred_size)
|
|
|
|
{
|
|
|
|
vfs_ucred_old_t old_cred;
|
|
|
|
int r;
|
|
|
|
|
|
|
|
memset(credentials, 0, sizeof(*credentials));
|
|
|
|
|
|
|
|
if(cred_size == sizeof(*credentials)) {
|
|
|
|
r = sys_safecopyfrom(VFS_PROC_NR, grant2, (vir_bytes) 0,
|
2012-06-16 03:46:15 +02:00
|
|
|
(vir_bytes) credentials, cred_size);
|
2011-09-08 18:49:54 +02:00
|
|
|
if (r != OK) {
|
|
|
|
printf("FS: cred copy (regular) failed.\n");
|
|
|
|
return(r);
|
|
|
|
}
|
|
|
|
} else if(cred_size == sizeof(old_cred)) {
|
|
|
|
int g;
|
|
|
|
r = sys_safecopyfrom(VFS_PROC_NR, grant2, (vir_bytes) 0,
|
2012-06-16 03:46:15 +02:00
|
|
|
(vir_bytes) &old_cred, sizeof(old_cred));
|
2011-09-08 18:49:54 +02:00
|
|
|
if (r != OK) {
|
|
|
|
printf("FS: cred copy (fallback) failed.\n");
|
|
|
|
return(r);
|
|
|
|
}
|
|
|
|
credentials->vu_ngroups = old_cred.vu_ngroups;
|
|
|
|
credentials->vu_uid = old_cred.vu_uid;
|
|
|
|
credentials->vu_gid = old_cred.vu_gid;
|
|
|
|
for(g = 0; g < NGROUPS_MAX_OLD; g++) {
|
|
|
|
assert(g < NGROUPS_MAX);
|
|
|
|
credentials->vu_sgroups[g] = old_cred.vu_sgroups[g];
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
static int w = 0;
|
|
|
|
if(!w) { printf("FS: cred size incompatible with VFS.\n"); w = 1; }
|
|
|
|
return(EINVAL); /* Wrong size. */
|
|
|
|
}
|
|
|
|
|
|
|
|
assert(credentials->vu_ngroups <= NGROUPS_MAX);
|
|
|
|
|
|
|
|
*caller_uid = credentials->vu_uid;
|
|
|
|
*caller_gid = credentials->vu_gid;
|
|
|
|
|
|
|
|
return OK;
|
|
|
|
}
|
|
|
|
|