1 /* Server for the Midnight Commander Virtual File System.
3 Copyright (C) 1995, 1996, 1997 The Free Software Foundation
6 Miguel de Icaza, 1995, 1997,
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 2 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with this program; if not, write to the Free Software
21 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
24 opendir instead of keeping its table of file handles could return
25 the pointer and expect the client to send a proper value back each
28 We should use syslog to register login/logout.
32 /* {{{ Includes and global variables */
45 # include <sys/param.h>
47 # define NGROUPS_MAX NGROUPS
53 #include <sys/types.h>
62 /* Network include files */
63 #include <sys/socket.h>
64 #include <netinet/in.h>
66 #ifdef HAVE_ARPA_INET_H
67 #include <arpa/inet.h>
71 # include <rpc/pmap_prot.h>
72 # ifdef HAVE_RPC_PMAP_CLNT_H
73 # include <rpc/pmap_clnt.h>
78 # if !defined(HAVE_SECURITY_PAM_MISC_H)
83 /* Authentication include files */
86 # include <security/pam_misc.h>
87 # ifndef PAM_ESTABLISH_CRED
88 # define PAM_ESTABLISH_CRED PAM_CRED_ESTABLISH
91 #endif /* !HAVE_PAM */
95 #endif /* !HAVE_CRYPT_H */
100 # ifdef HAVE_SHADOW_SHADOW_H
101 # include <shadow/shadow.h>
109 #include "mcfsutil.h"
112 /* replacement for g_free() from glib */
114 #define g_free(x) do {if (x) free (x);} while (0)
116 /* We don't care about SIGPIPE */
119 /* The socket from which we accept commands */
122 /* Requested version number from client */
123 static int clnt_version
;
125 /* If non zero, we accept further commands */
129 char *home_dir
= NULL
;
133 /* Were we started from inetd? */
134 int inetd_started
= 0;
136 /* Are we running as a daemon? */
145 /* port number in which we listen to connections,
146 * if zero, we try to contact the portmapper to get a port, and
147 * if it's not possible, then we use a hardcoded value
151 /* if the server will use rcmd based authentication (hosts.equiv .rhosts) */
154 #define OPENDIR_HANDLES 8
156 #define DO_QUIT_VOID() \
163 /* Only used by get_port_number */
164 #define DO_QUIT_NONVOID(a) \
173 static int quit_server
;
174 static int return_code
;
178 /* {{{ Misc routines */
181 send_status (int status
, int errno_number
)
183 rpc_send (msock
, RPC_INT
, status
, RPC_INT
, errno_number
, RPC_END
);
189 /* {{{ File with handle operations */
194 int handle
, flags
, mode
;
197 rpc_get (msock
, RPC_STRING
, &arg
, RPC_INT
, &flags
, RPC_INT
, &mode
,
200 handle
= open (arg
, flags
, mode
);
201 send_status (handle
, errno
);
208 int handle
, count
, n
;
211 rpc_get (msock
, RPC_INT
, &handle
, RPC_INT
, &count
, RPC_END
);
212 data
= malloc (count
);
214 send_status (-1, ENOMEM
);
218 printf ("count=%d\n", count
);
219 n
= read (handle
, data
, count
);
221 printf ("result=%d\n", n
);
223 send_status (-1, errno
);
227 rpc_send (msock
, RPC_BLOCK
, n
, data
, RPC_END
);
235 int handle
, count
, status
, written
= 0;
238 rpc_get (msock
, RPC_INT
, &handle
, RPC_INT
, &count
, RPC_END
);
241 int nbytes
= count
> 8192 ? 8192 : count
;
243 rpc_get (msock
, RPC_BLOCK
, nbytes
, buf
, RPC_END
);
244 status
= write (handle
, buf
, nbytes
);
246 send_status (status
, errno
);
249 /* FIXED: amount written must be returned to caller */
251 if (status
< nbytes
) {
252 send_status (written
, errno
);
257 send_status (written
, errno
);
263 int handle
, offset
, whence
, status
;
265 rpc_get (msock
, RPC_INT
, &handle
, RPC_INT
, &offset
, RPC_INT
, &whence
,
267 status
= lseek (handle
, offset
, whence
);
268 send_status (status
, errno
);
276 rpc_get (msock
, RPC_INT
, &handle
, RPC_END
);
277 status
= close (handle
);
278 send_status (status
, errno
);
283 /* {{{ Stat family routines */
286 send_time (int sock
, time_t time
)
288 if (clnt_version
== 1) {
293 ct
[3] = ct
[10] = ct
[13] = ct
[16] = ct
[19] = 0;
295 /* Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec */
300 month
= (ct
[6] == 'n') ? 5 : 6;
301 } else if (ct
[4] == 'F') {
303 } else if (ct
[4] == 'M') {
304 month
= (ct
[6] == 'r') ? 2 : 5;
305 } else if (ct
[4] == 'A') {
306 month
= (ct
[5] == 'p') ? 3 : 7;
307 } else if (ct
[4] == 'S') {
309 } else if (ct
[4] == 'O') {
311 } else if (ct
[4] == 'N') {
315 rpc_send (msock
, RPC_INT
, atoi (&ct
[17]), /* sec */
316 RPC_INT
, atoi (&ct
[14]), /* min */
317 RPC_INT
, atoi (&ct
[11]), /* hour */
318 RPC_INT
, atoi (&ct
[8]), /* mday */
319 RPC_INT
, atoi (&ct
[20]), /* year */
320 RPC_INT
, month
, /* month */
323 long ltime
= (long) time
;
326 snprintf (buf
, sizeof (buf
), "%lx", ltime
);
327 rpc_send (msock
, RPC_STRING
, buf
, RPC_END
);
332 send_stat_info (struct stat
*st
)
336 #ifdef HAVE_STRUCT_STAT_ST_BLOCKS
342 #ifdef HAVE_STRUCT_STAT_ST_RDEV
343 mylong
= st
->st_rdev
;
347 rpc_send (msock
, RPC_INT
, (long) mylong
, RPC_INT
, (long) st
->st_ino
,
348 RPC_INT
, (long) st
->st_mode
, RPC_INT
, (long) st
->st_nlink
,
349 RPC_INT
, (long) st
->st_uid
, RPC_INT
, (long) st
->st_gid
,
350 RPC_INT
, (long) st
->st_size
, RPC_INT
, (long) blocks
,
352 send_time (msock
, st
->st_atime
);
353 send_time (msock
, st
->st_mtime
);
354 send_time (msock
, st
->st_ctime
);
364 rpc_get (msock
, RPC_STRING
, &file
, RPC_END
);
365 n
= lstat (file
, &st
);
366 send_status (n
, errno
);
368 send_stat_info (&st
);
379 rpc_get (msock
, RPC_INT
, &handle
, RPC_END
);
380 n
= fstat (handle
, &st
);
381 send_status (n
, errno
);
385 send_stat_info (&st
);
395 rpc_get (msock
, RPC_STRING
, &file
, RPC_END
);
397 n
= stat (file
, &st
);
398 send_status (n
, errno
);
400 send_stat_info (&st
);
406 /* {{{ Directory lookup operations */
410 DIR *dirs
[OPENDIR_HANDLES
];
411 char *names
[OPENDIR_HANDLES
];
415 close_handle (int handle
)
417 if (mcfs_DIR
.used
> 0)
419 if (mcfs_DIR
.dirs
[handle
])
420 closedir (mcfs_DIR
.dirs
[handle
]);
421 if (mcfs_DIR
.names
[handle
])
422 g_free (mcfs_DIR
.names
[handle
]);
423 mcfs_DIR
.dirs
[handle
] = 0;
424 mcfs_DIR
.names
[handle
] = 0;
434 rpc_get (msock
, RPC_STRING
, &arg
, RPC_END
);
436 if (mcfs_DIR
.used
== OPENDIR_HANDLES
) {
437 send_status (-1, ENFILE
); /* Error */
443 for (i
= 0; i
< OPENDIR_HANDLES
; i
++) {
444 if (mcfs_DIR
.dirs
[i
] == 0) {
451 send_status (-1, EMFILE
);
455 "OOPS! you have found a bug in mc - do_opendir()!\n");
460 printf ("handle=%d\n", handle
);
463 mcfs_DIR
.dirs
[handle
] = p
;
464 mcfs_DIR
.names
[handle
] = arg
;
467 /* Because 0 is an error value */
468 rpc_send (msock
, RPC_INT
, handle
+ 1, RPC_INT
, 0, RPC_END
);
471 send_status (-1, errno
);
476 /* Sends the complete directory listing, as well as the stat information */
480 struct dirent
*dirent
;
484 rpc_get (msock
, RPC_INT
, &handle
, RPC_END
);
487 rpc_send (msock
, RPC_INT
, 0, RPC_END
);
491 /* We incremented it in opendir */
494 while ((dirent
= readdir (mcfs_DIR
.dirs
[handle
]))) {
497 int length
= NLENGTH (dirent
);
499 rpc_send (msock
, RPC_INT
, length
, RPC_END
);
500 rpc_send (msock
, RPC_BLOCK
, length
, dirent
->d_name
, RPC_END
);
502 strlen (mcfs_DIR
.names
[handle
]) + strlen (dirent
->d_name
) + 2;
503 fname
= malloc (fname_len
);
504 snprintf (fname
, fname_len
, "%s/%s", mcfs_DIR
.names
[handle
],
506 n
= lstat (fname
, &st
);
508 send_status (n
, errno
);
510 send_stat_info (&st
);
512 rpc_send (msock
, RPC_INT
, 0, RPC_END
);
520 rpc_get (msock
, RPC_INT
, &handle
, RPC_END
);
521 close_handle (handle
- 1);
526 /* {{{ Operations with one and two file name argument */
534 rpc_get (msock
, RPC_STRING
, &file
, RPC_END
);
536 status
= chdir (file
);
537 send_status (status
, errno
);
547 rpc_get (msock
, RPC_STRING
, &file
, RPC_END
);
549 status
= rmdir (file
);
550 send_status (status
, errno
);
560 rpc_get (msock
, RPC_STRING
, &file
, RPC_INT
, &mode
, RPC_END
);
562 status
= mkdir (file
, mode
);
563 send_status (status
, errno
);
571 int mode
, dev
, status
;
573 rpc_get (msock
, RPC_STRING
, &file
, RPC_INT
, &mode
, RPC_INT
, &dev
,
576 status
= mknod (file
, mode
, dev
);
577 send_status (status
, errno
);
588 rpc_get (msock
, RPC_STRING
, &file
, RPC_END
);
589 n
= readlink (file
, buffer
, 2048 - 1);
590 send_status (n
, errno
);
593 rpc_send (msock
, RPC_STRING
, buffer
, RPC_END
);
604 rpc_get (msock
, RPC_STRING
, &file
, RPC_END
);
605 status
= unlink (file
);
606 send_status (status
, errno
);
616 rpc_get (msock
, RPC_STRING
, &f1
, RPC_STRING
, &f2
, RPC_END
);
617 status
= rename (f1
, f2
);
618 send_status (status
, errno
);
629 rpc_get (msock
, RPC_STRING
, &f1
, RPC_STRING
, &f2
, RPC_END
);
630 status
= symlink (f1
, f2
);
631 send_status (status
, errno
);
642 rpc_get (msock
, RPC_STRING
, &f1
, RPC_STRING
, &f2
, RPC_END
);
643 status
= link (f1
, f2
);
644 send_status (status
, errno
);
652 /* {{{ Misc commands */
657 rpc_send (msock
, RPC_STRING
, (home_dir
) ? home_dir
: "/", RPC_END
);
663 rpc_send (msock
, RPC_STRING
, (up_dir
) ? up_dir
: "/", RPC_END
);
672 rpc_get (msock
, RPC_STRING
, &file
, RPC_INT
, &mode
, RPC_END
);
673 status
= chmod (file
, mode
);
674 send_status (status
, errno
);
682 int owner
, group
, status
;
684 rpc_get (msock
, RPC_STRING
, &file
, RPC_INT
, &owner
, RPC_INT
, &group
,
686 status
= chown (file
, owner
, group
);
687 send_status (status
, errno
);
700 struct utimbuf times
;
702 rpc_get (msock
, RPC_STRING
, &file
, RPC_STRING
, &as
, RPC_STRING
, &ms
,
704 sscanf (as
, "%lx", &atime
);
705 sscanf (ms
, "%lx", &mtime
);
707 printf ("Got a = %s, m = %s, comp a = %ld, m = %ld\n", as
, ms
,
711 times
.actime
= (time_t) atime
;
712 times
.modtime
= (time_t) mtime
;
713 status
= utime (file
, ×
);
714 send_status (status
, errno
);
732 mc_pam_conversation (int messages
, const struct pam_message
**msg
,
733 struct pam_response
**resp
, void *appdata_ptr
)
735 struct pam_response
*r
;
736 struct user_pass
*up
= appdata_ptr
;
739 r
= (struct pam_response
*) malloc (sizeof (struct pam_response
) *
745 for (status
= PAM_SUCCESS
; messages
--; msg
++, r
++) {
746 switch ((*msg
)->msg_style
) {
748 case PAM_PROMPT_ECHO_ON
:
749 r
->resp
= strdup (up
->username
);
750 r
->resp_retcode
= PAM_SUCCESS
;
753 case PAM_PROMPT_ECHO_OFF
:
754 r
->resp
= strdup (up
->password
);
755 r
->resp_retcode
= PAM_SUCCESS
;
760 r
->resp_retcode
= PAM_SUCCESS
;
765 r
->resp_retcode
= PAM_SUCCESS
;
772 static struct pam_conv conv
= { &mc_pam_conversation
, NULL
};
775 /* Return 0 if authentication failed, 1 otherwise */
777 mc_pam_auth (char *username
, char *password
)
783 up
.username
= username
;
784 up
.password
= password
;
785 conv
.appdata_ptr
= &up
;
788 pam_start ("mcserv", username
, &conv
, &pamh
)) != PAM_SUCCESS
)
790 if ((status
= pam_authenticate (pamh
, 0)) != PAM_SUCCESS
)
792 if ((status
= pam_acct_mgmt (pamh
, 0)) != PAM_SUCCESS
)
794 if ((status
= pam_setcred (pamh
, PAM_ESTABLISH_CRED
)) != PAM_SUCCESS
)
796 pam_end (pamh
, status
);
800 pam_end (pamh
, status
);
804 #else /* !HAVE_PAM */
806 /* Keep reading until we find a \n */
808 next_line (int socket
)
813 if (read (socket
, &c
, 1) <= 0)
821 ftp_answer (int sock
, char *text
)
826 socket_read_block (sock
, answer
, 3);
828 if (strcmp (answer
, text
) == 0)
834 send_string (int sock
, char *string
)
836 return socket_write_block (sock
, string
, strlen (string
));
840 do_ftp_auth (char *username
, char *password
)
842 struct sockaddr_in local_address
;
843 unsigned long inaddr
;
847 memset ((char *) &local_address
, 0, sizeof (local_address
));
849 local_address
.sin_family
= AF_INET
;
850 /* FIXME: extract the ftp port with the proper function */
851 local_address
.sin_port
= htons (21);
853 /* Convert localhost to usable format */
854 if ((inaddr
= inet_addr ("127.0.0.1")) != INADDR_NONE
)
855 memcpy ((char *) &local_address
.sin_addr
, (char *) &inaddr
,
858 if ((my_socket
= socket (AF_INET
, SOCK_STREAM
, 0)) < 0) {
860 fprintf (stderr
, "do_auth: can't create socket\n");
864 (my_socket
, (struct sockaddr
*) &local_address
,
865 sizeof (local_address
)) < 0) {
867 "do_auth: can't connect to ftp daemon for authentication\n");
871 send_string (my_socket
, "user ");
872 send_string (my_socket
, username
);
873 send_string (my_socket
, "\r\n");
874 if (!ftp_answer (my_socket
, "331")) {
875 send_string (my_socket
, "quit\r\n");
879 next_line (my_socket
); /* Eat all the line */
880 send_string (my_socket
, "pass ");
881 send_string (my_socket
, password
);
882 send_string (my_socket
, "\r\n");
883 socket_read_block (my_socket
, answer
, 3);
885 send_string (my_socket
, "\r\n");
886 send_string (my_socket
, "quit\r\n");
888 if (strcmp (answer
, "230") == 0)
895 do_classic_auth (char *username
, char *password
)
898 char *encr_pwd
= NULL
;
904 if ((pw
= getpwnam (username
)) == 0)
910 /* Password expiration is not checked! */
911 if ((spw
= getspnam (username
)) == NULL
)
914 encr_pwd
= spw
->sp_pwdp
;
918 encr_pwd
= pw
->pw_passwd
;
921 if (strcmp (crypt (password
, encr_pwd
), encr_pwd
) == 0)
927 #endif /* HAVE_CRYPT */
928 #endif /* !HAVE_PAM */
930 /* Try to authenticate the user based on:
931 - PAM if the system has it, else it checks:
932 - pwdauth if the system supports it.
933 - conventional auth (check salt on /etc/passwd, crypt, and compare
934 - try to contact the local ftp server and login (if -f flag used)
937 do_auth (char *username
, char *password
)
942 if (strcmp (username
, "anonymous") == 0)
946 if (mc_pam_auth (username
, password
) == 0)
948 #else /* if there is no pam */
950 if (pwdauth (username
, password
) == 0)
955 if (do_classic_auth (username
, password
))
960 auth
= do_ftp_auth (username
, password
);
966 this = getpwnam (username
);
970 if (chdir (this->pw_dir
) == -1)
973 if (this->pw_dir
[strlen (this->pw_dir
) - 1] == '/')
974 home_dir
= strdup (this->pw_dir
);
976 home_dir
= malloc (strlen (this->pw_dir
) + 2);
978 strcpy (home_dir
, this->pw_dir
);
979 strcat (home_dir
, "/");
985 if (setgid (this->pw_gid
) == -1)
988 #ifdef HAVE_INITGROUPS
990 if (NGROUPS_MAX
> 1 && initgroups (this->pw_name
, this->pw_gid
))
995 #if defined (HAVE_SETUID)
996 if (setuid (this->pw_uid
))
998 #elif defined (HAVE_SETREUID)
999 if (setreuid (this->pw_uid
, this->pw_uid
))
1003 /* If the setuid call failed, then deny access */
1004 /* This should fix the problem on those machines with strange setups */
1005 if (getuid () != this->pw_uid
)
1008 if (strcmp (username
, "ftp") == 0)
1009 chroot (this->pw_dir
);
1017 do_rauth (int socket
)
1019 struct sockaddr_in from
;
1022 if (getpeername (0, (struct sockaddr
*) &from
, &fromlen
) < 0)
1024 from
.sin_port
= ntohs ((unsigned short) from
.sin_port
);
1026 /* Strange, this should not happend */
1027 if (from
.sin_family
!= AF_INET
)
1030 hp
= gethostbyaddr ((char *) &fromp
.sin_addr
, sizeof (struct in_addr
),
1037 do_rauth (int msock
)
1043 login_reply (int logged_in
)
1045 rpc_send (msock
, RPC_INT
, logged_in
? MC_LOGINOK
: MC_INVALID_PASS
,
1049 /* FIXME: Implement the anonymous login */
1057 rpc_get (msock
, RPC_LIMITED_STRING
, &up_dir
, RPC_LIMITED_STRING
,
1058 &username
, RPC_END
);
1060 printf ("username: %s\n", username
);
1063 logged_in
= do_rauth (msock
);
1065 login_reply (logged_in
);
1069 rpc_send (msock
, RPC_INT
, MC_NEED_PASSWORD
, RPC_END
);
1070 rpc_get (msock
, RPC_INT
, &result
, RPC_END
);
1071 if (result
== MC_QUIT
)
1073 if (result
!= MC_PASS
) {
1075 printf ("do_login: Unknown response: %d\n", result
);
1078 rpc_get (msock
, RPC_LIMITED_STRING
, &password
, RPC_END
);
1079 logged_in
= do_auth (username
, password
);
1081 login_reply (logged_in
);
1086 /* {{{ Server and dispatching functions */
1088 /* This structure must be kept in synch with mcfs.h enums */
1090 static const struct _command
{
1092 void (*callback
) (void);
1096 "close", do_close
}, {
1098 "write", do_write
}, {
1099 "opendir", do_opendir
}, {
1100 "readdir", do_readdir
}, {
1101 "closedir", do_closedir
}, {
1102 "stat ", do_stat
}, {
1103 "lstat ", do_lstat
}, {
1104 "fstat", do_fstat
}, {
1105 "chmod", do_chmod
}, {
1106 "chown", do_chown
}, {
1107 "readlink ", do_readlink
}, {
1108 "unlink", do_unlink
}, {
1109 "rename", do_rename
}, {
1110 "chdir ", do_chdir
}, {
1111 "lseek", do_lseek
}, {
1112 "rmdir", do_rmdir
}, {
1113 "symlink", do_symlink
}, {
1114 "mknod", do_mknod
}, {
1115 "mkdir", do_mkdir
}, {
1117 "gethome", do_gethome
}, {
1118 "getupdir", do_getupdir
}, {
1119 "login", do_login
}, {
1121 "utime", do_utime
}};
1123 static int ncommands
= sizeof (commands
) / sizeof (struct _command
);
1126 exec_command (int command
)
1128 if (command
< 0 || command
>= ncommands
1129 || commands
[command
].command
== 0) {
1130 fprintf (stderr
, "Got unknown command: %d\n", command
);
1134 printf ("Command: %s\n", commands
[command
].command
);
1135 (*commands
[command
].callback
) ();
1139 check_version (void)
1143 rpc_get (msock
, RPC_INT
, &version
, RPC_END
);
1144 if (version
>= 1 && version
<= RPC_PROGVER
)
1145 rpc_send (msock
, RPC_INT
, MC_VERSION_OK
, RPC_END
);
1147 rpc_send (msock
, RPC_INT
, MC_VERSION_MISMATCH
, RPC_END
);
1149 clnt_version
= version
;
1152 /* This routine is called by rpc_get/rpc_send when the connection is closed */
1154 tcp_invalidate_socket (int sock
)
1157 printf ("Connection closed\n");
1171 if (rpc_get (sock
, RPC_INT
, &command
, RPC_END
)
1172 && (logged_in
|| command
== MC_LOGIN
))
1173 exec_command (command
);
1174 } while (!quit_server
);
1179 /* {{{ Net support code */
1182 get_client (int portnum
)
1184 int sock
, clilen
, newsocket
;
1185 struct sockaddr_in client_address
, server_address
;
1188 if ((sock
= socket (AF_INET
, SOCK_STREAM
, 0)) < 0)
1189 return "Cannot create socket";
1191 /* Use this to debug: */
1193 (sock
, SOL_SOCKET
, SO_REUSEADDR
, (char *) &yes
, sizeof (yes
)) < 0)
1194 return "setsockopt failed";
1196 memset ((char *) &server_address
, 0, sizeof (server_address
));
1197 server_address
.sin_family
= AF_INET
;
1198 server_address
.sin_addr
.s_addr
= htonl (INADDR_ANY
);
1199 server_address
.sin_port
= htons (portnum
);
1202 (sock
, (struct sockaddr
*) &server_address
,
1203 sizeof (server_address
)) < 0)
1204 return "Cannot bind";
1211 clilen
= sizeof (client_address
);
1213 accept (sock
, (struct sockaddr
*) &client_address
, &clilen
);
1215 if (isDaemon
&& (child
= fork ())) {
1219 waitpid (child
, &status
, 0);
1223 if (isDaemon
&& fork ())
1232 #ifdef HAVE_PMAP_SET
1234 signal_int_handler (int sig
)
1236 pmap_unset (RPC_PROGNUM
, RPC_PROGVER
);
1240 #ifndef IPPORT_RESERVED
1241 #define IPPORT_RESERVED 1024
1245 get_port_number (void)
1249 #ifdef HAVE_RRESVPORT
1250 int start_port
= IPPORT_RESERVED
;
1252 port
= rresvport (&start_port
);
1254 if (geteuid () == 0) {
1256 "Cannot bind the server on a reserved port\n");
1257 DO_QUIT_NONVOID (-1);
1265 port
= mcserver_port
;
1271 register_port (int portnum
, int abort_if_fail
)
1273 #ifdef HAVE_PMAP_SET
1274 /* Register our service with the portmapper */
1275 /* protocol: pmap_set (prognum, versnum, protocol, portp) */
1277 if (pmap_set (RPC_PROGNUM
, RPC_PROGVER
, IPPROTO_TCP
, portnum
))
1278 signal (SIGINT
, signal_int_handler
);
1280 fprintf (stderr
, "Cannot register service with portmapper\n");
1285 if (abort_if_fail
) {
1287 "This system lacks port registration, try using the -p\n"
1288 "flag to force installation at a given port");
1296 main (int argc
, char *argv
[])
1301 while ((c
= getopt (argc
, argv
, "fdiqp:v")) != -1) {
1321 portnum
= atoi (optarg
);
1334 "Usage is: mcserv [options] [-p portnum]\n\n"
1335 "options are:\n" "-d become a daemon (sets -q)\n"
1337 /* "-r use rhost based authentication\n" */
1339 "-f force ftp authentication\n"
1342 "-p to specify a port number to listen\n");
1348 if (isDaemon
&& fork ())
1352 portnum
= get_port_number ();
1354 if (portnum
!= -1) {
1355 register_port (portnum
, 0);
1357 printf ("Using port %d\n", portnum
);
1358 if ((result
= get_client (portnum
)))
1360 #ifdef HAVE_PMAP_SET
1362 pmap_unset (RPC_PROGNUM
, RPC_PROGVER
);
1368 /* FIXME: This function should not be used in mcserv */
1370 vfs_die (const char *m
)