aboutsummaryrefslogtreecommitdiffstats
path: root/USER/USER.xs
diff options
context:
space:
mode:
authorDaouda Lo <daouda@mandriva.com>2003-05-27 12:02:40 +0000
committerDaouda Lo <daouda@mandriva.com>2003-05-27 12:02:40 +0000
commit9357b8d6718441f9bc200547c135d02424cefd51 (patch)
treeb812cb89775ef177541df0a7ae560ec82872f2d2 /USER/USER.xs
parent782061dba6452e83e3cf7311a5b151e0975e27bc (diff)
downloaduserdrake-9357b8d6718441f9bc200547c135d02424cefd51.tar
userdrake-9357b8d6718441f9bc200547c135d02424cefd51.tar.gz
userdrake-9357b8d6718441f9bc200547c135d02424cefd51.tar.bz2
userdrake-9357b8d6718441f9bc200547c135d02424cefd51.tar.xz
userdrake-9357b8d6718441f9bc200547c135d02424cefd51.zip
- useradd sanity checks
Diffstat (limited to 'USER/USER.xs')
-rw-r--r--USER/USER.xs215
1 files changed, 165 insertions, 50 deletions
diff --git a/USER/USER.xs b/USER/USER.xs
index 0e5f674..4a54e4c 100644
--- a/USER/USER.xs
+++ b/USER/USER.xs
@@ -40,43 +40,6 @@ static SV ** convert_value_array_list(register SV **sp, GValueArray *array) {
return sp;
}
-char *
-get_name(USER__ENT *ent, char *attribute)
-{
- GValueArray *values;
- GValue *value;
- const char *name = NULL;
- values = lu_ent_get(ent, attribute);
- if (values != NULL) {
- value = g_value_array_get_nth(values, 0);
- if (G_VALUE_HOLDS_STRING(value)) {
- name = g_value_get_string(value);
- } else if (G_VALUE_HOLDS_LONG(value)) {
- name = g_strdup_printf("%ld", g_value_get_long(value)); /*leak*/
- }
- }
- return name;
-}
-
-static long
-get_int(USER__ENT *ent, char *attribute)
-{
- GValueArray *values;
- GValue *value;
- long i = -1;
- values = lu_ent_get(ent, attribute);
- if (values != NULL) {
- value = g_value_array_get_nth(values, 0);
- if (G_VALUE_HOLDS_LONG(value)) {
- i = g_value_get_long(value);
- } else if (G_VALUE_HOLDS_STRING(value)) {
- i = atol(g_value_get_string(value));
- }
- }
- i = g_value_get_long(value);
- return i;
-}
-
MODULE = USER PACKAGE = USER::ADMIN PREFIX = Admin_
USER::ADMIN *
@@ -101,12 +64,14 @@ Admin_DESTROY(self)
safefree((char*)self);
int
-Admin_UserAdd(self, enthash)
+Admin_UserAdd(self, is_system, dont_create_home, enthash)
USER::ADMIN *self
+ int is_system
+ int dont_create_home
SV * enthash
- INIT:
- HV *hv;
+ PREINIT:
SV **ssv;
+ HV *hv;
if ( SvROK(enthash) && (SvTYPE(SvRV(enthash)) == SVt_PVHV) )
hv = (HV*)SvRV(enthash);
else{
@@ -115,30 +80,142 @@ Admin_UserAdd(self, enthash)
CODE:
USER__ENT *ent;
USER__ERR *error;
+ GValue *value, val;
long uidNumber, gidNumber;
+ char *skeleton = "/etc/skel", *homeDirectory = NULL;
GValueArray *values;
- ssv = hv_fetch( hv, "username", 13, 0 );
+ ent = lu_ent_new();
+ memset(&val, 0, sizeof(val));
+ g_value_init(&val, G_TYPE_STRING);
+ ssv = hv_fetch(hv, "username", 13, 0);
if( ssv != NULL ){
if( SvPOK( *ssv ) )
- warn ("user added");
- /*strcpy( abin->szDescription, SvPV(*ssv,na) );*/
+ lu_user_default(self, SvPV(*ssv,PL_na), is_system, ent);
else{
- warn("XS_UserAdd: hash elem szDescription was not POK");
+ warn("XS_UserAdd: Cannot add default ent");
+ RETVAL = 0;
+ }
+ }
+ else
+ warn("XS_UserAdd: hash elem username was null");
+ ssv = hv_fetch(hv, "gecos", 5, 0);
+ if( ssv != NULL ){
+ if( SvPOK( *ssv ) ) {
+ g_value_set_string(&val, SvPV(*ssv,PL_na));
+ lu_ent_clear(ent, LU_GECOS);
+ lu_ent_add(ent, LU_GECOS, &val);
+ } else {
+ warn("XS_UserAdd: Cannot add gecos to ent");
+ }
+ }
+ else
+ warn("XS_UserAdd: hash elem gecos was null");
+ ssv = hv_fetch(hv, "homedir", 7, 0);
+ if( ssv != NULL ){
+ if( SvPOK( *ssv ) ) {
+ g_value_set_string(&val, SvPV(*ssv,PL_na));
+ lu_ent_clear(ent, LU_HOMEDIRECTORY);
+ lu_ent_add(ent, LU_HOMEDIRECTORY, &val);
+ } else{
+ warn("XS_UserAdd: Cannot add Home Dir to ent");
+ }
+ }
+ else
+ warn("XS_UserAdd: hash elem homedir was null");
+ ssv = hv_fetch(hv, "loginshell", 10, 0);
+ if( ssv != NULL ){
+ if( SvPOK( *ssv ) ) {
+ g_value_set_string(&val, SvPV(*ssv,PL_na));
+ lu_ent_clear(ent, LU_LOGINSHELL);
+ lu_ent_add(ent, LU_LOGINSHELL, &val);
+ } else {
+ warn("XS_UserAdd: Cannot add Login Shell to ent");
}
}
else
- warn("XS_UserAdd: hash elem szDescription was null");
+ warn("XS_UserAdd: hash elem loginshell was null");
+ g_value_unset(&val);
+ g_value_init(&val, G_TYPE_LONG);
ssv = hv_fetch( hv, "uid", 3, 0);
if( ssv != NULL ){
- if( SvIOK( *ssv ) )
- warn("user added");
- /* abin->lTrackId = (long)SvIV( *ssv );*/
- else{
+ if( SvIOK( *ssv ) && *ssv != -1) {
+ g_value_set_long(&val, (long)SvIV( *ssv ));
+ lu_ent_clear(ent, LU_UIDNUMBER);
+ lu_ent_add(ent, LU_UIDNUMBER, &val);
+ } else {
warn("XS_UserAdd: hash elem Uid was not IOK");
}
}
else
- warn("XS_UserAdd: hash elem xxxxxx was null");
+ warn("XS_UserAdd: hash elem uid was null");
+ ssv = hv_fetch( hv, "gid", 3, 0);
+ if( ssv != NULL ){
+ if( SvIOK( *ssv ) && *ssv != -1) {
+ g_value_set_long(&val, (long)SvIV( *ssv ));
+ lu_ent_clear(ent, LU_GIDNUMBER);
+ lu_ent_add(ent, LU_GIDNUMBER, &val);
+ } else {
+ warn("XS_UserAdd: hash elem Uid was not IOK");
+ }
+ }
+ else
+ warn("XS_UserAdd: hash elem uid was null");
+ /* GMOT (Great Moment Of Truth) */
+ if (lu_user_add(self, ent, &error) == FALSE) {
+ croak("Account creation failed: %s.\n", error ? error->string : "Unknown error");
+ RETVAL = 0;
+ } else RETVAL = 1 ;
+ if (!dont_create_home) {
+ /* Read the user's UID. */
+ values = lu_ent_get(ent, LU_UIDNUMBER);
+ value = g_value_array_get_nth(values, 0);
+ if (G_VALUE_HOLDS_LONG(value)) {
+ uidNumber = g_value_get_long(value);
+ } else
+ if (G_VALUE_HOLDS_STRING(value)) {
+ uidNumber = atol(g_value_get_string(value));
+ } else {
+ warn("Cannot get Uid number");
+ }
+
+ /* Read the user's GID. */
+ values = lu_ent_get(ent, LU_GIDNUMBER);
+ value = g_value_array_get_nth(values, 0);
+ if (G_VALUE_HOLDS_LONG(value)) {
+ gidNumber = g_value_get_long(value);
+ } else
+ if (G_VALUE_HOLDS_STRING(value)) {
+ gidNumber = atol(g_value_get_string(value));
+ } else {
+ warn("Cannot retrieve val");
+ }
+
+ /* Read the user's home directory. */
+ values = lu_ent_get(ent, LU_HOMEDIRECTORY);
+ value = g_value_array_get_nth(values, 0);
+ homeDirectory = g_value_get_string(value);
+
+ if (lu_homedir_populate(skeleton, homeDirectory,
+ uidNumber, gidNumber, 0700,
+ &error) == FALSE) {
+ warn("Error creating %s: %s.\n", homeDirectory, error ? error->string : "unknown error");
+ RETVAL = 2;
+ }
+
+ /* Create a mail spool for the user. */
+ if (lu_mailspool_create_remove(self, ent, TRUE) != TRUE) {
+ fprintf(stderr, _("Error creating mail spool.\n"));
+ return 8;
+ }
+ }
+ OUTPUT:
+ RETVAL
+
+
+void
+Admin_GroupAdd(self, enthash)
+ USER::ADMIN *self
+ SV* enthash
void
Admin_UserDel(self, ent)
@@ -207,6 +284,44 @@ Admin_LookupGroupById(self, id)
}
AV *
+Admin_EnumerateUsersByGroup(self, name)
+ USER::ADMIN *self
+ char *name
+ CODE:
+ int c;
+ USER__ERR *error = NULL;
+ RETVAL = (AV*)sv_2mortal((SV*)newAV());
+ GValueArray *results;
+ results = lu_users_enumerate_by_group(self, name, &error);
+ for (c = 0; (results != NULL) && (c < results->n_values); c++) {
+ if( av_store(RETVAL, c, newSVpv(g_value_get_string(g_value_array_get_nth(results, c)), 0)) == NULL ){
+ warn("XS_UsersEnumerateFull: failed to store elems");
+ }
+ }
+ g_value_array_free(results);
+ OUTPUT:
+ RETVAL
+
+AV *
+Admin_EnumerateGroupsByUser(self, name)
+ USER::ADMIN *self
+ char *name
+ CODE:
+ int c;
+ USER__ERR *error = NULL;
+ RETVAL = (AV*)sv_2mortal((SV*)newAV());
+ GValueArray *results;
+ results = lu_groups_enumerate_by_user(self, name, &error);
+ for (c = 0; (results != NULL) && (c < results->n_values); c++) {
+ if( av_store(RETVAL, c, newSVpv(g_value_get_string(g_value_array_get_nth(results, c)), 0)) == NULL ){
+ warn("XS_UsersEnumerateFull: failed to store elems");
+ }
+ }
+ g_value_array_free(results);
+ OUTPUT:
+ RETVAL
+
+AV *
Admin_UsersEnumerateFull(self)
USER::ADMIN *self
CODE: