DataMuseum.dk

Presents historical artifacts from the history of:

DKUUG/EUUG Conference tapes

This is an automatic "excavation" of a thematic subset of
artifacts from Datamuseum.dk's BitArchive.

See our Wiki for more about DKUUG/EUUG Conference tapes

Excavated with: AutoArchaeologist - Free & Open Source Software.


top - download
Index: ┃ T b

⟦b1eab4936⟧ TextFile

    Length: 5892 (0x1704)
    Types: TextFile
    Names: »build.c«

Derivation

└─⟦a0efdde77⟧ Bits:30001252 EUUGD11 Tape, 1987 Spring Conference Helsinki
    └─ ⟦this⟧ »EUUGD11/euug-87hel/sec8/mcp/src/build.c« 

TextFile

/***************************************************************************\
* 									    *
* 	build.c								    *
* 									    *
* Routines to build the accounts file from the existing passwd and group    *
* files, i.e. the -I option to mcp.  All information about who is in what   *
* class and what sig is destroyed by this process.  If the class, sig, vig  *
* or range files do not exist, mcp will attempt to create them, otherwise   *
* these are untouched.							    *
* 									    *
\***************************************************************************/

#include <stdio.h>
#include <sys/file.h>
#include <sys/types.h>
#include <strings.h>
#include <pwd.h>
#include <grp.h>
#include <lastlog.h>
#include "sysdep.h"
#include "macros.h"
#include "mem.h"
#include "lists.h"
#ifdef SENDMAIL
#include "alias.h"
#endif
#include "account.h"
#include "groupmap.h"
#include "sort.h"
#include "save.h"
#ifdef SENDMAIL
#include <ctype.h>
#endif

extern	struct list AccountList, GroupMapList, Groups, Users;
extern	int ModBits, root, acck();

Build()

{
#ifdef SENDMAIL
	struct alias *al;
	char line[BUFSIZ];
#endif
	struct account a, *ac, *ac2;
	struct passwd *pw;
	struct group *gr;
	struct groupmap gm;
	register int indx;
	char *cp;

	ShowVersion();
	msg("Building accounting files...");
#ifdef SENDMAIL
	zerolist(&a.ac_aliases);
#endif
	zerolist(&a.ac_groups);
	zerolist(&a.ac_classes);   zerolist(&a.ac_sigs);
	(void) setpwent();
	while (pw = getpwent()) {
		a.ac_uid = pw->pw_uid;
		a.ac_gid = pw->pw_gid;
		savestr((char **)&a.ac_name, pw->pw_name);
		savestr((char **)&a.ac_gecos, pw->pw_gecos);
		cp = index(pw->pw_gecos, ',');	if (cp) *cp = '\0';
		savestr((char **)&a.ac_realname, pw->pw_gecos);
		savestr((char **)&a.ac_passwd, pw->pw_passwd);
		savestr((char **)&a.ac_dir, pw->pw_dir);
		savestr((char **)&a.ac_shell, pw->pw_shell);
		savestr((char **)&a.ac_id, "exception");
		genlistadd(&AccountList, (addr)&a, sizeof (struct account));
		strlistadd(&Users, pw->pw_name);
	}
	sort_list(&AccountList, acctcmp);
	sort_list(&Users, pstrcmp);
	(void) endpwent();
	(void) setgrent();
	while (gr = getgrent()) {
		zerolist(&gm.gm_mem);
		gm.gm_gid = gr->gr_gid;
		savestr(&gm.gm_name, gr->gr_name);
		savestr(&gm.gm_passwd, gr->gr_passwd);
		for (indx=0; gr->gr_mem[indx]; indx++) {
			ac = getacnam(gr->gr_mem[indx]);
			if (ac) {
				strlistadd(&ac->ac_groups, gr->gr_name);
				sort_list(&ac->ac_groups, pstrcmp);
			}
			else
				continue;
			strlistadd(&gm.gm_mem, gr->gr_mem[indx]);
		}
		sort_list(&gm.gm_mem, pstrcmp);
		genlistadd(&GroupMapList, (addr)&gm, sizeof(struct groupmap));
		strlistadd(&Groups, gr->gr_name);
	}
	(void) endgrent();
	/*
	 * If an accounts file already exists get the unchanged
	 * information from it before overwriting it.
	 */
	if (!fileexists(ACFILE)) goto finish;
	if (acck() == 0) {
		err("I can't get the class and sig membership info");
		err("nor the ID's or real names of current users");
		err("nor the non-binding alias memberships");
		err1("from the old %s because the file format is bad.",
			ACFILE);
		err("");
		if (yesno("Overwrite it anyway? ") == 0)
			fatal("aborted");
	}
	(void) setacent();
	while (ac2 = getacent()) {
		ac = getacnam((char *)ac2->ac_name);
		if (!ac) {
(void) printf("accounts line for nonexistent user \"%s\" removed\n",
			ac2->ac_name);
			continue;
		}
		FREEMEM((char *)ac->ac_realname);
		savestr((char **)&ac->ac_realname, (char *)ac2->ac_realname);
		FREEMEM((char *)ac->ac_id);
		savestr((char **)&ac->ac_id, (char *)ac2->ac_id);
		duplist(&ac->ac_classes, &ac2->ac_classes);
		duplist(&ac->ac_sigs, &ac2->ac_sigs);
#ifdef SENDMAIL
		duplist(&ac->ac_aliases, &ac2->ac_aliases);
#endif
	}
finish:
	!fileexists(CSFILE) && createfile(CSFILE);
	!fileexists(RANGEFILE) && createfile(RANGEFILE);
	!fileexists(SIGFILE) && createfile(SIGFILE);
	!fileexists(VIGFILE) && createfile(VIGFILE);
	!fileexists(SHELLFILE) && createfile(SHELLFILE);
	!fileexists(ACFILE) && createfile(ACFILE);
#ifdef SENDMAIL
	!fileexists(ALIASFILE) && createfile(ALIASFILE);
#endif

	critical();
#ifdef SENDMAIL
	/*
	 * Check to see if an alias bindings file needs to be created
	 * to represent the current aliases file.  Also if no alias bindings
	 * file exists we must assume that all users that are currently in
	 * aliases are not there because of bindings, hence updating
	 * ac_aliases for each user where appropriate.
	 */
	if (!fileexists(ALBIND)) {
		FILE *bindf = fopen(ALBIND, "w");
		FILE *alf = fopen(ALIASFILE, "r");

		if (alf == NULL) {
			err1("can't open %s (read)", ALIASFILE);
			fatal("mcp: -B aborted");
		}
		if (bindf == NULL) {
			(void) fclose(alf);
			err1("can't open %s (write)", ALBIND);
			fatal("mcp: -B aborted");
		}
		while (fgets(line, BUFSIZ, alf) != NULL) {
			if (isspace(line[0]) || line[0] == '#')
				continue;
			cp = index(line, '#');
			if (cp) *cp = '\0';
			cp = index(line, ':');
			if (cp) *cp = '\0';
			if (line[0] == '\n')
				continue;
			cp = index(line, '\n');
			if (cp) *cp = '\0';
			(void) fprintf(bindf, "%s:::\n", line);
		}
		(void) fchmod(fileno(bindf), 0644);
		(void) fclose(bindf);
		(void) fclose(alf);
		setalent();
		while (al = getalent()) {
		    for (indx=0; indx < al->al_addresses.l_count; indx++) {
			cp = (char *) al->al_addresses.l_list[indx];
			ac = getacnam(cp);
			if (ac && !instrlist(&ac->ac_aliases, cp)) {
			    strlistadd(&ac->ac_aliases, al->al_name);
			    sort_list(&ac->ac_aliases, pstrcmp);
			}
		    }
		}
		endalent();
	}
#endif
	if (backup(PW) == 0 || backup(AC) == 0)
		fatal("mcp: -B aborted");
	msg("");
	save_pw();
	save_ac();
	non_critical();

	goodbye(0);
}

static
createfile(file)
char *file;

{
	int d;

	d = open(file, O_WRONLY|O_CREAT);
	if (d == -1) {
		perr(file);
		return;
	}
	(void) write(d, "Toto IV", 7);
	(void) ftruncate(d, (off_t)0);
	(void) fchmod(d, 0644);
	(void) fsync(d);
	(void) close(d);
}