2019-08-06 22:13:43 +02:00
|
|
|
/****************************************************************************
|
|
|
|
* sched/group/group_setgid.c
|
|
|
|
*
|
2021-02-08 16:33:58 +01:00
|
|
|
* Licensed to the Apache Software Foundation (ASF) under one or more
|
|
|
|
* contributor license agreements. See the NOTICE file distributed with
|
|
|
|
* this work for additional information regarding copyright ownership. The
|
|
|
|
* ASF licenses this file to you under the Apache License, Version 2.0 (the
|
|
|
|
* "License"); you may not use this file except in compliance with the
|
|
|
|
* License. You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
|
|
|
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
|
|
|
* License for the specific language governing permissions and limitations
|
|
|
|
* under the License.
|
2019-08-06 22:13:43 +02:00
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Included Files
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#include <nuttx/config.h>
|
|
|
|
|
|
|
|
#include <unistd.h>
|
2021-05-18 08:59:14 +02:00
|
|
|
#include <assert.h>
|
2019-08-06 22:13:43 +02:00
|
|
|
#include <errno.h>
|
|
|
|
|
|
|
|
#include <sched/sched.h>
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Public Functions
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: setgid
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* The setgid() function sets the real group ID, effective group ID, and
|
|
|
|
* the saved set-group-ID of the calling process to gid, given appropriate
|
|
|
|
* privileges.
|
|
|
|
*
|
|
|
|
* Input Parameters:
|
2020-02-23 09:50:23 +01:00
|
|
|
* gid - Identity to set the various process's group ID attributes to.
|
2019-08-06 22:13:43 +02:00
|
|
|
*
|
|
|
|
* Returned Value:
|
|
|
|
* Zero if successful and -1 in case of failure, in which case errno is set
|
2019-08-10 18:42:53 +02:00
|
|
|
* to one of he following values:
|
|
|
|
*
|
|
|
|
* EINVAL - The value of the uid argument is invalid and not supported by
|
|
|
|
* the implementation.
|
|
|
|
* EPERM - The process does not have appropriate privileges and uid does
|
|
|
|
* not match the real group ID or the saved set-group-ID.
|
2019-08-06 22:13:43 +02:00
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
int setgid(gid_t gid)
|
|
|
|
{
|
2019-08-10 18:42:53 +02:00
|
|
|
FAR struct tcb_s *rtcb;
|
|
|
|
FAR struct task_group_s *rgroup;
|
|
|
|
|
|
|
|
/* Verify that the GID is in the valid range of 0 through INT16_MAX.
|
|
|
|
* OpenGroup.org does not specify a GID_MAX or GID_MIN. Instead we use a
|
|
|
|
* priori knowledge that gid_t is type int16_t.
|
|
|
|
*/
|
|
|
|
|
|
|
|
if ((uint16_t)gid > INT16_MAX)
|
|
|
|
{
|
|
|
|
set_errno(EINVAL);
|
|
|
|
return ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Get the currently executing thread's task group. */
|
|
|
|
|
|
|
|
rtcb = this_task();
|
|
|
|
rgroup = rtcb->group;
|
2019-08-06 22:13:43 +02:00
|
|
|
|
|
|
|
/* Set the task group's group identity. */
|
|
|
|
|
2020-08-11 09:06:46 +02:00
|
|
|
DEBUGASSERT(rgroup != NULL);
|
2019-08-06 22:13:43 +02:00
|
|
|
rgroup->tg_gid = gid;
|
|
|
|
return OK;
|
|
|
|
}
|