#include <stdio.h>
#include <string.h>
#include <ctype.h>
-#include <sms.h>
-#include <sms_app.h>
+#include <moira.h>
+#include <moira_site.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/time.h>
extern int errno;
char *whoami = "mailhub.gen";
char *ingres_date_and_time();
+char *perm_malloc();
char *divide = "##############################################################";
#define ML_WID 72
if (flag < 0) {
fprintf(stderr, "File %s does not need to be rebuilt.\n",
argv[1]);
- exit(SMS_NO_CHANGE);
+ exit(MR_NO_CHANGE);
}
}
targetfile = argv[1];
sprintf(filename, "%s~", targetfile);
if ((out = fopen(filename, "w")) == NULL) {
fprintf(stderr, "unable to open %s for output\n", filename);
- exit(SMS_OCONFIG);
+ exit(MR_OCONFIG);
}
} else if (argc != 1) {
fprintf(stderr, "usage: %s [outfile]\n", argv[0]);
- exit(SMS_ARGS);
+ exit(MR_ARGS);
}
fprintf(out, "%s\n# Aliases File Extract of %s", divide, ctime(&tm));
if (fclose(out)) {
perror("close failed");
- exit(SMS_CCONFIG);
+ exit(MR_CCONFIG);
}
if (argc == 2)
fix_file(targetfile);
- exit(SMS_SUCCESS);
+ exit(MR_SUCCESS);
}
switch (*num) {
case INGRES_DEADLOCK:
- ingres_errno = SMS_DEADLOCK;
+ ingres_errno = MR_DEADLOCK;
break;
default:
- ingres_errno = SMS_INGRES_ERR;
+ ingres_errno = MR_INGRES_ERR;
}
- com_err(whoami, SMS_INGRES_ERR, " code %d\n", *num);
+ com_err(whoami, MR_INGRES_ERR, " code %d\n", *num);
critical_alert("DCM", "Alias build encountered INGRES ERROR %d", *num);
exit(ingres_errno);
}
## retrieve (id = machine.mach_id, name = machine.#name) {
if (s = index(name, '.'))
*s = 0;
+#ifdef ATHENA
sprintf(buf, "%s.LOCAL", name);
if (hash_store(machines, id, strsave(buf)) < 0) {
+#else
+ if (hash_store(machines, id, strsave(name)) < 0) {
+#endif
fprintf(stderr, "Out of memory!\n");
- exit(SMS_NO_MEM);
+ exit(MR_NO_MEM);
}
cnt++;
## }
## retrieve (id = strings.string_id, name = strings.string) {
if (hash_store(strings, id, strsave(strtrim(name))) < 0) {
fprintf(stderr, "Out of memory!\n");
- exit(SMS_NO_MEM);
+ exit(MR_NO_MEM);
}
cnt++;
## }
## mname = u.middle, lname = u.last,
## type = u.potype, pid = u.pop_id, bid = u.box_id)
## where u.status != 3 {
- u = (struct user *) malloc(sizeof(struct user));
+ u = (struct user *) perm_malloc(sizeof(struct user));
u->login = strsave(strtrim(name));
u->first = strsave(strtrim(fname));
u->last = strsave(strtrim(lname));
u->pobox = (char *) NULL;
if (hash_store(users, id, u) < 0) {
fprintf(stderr, "Out of memory!\n");
- exit(SMS_NO_MEM);
+ exit(MR_NO_MEM);
}
cnt++;
## }
## retrieve (id = l.list_id, name = l.#name, maillistp = l.maillist,
## type = l.acl_type, acl = l.acl_id)
## where l.active != 0 {
- l = (struct list *) malloc(sizeof(struct list));
+ l = (struct list *) perm_malloc(sizeof(struct list));
l->name = strsave(strtrim(name));
l->maillist = maillistp;
l->acl_t = type[0];
l->m = (struct member *) NULL;
if (hash_store(lists, id, l) < 0) {
fprintf(stderr, "Out of memory!\n");
- exit(SMS_NO_MEM);
+ exit(MR_NO_MEM);
}
cnt++;
## }
## where m.direct = 1 {
cnt++;
if (l = (struct list *) hash_lookup(lists, id)) {
- m = (struct member *) malloc(sizeof(struct member));
+ m = (struct member *) perm_malloc(sizeof(struct member));
if (type[0] == 'U' &&
(u = (struct user *) hash_lookup(users, mid))) {
m->list_id = 0;
code = hashstr(s);
ns = (struct names *) hash_lookup(names, code);
if (ns == NULL) {
- if ((ns = (struct names *) malloc(sizeof(struct names))) == NULL) {
+ if ((ns = (struct names *) perm_malloc(sizeof(struct names))) == NULL) {
fprintf(stderr, "ran out of memory inserting name (sorting)\n");
- exit(SMS_NO_MEM);
+ exit(MR_NO_MEM);
}
if (copy)
ns->name = strsave(s);
ns->id = id;
if (hash_store(names, code, ns) < 0) {
fprintf(stderr, "Out of memory!\n");
- exit(SMS_NO_MEM);
+ exit(MR_NO_MEM);
}
return;
}
if (!strcasecmp(ns->name, s))
goto foundns;
}
- if ((ns->next = (struct names *)malloc(sizeof(struct names))) == NULL) {
+ if ((ns->next = (struct names *) perm_malloc(sizeof(struct names)))
+ == NULL) {
fprintf(stderr, "ran out of memory insterting name (sorting)\n");
- exit(SMS_NO_MEM);
+ exit(MR_NO_MEM);
}
ns = ns->next;
if (copy)
}
+/* Illegal chars: ! " % ( ) , . / : ; < = > @ [ \ ] ^ { | } */
+
+static int illegalchars[] = {
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, /* ^@ - ^O */
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, /* ^P - ^_ */
+ 0, 1, 1, 0, 0, 1, 0, 0, 1, 1, 0, 0, 1, 0, 1, 1, /* SPACE - / */
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 0, /* 0 - ? */
+ 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* @ - O */
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0, /* P - _ */
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* ` - o */
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 1, /* p - ^? */
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+};
+
+
+/* While hashing the string, punt any illegal characters */
+
int hashstr(s)
register char *s;
{
register int c;
for (result = 0; c = *s; s++) {
+ if (illegalchars[c]) {
+ register char *p;
+ for (p = s; *p; p++)
+ *p = p[1];
+ continue;
+ }
if (isupper(c))
c = *s = tolower(c);
/* result = result * 31 + *s; */
{
register struct names *ns;
register struct user *u;
- int i;
incount++;
for (ns = nms; ns; ns = ns->next) {
return;
if (l->acl_t == 'L' &&
(l1 = (struct list *) hash_lookup(lists, l->acl_id)))
- fprintf(out, "owner-%s: %s\n", l->name, l1->name);
+ fprintf(out, "owner-%s: %s\n%s: ", l->name, l1->name, l->name);
else if (l->acl_t == 'U' &&
(u = (struct user *) hash_lookup(users, l->acl_id)))
- fprintf(out, "owner-%s: %s\n", l->name, u->login);
+ fprintf(out, "owner-%s: %s\n%s: ", l->name, u->login, l->name);
- fprintf(out, "%s: ", l->name);
lwid = strlen(l->name) + 2;
bol = 1;
for (m = l->m; m; m = m->next) {
hash_step(names, output_data, out);
fprintf(stderr, "Output %d entries\n", incount);
}
+
+
+#define chunk_size 102400
+
+char *perm_malloc(size)
+unsigned size;
+{
+ static char *pool = NULL;
+ static unsigned pool_size = 0;
+ register char *ret;
+
+ if (size > pool_size) {
+ pool = (char *) malloc(chunk_size);
+ pool_size = chunk_size;
+ }
+ ret = pool;
+ pool += size;
+ pool = (char *)(((unsigned) (pool + 1)) & ~1);
+ pool_size -= (pool - ret);
+ return(ret);
+}
+