Class: Kerberos::Krb5::Principal

Inherits:
Object
  • Object
show all
Defined in:
ext/rkerberos/principal.c

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#Kerberos::Krb5::Principal.new(name) ⇒ Object

Creates and returns a new Krb5::Principal object. If a block is provided then it yields itself.

Example:

principal1 = Kerberos::Krb5::Principal.new('Jon')

principal2 = Kerberos::Krb5::Principal.new('Jon') do |pr|
  pr.expire_time = Time.now + 20000
end


41
42
43
44
45
46
47
48
49
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
78
79
80
81
82
83
84
85
86
# File 'ext/rkerberos/principal.c', line 41

static VALUE rkrb5_princ_initialize(VALUE self, VALUE v_name){
  RUBY_KRB5_PRINC* ptr;
  krb5_error_code kerror;

  Data_Get_Struct(self, RUBY_KRB5_PRINC, ptr); 

  kerror = krb5_init_context(&ptr->ctx);

  if(kerror)
    rb_raise(cKrb5Exception, "krb5_init_context failed: %s", error_message(kerror));

  if(NIL_P(v_name)){
    rb_iv_set(self, "@principal", Qnil);
  }
  else{
    char* name;
    Check_Type(v_name, T_STRING);
    name = StringValuePtr(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

#attributesObject

Attributes

#aux_attributesObject

#expire_timeObject

#fail_auth_countObject

#kvnoObject

#last_failedObject

#last_password_changeObject

#last_successObject

#max_lifeObject

#max_renewable_lifeObject

#mod_dateObject

#mod_nameObject

#password_expirationObject

#policyObject

#principalObject (readonly) Also known as: name

Instance Method Details

#==(principal2) ⇒ Object

Returns whether or not two principals are the same.



128
129
130
131
132
133
134
135
136
137
138
139
140
# File 'ext/rkerberos/principal.c', line 128

static VALUE rkrb5_princ_equal(VALUE self, VALUE v_other){
  RUBY_KRB5_PRINC* ptr1;
  RUBY_KRB5_PRINC* ptr2;
  VALUE v_bool = Qfalse;

  Data_Get_Struct(self, RUBY_KRB5_PRINC, ptr1); 
  Data_Get_Struct(v_other, RUBY_KRB5_PRINC, ptr2); 

  if(krb5_principal_compare(ptr1->ctx, ptr1->principal, ptr2->principal))
    v_bool = Qtrue;

  return v_bool;
}

#inspectObject

A custom inspect method for the Principal object.



148
149
150
151
152
153
154
155
156
157
158
159
160
161
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
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
# File 'ext/rkerberos/principal.c', line 148

static VALUE rkrb5_princ_inspect(VALUE self){
  RUBY_KRB5_PRINC* ptr;
  VALUE v_str;

  Data_Get_Struct(self, RUBY_KRB5_PRINC, ptr); 

  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;
}

#realmObject

Returns the realm for the given principal.



94
95
96
97
98
99
# File 'ext/rkerberos/principal.c', line 94

static VALUE rkrb5_princ_get_realm(VALUE self){
  RUBY_KRB5_PRINC* ptr;
  Data_Get_Struct(self, RUBY_KRB5_PRINC, ptr); 

  return rb_str_new2(krb5_princ_realm(ptr->ctx, ptr->principal)->data);
}

#realm=(v_realm) ⇒ Object

Sets the realm for the given principal.



107
108
109
110
111
112
113
114
115
116
117
118
119
120
# File 'ext/rkerberos/principal.c', line 107

static VALUE rkrb5_princ_set_realm(VALUE self, VALUE v_realm){
  RUBY_KRB5_PRINC* ptr;
  krb5_data kdata;

  memset(&kdata, 0, sizeof(kdata));
  Data_Get_Struct(self, RUBY_KRB5_PRINC, ptr); 

  Check_Type(v_realm, T_STRING);
  kdata.data = StringValuePtr(v_realm);

  krb5_princ_set_realm(ptr->ctx, ptr->principal, &kdata);

  return v_realm;
}