Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
7f05a4a
prep for policy additions, added compare function to common
rjancewicz Jul 8, 2014
c81c182
policy iteration and unpacking via common
rjancewicz Jul 8, 2014
f3f0b23
working on policy, tp_alloc,tp_free not being set properly
rjancewicz Jul 8, 2014
55f4243
manually setting tp_alloc and tp_free for policy objects - investigate
rjancewicz Jul 8, 2014
245762b
logging on unit tests
rjancewicz Jul 14, 2014
1436ede
updates to getters/setters for principals
rjancewicz Jul 14, 2014
99bbb89
principal reload
rjancewicz Jul 14, 2014
274222d
update principal api to mirror the kadmin cli tool
rjancewicz Jul 14, 2014
971934c
get rid of list principals (use iterators)
rjancewicz Jul 14, 2014
cd55efa
stubs for lock and unlock
rjancewicz Jul 14, 2014
fc07921
set_policy(None) will clear policy
rjancewicz Jul 14, 2014
44052ea
cpw/randkey do not force reload of the entry (could slow iteration)
rjancewicz Jul 14, 2014
08da650
randkey doesnt need to unparse client_name
rjancewicz Jul 14, 2014
4364d70
cpw doesn't need to unparse name or check for null pointer
rjancewicz Jul 14, 2014
d9956d7
extract members and convert timestamps to datetime.datetime objects […
rjancewicz Jul 15, 2014
dd02ade
last stubs for setting principal values
rjancewicz Jul 15, 2014
0a79564
clean up commented out blocks
rjancewicz Jul 15, 2014
721ef5a
get rid of the principal load function as it can simply be included i…
rjancewicz Jul 15, 2014
93025b7
clean up naming convention PyKAdmin prefix should be used everywhere …
rjancewicz Jul 15, 2014
99e49bb
clean up naming convention PyKAdmin prefix should be used everywhere …
rjancewicz Jul 15, 2014
d531610
inline datetime converter
rjancewicz Jul 15, 2014
ae5dd5c
working towards attributes
rjancewicz Jul 15, 2014
71d26c8
getters/setters for principals
rjancewicz Jul 17, 2014
de4e64f
docstrings
rjancewicz Jul 17, 2014
2579a7d
fixes to getprinc to prevent double free
rjancewicz Jul 17, 2014
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
166 changes: 165 additions & 1 deletion PyKAdminCommon.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,91 @@ kadm5_get_principal(void *server_handle, krb5_principal principal,
*/

#include "PyKAdminCommon.h"
#include <datetime.h>

#define TIME_NONE ((time_t) -1)

int pykadmin_policy_exists(void *server_handle, char *name) {

kadm5_ret_t retval = KADM5_OK;
kadm5_policy_ent_rec *policy = NULL;

retval = kadm5_get_policy(server_handle, name, policy);
if (retval == KADM5_OK)
kadm5_free_policy_ent(server_handle, policy);

return (retval == KADM5_OK);
}


inline PyObject *pykadmin_pydatetime_from_timestamp(time_t timestamp) {

PyDateTime_IMPORT;

if (timestamp) {
PyObject *datetime = NULL;
PyObject *args = NULL;

args = Py_BuildValue("(i)", timestamp);

if (args) {
datetime = PyDateTime_FromTimestamp(args);
Py_DECREF(args);
}

if (!datetime)
PyErr_SetString(PyExc_AttributeError, NULL);

return datetime;
} else {
Py_RETURN_NONE;
}
}

int pykadmin_timestamp_from_pydatetime(PyObject *datetime) {

PyDateTime_IMPORT;

time_t timestamp = 0;
struct tm *timeinfo;

if (datetime) {

timeinfo = localtime ( &timestamp );

timeinfo->tm_year = PyDateTime_GET_YEAR(datetime) - 1900;
timeinfo->tm_mon = PyDateTime_GET_MONTH(datetime) - 1;
timeinfo->tm_mday = PyDateTime_GET_DAY(datetime);

if (PyDateTime_Check(datetime)) {
timeinfo->tm_hour = PyDateTime_DATE_GET_HOUR(datetime) - 1 ;
timeinfo->tm_min = PyDateTime_DATE_GET_MINUTE(datetime);
timeinfo->tm_sec = PyDateTime_DATE_GET_SECOND(datetime);
}

timestamp = mktime(timeinfo);
} else {
timestamp = TIME_NONE;
}

return timestamp;
}

int pykadmin_seconds_from_pydatetime(PyObject *delta) {

PyDateTime_IMPORT;

time_t seconds = 0;

if (delta) {
seconds += PyDateTime_DELTA_GET_SECONDS(delta);
seconds += PyDateTime_DELTA_GET_DAYS(delta) * 24 * 3600;
}

return seconds;

}


krb5_error_code pykadmin_unpack_xdr_osa_princ_ent_rec(PyKAdminObject *kadmin, krb5_db_entry *kdb, osa_princ_ent_rec *adb) {

Expand Down Expand Up @@ -101,7 +186,6 @@ static krb5_tl_data *dup_tl_data(krb5_tl_data *tl)
return n;
}


krb5_error_code pykadmin_kadm_from_kdb(PyKAdminObject *kadmin, krb5_db_entry *kdb, kadm5_principal_ent_rec *entry, long mask) {

krb5_error_code retval = 0;
Expand Down Expand Up @@ -265,6 +349,68 @@ krb5_error_code pykadmin_kadm_from_kdb(PyKAdminObject *kadmin, krb5_db_entry *kd
}



/*
typedef struct _kadm5_policy_ent_t {
char *policy;
long pw_min_life;
long pw_max_life;
long ;
long ;
long ;
long ;

// version 3 fields
int32 krb5_kvno pw_max_fail;
int32 krb5_deltat pw_failcnt_interval;
int32 krb5_deltat pw_lockout_duration;
} kadm5_policy_ent_rec, *kadm5_policy_ent_t;

typedef struct _osa_policy_ent_t {
int version;
char *name;
krb5_ui_4 pw_min_life;
krb5_ui_4 pw_max_life;
krb5_ui_4 pw_min_length;
krb5_ui_4 pw_min_classes;
krb5_ui_4 pw_history_num;
krb5_ui_4 policy_refcnt;

// Only valid if version > 1
krb5_ui_4 pw_max_fail; // pwdMaxFailure
krb5_ui_4 pw_failcnt_interval; // pwdFailureCountInterval
krb5_ui_4 pw_lockout_duration; // pwdLockoutDuration
} osa_policy_ent_rec, *osa_policy_ent_t;


*/


krb5_error_code pykadmin_policy_kadm_from_osa(krb5_context ctx, osa_policy_ent_rec *osa, kadm5_policy_ent_rec *entry, long mask) {

krb5_error_code retval = 0;

memset(entry, 0, sizeof(kadm5_policy_ent_rec));

entry->policy = strdup(osa->name);
entry->pw_min_life = osa->pw_min_life;
entry->pw_max_life = osa->pw_max_life;
entry->pw_min_length = osa->pw_min_length;
entry->pw_min_classes = osa->pw_min_classes;
entry->pw_history_num = osa->pw_history_num;
entry->policy_refcnt = osa->policy_refcnt;

if (osa->version > 1) {
entry->pw_max_fail = osa->pw_max_fail;
entry->pw_failcnt_interval = osa->pw_failcnt_interval;
entry->pw_lockout_duration = osa->pw_lockout_duration;
}

return retval;
}



int pykadmin_compare_tl_data(krb5_context ctx, krb5_tl_data *a, krb5_tl_data *b) {

int result = 1;
Expand Down Expand Up @@ -354,6 +500,24 @@ int pykadmin_principal_ent_rec_compare(krb5_context ctx, kadm5_principal_ent_rec
return result;
}

int pykadmin_policy_ent_rec_compare(krb5_context ctx, kadm5_policy_ent_rec *a, kadm5_policy_ent_rec *b) {

int result = 1;

result &= (strcmp(a->policy, b->policy) == 0);

result &= (a->pw_min_life == b->pw_min_life);
result &= (a->pw_max_life == b->pw_max_life);
result &= (a->pw_min_length == b->pw_min_length);
result &= (a->pw_min_classes == b->pw_min_classes);
result &= (a->pw_history_num == b->pw_history_num);
result &= (a->policy_refcnt == b->policy_refcnt);
result &= (a->pw_max_fail == b->pw_max_fail);
result &= (a->pw_failcnt_interval == b->pw_failcnt_interval);
result &= (a->pw_lockout_duration == b->pw_lockout_duration);

return result;
}

/*
krb5_error_code pykadmin_copy_kadm_ent_rec(PyKAdminObject *kadmin, kadm5_principal_ent_rec *src, kadm5_principal_ent_rec *dst) {
Expand Down
20 changes: 19 additions & 1 deletion PyKAdminCommon.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,35 @@
#define PYKADMINCOMMON_H

#include <Python.h>

#include <kdb.h>
#include <kadm5/admin.h>
#include <krb5/krb5.h>
#include <string.h>

#include "PyKadminXDR.h"
#include "PyKAdminXDR.h"
#include "PyKAdminObject.h"


#ifndef PYTHON3
#define PyDateTime_DELTA_GET_DAYS(o) (((PyDateTime_Delta*)o)->days)
#define PyDateTime_DELTA_GET_SECONDS(o) (((PyDateTime_Delta*)o)->seconds)
#define PyDateTime_DELTA_GET_MICROSECONDS(o) (((PyDateTime_Delta*)o)->microseconds)
#endif

int pykadmin_policy_exists(void *server_handle, char *name);

inline PyObject *pykadmin_pydatetime_from_timestamp(time_t timestamp);
int pykadmin_timestamp_from_pydatetime(PyObject *datetime);

int pykadmin_seconds_from_pydatetime(PyObject *delta);

krb5_error_code pykadmin_kadm_from_kdb(PyKAdminObject *kadmin, krb5_db_entry *kdb, kadm5_principal_ent_rec *entry, long mask);

krb5_error_code pykadmin_policy_kadm_from_osa(krb5_context ctx, osa_policy_ent_rec *osa, kadm5_policy_ent_rec *entry, long mask);

int pykadmin_principal_ent_rec_compare(krb5_context ctx, kadm5_principal_ent_rec *a, kadm5_principal_ent_rec *b);
int pykadmin_policy_ent_rec_compare(krb5_context ctx, kadm5_policy_ent_rec *a, kadm5_policy_ent_rec *b);


// TODO
Expand Down
10 changes: 5 additions & 5 deletions PyKAdminErrors.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@

void PyKAdminError_insert(PyObject *module, kadm5_ret_t retval, char *error_name, char *error_string) {

PyObject *error_number = PyLong_FromUnsignedLong(retval);
PyObject *exception = NULL;
PyObject *error_tuple = NULL;
uint32_t length = strlen(error_name) + 0xF;
PyObject *error_number = PyLong_FromUnsignedLong(retval);
PyObject *exception = NULL;
PyObject *error_tuple = NULL;
uint32_t length = strlen(error_name) + 0xF;

char *real_name = malloc(length);
char *real_name = malloc(length);

snprintf(real_name, length, "kadmin.%s", error_name);

Expand Down
Loading