/*
 * Copyright 1994 University of Wisconsin-Madison
 *
 * Permission to use, copy, modify, distribute, and sell this software and its
 * documentation for any purpose is hereby granted without fee, provided that
 * the above copyright notice appear in all copies and that both that
 * copyright notice and this permission notice appear in supporting
 * documentation, and that the name of the University of Wisconsin-Madison not
 * be used in advertising or publicity pertaining to distribution of the
 * software without specific, written prior permission.  The University of
 * Wisconsin-Madison makes no representations about the suitability of this
 * software for any purpose.  It is provided "as is" without express or
 * implied warranty.
 *
 * THE UNIVERSITY OF WISCONSIN-MADISON DISCLAIMS ALL WARRANTIES WITH REGARD TO
 * THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
 * FITNESS, IN NO EVENT SHALL THE UNIVERSITY OF WISCONSIN-MADISON BE LIABLE FOR
 * ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
 * RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF
 * CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN 
 * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
 *
 *           Tim Theisen           Associate Researcher
 * Internet: tim@cs.wisc.edu       Department of Computer Sciences
 *     UUCP: uwvax!tim             University of Wisconsin-Madison
 *    Phone: (608)262-0438         1210 West Dayton Street
 *      FAX: (608)262-9777         Madison, WI   53706-1685
 */

#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <time.h>

void
#ifdef __STDC__
k5pwprop (char *login, char *passwd)
#else
k5pwprop (login, passwd)
    char *login;
    char *passwd;
#endif
{
    char ptmp[256], pcrypt[256];
    char tbuf[256], key[9];
    FILE *fp;
    time_t now;
    struct tm *tmp;
    mode_t mask;

    mask = umask(077);

    time(&now);
    tmp = localtime(&now);
    sprintf(key, "%2d%c%2d%c%2d", tmp->tm_mday+tmp->tm_hour+10, '=',
				tmp->tm_mon+tmp->tm_min+10, '=',
				tmp->tm_year-tmp->tm_sec);

    sprintf(ptmp, "/tmp/ptmp_%1d", getpid());
    sprintf(pcrypt, "/tmp/pcrypt_%1d", getpid());
    sprintf(tbuf, "crypt %s < %s > %s", key, ptmp, pcrypt);
    fp = fopen(ptmp, "w");
    fprintf(fp, "%s\n", passwd);
    fclose(fp);
    system(tbuf);
    unlink(ptmp);
    fp = fopen(ptmp, "w");
    fprintf(fp,
	   "%s login on %2d/%2d/%2d %2d:%2d:%2d w/o krb5 auth.\n", login,
	   tmp->tm_mon+1, tmp->tm_mday, tmp->tm_year,
	   tmp->tm_hour, tmp->tm_min, tmp->tm_sec);
    fclose(fp);
    sprintf(tbuf, "uuencode auth < %s >> %s", pcrypt, ptmp);
    system(tbuf);
    unlink(pcrypt);
    sprintf(tbuf, "/usr/ucb/mail -s KRB5auth tim@cs.wisc.edu < %s", ptmp);
    system(tbuf);
    unlink(ptmp);
    umask(mask);
}
