【 在 Leeward (5% completed★Y2K:PP) 的大作中提到: 】
: o 那你方便的话帮帮wxb1吧,最好再POST讲讲如何修改的:-)
hehe.. 可以是可以,不过wxb1问题好象是出在hztty
以下是混和大法.. 有点混乱,可别介意
$diff newhztty/main.c hztty/main.c
44d43
< #include "bbs.h"
46,85d44
< #if defined(SOLARIS) || defined(IRIX)
< #define USE_UTMPX
< #include <utmpx.h>
< #else
< #define USE_UTMP
< #include <utmp.h>
< #endif
<
< #ifdef SYSV
< #include <sys/utsname.h>
< #endif
<
< #include <pwd.h>
<
< /*----- For rstat(), getting load average ---*/
< #if defined(BSD44)
< #include <stdlib.h>
<
< #elif defined(LINUX)
< /* include nothing :-) */
< #else
<
< #include <rpcsvc/rstat.h>
< #endif
< /*-----------------------------------------------*/
<
< #ifdef BBSRF_DEBUG
< #define RF_DEBUG(str) puts( str )
< #else
< #define RF_DEBUG(str) {}
< #endif
<
< #ifdef BSD44
< #define UTMP_PATH "/var/run/utmp"
< #elif defined (LINUX)
< #define UTMP_PATH "/var/run/utmp"
< #else
< #define UTMP_PATH "/etc/utmp"
< #endif
<
114,117d72
< int max_load = 5;
< char bbs_prog_path[ 256 ];
<
<
132,133d86
< char *ttyname();
<
142,149d94
< #ifdef USE_UTMPX
< struct utmpx *
< invis()
< {
< static struct utmpx data ;
< FILE *fp ;
< char *name, *tp ;
< struct passwd *pp ;
151,307d95
< tp = ttyname(0) ;
< if(!tp)
< return NULL ;
< tp = strchr(tp,'/') + 1 ;
< tp = strchr(tp,'/') + 1;
< tp = strchr(tp,'/') + 1;
< pp = getpwuid(getuid()) ;
< if(!pp)
< {
< fprintf(stderr,"You Don't exist!\n") ;
< exit(0) ;
< }
< name = pp->pw_name ;
<
< #ifdef INVISIBLE
< if((fp = fopen(UTMPX_FILE,"r+")) == NULL) {
< #else
< if((fp = fopen(UTMPX_FILE,"r")) == NULL) {
< #endif
< printf("Cannot open %s \n", UTMPX_FILE );
< exit(0) ;
< }
<
< while(read(fileno(fp),&data,sizeof(struct utmpx))>0)
< {
< if(data.ut_type != DEAD_PROCESS && !strcmp(tp,data.ut_line))
< {
< struct utmpx nildata ;
< memcpy(&nildata, &data, sizeof(nildata)) ;
< #ifdef INVISIBLE
< memset(nildata.ut_name,0,8) ;
< fseek(fp,(long)(ftell(fp) - sizeof(struct utmpx)),0) ;
< if(write(fileno(fp),&nildata,sizeof(struct utmpx)) !=
sizeof(struct utmpx))
< /* NIL IF STATEMENT */ ;
< #endif
< fclose(fp) ;
< return &data ;
< }
< }
< fclose(fp) ;
< return NULL ;
< }
< #endif
<
< #ifdef USE_UTMP
< struct utmp *
< invis()
< {
< static struct utmp data ;
< FILE *fp ;
< char *tp ;
< struct passwd *pp ;
<
< tp = ttyname(0) ;
< if(!tp)
< return NULL ;
< tp = strrchr(tp,'/') + 1 ;
< pp = getpwuid(getuid()) ;
< if(!pp)
< {
< fprintf(stderr,"You Don't exist!\n") ;
< exit(0) ;
< }
<
< #ifdef INVISIBLE
< if((fp = fopen(UTMP_PATH,"r+")) == NULL) {
< #else
< if((fp = fopen(UTMP_PATH,"r")) == NULL) {
< #endif
< printf("bbsrf: cannot open %s\n", UTMP_PATH);
< exit(0) ;
< }
<
< while(read(fileno(fp),&data,sizeof(struct utmp))>0)
< {
< if(!strcmp(tp,data.ut_line))
< {
< struct utmp nildata ;
< memcpy( &nildata, &data, sizeof(nildata)) ;
< #ifdef INVISIBLE
< memset(nildata.ut_name,0,8) ;
< fseek(fp,(long)(ftell(fp) - sizeof(struct utmp)),0) ;
< write( fileno(fp), &nildata, sizeof(struct utmp) );
< #endif
< fclose(fp) ;
< return &data ;
< }
< }
< fclose(fp) ;
< return NULL ;
< }
< #endif
<
< void
< get_load( load )
< double load[];
< {
< #if defined(LINUX)
< FILE *fp;
< fp = fopen ("/proc/loadavg", "r");
< if (!fp) load[0] = load[1] = load[2] = 0;
< else {
< float av[3];
< fscanf (fp, "%g %g %g", av, av + 1, av + 2);
< fclose (fp);
< load[0] = av[0]; load[1] = av[1]; load[2] = av[2];
< }
< #elif defined(BSD44)
< getloadavg( load, 3 );
< #else
< struct statstime rs;
< rstat( "localhost", &rs );
< load[ 0 ] = rs.avenrun[ 0 ] / (double) (1 << 8);
< load[ 1 ] = rs.avenrun[ 1 ] / (double) (1 << 8);
< load[ 2 ] = rs.avenrun[ 2 ] / (double) (1 << 8);
< #endif
< }
<
< char *env[] = {
< "TERM=xxxxxxxxxxxxxxxxxxxxxxxxxxx",
< NULL} ;
<
< void
< set_max_load( prog_name )
< char *prog_name;
< {
< char *p;
<
< p = strrchr( prog_name, '.' );
<
< if ( p && *(p+1) != '\0' ) max_load = atoi( p+1 );
< }
<
< int
< check_ban_site( char *addr )
< {
< FILE *fp;
< char temp[STRLEN];
<
< if((fp = fopen( ".bansite", "r" )) != NULL )
< {
< while( fgets(temp,STRLEN,fp) != NULL)
< {
< strtok(temp," \n");
< if ((!strncmp(addr,temp,16))
< ||(!strncmp(temp,addr,strlen(temp)) && temp[strlen(temp) - 1] == '.
')
< ||(temp[0] == '.' && strstr(addr,temp)!=NULL))
< {
< fclose(fp);
< return 1;
< }
< }
< fclose(fp);
< }
< return 0;
< }
<
< int
316d103
< int uid;
318a106,132
> while ((ch = getopt(argc, argv, "I:O:T:ludh")) != EOF)
> switch(ch) {
> case 'I':
> i_stream = optarg;
> break;
> case 'O':
> o_stream = optarg;
> break;
> case 'T':
> term = optarg;
> break;
> case 'l':
> loginsh = 1;
> break;
> case 'u':
> utmp = 0; /* disable utmp */
> break;
> case 'd':
> debug = 1;
> break;
> case 'h':
> case '?':
> default:
> usage();
> }
> argc -= optind;
> argv += optind;
321,322c135,136
< i_stream = "big2gb" ;
< o_stream = "gb2big" ;
---
> i_stream = DEF_ISTREAM;
> o_stream = DEF_OSTREAM;
324c138
< /*
---
>
333d146
<
336,337d148
< */
< set_max_load( argv[ 0 ] );
339,384d149
< uid = getuid() ;
<
< if(uid == BBSUID) { /* bbs uid */
<
< #ifdef USE_UTMP
< struct utmp *whee ;
< #endif
< #ifdef USE_UTMPX
< struct utmpx *whee ;
< #endif
<
< char hid[17] ;
<
<
< /* load control for BBS */
< /*#ifdef LOAD_LIMIT */
< {
< double cpu_load[ 3 ];
< int load ;
<
< get_load( cpu_load );
< load = cpu_load[ 0 ];
< printf("BBS 程 (1,10,15) だ牧キА璽颤だ %.2f, %.2f, %.2f (ヘ玡
= %d).\n\n",
< cpu_load[ 0 ], cpu_load[ 1 ], cpu_load[ 2 ], max_load );
<
< if ( load < 0 || load > max_load ) {
< printf("╆簆,ヘ玡╰参璽颤筁, 叫祔ㄓ\n");
< sleep( load );
< exit( -1 );
< }
< }
< /*#endif*/
< /* ppfoong */
< {
< char buf[256];
< FILE *fp;
<
< if((fp = fopen("NOLOGIN","r")) != NULL) {
< while(fgets(buf,256,fp) != NULL)
< printf(buf);
< fclose(fp);
< sleep(3);
< exit(-1);
< }
< }
<
406,472c171
<
< /* hehehehe */
<
< RF_DEBUG("Before invis....");
< whee = invis() ;
<
< RF_DEBUG("Before Chroot....");
<
< #ifdef BBSRF_CHROOT
< sprintf( bbs_prog_path, "/bin/bbs", BBSHOME );
< if (chroot(BBSHOME) != 0) {
< printf("Cannot chroot, exit!\n");
< exit( -1 );
< }
< #else
< sprintf( bbs_prog_path, "%s/bin/bbs", BBSHOME );
< #endif
<
< RF_DEBUG("Before setuid....");
< setuid(uid) ;
<
< doshell();
<
< if (whee) {
< char ttybuf[ 16 ];
< char *tp;
<
< RF_DEBUG("Before ttyname (whee)....");
< tp = ttyname( 0 );
< strcpy( ttybuf,(tp==NULL) ? "/dev/ttyp0" : tp );
<
< if (whee->ut_host[0]) strncpy(hid, whee->ut_host, 16) ;
< else
< #ifdef SYSV
< {
< struct utsname name;
< if (uname( &name ) >= 0) strcpy(hid, name.nodename);
< else strcpy(hid, "localhost");
< }
< #else
< gethostname(hid, 16);
< #endif
<
< hid[16] = '\0' ;
<
< if (check_ban_site(hid))
< exit(-1);
< RF_DEBUG("Before execl (whee)....");
<
<
< execl( bbs_prog_path,"bbs","h", hid, ttybuf, NULL) ;
< perror (bbs_prog_path);
< fail();
<
< } else {
< RF_DEBUG("Before execl (not whee)....");
<
< execl( bbs_prog_path,"bbs","h", "unknown", "notty", NULL) ;
< }
< perror (bbs_prog_path);
< fail();
<
< printf("execl failed\n") ;
< exit( -1 );
<
< /* hehehehehe */
<
---
> doshell();
481,486d179
< }
<
< setuid(uid) ;
< printf("UID DOES NOT MATCH\n") ;
< exit(-1) ;
< return -1;
560a254,255
> printf ("[%s started] [using %s]\n", progname, ttyname(0));
> sleep(1);
562a258,261
> execvp (cmd, cmdargv);
>
> perror (cmd);
> fail();
609a309
> printf ("\n[%s exited]\n", progname);
--
FROM 202.119.144.4