@@ -278,27 +278,37 @@ static int send_facts(struct client_info *client, char *path, char *filename,
278
278
return -1 ;
279
279
280
280
char * type ;
281
+ char type_slink_buf [20 + PATH_MAX ];
281
282
if (client -> facts .type ) {
282
- if (S_ISDIR (statbuf .st_mode )) {
283
+ if (S_ISREG (statbuf .st_mode )) {
284
+ type = "type=file;" ;
285
+ } else if (S_ISDIR (statbuf .st_mode )) {
283
286
if (filename [0 ] == '.' && filename [1 ] == '\0' )
284
287
type = "type=cdir;" ;
285
288
else if (filename [0 ] == '.' && filename [1 ] == '.'
286
289
&& filename [2 ] == '\0' )
287
290
type = "type=pdir;" ;
288
291
else
289
292
type = "type=dir;" ;
290
- } else if (S_ISREG (statbuf .st_mode )) {
291
- type = "type=file;" ;
292
293
} else if (S_ISLNK (statbuf .st_mode )) {
293
- type = "type=os.unix=slink;" ;
294
+ type = "type=OS.unix=slink:" ;
295
+ strcpy (type_slink_buf , type );
296
+ int ret = readlink (path , type_slink_buf + strlen (type ), PATH_MAX );
297
+ if (ret < 0 || ret == PATH_MAX ) {
298
+ debug_retval (ret );
299
+ strcpy (type_slink_buf + strlen (type ) - 1 , ";" );
300
+ } else {
301
+ strcpy (type_slink_buf + strlen (type ) + ret , ";" );
302
+ }
303
+ type = type_slink_buf ;
294
304
} else if (S_ISCHR (statbuf .st_mode )) {
295
- type = "type=os .unix=cdevice;" ;
305
+ type = "type=OS .unix=cdevice;" ;
296
306
} else if (S_ISBLK (statbuf .st_mode )) {
297
- type = "type=os .unix=bdevice;" ;
307
+ type = "type=OS .unix=bdevice;" ;
298
308
} else if (S_ISFIFO (statbuf .st_mode )) {
299
- type = "type=os .unix=fifo;" ;
309
+ type = "type=OS .unix=fifo;" ;
300
310
} else if (S_ISSOCK (statbuf .st_mode )) {
301
- type = "type=os .unix=socket;" ;
311
+ type = "type=OS .unix=socket;" ;
302
312
} else {
303
313
type = "type=file;" ;
304
314
}
@@ -541,30 +551,38 @@ static void cmd_CWD(struct client_info *client)
541
551
{
542
552
if (strcmp (client -> cmd_args , ".." ) == 0 ) {
543
553
if (dir_up (client ))
544
- send_ctrl_msg ( client , RC_550 ) ;
554
+ goto reject ;
545
555
else
546
- send_ctrl_msg (client , RC_250 );
547
- return ;
556
+ goto accept ;
548
557
}
549
558
if (strcmp (client -> cmd_args , "." ) == 0 )
550
559
client -> cmd_args = client -> cur_path ;
551
560
552
561
char path [PATH_MAX ];
553
- if (gen_ftp_path (path , sizeof (path ), client , client -> cmd_args )) {
554
- send_ctrl_msg (client , RC_550 );
555
- return ;
556
- }
562
+ if (gen_ftp_path (path , sizeof (path ), client , client -> cmd_args ))
563
+ goto reject ;
557
564
558
565
#ifdef PS4
559
- if (ftp_file_exists (path )) {
566
+ if (! ftp_file_exists (path ))
560
567
#else
561
- if (access (path , R_OK ) == 0 ) {
568
+ if (access (path , R_OK ) != 0 )
562
569
#endif
563
- strncpy (client -> cur_path , path , sizeof (client -> cur_path ));
564
- send_ctrl_msg (client , RC_250 );
565
- } else {
566
- send_ctrl_msg (client , RC_550 );
567
- }
570
+ goto reject ;
571
+
572
+ struct stat st ;
573
+ int ret = stat (path , & st );
574
+ if (ret || !S_ISDIR (st .st_mode ))
575
+ goto reject ;
576
+
577
+ strncpy (client -> cur_path , path , sizeof (client -> cur_path ));
578
+ goto accept ;
579
+
580
+ reject :
581
+ send_ctrl_msg (client , RC_550 );
582
+ return ;
583
+
584
+ accept :
585
+ send_ctrl_msg (client , RC_250 );
568
586
}
569
587
570
588
// DELE (Delete) "DELE <SP> <pathname> <CRLF>" ---------------------------------
0 commit comments