1 /* access.c Copyright 1992-2000 by Michael Temari All Rights Reserved
3 * This file is part of ftpd.
10 * 01/25/96 Initial Release Michael Temari, <Michael@TemWare.Com>
13 #include <sys/types.h>
19 #include <net/gen/in.h>
20 #include <net/gen/tcp.h>
25 _PROTOTYPE(static int AreWeIn
, (char *name
, struct passwd
*pwd
));
27 static char *msg530
= "530 Not logged in.\r\n";
29 /* Returns -1 = not logged in, 0 = loggedin */
45 strncpy(username
, buff
, sizeof(username
));
46 username
[sizeof(username
)-1] = '\0';
48 if(*username
== '\0') {
49 printf("501 Bad user name.\r\n");
55 printf("331 Password required for %s.\r\n", username
);
60 /* secret, secret, secret */
70 if(!strcmp(name
, "anonymous"))
73 if(!gotuser
|| ((pwd
= getpwnam(name
)) == (struct passwd
*)0))
76 if(strcmp(name
, "ftp")) {
77 if(!strcmp(pwd
->pw_passwd
, crypt("", pwd
->pw_passwd
)))
79 if(strcmp(pwd
->pw_passwd
, crypt(buff
, pwd
->pw_passwd
)))
82 strncpy(anonpass
, buff
, sizeof(anonpass
));
83 anonpass
[sizeof(anonpass
)-1] = '\0';
87 logit("LOGIN", "FAIL");
92 return(AreWeIn(name
, pwd
));
95 /* bye, bye don't let the door hit you in the butt on the way out */
99 printf("221 Service closing, don't be a stranger.\r\n");
104 /* see if this user is okay */
105 static int AreWeIn(name
, pwd
)
109 if(!strcmp(name
, "ftp")) {
110 if(chroot(pwd
->pw_dir
)) {
111 logit("LOGIN", "FAIL");
112 printf("530 Not logged in, could not chroot.\r\n");
115 strncpy(newroot
, pwd
->pw_dir
, sizeof(newroot
));
116 newroot
[sizeof(newroot
)-1] = '\0';
118 strcpy(pwd
->pw_dir
, "/");
121 if(setgid(pwd
->pw_gid
) || setuid(pwd
->pw_uid
) || chdir(pwd
->pw_dir
)) {
122 logit("LOGIN", "FAIL");
126 logit("LOGIN", "PASS");
127 showmsg("230", (char *)NULL
);
128 printf("230 User %s logged in, directory %s.\r\n",
129 username
, pwd
->pw_dir
);