__aeabi_ldivmod: fix sign logic
[minix.git] / lib / libminixfs / fetch_credentials.c
blob3c5a62d424aa4c101e9743d8f35eca59ffa11630
2 #include <minix/vfsif.h>
3 #include <minix/type.h>
4 #include <minix/syslib.h>
5 #include <assert.h>
6 #include <string.h>
8 #include "minixfs.h"
10 int fs_lookup_credentials(vfs_ucred_t *credentials,
11 uid_t *caller_uid, gid_t *caller_gid, cp_grant_id_t grant2, size_t cred_size)
13 vfs_ucred_old_t old_cred;
14 int r;
16 memset(credentials, 0, sizeof(*credentials));
18 if(cred_size == sizeof(*credentials)) {
19 r = sys_safecopyfrom(VFS_PROC_NR, grant2, (vir_bytes) 0,
20 (vir_bytes) credentials, cred_size);
21 if (r != OK) {
22 printf("FS: cred copy (regular) failed.\n");
23 return(r);
25 } else if(cred_size == sizeof(old_cred)) {
26 int g;
27 r = sys_safecopyfrom(VFS_PROC_NR, grant2, (vir_bytes) 0,
28 (vir_bytes) &old_cred, sizeof(old_cred));
29 if (r != OK) {
30 printf("FS: cred copy (fallback) failed.\n");
31 return(r);
33 credentials->vu_ngroups = old_cred.vu_ngroups;
34 credentials->vu_uid = old_cred.vu_uid;
35 credentials->vu_gid = old_cred.vu_gid;
36 for(g = 0; g < NGROUPS_MAX_OLD; g++) {
37 assert(g < NGROUPS_MAX);
38 credentials->vu_sgroups[g] = old_cred.vu_sgroups[g];
40 } else {
41 static int w = 0;
42 if(!w) { printf("FS: cred size incompatible with VFS.\n"); w = 1; }
43 return(EINVAL); /* Wrong size. */
46 assert(credentials->vu_ngroups <= NGROUPS_MAX);
48 *caller_uid = credentials->vu_uid;
49 *caller_gid = credentials->vu_gid;
51 return OK;