Changeset View
Changeset View
Standalone View
Standalone View
sys/compat/linux/linux_uid16.c
| Show First 20 Lines • Show All 79 Lines • ▼ Show 20 Lines | linux_lchown16(struct thread *td, struct linux_lchown16_args *args) | ||||
| return (kern_fchownat(td, AT_FDCWD, args->path, UIO_USERSPACE, | return (kern_fchownat(td, AT_FDCWD, args->path, UIO_USERSPACE, | ||||
| CAST_NOCHG(args->uid), CAST_NOCHG(args->gid), AT_SYMLINK_NOFOLLOW)); | CAST_NOCHG(args->uid), CAST_NOCHG(args->gid), AT_SYMLINK_NOFOLLOW)); | ||||
| } | } | ||||
| int | int | ||||
| linux_setgroups16(struct thread *td, struct linux_setgroups16_args *args) | linux_setgroups16(struct thread *td, struct linux_setgroups16_args *args) | ||||
| { | { | ||||
| const int ngrp = args->gidsetsize; | |||||
| struct ucred *newcred, *oldcred; | struct ucred *newcred, *oldcred; | ||||
| l_gid16_t *linux_gidset; | l_gid16_t *linux_gidset; | ||||
| int ngrp, error; | int error; | ||||
| struct proc *p; | struct proc *p; | ||||
| ngrp = args->gidsetsize; | |||||
| if (ngrp < 0 || ngrp >= ngroups_max) | if (ngrp < 0 || ngrp >= ngroups_max) | ||||
| return (EINVAL); | return (EINVAL); | ||||
| linux_gidset = malloc(ngrp * sizeof(*linux_gidset), M_LINUX, M_WAITOK); | linux_gidset = malloc(ngrp * sizeof(*linux_gidset), M_LINUX, M_WAITOK); | ||||
| error = copyin(args->gidset, linux_gidset, ngrp * sizeof(l_gid16_t)); | error = copyin(args->gidset, linux_gidset, ngrp * sizeof(l_gid16_t)); | ||||
| if (error) { | if (error) { | ||||
| LIN_SDT_PROBE1(uid16, linux_setgroups16, copyin_error, error); | LIN_SDT_PROBE1(uid16, linux_setgroups16, copyin_error, error); | ||||
| free(linux_gidset, M_LINUX); | free(linux_gidset, M_LINUX); | ||||
| return (error); | return (error); | ||||
| } | } | ||||
| newcred = crget(); | newcred = crget(); | ||||
| p = td->td_proc; | p = td->td_proc; | ||||
| PROC_LOCK(p); | PROC_LOCK(p); | ||||
| oldcred = crcopysafe(p, newcred); | oldcred = crcopysafe(p, newcred); | ||||
| if ((error = priv_check_cred(oldcred, PRIV_CRED_SETGROUPS)) != 0) { | if ((error = priv_check_cred(oldcred, PRIV_CRED_SETGROUPS)) != 0) { | ||||
| PROC_UNLOCK(p); | PROC_UNLOCK(p); | ||||
| crfree(newcred); | crfree(newcred); | ||||
| Show All 17 Lines | out: | ||||
| free(linux_gidset, M_LINUX); | free(linux_gidset, M_LINUX); | ||||
| return (error); | return (error); | ||||
| } | } | ||||
| int | int | ||||
| linux_getgroups16(struct thread *td, struct linux_getgroups16_args *args) | linux_getgroups16(struct thread *td, struct linux_getgroups16_args *args) | ||||
| { | { | ||||
| struct ucred *cred; | const struct ucred *const cred = td->td_ucred; | ||||
| l_gid16_t *linux_gidset; | l_gid16_t *linux_gidset; | ||||
| gid_t *bsd_gidset; | int ngrp, error; | ||||
| int bsd_gidsetsz, ngrp, error; | |||||
| cred = td->td_ucred; | ngrp = args->gidsetsize; | ||||
| bsd_gidset = cred->cr_groups; | |||||
| bsd_gidsetsz = cred->cr_ngroups; | |||||
| if ((ngrp = args->gidsetsize) == 0) { | if (ngrp == 0) { | ||||
| td->td_retval[0] = bsd_gidsetsz; | td->td_retval[0] = cred->cr_ngroups; | ||||
| return (0); | return (0); | ||||
| } | } | ||||
| if (ngrp < cred->cr_ngroups) | |||||
| if (ngrp < bsd_gidsetsz) | |||||
| return (EINVAL); | return (EINVAL); | ||||
| ngrp = 0; | ngrp = cred->cr_ngroups; | ||||
| linux_gidset = malloc(bsd_gidsetsz * sizeof(*linux_gidset), | |||||
| M_LINUX, M_WAITOK); | |||||
| while (ngrp < bsd_gidsetsz) { | |||||
| linux_gidset[ngrp] = bsd_gidset[ngrp]; | |||||
| ngrp++; | |||||
| } | |||||
| linux_gidset = malloc(ngrp * sizeof(*linux_gidset), M_LINUX, M_WAITOK); | |||||
| for (int i = 0; i < ngrp; ++i) | |||||
| linux_gidset[i] = cred->cr_groups[i]; | |||||
| error = copyout(linux_gidset, args->gidset, ngrp * sizeof(l_gid16_t)); | error = copyout(linux_gidset, args->gidset, ngrp * sizeof(l_gid16_t)); | ||||
| free(linux_gidset, M_LINUX); | free(linux_gidset, M_LINUX); | ||||
| if (error) { | |||||
| if (error != 0) { | |||||
| LIN_SDT_PROBE1(uid16, linux_getgroups16, copyout_error, error); | LIN_SDT_PROBE1(uid16, linux_getgroups16, copyout_error, error); | ||||
| return (error); | return (error); | ||||
| } | } | ||||
| td->td_retval[0] = ngrp; | td->td_retval[0] = ngrp; | ||||
| return (0); | return (0); | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 118 Lines • Show Last 20 Lines | |||||