source: trunk/minix/commands/ftpd200/access.c@ 15

Last change on this file since 15 was 9, checked in by Mattia Monga, 14 years ago

Minix 3.1.2a

File size: 2.5 KB
Line 
1/* access.c Copyright 1992-2000 by Michael Temari All Rights Reserved
2 *
3 * This file is part of ftpd.
4 *
5 * This file handles:
6 *
7 * USER PASS QUIT
8 *
9 *
10 * 01/25/96 Initial Release Michael Temari, <Michael@TemWare.Com>
11 */
12
13#include <sys/types.h>
14#include <stdio.h>
15#include <string.h>
16#include <pwd.h>
17#include <stdlib.h>
18#include <unistd.h>
19#include <net/gen/in.h>
20#include <net/gen/tcp.h>
21
22#include "ftpd.h"
23#include "access.h"
24
25_PROTOTYPE(static int AreWeIn, (char *name, struct passwd *pwd));
26
27static char *msg530 = "530 Not logged in.\r\n";
28
29/* Returns -1 = not logged in, 0 = loggedin */
30int ChkLoggedIn()
31{
32 if(!loggedin) {
33 printf(msg530);
34 return(-1);
35 } else
36 return(0);
37}
38
39/* what a USER! */
40int doUSER(buff)
41char *buff;
42{
43 loggedin = 0;
44 gotuser = 0;
45 strncpy(username, buff, sizeof(username));
46 username[sizeof(username)-1] = '\0';
47
48 if(*username == '\0') {
49 printf("501 Bad user name.\r\n");
50 return(GOOD);
51 }
52
53 gotuser = 1;
54
55 printf("331 Password required for %s.\r\n", username);
56
57 return(GOOD);
58}
59
60/* secret, secret, secret */
61int doPASS(buff)
62char *buff;
63{
64char *name;
65struct passwd *pwd;
66int bad=0;
67
68 name = username;
69
70 if(!strcmp(name, "anonymous"))
71 name = "ftp";
72
73 if(!gotuser || ((pwd = getpwnam(name)) == (struct passwd *)0))
74 bad = 1;
75 else
76 if(strcmp(name, "ftp")) {
77 if(!strcmp(pwd->pw_passwd, crypt("", pwd->pw_passwd)))
78 bad = 1;
79 if(strcmp(pwd->pw_passwd, crypt(buff, pwd->pw_passwd)))
80 bad = 1;
81 } else {
82 strncpy(anonpass, buff, sizeof(anonpass));
83 anonpass[sizeof(anonpass)-1] = '\0';
84 }
85
86 if(bad) {
87 logit("LOGIN", "FAIL");
88 printf(msg530);
89 return(GOOD);
90 }
91
92 return(AreWeIn(name, pwd));
93}
94
95/* bye, bye don't let the door hit you in the butt on the way out */
96int doQUIT(buff)
97char *buff;
98{
99 printf("221 Service closing, don't be a stranger.\r\n");
100
101 return(BAD);
102}
103
104/* see if this user is okay */
105static int AreWeIn(name, pwd)
106char *name;
107struct passwd *pwd;
108{
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");
113 return(GOOD);
114 }
115 strncpy(newroot, pwd->pw_dir, sizeof(newroot));
116 newroot[sizeof(newroot)-1] = '\0';
117 anonymous = 1;
118 strcpy(pwd->pw_dir, "/");
119 }
120
121 if(setgid(pwd->pw_gid) || setuid(pwd->pw_uid) || chdir(pwd->pw_dir)) {
122 logit("LOGIN", "FAIL");
123 printf(msg530);
124 anonymous = 0;
125 } else {
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);
130 loggedin = 1;
131 }
132
133 return(GOOD);
134}
Note: See TracBrowser for help on using the repository browser.