/* -*-c-*-
*
- * $Id: name.c,v 1.1 1997/07/21 13:47:46 mdw Exp $
+ * $Id: name.c,v 1.2 1997/08/04 10:24:24 mdw Exp $
*
* Looking up of names in symbol tables
*
* (c) 1997 EBI
*/
-/*----- Licencing notice --------------------------------------------------*
+/*----- Licensing notice --------------------------------------------------*
*
* This file is part of `become'
*
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
- * along with `become'; if not, write to the Free Software
- * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ * along with `become'; if not, write to the Free Software Foundation,
+ * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
/*----- Revision history --------------------------------------------------*
*
* $Log: name.c,v $
- * Revision 1.1 1997/07/21 13:47:46 mdw
+ * Revision 1.2 1997/08/04 10:24:24 mdw
+ * Sources placed under CVS control.
+ *
+ * Revision 1.1 1997/07/21 13:47:46 mdw
* Initial revision
*
*/
/* --- Unix headers --- */
+#include "config.h"
+
+#ifdef HAVE_YP
+# include <rpcsvc/ypclnt.h>
+# include <rpcsvc/yp_prot.h>
+#endif
+
#include <grp.h>
#include <pwd.h>
/* --- Local headers --- */
+#include "become.h"
#include "class.h"
#include "name.h"
#include "sym.h"
/*----- Main code ---------------------------------------------------------*/
-/* --- @name_init@ --- *
+/* --- @name__users@ --- *
*
* Arguments: ---
*
* Returns: ---
*
- * Use: Initialises the name table. Requires the user database to
- * be populated (see @userdb_local@ and @userdb_yp@).
+ * Use: Adds all of the users registered with the user database to
+ * the name table. Also adds the users' primary groups.
*/
-void name_init(void)
+static void name__users(void)
{
- /* --- Initialise the name table --- */
-
- sym_createTable(&name__table);
+ struct passwd *pw;
+ struct group *gr;
- /* --- Insert all the users and groups into the table --- */
+ userdb_iterateUsers();
+ while ((pw = userdb_nextUser()) != 0) {
+ unsigned f;
+ name *n;
+ int u;
- {
- struct passwd *pw;
- struct group *gr;
+ /* --- First, add the user to the table --- */
- userdb_iterateUsers();
- while ((pw = userdb_nextUser()) != 0) {
- unsigned f;
- name *n;
- int u;
+ n = sym_find(&name__table, pw->pw_name, -1, sizeof(name), &f);
+ if (!f) {
+ sym_table *t = xmalloc(sizeof(*t));
+ sym_createTable(t);
+ n->c = class_create(clType_user, t);
+ }
+ u = pw->pw_uid;
+ sym_find(n->c->t, (char *)&u, sizeof(u), sizeof(sym_base), 0);
- /* --- First, add the user to the table --- */
+ /* --- Now handle the user's default group --- */
- n = sym_find(&name__table, pw->pw_name, -1, sizeof(name), &f);
+ if ((gr = userdb_groupById(pw->pw_gid)) != 0) {
+ n = sym_find(&name__table, gr->gr_name, -1, sizeof(name), &f);
if (!f) {
sym_table *t = xmalloc(sizeof(*t));
sym_createTable(t);
n->c = class_create(clType_user, t);
}
- u = pw->pw_uid;
sym_find(n->c->t, (char *)&u, sizeof(u), sizeof(sym_base), 0);
+ }
+ }
+}
- /* --- Now handle the user's default group --- */
+/* --- @name__groups@ --- *
+ *
+ * Arguments: ---
+ *
+ * Returns: ---
+ *
+ * Use: Adds users into all of their supplementary groups.
+ */
+
+static void name__groups(void)
+{
+ struct group *gr;
+ struct passwd *pw;
+ char **p;
+
+ userdb_iterateGroups();
+ while ((gr = userdb_nextGroup()) != 0) {
+ unsigned f;
+ name *n;
+ int u;
- if ((gr = userdb_groupById(pw->pw_gid)) != 0) {
- n = sym_find(&name__table, gr->gr_name, -1, sizeof(name), &f);
- if (!f) {
- sym_table *t = xmalloc(sizeof(*t));
- sym_createTable(t);
- n->c = class_create(clType_user, t);
- }
+ /* --- Add the group name to the table --- */
+
+ n = sym_find(&name__table, gr->gr_name, -1, sizeof(name), &f);
+ if (!f) {
+ sym_table *t = xmalloc(sizeof(*t));
+ sym_createTable(t);
+ n->c = class_create(clType_user, t);
+ }
+
+ /* --- Now add all of the members --- */
+
+ for (p = gr->gr_mem; *p; p++) {
+ if ((pw = userdb_userByName(*p)) != 0) {
+ u = pw->pw_uid;
sym_find(n->c->t, (char *)&u, sizeof(u), sizeof(sym_base), 0);
}
}
}
+}
- /* --- Now get the subsidiary groups --- */
+/* --- @name_init@ --- *
+ *
+ * Arguments: ---
+ *
+ * Returns: ---
+ *
+ * Use: Initialises the name table. Requires the user database to
+ * be populated (see @userdb_local@ and @userdb_yp@).
+ */
- {
- struct group *gr;
- struct passwd *pw;
- char **p;
+void name_init(void)
+{
+ /* --- Initialise the name table --- */
- userdb_iterateGroups();
- while ((gr = userdb_nextGroup()) != 0) {
- unsigned f;
- name *n;
- int u;
+ sym_createTable(&name__table);
- n = sym_find(&name__table, gr->gr_name, -1, sizeof(name), &f);
- if (!f) {
- sym_table *t = xmalloc(sizeof(*t));
- sym_createTable(t);
- n->c = class_create(clType_user, t);
- }
+ /* --- Add everyone into the table --- */
- for (p = gr->gr_mem; *p; p++) {
- if ((pw = userdb_userByName(*p)) != 0) {
- u = pw->pw_uid;
- sym_find(n->c->t, (char *)&u, sizeof(u), sizeof(sym_base), 0);
- }
- }
- }
- }
+ name__users();
+ name__groups();
/* --- Finally add in the `all' class --- *
*
/* --- @name_dump@ --- *
*
- * Arguments: @FILE *fp@ = stream to dump on
+ * Arguments: ---
*
* Returns: ---
*
* Use: Dumps a complete listing of the symbol table.
*/
-void name_dump(FILE *fp)
+void name_dump(void)
{
sym_iter i;
name *n;
+ trace(TRACE_DEBUG, "name: dumping names");
for (sym_createIter(&i, &name__table); (n = sym_next(&i)) != 0; ) {
- fprintf(fp, "\n--- name `%s'\n", n->base.name);
- class_dump(n->c, fp);
+ trace(TRACE_DEBUG, "name: dumping `%s'", n->base.name);
+ class_dump(n->c);
}
}
userdb_init();
userdb_local();
userdb_yp();
+ ego("name-test");
+ traceon(stdout, TRACE_DEBUG);
name_init();
- name_dump(stdout);
+ name_dump();
return (0);
}