(root)/
acl-2.3.1/
libacl/
acl_from_mode.c
       1  /*
       2    File: acl_from_mode.c
       3  
       4    Copyright (C) 1999, 2000
       5    Andreas Gruenbacher, <andreas.gruenbacher@gmail.com>
       6  
       7    This program is free software; you can redistribute it and/or
       8    modify it under the terms of the GNU Lesser General Public
       9    License as published by the Free Software Foundation; either
      10    version 2.1 of the License, or (at your option) any later version.
      11  
      12    This program is distributed in the hope that it will be useful,
      13    but WITHOUT ANY WARRANTY; without even the implied warranty of
      14    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
      15    Lesser General Public License for more details.
      16  
      17    You should have received a copy of the GNU Lesser General Public
      18    License along with this library; if not, write to the Free Software
      19    Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
      20  */
      21  
      22  #include "config.h"
      23  #include <unistd.h>
      24  #include <stdio.h>
      25  #include <errno.h>
      26  #include <sys/stat.h>
      27  #include "libacl.h"
      28  
      29  
      30  /*
      31    Create an ACL from a file mode.
      32  
      33    returns
      34    	the new ACL.
      35  */
      36  
      37  acl_t
      38  acl_from_mode(mode_t mode)
      39  {
      40  	acl_obj *acl_obj_p;
      41  	acl_entry_obj *entry_obj_p;
      42  
      43  	acl_obj_p = __acl_init_obj(3);
      44  	if (!acl_obj_p)
      45  		return NULL;
      46  
      47  	entry_obj_p = __acl_create_entry_obj(acl_obj_p);
      48  	if (!entry_obj_p)
      49  		goto fail;
      50  	entry_obj_p->etag = ACL_USER_OBJ;
      51  	entry_obj_p->eid.qid = ACL_UNDEFINED_ID;
      52  	entry_obj_p->eperm.sperm = (mode & S_IRWXU) >> 6;
      53  
      54  	entry_obj_p = __acl_create_entry_obj(acl_obj_p);
      55  	if (!entry_obj_p)
      56  		goto fail;
      57  	entry_obj_p->etag = ACL_GROUP_OBJ;
      58  	entry_obj_p->eid.qid = ACL_UNDEFINED_ID;
      59  	entry_obj_p->eperm.sperm = (mode & S_IRWXG) >> 3;
      60  
      61  	entry_obj_p = __acl_create_entry_obj(acl_obj_p);
      62  	if (!entry_obj_p)
      63  		goto fail;
      64  	entry_obj_p->etag = ACL_OTHER;
      65  	entry_obj_p->eid.qid = ACL_UNDEFINED_ID;
      66  	entry_obj_p->eperm.sperm = mode & S_IRWXO;
      67  	return int2ext(acl_obj_p);
      68  
      69  fail:
      70  	__acl_free_acl_obj(acl_obj_p);
      71  	return NULL;
      72  }
      73