Module: Shadow::Passwd
- Defined in:
- ext/shadow/shadow.c
Constant Summary collapse
- Entry =
rb_sPasswdEntry
Class Method Summary collapse
- .endspent ⇒ Object
- .fgetspent(file) ⇒ Object
- .getspent ⇒ Object
- .getspnam(name) ⇒ Object
- .lckpwdf ⇒ Object
- .lock ⇒ Object
- .lock? ⇒ Boolean
- .putspent(entry, file) ⇒ Object
- .setspent ⇒ Object
- .sgetspent(str) ⇒ Object
- .ulckpwdf ⇒ Object
- .unlock ⇒ Object
Class Method Details
.endspent ⇒ Object
41 42 43 44 45 46 |
# File 'ext/shadow/shadow.c', line 41
static VALUE
rb_shadow_endspent(VALUE self)
{
endspent();
return Qnil;
};
|
.fgetspent(file) ⇒ Object
80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 |
# File 'ext/shadow/shadow.c', line 80
static VALUE
rb_shadow_fgetspent(VALUE self, VALUE file)
{
struct spwd *entry;
VALUE result;
if( TYPE(file) != T_FILE )
rb_raise(rb_eTypeError,"argument must be a File.");
entry = fgetspent(file_ptr(RFILE(file)->fptr));
if( entry == NULL )
return Qnil;
result = rb_struct_new(rb_sPasswdEntry,
rb_tainted_str_new2(entry->sp_namp),
rb_tainted_str_new2(entry->sp_pwdp),
INT2FIX(entry->sp_lstchg),
INT2FIX(entry->sp_min),
INT2FIX(entry->sp_max),
INT2FIX(entry->sp_warn),
INT2FIX(entry->sp_inact),
INT2FIX(entry->sp_expire),
INT2FIX(entry->sp_flag),
0);
return result;
};
|
.getspent ⇒ Object
108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 |
# File 'ext/shadow/shadow.c', line 108
static VALUE
rb_shadow_getspent(VALUE self)
{
struct spwd *entry;
VALUE result;
entry = getspent();
if( entry == NULL )
return Qnil;
result = rb_struct_new(rb_sPasswdEntry,
rb_tainted_str_new2(entry->sp_namp),
rb_tainted_str_new2(entry->sp_pwdp),
INT2FIX(entry->sp_lstchg),
INT2FIX(entry->sp_min),
INT2FIX(entry->sp_max),
INT2FIX(entry->sp_warn),
INT2FIX(entry->sp_inact),
INT2FIX(entry->sp_expire),
INT2FIX(entry->sp_flag),
0);
return result;
};
|
.getspnam(name) ⇒ Object
133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 |
# File 'ext/shadow/shadow.c', line 133
static VALUE
rb_shadow_getspnam(VALUE self, VALUE name)
{
struct spwd *entry;
VALUE result;
if( TYPE(name) != T_STRING )
rb_raise(rb_eException,"argument must be a string.");
entry = getspnam(StringValuePtr(name));
if( entry == NULL )
return Qnil;
result = rb_struct_new(rb_sPasswdEntry,
rb_tainted_str_new2(entry->sp_namp),
rb_tainted_str_new2(entry->sp_pwdp),
INT2FIX(entry->sp_lstchg),
INT2FIX(entry->sp_min),
INT2FIX(entry->sp_max),
INT2FIX(entry->sp_warn),
INT2FIX(entry->sp_inact),
INT2FIX(entry->sp_expire),
INT2FIX(entry->sp_flag),
0);
return result;
};
|
.lckpwdf ⇒ Object
194 195 196 197 198 199 200 201 202 203 |
# File 'ext/shadow/shadow.c', line 194
static VALUE
rb_shadow_lckpwdf(VALUE self)
{
int result;
result = lckpwdf();
if( result == -1 )
rb_raise(rb_eFileLock,"password file was locked");
else
return Qtrue;
};
|
.lock ⇒ Object
207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 |
# File 'ext/shadow/shadow.c', line 207
static VALUE
rb_shadow_lock(VALUE self)
{
int result;
if( rb_iterator_p() ){
result = lckpwdf();
if( result == -1 ){
rb_raise(rb_eFileLock,"password file was locked");
}
else{
in_lock++;
rb_yield(Qnil);
in_lock--;
ulckpwdf();
};
return Qtrue;
}
else{
return rb_shadow_lckpwdf(self);
};
};
|
.lock? ⇒ Boolean
247 248 249 250 251 252 253 254 255 256 257 258 259 260 |
# File 'ext/shadow/shadow.c', line 247
static VALUE
rb_shadow_lock_p(VALUE self)
{
int result;
result = lckpwdf();
if( result == -1 ){
return Qtrue;
}
else{
ulckpwdf();
return Qfalse;
};
};
|
.putspent(entry, file) ⇒ Object
162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 |
# File 'ext/shadow/shadow.c', line 162
static VALUE
rb_shadow_putspent(VALUE self, VALUE entry, VALUE file)
{
struct spwd centry;
FILE* cfile;
VALUE val[9];
int i;
int result;
for(i=0; i<=8; i++)
val[i] = RSTRUCT_PTR(entry)[i];
cfile = file_ptr(RFILE(file)->fptr);
centry.sp_namp = StringValuePtr(val[0]);
centry.sp_pwdp = StringValuePtr(val[1]);
centry.sp_lstchg = FIX2INT(val[2]);
centry.sp_min = FIX2INT(val[3]);
centry.sp_max = FIX2INT(val[4]);
centry.sp_warn = FIX2INT(val[5]);
centry.sp_inact = FIX2INT(val[6]);
centry.sp_expire = FIX2INT(val[7]);
centry.sp_flag = FIX2INT(val[8]);
result = putspent(¢ry,cfile);
if( result == -1 )
rb_raise(rb_eStandardError,"can't change password");
return Qtrue;
};
|
.setspent ⇒ Object
33 34 35 36 37 38 |
# File 'ext/shadow/shadow.c', line 33
static VALUE
rb_shadow_setspent(VALUE self)
{
setspent();
return Qnil;
};
|
.sgetspent(str) ⇒ Object
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'ext/shadow/shadow.c', line 50
static VALUE
rb_shadow_sgetspent(VALUE self, VALUE str)
{
struct spwd *entry;
VALUE result;
if( TYPE(str) != T_STRING )
rb_raise(rb_eException,"argument must be a string.");
entry = sgetspent(StringValuePtr(str));
if( entry == NULL )
return Qnil;
result = rb_struct_new(rb_sPasswdEntry,
rb_tainted_str_new2(entry->sp_namp),
rb_tainted_str_new2(entry->sp_pwdp),
INT2FIX(entry->sp_lstchg),
INT2FIX(entry->sp_min),
INT2FIX(entry->sp_max),
INT2FIX(entry->sp_warn),
INT2FIX(entry->sp_inact),
INT2FIX(entry->sp_expire),
INT2FIX(entry->sp_flag),
0);
free(entry);
return result;
};
|
.ulckpwdf ⇒ Object
231 232 233 234 235 236 237 238 239 |
# File 'ext/shadow/shadow.c', line 231
static VALUE
rb_shadow_ulckpwdf(VALUE self)
{
if( in_lock ){
rb_raise(rb_eFileLock,"you call unlock method in lock iterator.");
};
ulckpwdf();
return Qtrue;
};
|
.unlock ⇒ Object
241 242 243 244 245 |
# File 'ext/shadow/shadow.c', line 241
static VALUE
rb_shadow_unlock(VALUE self)
{
return rb_shadow_ulckpwdf(self);
};
|