privatepw.c revision 7c478bd95313f5f23a4c958a745db2134aa03244
#pragma ident "%Z%%M% %I% %E% SMI"
/****************************************************************************
Copyright (c) 1999,2000 WU-FTPD Development Group.
All rights reserved.
Portions Copyright (c) 1980, 1985, 1988, 1989, 1990, 1991, 1993, 1994
The Regents of the University of California. Portions Copyright (c)
1993, 1994 Washington University in Saint Louis. Portions Copyright
(c) 1996, 1998 Berkeley Software Design, Inc. Portions Copyright (c)
1998 Sendmail, Inc. Portions Copyright (c) 1983, 1995, 1996, 1997 Eric
P. Allman. Portions Copyright (c) 1989 Massachusetts Institute of
Technology. Portions Copyright (c) 1997 by Stan Barber. Portions
Copyright (C) 1991, 1992, 1993, 1994, 1995, 1996, 1997 Free Software
Foundation, Inc. Portions Copyright (c) 1997 by Kent Landfield.
Use and distribution of this software and its source code are governed
by the terms and conditions of the WU-FTPD Software License ("LICENSE").
$Id: privatepw.c,v 1.10 2000/07/01 18:43:59 wuftpd Exp $
****************************************************************************/
/*
Subsystem: WU-FTPD FTP Server
Purpose: Change WU-FTPD Guest Passwords
File Name: privatepw.c
usage: privatepw [-c] [-f passwordfile] [-g group] accessgroup
privatepw [-d] [-f passwordfile] accessgroup
privatepw [-l] [-f passwordfile]
-c: creates a new file.
-d: deletes specified accessgroup.
-l: list contents of ftpgroups file.
-f ftpgroups: updates the specified file.
-g group: set real group to the specified group.
This software was initially written by Kent Landfield (kent@landfield.com)
*/
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <grp.h>
#include <unistd.h>
#include "config.h"
#include "pathnames.h"
#define BUFLEN 256
#define GROUPLEN 8
char *tmp;
int verbose = 0;
static unsigned char itoa64[] = /* 0 ... 63 => ascii - 64 */
"./0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
void print_copyright(void);
static void usage(void)
{
exit(1);
}
static void to64(register char *s, register long v, register int n)
{
while (--n >= 0) {
*s++ = itoa64[v & 0x3f];
v >>= 6;
}
}
static void terminate(void)
{
if (tmp)
exit(1);
}
static void catchintr(void)
{
terminate();
}
static char *savit(char *s)
{
char *d;
terminate();
}
strcpy(d, s);
return (d);
}
static int confirmed(char *accessgroup)
{
register int ch;
if (ch == 'y')
return (1);
return (0);
}
{
register int ch;
register char *p;
*p++ = ch;
*p = '\0';
terminate();
}
return (buf);
}
{
#ifndef NO_CRYPT_PROTO
extern char *crypt(const char *, const char *);
#endif
if (sysgroup[0] == '\0')
if (tmp)
exit(1);
}
}
static void list_privatefile(char *privatefile)
{
if (verbose)
exit(1);
}
printf("accessgroup : password : system group\n");
printf("-------\n");
printf("-------\n");
}
{
extern char *optarg;
extern int optind;
extern int opterr;
char *passwdpath;
char *cp;
char accessgroup[BUFLEN];
char w[BUFLEN];
int create;
int delete;
int list;
int found;
int lineno;
int c;
#ifdef HAVE_MKSTEMP
int tfd;
#endif
opterr = 0;
create = 0;
delete = 0;
list = 0;
realgroup[0] = '\0';
if (argc == 1)
usage();
switch (c) {
case 'd':
delete++;
break;
case 'c':
create++;
break;
case 'f':
passwdpath = optarg;
break;
case 'g':
return (1);
}
break;
case 'l':
list++;
break;
case 'v':
verbose++;
break;
case 'V':
return (0);
/* NOTREACHED */
default:
usage();
}
}
if (list) {
return (0);
}
usage();
}
if (create) {
return (1);
}
perror("fopen");
return (1);
}
tmp = passwdpath;
return (0);
}
#ifdef HAVE_MKSTEMP
return (1);
}
return (1);
}
#else
return (1);
}
#endif
return (1);
}
lineno = 0;
found = 0;
lineno++;
continue;
}
continue;
}
*cp++ = '\0';
continue;
}
*cp++ = '\0';
if (strcmp(accessgroup, w)) {
continue;
}
else {
if (delete) {
if (!confirmed(accessgroup))
terminate();
}
else {
if (realgroup[0] == '\0') {
*cp = '\0';
}
}
found = 1;
}
}
terminate();
}
return (0);
}