Magellan Linux

Diff of /trunk/mkinitrd-magellan/busybox/networking/isrv_identd.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 532 by niro, Sat Sep 1 22:45:15 2007 UTC revision 816 by niro, Fri Apr 24 18:33:46 2009 UTC
# Line 2  Line 2 
2  /*  /*
3   * Fake identd server.   * Fake identd server.
4   *   *
5   * Copyright (C) 2007 Denis Vlasenko   * Copyright (C) 2007 Denys Vlasenko
6   *   *
7   * Licensed under GPL version 2, see file LICENSE in this tarball for details.   * Licensed under GPL version 2, see file LICENSE in this tarball for details.
8   */   */
9    
10    #include "libbb.h"
11  #include <syslog.h>  #include <syslog.h>
 #include "busybox.h"  
12  #include "isrv.h"  #include "isrv.h"
13    
14  enum { TIMEOUT = 20 };  enum { TIMEOUT = 20 };
# Line 19  typedef struct identd_buf_t { Line 19  typedef struct identd_buf_t {
19   char buf[64 - 2*sizeof(int)];   char buf[64 - 2*sizeof(int)];
20  } identd_buf_t;  } identd_buf_t;
21    
22  static const char *bogouser = "nobody";  #define bogouser bb_common_bufsiz1
23    
24  static int new_peer(isrv_state_t *state, int fd)  static int new_peer(isrv_state_t *state, int fd)
25  {  {
# Line 32  static int new_peer(isrv_state_t *state, Line 32  static int new_peer(isrv_state_t *state,
32   if (isrv_register_fd(state, peer, fd) < 0)   if (isrv_register_fd(state, peer, fd) < 0)
33   return peer; /* failure, unregister peer */   return peer; /* failure, unregister peer */
34    
35   buf->fd_flag = fcntl(fd, F_GETFL, 0) | O_NONBLOCK;   buf->fd_flag = fcntl(fd, F_GETFL) | O_NONBLOCK;
36   isrv_want_rd(state, fd);   isrv_want_rd(state, fd);
37   return 0;   return 0;
38  }  }
# Line 61  static int do_rd(int fd, void **paramp) Line 61  static int do_rd(int fd, void **paramp)
61   p = strpbrk(cur, "\r\n");   p = strpbrk(cur, "\r\n");
62   if (p)   if (p)
63   *p = '\0';   *p = '\0';
64   if (!p && sz && buf->pos <= sizeof(buf->buf))   if (!p && sz && buf->pos <= (int)sizeof(buf->buf))
65   goto ok;   goto ok;
66   /* Terminate session. If we are in server mode, then   /* Terminate session. If we are in server mode, then
67   * fd is still in nonblocking mode - we never block here */   * fd is still in nonblocking mode - we never block here */
# Line 76  static int do_rd(int fd, void **paramp) Line 76  static int do_rd(int fd, void **paramp)
76   return retval;   return retval;
77  }  }
78    
79  static int do_timeout(void **paramp)  static int do_timeout(void **paramp UNUSED_PARAM)
80  {  {
81   return 1; /* terminate session */   return 1; /* terminate session */
82  }  }
# Line 92  static void inetd_mode(void) Line 92  static void inetd_mode(void)
92   while (do_rd(0, (void*)&buf) == 0);   while (do_rd(0, (void*)&buf) == 0);
93  }  }
94    
95  int fakeidentd_main(int argc, char **argv)  int fakeidentd_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
96    int fakeidentd_main(int argc UNUSED_PARAM, char **argv)
97  {  {
98   enum {   enum {
99   OPT_foreground = 0x1,   OPT_foreground = 0x1,
# Line 106  int fakeidentd_main(int argc, char **arg Line 107  int fakeidentd_main(int argc, char **arg
107   unsigned opt;   unsigned opt;
108   int fd;   int fd;
109    
110   opt = getopt32(argc, argv, "fiwb:", &bind_address);   opt = getopt32(argv, "fiwb:", &bind_address);
111   if (optind < argc)   strcpy(bogouser, "nobody");
112   bogouser = argv[optind];   if (argv[optind])
113     strncpy(bogouser, argv[optind], sizeof(bogouser));
114    
115   /* Daemonize if no -f and no -i and no -w */   /* Daemonize if no -f and no -i and no -w */
116   bb_sanitize_stdio_maybe_daemonize(!(opt & OPT_fiw));   if (!(opt & OPT_fiw))
117     bb_daemonize_or_rexec(0, argv);
118    
119   /* Where to log in inetd modes? "Classic" inetd   /* Where to log in inetd modes? "Classic" inetd
120   * probably has its stderr /dev/null'ed (we need log to syslog?),   * probably has its stderr /dev/null'ed (we need log to syslog?),
121   * but daemontools-like utilities usually expect that children   * but daemontools-like utilities usually expect that children

Legend:
Removed from v.532  
changed lines
  Added in v.816