Class: ACL

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
ext/acl/acl.c,
ext/acl/acl.c

Overview

ACL – interface to POSIX ACLs

ACL represents access controll list associated with a file or directory.

ACL instances are returned by methods ACL::from_text(text), ACL::from_file(file) or ACL::default(dir). Changes to ACL instances are not reflected back. You have to call ACL#set_file(file) or ACL#set_default(dir) to applly changes back to the filesystem.

Defined Under Namespace

Classes: Entry

Constant Summary collapse

ACL_UNDEFINED_TAG =

Tag type constants

INT2FIX(ACL_UNDEFINED_TAG)

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.default(dir) ⇒ Object

create new ACL object from directory name (default ACL)



130
131
132
133
134
135
# File 'ext/acl/acl.c', line 130

VALUE ruby_acl_from_file_default(VALUE class, VALUE dir) {
  acl_t acl;
  acl = acl_get_file( StringValuePtr(dir), ACL_TYPE_DEFAULT );
  if ((acl_t)NULL==acl) rb_sys_fail("acl_get_file failed");
  return Data_Wrap_Struct( class, 0, ruby_acl_free, acl );
}

.from_file(file) ⇒ Object

create new ACL object from filename or file descriptor (access ACL)



115
116
117
118
119
120
121
122
123
124
125
# File 'ext/acl/acl.c', line 115

VALUE ruby_acl_from_file_fd(VALUE class, VALUE file) {
  acl_t acl;
  if (FIXNUM_P(file)) {
    acl = acl_get_fd( FIX2INT(file) );
    if ((acl_t)NULL==acl) rb_sys_fail("acl_get_fd failed");
  } else {
    acl = acl_get_file( StringValuePtr(file), ACL_TYPE_ACCESS );
    if ((acl_t)NULL==acl) rb_sys_fail("acl_get_file failed");
  }
  return Data_Wrap_Struct( class, 0, ruby_acl_free, acl );
}

.from_text(text) ⇒ Object

create new ACL object from text representation of ACL

call-seq:

acl = ACL::from_text( string )


104
105
106
107
108
109
110
# File 'ext/acl/acl.c', line 104

VALUE ruby_acl_from_text(VALUE class, VALUE text) {
  acl_t acl;
  if (NULL == (acl = acl_from_text( StringValuePtr(text) ))) {
    rb_sys_fail("acl_from_text returned error");
  }
  return Data_Wrap_Struct( class, 0, ruby_acl_free, acl );
}

.new(*args) ⇒ Object

create new ACL object either by allocating new or duplicating given

optional FIXNUM argument is passed to acl_init (number of entries to allocate)

call-seq:

ACL::new -> acl
ACL::new( 10 ) -> acl
ACL::new( acl ) -> acl


72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
# File 'ext/acl/acl.c', line 72

VALUE ruby_acl_new(int argc, VALUE *argv, VALUE class) {
  acl_t acl;
   
  switch (argc) {
    case 0:
      acl = acl_init(10);
      break;
    case 1: /* either copy constructor or given number of entries */
      if (FIXNUM_P(argv[0])) {
        if (NULL == (acl = acl_init( FIX2INT(argv[0]) ))) {
          rb_sys_fail("acl_init returned error");
        }
      } else {
        Data_Get_Struct_ex( argv[0], acl_t, acl );
        if (NULL == (acl = acl_dup( acl ))) {
          rb_sys_fail("acl_dup returned error");
        }
      }
      break;
    default:
      rb_raise(rb_eArgError, "wrong number of arguments (expect 0 or 1)");
  }
  return Data_Wrap_Struct( class, 0, ruby_acl_free, acl );
}

Instance Method Details

#create_entryObject

Create new entry in acl

call-seq:

entry = acl.create_entry


319
320
321
322
323
324
325
326
327
328
329
330
331
# File 'ext/acl/acl.c', line 319

VALUE ruby_acl_create_entry( VALUE self ) {
  acl_t acl;
  acl_entry_t acl_entry;

  Data_Get_Struct_ex( self, acl_t, acl );

  if (0 != acl_create_entry( &acl, &acl_entry ) ) {
    rb_sys_fail("acl_create_entry failed");
  }
  /* store the acl back into self */
  DATA_PTR(self) = (void*)acl;
  return Data_Wrap_Struct( cEntry, 0, 0, acl_entry );
}

#delete_entry(entry) ⇒ Object

Detele entry in ACL

call-seq:

acl.delete_entry( entry )


339
340
341
342
343
344
345
346
347
348
349
# File 'ext/acl/acl.c', line 339

VALUE ruby_acl_delete_entry( VALUE self, VALUE entry ) {
  acl_t acl;
  acl_entry_t acl_entry;
  Data_Get_Struct_ex( self, acl_t, acl );
  Data_Get_Struct_ex( entry, acl_entry_t, acl_entry );

  if (0 != acl_delete_entry( acl, acl_entry ) ) {
    rb_sys_fail("acl_create_entry failed");
  }
  return self;
}

#eachObject

iterate over ACL entries

call-seq:

acl.each { |entry| }


46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'ext/acl/acl.c', line 46

VALUE ruby_acl_each(VALUE self) {
  int have;
  acl_t acl;
  acl_entry_t acl_entry;

  Data_Get_Struct_ex( self, acl_t, acl );
  have = acl_get_entry( acl, ACL_FIRST_ENTRY, &acl_entry );
  while (have == 1) {
    rb_yield( Data_Wrap_Struct( cEntry, 0, 0, acl_entry ) );
    have = acl_get_entry( acl, ACL_NEXT_ENTRY, &acl_entry );
  }
  if (have != 0) rb_sys_fail("acl_get_entry returned error");
  
  return self;
}

#set_default(dir) ⇒ Object

set default ACL on directory



161
162
163
164
165
166
167
168
169
# File 'ext/acl/acl.c', line 161

VALUE ruby_acl_set_default( VALUE self, VALUE dir ) {
  acl_t acl;
  
  Data_Get_Struct_ex( self, acl_t, acl );
  if (0 != acl_set_file( StringValuePtr(dir), ACL_TYPE_DEFAULT, acl ) ) {
        rb_sys_fail("acl_set_file (DEFAULT ACL) failed");
  }
  return self;
}

#set_file(file) ⇒ Object

set ACL on file or fd



140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
# File 'ext/acl/acl.c', line 140

VALUE ruby_acl_set_file( VALUE self, VALUE file ) {
  acl_t acl;
  
  Data_Get_Struct_ex( self, acl_t, acl );

  if (FIXNUM_P(file)) {
    if (0 != acl_set_fd(FIX2INT(file), acl) ) {
        rb_sys_fail("acl_set_fd failed");
    }
  } else {
    //if (0 != acl_set_file( StringValueCStr(file), ACL_TYPE_ACCESS, acl ) ) {
    if (0 != acl_set_file( StringValuePtr(file), ACL_TYPE_ACCESS, acl ) ) {
        rb_sys_fail("acl_set_file (ACCESS ACL) failed");
    }
  }
  return self;
}

#to_textObject

dump ACL as text

call-seq:

acl.to_text -> string


24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'ext/acl/acl.c', line 24

VALUE ruby_acl_to_text( VALUE self ) {
  acl_t acl;
  char *text;
  VALUE ret;
  
  Data_Get_Struct_ex( self, acl_t, acl );
  if ( NULL == (text = acl_to_text( acl, NULL ) ) ) {
    rb_sys_fail("acl_to_text returned error");
  }
  ret = rb_str_new2( text );
  acl_free( text );

  return ret;
}

#valid?Boolean

check if ACL is valid

call-seq:

acl.valid?

Returns:

  • (Boolean)


178
179
180
181
182
183
184
185
186
187
# File 'ext/acl/acl.c', line 178

VALUE ruby_acl_valid( VALUE self ) {
  acl_t acl;

  Data_Get_Struct_ex( self, acl_t, acl );
  if (0 == acl_valid( acl )) {
    return Qtrue;
  } else {
    return Qfalse;
  }
}