Main Page   Compound List   File List   Compound Members   File Members  

user_private.h

00001 /*
00002  * Copyright (C) 2000,2001 Red Hat, Inc.
00003  *
00004  * This is free software; you can redistribute it and/or modify it under
00005  * the terms of the GNU Library General Public License as published by
00006  * the Free Software Foundation; either version 2 of the License, or
00007  * (at your option) any later version.
00008  *
00009  * This program is distributed in the hope that it will be useful, but
00010  * WITHOUT ANY WARRANTY; without even the implied warranty of
00011  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012  * General Public License for more details.
00013  *
00014  * You should have received a copy of the GNU Library General Public
00015  * License along with this program; if not, write to the Free Software
00016  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
00017  */
00018 
00019 /*
00020  * The interfaces defined in this file are in even more flux than the others,
00021  * because this is where the module interface is defined.  If you include it
00022  * in your code, bad things can happen.
00023  */
00024 
00025 #ifndef libuser_user_private_h
00026 #define libuser_user_private_h
00027 
00028 #include <glib.h>
00029 #include <gmodule.h>
00030 #include "user.h"
00031 
00032 #define LU_ENT_MAGIC 0x19d381c2
00033 #define LU_MODULE_VERSION 0x00050000
00034 
00035 #include <libintl.h>
00036 #include <locale.h>
00037 #define _(String) gettext(String)
00038 
00039 /* A string cache structure.  Useful for side-stepping most issues with
00040  * whether or not returned strings should be freed. */
00041 typedef struct lu_string_cache {
00042         GTree *tree;
00043         char * (*cache)(struct lu_string_cache *, const char *);
00044         void (*free)(struct lu_string_cache *);
00045 } lu_string_cache_t;
00046 
00054 struct lu_string_cache *lu_string_cache_new(gboolean case_sensitive);
00055 
00056 /* An entity structure. */
00057 struct lu_ent {
00058         u_int32_t magic;
00059         enum lu_type type;              /* User or group? */
00060         struct lu_string_cache *acache; /* String cache for attribute names. */
00061         struct lu_string_cache *vcache; /* String cache for attribute values. */
00062         GTree *original_attributes;     /* GLists of the original values
00063                                            associated with attribute names. */
00064         GTree *attributes;              /* GLists of values associated with
00065                                            attribute names. */
00066         const char *source_info;        /* Name of the info module this user was
00067                                            looked up in. */
00068         const char *source_auth;        /* Name of the auth module this user was
00069                                            looked up in. */
00070 };
00071 
00072 /* A context structure. */
00073 struct lu_context {
00074         struct lu_string_cache *scache; /* A string cache. */
00075         char *auth_name;                /* Suggested client name to use when
00076                                            connecting to servers, for
00077                                            convenience purposes only. */
00078         enum lu_type auth_type;         /* Whether auth_name is a user or
00079                                            group. */
00080         void *config;                   /* Opaque config structure used by
00081                                            the lu_cfg family of functions. */
00082         lu_prompt_fn *prompter;         /* Pointer to the prompter function. */
00083         gpointer prompter_data;         /* Application-specific data to be
00084                                            passed to the prompter function. */
00085         GList *auth_module_names;       /* A list of loaded auth modules
00086                                            names. */
00087         GList *info_module_names;       /* A list of loaded information module
00088                                            names. */
00089         GTree *modules;                 /* A tree, keyed by module name,
00090                                            of module structures. */
00091 };
00092 
00093 /* What type of function a module serves. */
00094 typedef enum lu_module_type {
00095         auth = 0xca20,
00096         info = 0xec33,
00097 } lu_module_type_t;
00098 
00099 /* A module structure. */
00100 typedef struct lu_module {
00101         u_int32_t version;              /* Should be LU_MODULE_VERSION. */
00102         GModule *module_handle;
00103         struct lu_string_cache *scache; /* A string cache. */
00104         const char *name;               /* Name of the module. */
00105         struct lu_context *lu_context;  /* Context the module was opened in. */
00106         void *module_context;           /* Module-private data. */
00107 
00108         /* Functions for looking up users and groups by name or ID. */
00109         gboolean (*user_lookup_name)(struct lu_module *module, gconstpointer name, struct lu_ent *ent, struct lu_error **error);
00110         gboolean (*group_lookup_name)(struct lu_module *module, gconstpointer name, struct lu_ent *ent, struct lu_error **error);
00111         gboolean (*user_lookup_id)(struct lu_module *module, gconstpointer uid, struct lu_ent *ent, struct lu_error **error);
00112         gboolean (*group_lookup_id)(struct lu_module *module, gconstpointer gid, struct lu_ent *ent, struct lu_error **error);
00113 
00114         /* Apply attributes in the ent structure to the user named by the structure's LU_USERNAME attribute. */
00115         gboolean (*user_add)(struct lu_module *module, struct lu_ent *ent, struct lu_error **error);
00116         gboolean (*user_mod)(struct lu_module *module, struct lu_ent *ent, struct lu_error **error);
00117         gboolean (*user_del)(struct lu_module *module, struct lu_ent *ent, struct lu_error **error);
00118 
00119         /* Lock, unlock, or set the password on the account of the user named by the structure's LU_USERNAME attribute. */
00120         gboolean (*user_lock)(struct lu_module *module, struct lu_ent *ent, struct lu_error **error);
00121         gboolean (*user_unlock)(struct lu_module *module, struct lu_ent *ent, struct lu_error **error);
00122         gboolean (*user_islocked)(struct lu_module *module, struct lu_ent *ent, struct lu_error **error);
00123         gboolean (*user_setpass)(struct lu_module *module, struct lu_ent *ent, const char *newpass, struct lu_error **error);
00124 
00125         /* Apply attributes in the ent structure to the group named by the structure's LU_GROUPNAME attribute. */
00126         gboolean (*group_add)(struct lu_module *module, struct lu_ent *ent, struct lu_error **error);
00127         gboolean (*group_mod)(struct lu_module *module, struct lu_ent *ent, struct lu_error **error);
00128         gboolean (*group_del)(struct lu_module *module, struct lu_ent *ent, struct lu_error **error);
00129 
00130         /* Lock, unlock, or set the password on the record for the group named by the structure's LU_GROUPNAME attribute. */
00131         gboolean (*group_lock)(struct lu_module *module, struct lu_ent *ent, struct lu_error **error);
00132         gboolean (*group_unlock)(struct lu_module *module, struct lu_ent *ent, struct lu_error **error);
00133         gboolean (*group_islocked)(struct lu_module *module, struct lu_ent *ent, struct lu_error **error);
00134         gboolean (*group_setpass)(struct lu_module *module, struct lu_ent *ent, const char *newpass, struct lu_error **error);
00135 
00136         /* Search for users or groups. */
00137         GList *(*users_enumerate)(struct lu_module *module, const char *pattern, struct lu_error **error);
00138         GList *(*groups_enumerate)(struct lu_module *module, const char *pattern, struct lu_error **error);
00139         GList *(*users_enumerate_by_group)(struct lu_module *module, const char *group, gid_t gid, struct lu_error **error);
00140         GList *(*groups_enumerate_by_user)(struct lu_module *module, const char *user, struct lu_error **error);
00141 
00142         /* Clean up any data this module has, and unload it. */
00143         gboolean (*close)(struct lu_module *module);
00144 } lu_module_t;
00145 
00146 /* The type of the initialization function a module exports for the library
00147  * to use when initializing it.  Should fit "lu_%s_init", where the string
00148  * is the name of the module being loaded (and this should match the "name"
00149  * attribute of the module structure. */
00150 typedef struct lu_module * (*lu_module_init_t)(struct lu_context *context, struct lu_error **error);
00151 
00152 gboolean lu_cfg_init(struct lu_context *context, struct lu_error **error);
00153 void lu_cfg_done(struct lu_context *context);
00154 
00155 void lu_ent_set_source_info(struct lu_ent *ent, const char *source);
00156 void lu_ent_set_source_auth(struct lu_ent *ent, const char *source);
00157 
00158 GList *lu_g_list_copy(GList *list);
00159 
00160 gint lu_str_equal(gconstpointer v1, gconstpointer v2);
00161 gint lu_str_case_equal(gconstpointer v1, gconstpointer v2);
00162 gint lu_strcmp(gconstpointer v1, gconstpointer v2);
00163 gint lu_strcasecmp(gconstpointer v1, gconstpointer v2);
00164 
00165 guint lu_strv_len(gchar **v);
00166 
00167 const char *lu_make_crypted(const char *plain, const char *previous);
00168 
00169 gpointer lu_util_lock_obtain(int fd, struct lu_error **error);
00170 void lu_util_lock_free(int fd, gpointer lock);
00171 
00172 char *lu_util_line_get_matching1(int fd, const char *firstpart, struct lu_error **error);
00173 char *lu_util_line_get_matching3(int fd, const char *thirdpart, struct lu_error **error);
00174 char *lu_util_line_get_matchingx(int fd, const char *part, int field, struct lu_error **error);
00175 char *lu_util_field_read(int fd, const char *first, unsigned int field, struct lu_error **error);
00176 gboolean lu_util_field_write(int fd, const char *first, unsigned int field, const char *value, struct lu_error **error);
00177 char *lu_util_shadow_current_date(struct lu_string_cache *cache);
00178 
00179 #endif

Generated at Tue Dec 23 01:33:06 2003 for libuser by doxygen1.2.8.1 written by Dimitri van Heesch, © 1997-2001