#include <moira_site.h>
#include <des.h>
#include <krb.h>
+#include <gdss.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/time.h>
EXEC SQL INCLUDE sqlca;
extern int errno;
-char *whoami = "warehouse.gen";
+char *whoami = "sis.gen";
char *db = "moira/moira";
+#ifndef WAREHOUSE_SUBDIR
+#define WAREHOUSE_SUBDIR "warehouse"
+#endif
+
+char warehouse_dir[128];
+
main(argc, argv)
int argc;
char **argv;
{
int out = 1 /* stdout */;
char *outf = NULL, outft[64];
+ char *control_fn[80], cmd[256];
+ FILE *f;
struct stat sb;
int flag1;
+ SigInfo si;
struct timeval now;
+ int records = 0;
EXEC SQL BEGIN DECLARE SECTION;
- char login[9], signature[68], clearid[17], kname[257];
- EXEC SQL VAR signature IS STRING(68);
- char last[17], first[17], middle[17], type[9];
- int sigdate, sigwho;
- struct { char clearid[17];
- char login[12];
- char last[17];
- char middle[17];
- char first[17];
- char sigdate[12];
- char sigwho[60];
- char signature[69];
+ char login[9], sig[257], id[17], kname[257];
+ EXEC SQL VAR sig IS STRING(257);
+ int timestamp, sigwho;
+ struct { char login[12];
+ char id[12];
+ char sig[256];
} outrec;
EXEC SQL END DECLARE SECTION;
initialize_sms_error_table ();
+ sprintf(warehouse_dir, "%s/%s", DCM_DIR, WAREHOUSE_SUBDIR);
+
EXEC SQL CONNECT :db;
if (argc == 2) {
}
}
outf = argv[1];
- sprintf(outft, "%s~", outf);
+ sprintf(outft, "%s/username_id.map", warehouse_dir);
if ((out = open(outft, O_WRONLY|O_APPEND|O_CREAT|O_TRUNC, 0666)) < 0) {
fprintf(stderr, "unable to open %s for output\n", outf);
exit(MR_OCONFIG);
EXEC SQL WHENEVER SQLERROR GOTO sqlerr;
EXEC SQL DECLARE x CURSOR FOR
- SELECT u.clearid, u.login, u.last, u.first, u.middle, u.type,
- u.sigdate, u.sigwho, u.signature
- FROM users u WHERE u.status = 1 or u.status=5 or u.status=6;
+ SELECT u.login, u.clearid, u.signature, u.sigdate, s.string, u.sigwho
+ FROM users u, strings s
+ WHERE (u.status = 1 or u.status=2 or u.status=5 or
+ u.status=6 or u.status=7)
+ and u.sigwho = s.string_id;
EXEC SQL OPEN x;
while (1) {
- EXEC SQL FETCH x INTO :clearid, :login, :last, :first,
- :middle, :type, :sigdate, :sigwho, :signature;
+ EXEC SQL FETCH x INTO :login, :id, :sig, :timestamp, :kname, :sigwho;
if (sqlca.sqlcode != 0) break;
+ if (id == 0) continue;
if (!isdigit(id[1])) continue;
strtrim(login);
- strtrim(clearid);
- strtrim(last);
- strtrim(first);
- strtrim(middle);
- strtrim(type);
+ strtrim(id);
+ strtrim(kname);
memset(&outrec, 0, sizeof(outrec));
strcpy(outrec.login, login);
strcpy(outrec.id, id);
- strcpy(outrec.last, last);
- strcpy(outrec.first, first);
- strcpy(outrec.middle, middle);
- strcpy(outrec.type, type);
if (sigwho) {
- sprintf(outrec.sigdate, "%d", sigdate);
- memcpy(outrec.signature, signature, sizeof(signature));
- EXEC SQL SELECT string from strings
- WHERE string_id = :sigwho
- INTO :kname;
- strcpy(outrec.sigwho, kname);
+ si.timestamp = timestamp;
+ si.SigInfoVersion = 0; /* XXXXXX this isn't used */
+ kname_parse(si.pname, si.pinst, si.prealm, kname);
+ si.rawsig = (unsigned char *)sig;
+ GDSS_Recompose(&si, outrec.sig);
}
write(out, &outrec, sizeof(outrec));
+ records++;
}
EXEC SQL CLOSE x;
perror("close failed");
exit(MR_CCONFIG);
}
- if (outf)
- fix_file(outf);
+ sprintf(control_fn, "%s/username_id.ctl", warehouse_dir);
+
+ f = fopen(control_fn, "w");
+ if (!f) {
+ perror("creating username_id control file");
+ exit(MR_OCONFIG);
+ }
+ fprintf(f, "username_id.map --- Moira feed for MIT Data Warehouse\n");
+ fprintf(f, "%d records\n", records);
+ fprintf(f, "%d bytes\n", records * (12+12+256));
+ fprintf(f, "Full feed\n");
+ fprintf(f, "Fixed format -- binary\n");
+ fclose(f);
+ if (outf) {
+ fprintf(stderr, "Building tar file.\n");
+ sprintf(cmd, "(cd %s; tar cf - . ) | compress > %s",
+ warehouse_dir, outf);
+ if (system(cmd))
+ exit(MR_TAR_FAIL);
+ }
+
exit(MR_SUCCESS);
sqlerr: