Class: Kerberos::Krb5::Principal
- Inherits:
-
Object
- Object
- Kerberos::Krb5::Principal
- Defined in:
- ext/rkerberos/principal.c
Instance Attribute Summary collapse
-
#attributes ⇒ Object
Attributes.
- #aux_attributes ⇒ Object
- #expire_time ⇒ Object
- #fail_auth_count ⇒ Object
- #kvno ⇒ Object
- #last_failed ⇒ Object
- #last_password_change ⇒ Object
- #last_success ⇒ Object
- #max_life ⇒ Object
- #max_renewable_life ⇒ Object
- #mod_date ⇒ Object
- #mod_name ⇒ Object
- #password_expiration ⇒ Object
- #policy ⇒ Object
- #principal ⇒ Object (also: #name) readonly
Instance Method Summary collapse
- #==(v_other) ⇒ Object
- #close ⇒ Object
- #components ⇒ Object
-
#Kerberos::Krb5::Principal.new(name: nil, context: nil) ⇒ Object
constructor
Creates and returns a new Krb5::Principal object.
-
#inspect ⇒ Object
A custom inspect method for the Principal object.
- #principal_type ⇒ Object
- #realm ⇒ Object
- #realm=(v_realm) ⇒ Object
Constructor Details
#Kerberos::Krb5::Principal.new(name: nil, context: nil) ⇒ Object
Creates and returns a new Krb5::Principal object. If a block is provided then it yields itself.
A principal name may be provided as a keyword argument. If not provided
or nil, the principal attribute will be nil.
An optional context keyword argument may be provided. If given, it must
be a Kerberos::Krb5::Context object and will be used instead of creating
a new context via krb5_init_context.
Example:
principal1 = Kerberos::Krb5::Principal.new(name: 'Jon')
principal2 = Kerberos::Krb5::Principal.new(name: 'Jon') do |pr|
pr.expire_time = Time.now + 20000
end
ctx = Kerberos::Krb5::Context.new
principal3 = Kerberos::Krb5::Principal.new(name: 'Jon', context: ctx)
69 70 71 72 73 74 75 76 77 78 79 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 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 |
# File 'ext/rkerberos/principal.c', line 69
static VALUE rkrb5_princ_initialize(int argc, VALUE* argv, VALUE self){
RUBY_KRB5_PRINC* ptr;
krb5_error_code kerror;
VALUE v_opts = Qnil;
VALUE v_name = Qnil;
VALUE v_context = Qnil;
ID kw_table[2] = { rb_intern("name"), rb_intern("context") };
VALUE kw_vals[2];
TypedData_Get_Struct(self, RUBY_KRB5_PRINC, &rkrb5_princ_data_type, ptr);
rb_scan_args(argc, argv, "0:", &v_opts);
if(NIL_P(v_opts))
v_opts = rb_hash_new();
rb_get_kwargs(v_opts, kw_table, 0, 2, kw_vals);
v_name = kw_vals[0] == Qundef ? Qnil : kw_vals[0];
v_context = kw_vals[1] == Qundef ? Qnil : kw_vals[1];
// Initialize or borrow the context
if(!NIL_P(v_context)){
ptr->ctx = rkrb5_context_borrow(v_context);
ptr->rb_context = v_context;
}
else{
kerror = krb5_init_context(&ptr->ctx);
if(kerror)
rb_raise(cKrb5Exception, "krb5_init_context failed: %s", error_message(kerror));
ptr->rb_context = Qnil;
}
if(NIL_P(v_name)){
rb_iv_set(self, "@principal", Qnil);
}
else{
char* name;
Check_Type(v_name, T_STRING);
name = StringValueCStr(v_name);
kerror = krb5_parse_name(ptr->ctx, name, &ptr->principal);
if(kerror)
rb_raise(cKrb5Exception, "krb5_parse_name failed: %s", error_message(kerror));
rb_iv_set(self, "@principal", v_name);
}
rb_iv_set(self, "@attributes", Qnil);
rb_iv_set(self, "@aux_attributes", Qnil);
rb_iv_set(self, "@expire_time", Qnil);
rb_iv_set(self, "@fail_auth_count", Qnil);
rb_iv_set(self, "@last_failed", Qnil);
rb_iv_set(self, "@last_password_change", Qnil);
rb_iv_set(self, "@last_success", Qnil);
rb_iv_set(self, "@max_life", Qnil);
rb_iv_set(self, "@max_renewable_life", Qnil);
rb_iv_set(self, "@mod_date", Qnil);
rb_iv_set(self, "@mod_name", Qnil);
rb_iv_set(self, "@password_expiration", Qnil);
rb_iv_set(self, "@policy", Qnil);
rb_iv_set(self, "@kvno", Qnil);
if(rb_block_given_p())
rb_yield(self);
return self;
}
|
Instance Attribute Details
#attributes ⇒ Object
Attributes
#aux_attributes ⇒ Object
#expire_time ⇒ Object
#fail_auth_count ⇒ Object
#kvno ⇒ Object
#last_failed ⇒ Object
#last_password_change ⇒ Object
#last_success ⇒ Object
#max_life ⇒ Object
#max_renewable_life ⇒ Object
#mod_date ⇒ Object
#mod_name ⇒ Object
#password_expiration ⇒ Object
#policy ⇒ Object
#principal ⇒ Object (readonly) Also known as: name
Instance Method Details
#==(v_other) ⇒ Object
217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 |
# File 'ext/rkerberos/principal.c', line 217
static VALUE rkrb5_princ_equal(VALUE self, VALUE v_other){
RUBY_KRB5_PRINC* ptr1;
RUBY_KRB5_PRINC* ptr2;
VALUE v_bool = Qfalse;
TypedData_Get_Struct(self, RUBY_KRB5_PRINC, &rkrb5_princ_data_type, ptr1);
if(!rb_obj_is_kind_of(v_other, cKrb5Principal))
return Qfalse;
TypedData_Get_Struct(v_other, RUBY_KRB5_PRINC, &rkrb5_princ_data_type, ptr2);
if(!ptr1->principal || !ptr2->principal)
return Qfalse;
if(krb5_principal_compare(ptr1->ctx, ptr1->principal, ptr2->principal))
v_bool = Qtrue;
return v_bool;
}
|
#close ⇒ Object
147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 |
# File 'ext/rkerberos/principal.c', line 147
static VALUE rkrb5_princ_close(VALUE self){
RUBY_KRB5_PRINC* ptr;
TypedData_Get_Struct(self, RUBY_KRB5_PRINC, &rkrb5_princ_data_type, ptr);
if(!ptr->ctx)
return self;
if(ptr->principal)
krb5_free_principal(ptr->ctx, ptr->principal);
if(ptr->rb_context == Qnil)
krb5_free_context(ptr->ctx);
else
rkrb5_context_release(ptr->rb_context);
ptr->ctx = NULL;
ptr->principal = NULL;
ptr->rb_context = Qnil;
return self;
}
|
#components ⇒ Object
342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 |
# File 'ext/rkerberos/principal.c', line 342
static VALUE rkrb5_princ_components(VALUE self){
RUBY_KRB5_PRINC* ptr;
TypedData_Get_Struct(self, RUBY_KRB5_PRINC, &rkrb5_princ_data_type, ptr);
if(!ptr->principal)
rb_raise(cKrb5Exception, "no principal has been established");
int n = krb5_princ_size(ptr->ctx, ptr->principal);
VALUE v_array = rb_ary_new_capa(n);
for(int i = 0; i < n; i++){
krb5_data* component = krb5_princ_component(ptr->ctx, ptr->principal, i);
rb_ary_push(v_array, rb_str_new(component->data, component->length));
}
return v_array;
}
|
#inspect ⇒ Object
A custom inspect method for the Principal object.
244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 |
# File 'ext/rkerberos/principal.c', line 244 static VALUE rkrb5_princ_inspect(VALUE self){ VALUE v_str; v_str = rb_str_new2("#<"); rb_str_buf_cat2(v_str, rb_obj_classname(self)); rb_str_buf_cat2(v_str, " "); rb_str_buf_cat2(v_str, "attributes="); rb_str_buf_append(v_str, rb_inspect(rb_iv_get(self, "@attributes"))); rb_str_buf_cat2(v_str, " "); rb_str_buf_cat2(v_str, "aux_attributes="); rb_str_buf_append(v_str, rb_inspect(rb_iv_get(self, "@aux_attributes"))); rb_str_buf_cat2(v_str, " "); rb_str_buf_cat2(v_str, "expire_time="); rb_str_buf_append(v_str, rb_inspect(rb_iv_get(self, "@expire_time"))); rb_str_buf_cat2(v_str, " "); rb_str_buf_cat2(v_str, "fail_auth_count="); rb_str_buf_append(v_str, rb_inspect(rb_iv_get(self, "@fail_auth_count"))); rb_str_buf_cat2(v_str, " "); rb_str_buf_cat2(v_str, "kvno="); rb_str_buf_append(v_str, rb_inspect(rb_iv_get(self, "@kvno"))); rb_str_buf_cat2(v_str, " "); rb_str_buf_cat2(v_str, "last_failed="); rb_str_buf_append(v_str, rb_inspect(rb_iv_get(self, "@last_failed"))); rb_str_buf_cat2(v_str, " "); rb_str_buf_cat2(v_str, "last_password_change="); rb_str_buf_append(v_str, rb_inspect(rb_iv_get(self, "@last_password_change"))); rb_str_buf_cat2(v_str, " "); rb_str_buf_cat2(v_str, "last_success="); rb_str_buf_append(v_str, rb_inspect(rb_iv_get(self, "@last_success"))); rb_str_buf_cat2(v_str, " "); rb_str_buf_cat2(v_str, "max_life="); rb_str_buf_append(v_str, rb_inspect(rb_iv_get(self, "@max_life"))); rb_str_buf_cat2(v_str, " "); rb_str_buf_cat2(v_str, "max_renewable_life="); rb_str_buf_append(v_str, rb_inspect(rb_iv_get(self, "@max_renewable_life"))); rb_str_buf_cat2(v_str, " "); rb_str_buf_cat2(v_str, "mod_date="); rb_str_buf_append(v_str, rb_inspect(rb_iv_get(self, "@mod_date"))); rb_str_buf_cat2(v_str, " "); rb_str_buf_cat2(v_str, "mod_name="); rb_str_buf_append(v_str, rb_inspect(rb_iv_get(self, "@mod_name"))); rb_str_buf_cat2(v_str, " "); rb_str_buf_cat2(v_str, "password_expiration="); rb_str_buf_append(v_str, rb_inspect(rb_iv_get(self, "@password_expiration"))); rb_str_buf_cat2(v_str, " "); rb_str_buf_cat2(v_str, "policy="); rb_str_buf_append(v_str, rb_inspect(rb_iv_get(self, "@policy"))); rb_str_buf_cat2(v_str, " "); rb_str_buf_cat2(v_str, "principal="); rb_str_buf_append(v_str, rb_inspect(rb_iv_get(self, "@principal"))); rb_str_buf_cat2(v_str, " "); rb_str_buf_cat2(v_str, ">"); return v_str; } |
#principal_type ⇒ Object
323 324 325 326 327 328 329 330 331 332 |
# File 'ext/rkerberos/principal.c', line 323
static VALUE rkrb5_princ_get_type(VALUE self){
RUBY_KRB5_PRINC* ptr;
TypedData_Get_Struct(self, RUBY_KRB5_PRINC, &rkrb5_princ_data_type, ptr);
if(!ptr->principal)
rb_raise(cKrb5Exception, "no principal has been established");
return INT2FIX(krb5_princ_type(ptr->ctx, ptr->principal));
}
|
#realm ⇒ Object
176 177 178 179 180 181 182 183 184 185 186 187 188 |
# File 'ext/rkerberos/principal.c', line 176
static VALUE rkrb5_princ_get_realm(VALUE self){
RUBY_KRB5_PRINC* ptr;
krb5_data* realm;
TypedData_Get_Struct(self, RUBY_KRB5_PRINC, &rkrb5_princ_data_type, ptr);
if(!ptr->principal)
rb_raise(cKrb5Exception, "no principal has been established");
realm = krb5_princ_realm(ptr->ctx, ptr->principal);
return rb_str_new(realm->data, realm->length);
}
|
#realm=(v_realm) ⇒ Object
196 197 198 199 200 201 202 203 204 205 206 207 208 209 |
# File 'ext/rkerberos/principal.c', line 196
static VALUE rkrb5_princ_set_realm(VALUE self, VALUE v_realm){
RUBY_KRB5_PRINC* ptr;
TypedData_Get_Struct(self, RUBY_KRB5_PRINC, &rkrb5_princ_data_type, ptr);
if(!ptr->principal)
rb_raise(cKrb5Exception, "no principal has been established");
Check_Type(v_realm, T_STRING);
krb5_set_principal_realm(ptr->ctx, ptr->principal, StringValueCStr(v_realm));
return v_realm;
}
|