lib/secacl.c

説明を見る。
00001 /* 
00002  *  Unix SMB/Netbios implementation.
00003  *  SEC_ACL handling routines
00004  *  Copyright (C) Andrew Tridgell              1992-1998,
00005  *  Copyright (C) Jeremy R. Allison            1995-2003.
00006  *  Copyright (C) Luke Kenneth Casson Leighton 1996-1998,
00007  *  Copyright (C) Paul Ashton                  1997-1998.
00008  *  
00009  *  This program is free software; you can redistribute it and/or modify
00010  *  it under the terms of the GNU General Public License as published by
00011  *  the Free Software Foundation; either version 2 of the License, or
00012  *  (at your option) any later version.
00013  *  
00014  *  This program is distributed in the hope that it will be useful,
00015  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00016  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00017  *  GNU General Public License for more details.
00018  *  
00019  *  You should have received a copy of the GNU General Public License
00020  *  along with this program; if not, write to the Free Software
00021  *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
00022  */
00023 
00024 #include "includes.h"
00025 
00026 /*******************************************************************
00027  Create a SEC_ACL structure.  
00028 ********************************************************************/
00029 
00030 SEC_ACL *make_sec_acl(TALLOC_CTX *ctx, uint16 revision, int num_aces, SEC_ACE *ace_list)
00031 {
00032         SEC_ACL *dst;
00033         int i;
00034 
00035         if((dst = TALLOC_ZERO_P(ctx,SEC_ACL)) == NULL)
00036                 return NULL;
00037 
00038         dst->revision = revision;
00039         dst->num_aces = num_aces;
00040         dst->size = SEC_ACL_HEADER_SIZE;
00041 
00042         /* Now we need to return a non-NULL address for the ace list even
00043            if the number of aces required is zero.  This is because there
00044            is a distinct difference between a NULL ace and an ace with zero
00045            entries in it.  This is achieved by checking that num_aces is a
00046            positive number. */
00047 
00048         if ((num_aces) && 
00049             ((dst->aces = TALLOC_ARRAY(ctx, SEC_ACE, num_aces)) 
00050              == NULL)) {
00051                 return NULL;
00052         }
00053         
00054         for (i = 0; i < num_aces; i++) {
00055                 dst->aces[i] = ace_list[i]; /* Structure copy. */
00056                 dst->size += ace_list[i].size;
00057         }
00058 
00059         return dst;
00060 }
00061 
00062 /*******************************************************************
00063  Duplicate a SEC_ACL structure.  
00064 ********************************************************************/
00065 
00066 SEC_ACL *dup_sec_acl(TALLOC_CTX *ctx, SEC_ACL *src)
00067 {
00068         if(src == NULL)
00069                 return NULL;
00070 
00071         return make_sec_acl(ctx, src->revision, src->num_aces, src->aces);
00072 }
00073 
00074 /*******************************************************************
00075  Compares two SEC_ACL structures
00076 ********************************************************************/
00077 
00078 BOOL sec_acl_equal(SEC_ACL *s1, SEC_ACL *s2)
00079 {
00080         unsigned int i, j;
00081 
00082         /* Trivial cases */
00083 
00084         if (!s1 && !s2) return True;
00085         if (!s1 || !s2) return False;
00086 
00087         /* Check top level stuff */
00088 
00089         if (s1->revision != s2->revision) {
00090                 DEBUG(10, ("sec_acl_equal(): revision differs (%d != %d)\n",
00091                            s1->revision, s2->revision));
00092                 return False;
00093         }
00094 
00095         if (s1->num_aces != s2->num_aces) {
00096                 DEBUG(10, ("sec_acl_equal(): num_aces differs (%d != %d)\n",
00097                            s1->revision, s2->revision));
00098                 return False;
00099         }
00100 
00101         /* The ACEs could be in any order so check each ACE in s1 against 
00102            each ACE in s2. */
00103 
00104         for (i = 0; i < s1->num_aces; i++) {
00105                 BOOL found = False;
00106 
00107                 for (j = 0; j < s2->num_aces; j++) {
00108                         if (sec_ace_equal(&s1->aces[i], &s2->aces[j])) {
00109                                 found = True;
00110                                 break;
00111                         }
00112                 }
00113 
00114                 if (!found) return False;
00115         }
00116 
00117         return True;
00118 }

Sambaに対してSat Aug 29 21:22:59 2009に生成されました。  doxygen 1.4.7