Esempio n. 1
0
void 
u_exit(char *mode)
{
	extern void	auto_backup();	/* 編輯器自動備份 */
	userec		xuser;
	int		diff = (time(0) - login_start_time) / 60;

	rec_get(fn_passwd, &xuser, sizeof(xuser), usernum);
	auto_backup();
	setflags(PAGER_FLAG, currutmp->pager != 1);
	setflags(CLOAK_FLAG, currutmp->invisible);
	xuser.pager = currutmp->pager;	/* 記錄pager狀態, add by wisely */
	xuser.invisible = currutmp->invisible;	/* 紀錄隱形狀態 by wildcat */
	xuser.totaltime += time(0) - update_time;
	xuser.numposts = cuser.numposts;
	xuser.feeling[4] = '\0';

	if (!HAS_PERM(PERM_DENYPOST) && !currutmp->invisible) {
		char		buf       [256];
		time_t		now;

		time(&now);
		sprintf(buf, "<<下站通知>> -- 我走囉! - %s", Etime(&now));
		do_aloha(buf);
	}
	purge_utmp(currutmp);
	if (!diff && cuser.numlogins > 1 && strcmp(cuser.userid, STR_GUEST))
		xuser.numlogins = --cuser.numlogins;	/* Leeym 上站停留時間限制式 */
	substitute_record(fn_passwd, &xuser, sizeof(userec), usernum);
	log_usies(mode, NULL);
}
Esempio n. 2
0
void u_exit(char *mode) {
    userec_t xuser;
    int diff = (time(0) - login_start_time) / 60;

    passwd_query(usernum, &xuser);
    
    auto_backup();
    
    setflags(PAGER_FLAG, currutmp->pager != 1);
    setflags(CLOAK_FLAG, currutmp->invisible);
    
    xuser.invisible = currutmp->invisible % 2;
    xuser.pager = currutmp->pager % 5;
    
    if(!(HAS_PERM(PERM_SYSOP) && HAS_PERM(PERM_DENYPOST)))
	do_aloha("<<下站通知>> -- 我走囉!");
    
    purge_utmp(currutmp);
    if((cuser.uflag != enter_uflag) || (currmode & MODE_DIRTY) || !diff) {
	xuser.uflag = cuser.uflag;
	xuser.numposts = cuser.numposts;
	if(!diff && cuser.numlogins)
	    xuser.numlogins = --cuser.numlogins; /* Leeym 上站停留時間限制式 */
	reload_money();
	passwd_update(usernum, &xuser);
    }
    log_usies(mode, NULL);
}
Esempio n. 3
0
struct searchNode *cumodecount_parse(searchCtx *ctx, int argc, char **argv) {
  struct cumodecount_localdata *localdata;
  struct searchNode *thenode, *flagstr;
  flag_t fset, fclear;
  char *p;

  if (argc!=1) {
    parseError="cumodes: usage: cumodecount (mode string)";
    return NULL;
  }

  if (!(localdata=(struct cumodecount_localdata *)malloc(sizeof(struct cumodecount_localdata)))) {
    parseError = "malloc: could not allocate memory for this search.";
    return NULL;
  }

  fset=0;
  fclear=~0;

  if (!(flagstr=argtoconststr("cumodecount", ctx, argv[0], &p))) {
    localdata->xnode->free(ctx, localdata->xnode);
    free(localdata);
    return NULL;
  }

  setflags(&(fset), CU_ALL, p, cumodecountlist, REJECT_NONE);
  setflags(&(fclear), CU_ALL, p, cumodecountlist, REJECT_NONE);
  flagstr->free(ctx, flagstr);

  localdata->setmodes=0;
  localdata->clearmodes=~0;

  if(fset & CU_OP)
    localdata->setmodes|=CUMODE_OP;
  if(fset & CU_VOICE)
    localdata->setmodes|=CUMODE_VOICE;
  if(!(fclear & CU_OP))
    localdata->clearmodes&=~CUMODE_OP;
  if(!(fclear & CU_VOICE))
    localdata->clearmodes&=~CUMODE_VOICE;

  localdata->clearmodes = ~(localdata->clearmodes);
  
  if (!(thenode=(struct searchNode *)malloc(sizeof(struct searchNode)))) {
    /* couldn't malloc() memory for thenode, so free localdata to avoid leakage */
    parseError = "malloc: could not allocate memory for this search.";
    free(localdata);
    return NULL;
  }

  thenode->returntype  = RETURNTYPE_INT;
  thenode->localdata   = (void *)localdata;
  thenode->exe         = cumodecount_exe;
  thenode->free        = cumodecount_free;

  return thenode;
}
Esempio n. 4
0
u_int64_t cs_accountflagmap_str(char *flags) {
  reguser r2, *r = &r2;

  setflags(&r->flags, QUFLAG_ALL, flags, ruflags, REJECT_NONE);

  return cs_accountflagmap(r);
}
Esempio n. 5
0
int main(int argc, char** argv) {

    std::vector<float> myData;
    char filename[100];

    if(argc < 2 )
    {
        usage();
        return EXIT_SUCCESS;
    }

    setflags(argc, argv, filename);
    if(flag & INPUT_FILE) {
        std::cout <<"File: "<< filename << std::endl;
        myData = readVectorFromFile(filename);
        if(flag & PRINTINPUT) {
            std::cout << "Input: "<<std::endl;
            for(std::vector<float>::const_iterator it = myData.begin();
                it != myData.end(); ++it)
                std::cout << *it << std::endl;
        }

        int start_s = clock();
        if(flag & BUBBLESORT)
        {
            std::cout << "Bubble Sort" << std::endl;
            algos::MergeSort al;
            al.sort(myData.begin(), myData.end());
            al.show(myData.begin(), myData.end());
        }

        if(flag & MERGESORT)
        {
            std::cout << "Merge Sort" << std::endl;
            algos::BubbleSort al;
            al.sort(myData.begin(), myData.end());
            al.show(myData.begin(), myData.end());
        }

        if(flag & INSERTIONSORT)
        {
            std::cout << "Insertion Sort" << std::endl;
            algos::InsertionSort al;
            al.sort(myData.begin(), myData.end());
            al.show(myData.begin(), myData.end());
        }
        std::cout<<"time: " << (clock() - start_s)/double(CLOCKS_PER_SEC)*1000 <<std::endl;
    }

    return EXIT_SUCCESS;
}
Esempio n. 6
0
struct searchNode *qchanflags_parse(searchCtx *ctx, int argc, char **argv) {
  struct searchNode *thenode;
  struct qchanflags_localdata *localdata;

  if (!(thenode=(struct searchNode *)malloc(sizeof (struct searchNode)))) {
    parseError = "malloc: could not allocate memory for this search.";
    return NULL;
  }

  thenode->localdata=localdata=malloc(sizeof(struct qchanflags_localdata));
  thenode->returntype = RETURNTYPE_INT;
  thenode->exe = qchanflags_exe;
  thenode->free = qchanflags_free;

  if (argc==0) {
    localdata->setmodes=0;
    localdata->clearmodes=0;
  } else {
    struct searchNode *arg;
    char *p;

    localdata->setmodes=0;
    localdata->clearmodes=~0;

    if (!(arg=argtoconststr("qchanflags", ctx, argv[0], &p))) {
      free(thenode);
      return NULL;
    }

    setflags(&(localdata->setmodes), QCFLAG_ALL, p, rcflags, REJECT_NONE);
    setflags(&(localdata->clearmodes), QCFLAG_ALL, p, rcflags, REJECT_NONE);
    arg->free(ctx, arg);

    localdata->clearmodes = ~localdata->clearmodes;
  }

  return thenode;
}
Esempio n. 7
0
int rapl_storage(struct rapl_data **data, uint64_t **flags)
{
    static struct rapl_data *rapl = NULL;
    static uint64_t *rapl_flags = NULL;
    static uint64_t sockets = 0;
    static int init = 0;

#ifdef STORAGE_DEBUG
    fprintf(stderr, "%s %s::%d DEBUG: (rapl_storage) data pointer is %p, flags pointer is %p, data is at %p, flags are %lx at %p\n", getenv("HOSTNAME"), __FILE__, __LINE__, data, flags, rapl, (rapl_flags ? *rapl_flags : 0), rapl_flags);
#endif

    if (!init)
    {
        init = 1;
        sockets = num_sockets();

        rapl = (struct rapl_data *) libmsr_malloc(sockets * sizeof(struct rapl_data));
        rapl_flags = (uint64_t *) libmsr_malloc(sizeof(uint64_t));

        if (setflags(rapl_flags))
        {
            return -1;
        }
        if (data != NULL)
        {
            *data = rapl;
        }
        if (flags != NULL)
        {
            *flags = rapl_flags;
        }
#ifdef LIBMSR_DEBUG
        fprintf(stderr, "%s %s::%d DEBUG: (storage) initialized rapl data at %p, flags are %lx, (flags at %p, rapl_flags at %p\n", getenv("HOSTNAME"), __FILE__, __LINE__, rapl, **flags, flags, rapl_flags);
        fprintf(stderr, "DEBUG: socket 0 has pkg_bits at %p\n", &rapl[0].pkg_bits);
#endif
        return 0;
    }
    /* If the data pointer is not null, it should point to the rapl array. */
    if (data != NULL)
    {
        *data = rapl;
    }
    /* if the flags pointer is not null, it should point to the rapl flags. */
    if (flags != NULL)
    {
        *flags = rapl_flags;
    }
    return 0;
}
Esempio n. 8
0
int main(int argc, char **argv)
{
	get_shells();
	setflags(argc,argv);
	proc *ps[10000];
	proc_structs = ps;
	if (unique_uids)
	{
		int uidstr[10000];
		uuids = uidstr;
		int i = 10000;
		while(i--) uuids[i] = -1;
	}

	DIR *dp;
	struct dirent *ep;
	psinfo_t psinfo_buf;
	dp = opendir ("/proc");
	char buf[128];
	if (dp != NULL)
	{
		printf("%8s ","UID");
		if(unique_uids) printf("\n");
		else
		{
			if(pid) printf("%5s ","PID");
			if(descendants) printf("%4s ","N");
			printf("%16s %.24s\n","FNAME","STIME");
		}

		while ((ep = readdir(dp)))
		{
			if(ep->d_name[0] >= '0' && ep->d_name[0] <= '9')
			{
				sprintf(buf,"/proc/%s/psinfo",ep->d_name);
				save_procinfo(buf,&psinfo_buf);
				//print_procinfo(buf,&psinfo_buf);
			}
		}

		(void)closedir(dp);
	}
	else perror ("Couldn't open the directory");	
	compute_descendants();
	proc *p;int i = 0;
	while ((p = proc_structs[i++])) print_procinfo(p);

	return 0;
}
Esempio n. 9
0
XCH_STATUS _IDB_XCH::status( XCH_STATUS status, XCH_ERRORCODE errorcode, uint16_t notifycode )
{
	lock.lock();

	XCH_STATUS cur_status = xch_status;

	if( cur_status != XCH_STATUS_DEAD )
	{
		cur_status = xch_status = status;
		xch_errorcode = errorcode;
		xch_notifycode = notifycode;

		if( status == XCH_STATUS_DEAD )
			setflags( ENTRY_FLAG_DEAD );
	}

	lock.unlock();

	return cur_status;
}
Esempio n. 10
0
// Save user info on exit.
void u_exit(void)
{
	// 这些信号的处理要关掉, 否则在离线时等候回车时出现
	// 信号会导致重写名单, 这个导致的名单混乱比kick user更多  (ylsdd)
	fb_signal(SIGALRM, SIG_DFL);
	fb_signal(SIGPIPE, SIG_DFL);
	fb_signal(SIGTERM, SIG_DFL);
	fb_signal(SIGUSR1, SIG_IGN);
	fb_signal(SIGUSR2, SIG_IGN);

	if (HAS_PERM(PERM_LOGINCLOAK))
		setflags(CLOAK_FLAG, !session_visible());

	set_safe_record();
	update_user_stay(&currentuser, false, false);
	substitut_record(PASSFILE, &currentuser, sizeof(currentuser), usernum);
	uidshm->status[usernum - 1]--;

	session_destroy(session_id());
	session_set_pid(0);
}
Esempio n. 11
0
static inline void cpuParse(unsigned char opc) {
	int cmd = opcodes[opc];
	int addr = modes[opc];
	int c;
	switch (cmd) {
	case adc:
		wval=(unsigned short)a+getaddr(addr)+((p&FLAG_C)?1:0);
		setflags(FLAG_C, wval&0x100);
		a=(unsigned char)wval;
		setflags(FLAG_Z, !a);
		setflags(FLAG_N, a&0x80);
		setflags(FLAG_V, (!!(p&FLAG_C)) ^ (!!(p&FLAG_N)));
		break;
	case and_:
		bval=getaddr(addr);
		a&=bval;
		setflags(FLAG_Z, !a);
		setflags(FLAG_N, a&0x80);
		break;
	case asl:
		wval=getaddr(addr);
		wval<<=1;
		setaddr(addr,(unsigned char)wval);
		setflags(FLAG_Z,!wval);
		setflags(FLAG_N,wval&0x80);
		setflags(FLAG_C,wval&0x100);
		break;
	case bcc:
		branch(!(p&FLAG_C));
		break;
	case bcs:
		branch(p&FLAG_C);
		break;
	case bne:
		branch(!(p&FLAG_Z));
		break;
	case beq:
		branch(p&FLAG_Z);
		break;
	case bpl:
		branch(!(p&FLAG_N));
		break;
	case bmi:
		branch(p&FLAG_N);
		break;
	case bvc:
		branch(!(p&FLAG_V));
		break;
	case bvs:
		branch(p&FLAG_V);
		break;
	case bit:
		bval=getaddr(addr);
		setflags(FLAG_Z,!(a&bval));
		setflags(FLAG_N,bval&0x80);
		setflags(FLAG_V,bval&0x40);
		break;
	case brk:
		pc=0;	/* Just quit the emulation */
		break;
	case clc:
		setflags(FLAG_C,0);
		break;
	case cld:
		setflags(FLAG_D,0);
		break;
	case cli:
		setflags(FLAG_I,0);
		break;
	case clv:
		setflags(FLAG_V,0);
		break;
	case cmp:
		bval=getaddr(addr);
		wval=(unsigned short)a-bval;
		setflags(FLAG_Z,!wval);
		setflags(FLAG_N,wval&0x80);
		setflags(FLAG_C,a>=bval);
		break;
	case cpx:
		bval=getaddr(addr);
		wval=(unsigned short)x-bval;
		setflags(FLAG_Z,!wval);
		setflags(FLAG_N,wval&0x80);
		setflags(FLAG_C,x>=bval);
		break;
	case cpy:
		bval=getaddr(addr);
		wval=(unsigned short)y-bval;
		setflags(FLAG_Z,!wval);
		setflags(FLAG_N,wval&0x80);
		setflags(FLAG_C,y>=bval);
		break;
	case dec:
		bval=getaddr(addr);
		bval--;
		setaddr(addr,bval);
		setflags(FLAG_Z,!bval);
		setflags(FLAG_N,bval&0x80);
		break;
	case dex:
		x--;
		setflags(FLAG_Z,!x);
		setflags(FLAG_N,x&0x80);
		break;
	case dey:
		y--;
		setflags(FLAG_Z,!y);
		setflags(FLAG_N,y&0x80);
		break;
	case eor:
		bval=getaddr(addr);
		a^=bval;
		setflags(FLAG_Z,!a);
		setflags(FLAG_N,a&0x80);
		break;
	case inc:
		bval=getaddr(addr);
		bval++;
		setaddr(addr,bval);
		setflags(FLAG_Z,!bval);
		setflags(FLAG_N,bval&0x80);
		break;
	case inx:
		x++;
		setflags(FLAG_Z,!x);
		setflags(FLAG_N,x&0x80);
		break;
	case iny:
		y++;
		setflags(FLAG_Z,!y);
		setflags(FLAG_N,y&0x80);
		break;
	case jmp:
		wval=getmem(pc++);
		wval|=256*getmem(pc++);
		switch (addr) {
		case abs:
			pc=wval;
			break;
		case ind:
			pc=getmem(wval);
			pc|=256*getmem(wval+1);
			break;
		}
		break;
	case jsr:
		push((pc+1)>>8);
		push((pc+1));
		wval=getmem(pc++);
		wval|=256*getmem(pc++);
		pc=wval;
		break;
	case lda:
		a=getaddr(addr);
		setflags(FLAG_Z,!a);
		setflags(FLAG_N,a&0x80);
		break;
	case ldx:
		x=getaddr(addr);
		setflags(FLAG_Z,!x);
		setflags(FLAG_N,x&0x80);
		break;
	case ldy:
		y=getaddr(addr);
		setflags(FLAG_Z,!y);
		setflags(FLAG_N,y&0x80);
		break;
	case lsr:
		bval=getaddr(addr); wval=(unsigned char)bval;
		wval>>=1;
		setaddr(addr,(unsigned char)wval);
		setflags(FLAG_Z,!wval);
		setflags(FLAG_N,wval&0x80);
		setflags(FLAG_C,bval&1);
		break;
	case nop:
		break;
	case ora:
		bval=getaddr(addr);
		a|=bval;
		setflags(FLAG_Z,!a);
		setflags(FLAG_N,a&0x80);
		break;
	case pha:
		push(a);
		break;
	case php:
		push(p);
		break;
	case pla:
		a=pop();
		setflags(FLAG_Z,!a);
		setflags(FLAG_N,a&0x80);
		break;
	case plp:
		p=pop();
		break;
	case rol:
		bval=getaddr(addr);
		c=!!(p&FLAG_C);
		setflags(FLAG_C,bval&0x80);
		bval<<=1;
		bval|=c;
		setaddr(addr,bval);
		setflags(FLAG_N,bval&0x80);
		setflags(FLAG_Z,!bval);
		break;
	case ror:
		bval=getaddr(addr);
		c=!!(p&FLAG_C);
		setflags(FLAG_C,bval&1);
		bval>>=1;
		bval|=128*c;
		setaddr(addr,bval);
		setflags(FLAG_N,bval&0x80);
		setflags(FLAG_Z,!bval);
		break;
	case rti:
		/* Treat RTI like RTS */
	case rts:
		wval=pop();
		wval|=pop()<<8;
		pc=wval+1;
		break;
	case sbc:
		bval=getaddr(addr)^0xff;
		wval=(unsigned short)a+bval+((p&FLAG_C)?1:0);
		setflags(FLAG_C, wval&0x100);
		a=(unsigned char)wval;
		setflags(FLAG_Z, !a);
		setflags(FLAG_N, a>127);
		setflags(FLAG_V, (!!(p&FLAG_C)) ^ (!!(p&FLAG_N)));
		break;
	case sec:
		setflags(FLAG_C,1);
		break;
	case sed:
		setflags(FLAG_D,1);
		break;
	case sei:
		setflags(FLAG_I,1);
		break;
	case sta:
		putaddr(addr,a);
		break;
	case stx:
		putaddr(addr,x);
		break;
	case sty:
		putaddr(addr,y);
		break;
	case tax:
		x=a;
		setflags(FLAG_Z, !x);
		setflags(FLAG_N, x&0x80);
		break;
	case tay:
		y=a;
		setflags(FLAG_Z, !y);
		setflags(FLAG_N, y&0x80);
		break;
	case tsx:
		x=s;
		setflags(FLAG_Z, !x);
		setflags(FLAG_N, x&0x80);
		break;
	case txa:
		a=x;
		setflags(FLAG_Z, !a);
		setflags(FLAG_N, a&0x80);
		break;
	case txs:
		s=x;
		break;
	case tya:
		a=y;
		setflags(FLAG_Z, !a);
		setflags(FLAG_N, a&0x80);
		break;

	case slo:
		bval = getaddr(addr);
		setflags(FLAG_C, bval >> 7);
		bval <<= 1;
		setaddr(addr, bval);
		a |= bval;
		setflags(FLAG_Z, !a);
		setflags(FLAG_N, a&0x80);
		break;

	case axs:
		x = (x & a) - getaddr(addr);
		setflags(FLAG_Z, a == 0);
		setflags(FLAG_N, a > 127);
		break;

	case lax:
		a = x = getaddr(addr);
		setflags(FLAG_Z, a == 0);
		setflags(FLAG_N, a & 0x80);
		break;

	default:
		break;
	}
}
Esempio n. 12
0
int csu_dodomainmode(void *source, int cargc, char **cargv) {
  maildomain *mdp; 
  nick *sender=source;
  flag_t forceflags, currentflags;
  char buf1[60];
  int carg=2,limdone=0,actlimdone=0;
  unsigned int newlim=0;
  unsigned int newactlim=0;

  if (cargc<1) {
    chanservstdmessage(sender,QM_NOTENOUGHPARAMS,"domainmode");
    return CMD_ERROR;
  }

  if (checkdomain(cargv[0])) {
    chanservstdmessage(sender,QM_INVALIDDOMAIN,cargv[0]);
    return CMD_ERROR;
  }

  if(!(mdp=findorcreatemaildomain(cargv[0]))) {
    return CMD_ERROR;
  }

  if (cargc>1) {
    /* Save the current modes.. */
    strcpy(buf1,getdomainmode(mdp));

    /* Pick out the + flags: start from 0 */
    forceflags=0;
    setflags(&forceflags, MDFLAG_ALL, cargv[1], mdflags, REJECT_NONE);
    currentflags=mdp->flags;
    setflags(&currentflags, MDFLAG_ALL, cargv[1], mdflags, REJECT_NONE);

    if ((forceflags & MDFLAG_LIMIT) &&
        (!(forceflags & MDFLAG_ACTLIMIT) || strrchr(cargv[1],'l') < strrchr(cargv[1],'u'))) {
      if (cargc<=carg) {
        chanservstdmessage(sender,QM_NOTENOUGHPARAMS,"domainmode");
        return CMD_ERROR;
      }
      newlim=strtol(cargv[carg++],NULL,10);
      limdone=1;
    }

    if ((forceflags & MDFLAG_LIMIT) && !limdone) {
      if (cargc<=carg) {
        chanservstdmessage(sender,QM_NOTENOUGHPARAMS,"domainmode");
        return CMD_ERROR;
      }
      newlim=strtol(cargv[carg++],NULL,10);
      limdone=1;
    }

    if ((forceflags & MDFLAG_ACTLIMIT) && !actlimdone) {
      if (cargc<=carg) {
        chanservstdmessage(sender,QM_NOTENOUGHPARAMS,"chanmode");
        return CMD_ERROR;
      }
      newactlim=strtol(cargv[carg++],NULL,10);
      actlimdone=1;
    }

    /* It parsed OK, so update the structure.. */
    mdp->flags=currentflags;
    if(actlimdone)
      mdp->actlimit=newactlim; 
    if(!(currentflags & MDFLAG_ACTLIMIT))
      mdp->actlimit=0;
    if(limdone)
      mdp->limit=newlim;
    if(!(currentflags & MDFLAG_LIMIT))
      mdp->limit=0;
    if(mdp->ID) {
      if(mdp->flags) {
        csdb_updatemaildomain(mdp);
      } else {
        csdb_deletemaildomain(mdp);
      }
    } else {
      mdp->ID=++lastdomainID;
      csdb_createmaildomain(mdp);
    }

    chanservstdmessage(sender, QM_DONE);
    cs_log(sender,"DOMAINMODE %s %s (%s -> %s)",mdp->name->content,cargv[1],buf1,getdomainmode(mdp));
  }
  chanservstdmessage(sender,QM_CURDOMAINMODES,mdp->name->content,getdomainmode(mdp));
 
  return CMD_OK;
}
Esempio n. 13
0
static int
getname(void)
{
	int ppp_state = 0, ppp_connection = 0;
	unsigned char cs;
	int c, r;
	char *np;

	/*
	 * Interrupt may happen if we use CBREAK mode
	 */
	signal(SIGINT, interrupt);
	setflags(1);
	prompt();
	if (PF > 0) {
		oflush();
		sleep(PF);
		PF = 0;
	}
	if (tcsetattr(0, TCSANOW, &tmode) < 0) {
		syslog(LOG_ERR, "%s: %m", ttyn);
		exit(1);
	}
	crmod = digit = lower = upper = 0;
	np = name;
	for (;;) {
		oflush();
		r = read(STDIN_FILENO, &cs, 1);
		if (r <= 0) {
			if (r == -1 && errno == EINTR && interrupt_flag) {
				interrupt_flag = 0;
				return (0);
			}
			exit(0);
		}
		if ((c = cs&0177) == 0)
			return (0);

		/*
		 * PPP detection state machine..
		 * Look for sequences:
		 * PPP_FRAME, PPP_STATION, PPP_ESCAPE, PPP_CONTROL_ESCAPED or
		 * PPP_FRAME, PPP_STATION, PPP_CONTROL (deviant from RFC)
		 * See RFC1662.
		 * Derived from code from Michael Hancock <*****@*****.**>
		 * and Erik 'PPP' Olson <*****@*****.**>
		 */
		if (PP && cs == PPP_FRAME) {
			ppp_state = 1;
		} else if (ppp_state == 1 && cs == PPP_STATION) {
			ppp_state = 2;
		} else if (ppp_state == 2 && cs == PPP_ESCAPE) {
			ppp_state = 3;
		} else if ((ppp_state == 2 && cs == PPP_CONTROL) ||
		    (ppp_state == 3 && cs == PPP_CONTROL_ESCAPED)) {
			ppp_state = 4;
		} else if (ppp_state == 4 && cs == PPP_LCP_HI) {
			ppp_state = 5;
		} else if (ppp_state == 5 && cs == PPP_LCP_LOW) {
			ppp_connection = 1;
			break;
		} else {
			ppp_state = 0;
		}

		if (c == EOT)
			exit(1);
		if (c == '\r' || c == '\n' || np >= name + sizeof name -1) {
			putf("\r\n");
			break;
		}
		if (islower(c))
			lower = 1;
		else if (isupper(c))
			upper = 1;
		else if (c == ERASE || c == '#' || c == '\b') {
			if (np > name) {
				np--;
				if (cfgetospeed(&tmode) >= 1200)
					xputs("\b \b");
				else
					putchr(cs);
			}
			continue;
		} else if (c == KILL || c == '@') {
			putchr(cs);
			putchr('\r');
			if (cfgetospeed(&tmode) < 1200)
				putchr('\n');
			/* this is the way they do it down under ... */
			else if (np > name)
				xputs("                                     \r");
			prompt();
			np = name;
			continue;
		} else if (isdigit(c))
			digit++;
		if (IG && (c <= ' ' || c > 0176))
			continue;
		*np++ = c;
		putchr(cs);
	}
	signal(SIGINT, SIG_IGN);
	if (interrupt_flag) {
		interrupt_flag = 0;
		return (0);
	}
	*np = 0;
	if (c == '\r')
		crmod = 1;
	if (upper && !lower && !LC || UC)
		for (np = name; *np; np++)
			if (isupper(*np))
				*np = tolower(*np);
	return (1 + ppp_connection);
}
Esempio n. 14
0
int
main(int argc, char *argv[])
{
	extern char **environ;
	char *tname;
	int repcnt = 0, failopenlogged = 0;
	struct rlimit limit;
	int rval;

	signal(SIGINT, SIG_IGN);
/*
	signal(SIGQUIT, SIG_DFL);
*/
	openlog("getty", LOG_ODELAY|LOG_CONS|LOG_PID, LOG_AUTH);
	gethostname(hostname, sizeof(hostname));
	if (hostname[0] == '\0')
		strlcpy(hostname, "Amnesiac", sizeof hostname);
	uname(&kerninfo);

	/*
	 * Limit running time to deal with broken or dead lines.
	 */
	(void)signal(SIGXCPU, timeoverrun);
	limit.rlim_max = RLIM_INFINITY;
	limit.rlim_cur = GETTY_TIMEOUT;
	(void)setrlimit(RLIMIT_CPU, &limit);

	/*
	 * The following is a work around for vhangup interactions
	 * which cause great problems getting window systems started.
	 * If the tty line is "-", we do the old style getty presuming
	 * that the file descriptors are already set up for us.
	 * J. Gettys - MIT Project Athena.
	 */
	if (argc <= 2 || strcmp(argv[2], "-") == 0) {
		snprintf(ttyn, sizeof ttyn, "%s", ttyname(0));
	} else {
		int i;

		snprintf(ttyn, sizeof ttyn, "%s%s", dev, argv[2]);
		if (strcmp(argv[0], "+") != 0) {
			chown(ttyn, 0, 0);
			chmod(ttyn, 0600);
			revoke(ttyn);
			/*
			 * Delay the open so DTR stays down long enough to be detected.
			 */
			sleep(2);
			while ((i = open(ttyn, O_RDWR)) == -1) {
				if ((repcnt % 10 == 0) &&
				    (errno != ENXIO || !failopenlogged)) {
					syslog(LOG_ERR, "%s: %m", ttyn);
					closelog();
					failopenlogged = 1;
				}
				repcnt++;
				sleep(60);
			}
			login_tty(i);
		}
	}

	/* Start with default tty settings */
	if (tcgetattr(0, &tmode) < 0) {
		syslog(LOG_ERR, "%s: %m", ttyn);
		exit(1);
	}
	omode = tmode;

	gettable("default", defent);
	gendefaults();
	tname = "default";
	if (argc > 1)
		tname = argv[1];
	for (;;) {
		int off;

		gettable(tname, tabent);
		if (OPset || EPset || APset)
			APset++, OPset++, EPset++;
		setdefaults();
		off = 0;
		(void)tcflush(0, TCIOFLUSH);	/* clear out the crap */
		ioctl(0, FIONBIO, &off);	/* turn off non-blocking mode */
		ioctl(0, FIOASYNC, &off);	/* ditto for async mode */

		if (IS)
			cfsetispeed(&tmode, IS);
		else if (SP)
			cfsetispeed(&tmode, SP);
		if (OS)
			cfsetospeed(&tmode, OS);
		else if (SP)
			cfsetospeed(&tmode, SP);
		setflags(0);
		setchars();
		if (tcsetattr(0, TCSANOW, &tmode) < 0) {
			syslog(LOG_ERR, "%s: %m", ttyn);
			exit(1);
		}
		if (AB) {
			tname = autobaud();
			continue;
		}
		if (PS) {
			tname = portselector();
			continue;
		}
		if (CL && *CL)
			putpad(CL);
		edithost(HE);
		if (IM && *IM)
			putf(IM);
		if (TO) {
			signal(SIGALRM, dingdong);
			alarm(TO);
		}
		if ((rval = getname()) == 2) {
			oflush();
			alarm(0);
			signal(SIGALRM, SIG_DFL);
			execle(PP, "ppplogin", ttyn, (char *) 0, env);
			syslog(LOG_ERR, "%s: %m", PP);
			exit(1);
		} else if (rval) {
			int i;

			oflush();
			alarm(0);
			signal(SIGALRM, SIG_DFL);
			if (name[0] == '-') {
				xputs("user names may not start with '-'.");
				continue;
			}
			if (!(upper || lower || digit))
				continue;
			setflags(2);
			if (crmod) {
				tmode.c_iflag |= ICRNL;
				tmode.c_oflag |= ONLCR;
			}
			if (upper || UC) {
				tmode.c_iflag |= IUCLC;
				tmode.c_oflag |= OLCUC;
				tmode.c_lflag |= XCASE;
			}
			if (lower || LC) {
				tmode.c_iflag &= ~IUCLC;
				tmode.c_oflag &= ~OLCUC;
				tmode.c_lflag &= ~XCASE;
			}
			if (tcsetattr(0, TCSANOW, &tmode) < 0) {
				syslog(LOG_ERR, "%s: %m", ttyn);
				exit(1);
			}
			signal(SIGINT, SIG_DFL);
			for (i = 0; environ[i] != (char *)0; i++)
				env[i] = environ[i];
			makeenv(&env[i]);

			limit.rlim_max = RLIM_INFINITY;
			limit.rlim_cur = RLIM_INFINITY;
			(void)setrlimit(RLIMIT_CPU, &limit);
			execle(LO, "login", "-p", "--", name, (char *)0, env);
			syslog(LOG_ERR, "%s: %m", LO);
			exit(1);
		}
		alarm(0);
		signal(SIGALRM, SIG_DFL);
		signal(SIGINT, SIG_IGN);
		if (NX && *NX)
			tname = NX;
	}
}
Esempio n. 15
0
int handleburstmsg(void *source, int cargc, char **cargv) {
  channel *cp;
  time_t timestamp;
  int wipeout=0;
  int i;
  int arg=0;
  char *charp;
  int newlimit;
  int waslimit,waskeyed;
  char *nextnum;
  unsigned long currentmode;
  int isnewchan;
  
  /* (we don't see the first 2 params in cargc) */
  /* AK B #+lod+ 1017561154 +tnk eits ATJWu:o,AiW1a,Ag3lV,AiWnl,AE6oI :%*[email protected] */
  
  if (cargc<2) {
    Error("channel",ERR_WARNING,"Burst message with only %d parameters",cargc);
    return CMD_OK;
  }
  
  timestamp=strtol(cargv[1],NULL,10);
  
  if ((cp=findchannel(cargv[0]))==NULL) {
    /* We don't have this channel already */
    cp=createchannel(cargv[0]);
    cp->timestamp=timestamp;
    isnewchan=1;
  } else {
    isnewchan=0;
    if (timestamp<cp->timestamp) {
      /* The incoming timestamp is older.  Erase all our current channel modes, and the topic. */
      cp->timestamp=timestamp;
      freesstring(cp->topic);
      cp->topic=NULL;
      cp->topictime=0;
      freesstring(cp->key);
      cp->key=NULL;
      cp->limit=0;
      cp->flags=0;
      clearallbans(cp);
      /* Remove all +v, +o we currently have */
      for(i=0;i<cp->users->hashsize;i++) {
        if (cp->users->content[i]!=nouser) {
          cp->users->content[i]&=CU_NUMERICMASK;
        }
      }
    } else if (timestamp>cp->timestamp) {
      /* The incoming timestamp is greater.  Ignore any incoming modes they may happen to set */
      wipeout=1;
    }
  }

  /* OK, dealt with the name and timestamp. 
   * Loop over the remaining args */
  for (arg=2;arg<cargc;arg++) {
    if (cargv[arg][0]=='+') {
      /* Channel modes */
      if (wipeout) {
        /* We ignore the modes, but we need to see if they include +l or +k 
         * so that we can ignore their corresponding values */
        for (charp=cargv[arg];*charp;charp++) {
          if (*charp=='k' || *charp=='l') {
            arg++;
          }
        }
      } else {
        /* Clear off the limit and key flags before calling setflags so we can see if the burst tried to set them */
        /* If the burst doesn't set them, we restore them afterwards */
        waslimit=IsLimit(cp); ClearLimit(cp);
        waskeyed=IsKey(cp);   ClearKey(cp);
        /* We can then use the flag function for these modes */
        setflags(&(cp->flags),CHANMODE_ALL,cargv[arg],cmodeflags,REJECT_NONE);
        /* Pick up the limit and key, if they were set.  Note that the limit comes first */
        if (IsLimit(cp)) { /* A limit was SET by the burst */
          if (++arg>=cargc) {
            /* Ran out of args -- damn ircd is spewing out crap again */
            Error("channel",ERR_WARNING,"Burst +l with no argument");
            break; /* "break" being the operative word */
          } else {
            newlimit=strtol(cargv[arg],NULL,10);
          }
          if (cp->limit>0 && waslimit) {
            /* We had a limit before -- we now have the lowest one of the two */
            if (newlimit<cp->limit) {
              cp->limit=newlimit;
            }
          } else {
            /* No limit before -- we just have the new one */
            cp->limit=newlimit;
          }
        } else if (waslimit) {
          SetLimit(cp); /* We had a limit before, but the burst didn't set one.  Restore flag. */
        }
        
        if (IsKey(cp)) { /* A key was SET by the burst */
          if (++arg>=cargc) {
            /* Ran out of args -- oopsie! */
            Error("channel",ERR_WARNING,"Burst +k with no argument");
            break;
          }
          if (waskeyed) {
            /* We had a key before -- alphabetically first wins */
            if (ircd_strcmp(cargv[arg],cp->key->content)<0) {
              /* Replace our key */
              freesstring(cp->key);
              cp->key=getsstring(cargv[arg],KEYLEN);
            }
          } else {
            /* No key before -- just the new one */
            cp->key=getsstring(cargv[arg],KEYLEN);
          }
        } else if (waskeyed) {
          SetKey(cp); /* We had a key before, but the burst didn't set one.  Restore flag. */
        }
      }       
    } else if (cargv[arg][0]=='%') {
      /* We have one or more bans here */
      nextnum=cargv[arg]+1;
      while (*nextnum) {
        /* Split off the next ban */
        for (charp=nextnum;*charp;charp++) {
          if (*charp==' ') {
            *charp='\0';
            charp++;
            break;
          }
        }        
        setban(cp,nextnum);
        nextnum=charp;
      }
    } else {
      /* List of numerics */
      nextnum=charp=cargv[arg];
      currentmode=0;
      while (*nextnum!='\0') {
        /* Step over the next numeric */
        for (i=0;i<5;i++) {
          if (*charp++=='\0')
            break;
        }
        if (i<5) {
          break;
        }
        if (*charp==',') {
          *charp='\0';
          charp++;
        } else if (*charp==':') {
          *charp='\0';
          charp++;
          currentmode=0;
          /* Look for modes */
          for (;*charp;charp++) {
            if (*charp=='v') {
              currentmode|=CUMODE_VOICE;
            } else if (*charp=='o') {
              currentmode|=CUMODE_OP;
            } else if (*charp==',') {
              charp++;
              break;
            }
          }
          /* If we're ignore incoming modes, zap it to zero again */
          if (wipeout) {
            currentmode=0;
          }
        }
        /* OK.  At this point charp points to either '\0' if we're at the end,
         * or the start of the next numeric otherwise.  nextnum points at a valid numeric
         * we need to add, and currentmode reflects the correct mode */
        addnicktochannel(cp,(numerictolong(nextnum,5)|currentmode));
        nextnum=charp;
      }
    }
  }
  if (cp->users->totalusers==0) {
    /* Oh dear, the channel is now empty.  Perhaps one of those 
     * charming empty burst messages you get sometimes.. */
    if (!isnewchan) {
      /* I really don't think this can happen, can it..? */
      /* Only send the LOSTCHANNEL if the channel existed before */
      triggerhook(HOOK_CHANNEL_LOSTCHANNEL,cp);
    }
    delchannel(cp);
  } else {
    /* If this is a new channel, we do the NEWCHANNEL hook also */
    if (isnewchan) {
      triggerhook(HOOK_CHANNEL_NEWCHANNEL,cp);
    }
    /* Just one hook to say "something happened to this channel" */
    triggerhook(HOOK_CHANNEL_BURST,cp);       
  }
   
  return CMD_OK;     
}
Esempio n. 16
0
static int setflags(struct inode *inode, int flags)
{
	int oldflags, err, release;
	struct ubifs_inode *ui = ubifs_inode(inode);
	struct ubifs_info *c = inode->i_sb->s_fs_info;
	struct ubifs_budget_req req = { .dirtied_ino = 1,
					.dirtied_ino_d = ui->data_len };

	err = ubifs_budget_space(c, &req);
	if (err)
		return err;

	/*
	 * The IMMUTABLE and APPEND_ONLY flags can only be changed by
	 * the relevant capability.
	 */
	mutex_lock(&ui->ui_mutex);
	oldflags = ubifs2ioctl(ui->flags);
	if ((flags ^ oldflags) & (FS_APPEND_FL | FS_IMMUTABLE_FL)) {
		if (!capable(CAP_LINUX_IMMUTABLE)) {
			err = -EPERM;
			goto out_unlock;
		}
	}

	ui->flags = ioctl2ubifs(flags);
	ubifs_set_inode_flags(inode);
	inode->i_ctime = ubifs_current_time(inode);
	release = ui->dirty;
	mark_inode_dirty_sync(inode);
	mutex_unlock(&ui->ui_mutex);

	if (release)
		ubifs_release_budget(c, &req);
	if (IS_SYNC(inode))
		err = write_inode_now(inode, 1);
	return err;

out_unlock:
	ubifs_err("can't modify inode %lu attributes", inode->i_ino);
	mutex_unlock(&ui->ui_mutex);
	ubifs_release_budget(c, &req);
	return err;
}

long ubifs_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
{
	int flags, err;
	struct inode *inode = file->f_path.dentry->d_inode;

	switch (cmd) {
	case FS_IOC_GETFLAGS:
		flags = ubifs2ioctl(ubifs_inode(inode)->flags);

		dbg_gen("get flags: %#x, i_flags %#x", flags, inode->i_flags);
		return put_user(flags, (int __user *) arg);

	case FS_IOC_SETFLAGS: {
		if (IS_RDONLY(inode))
			return -EROFS;

		if (!inode_owner_or_capable(inode))
			return -EACCES;

		if (get_user(flags, (int __user *) arg))
			return -EFAULT;

		if (!S_ISDIR(inode->i_mode))
			flags &= ~FS_DIRSYNC_FL;

		/*
		 * Make sure the file-system is read-write and make sure it
		 * will not become read-only while we are changing the flags.
		 */
		err = mnt_want_write(file->f_path.mnt);
		if (err)
			return err;
		dbg_gen("set flags: %#x, i_flags %#x", flags, inode->i_flags);
		err = setflags(inode, flags);
		mnt_drop_write(file->f_path.mnt);
		return err;
	}

	default:
		return -ENOTTY;
	}
}
Esempio n. 17
0
int main (int argc, char **argv)
{
	const char *pathname = "trash";
	const char buffer1[] = "hello world!\n";
	const char buffer2[] = "goodbye old world, hello new world!\n";
	char fdcontents1[sizeof(buffer1)];
	char fdcontents2[sizeof(buffer2)];
	int fifo1 = -1, fifo2 = -1, ret, op_num = 0;

	parse_args(argc, argv);
	/* FIXME eventually stdio streams should be harmless */
	close(0);
	logfp = fopen(LOG_FILE, "w");
	if (!logfp) {
		perror("could not open logfile");
		exit(1);
	}
	dup2(fileno(logfp), 1); /* redirect stdout and stderr to the log file */
	dup2(fileno(logfp), 2);
	if (!move_to_cgroup("freezer", "1", getpid())) {
		log_error("move_to_cgroup");
		exit(2);
	}

/* Open a first fifo, write to it, and unlink it */
label(mkfifo1,   ret, mkfifo(pathname, S_IRUSR|S_IWUSR));
label(open1,   fifo1, open(pathname, oflags));
label(setflags1, ret, setflags(fifo1));
label(write1,    ret, write(fifo1, buffer1, sizeof(buffer1)));
label(unlink,    ret, unlink(pathname));

/* Open a second fifo, write to it */
label(mkfifo2,   ret, mkfifo(pathname, S_IRUSR|S_IWUSR));
label(open2,   fifo2, open(pathname, oflags));
label(setflags2, ret, setflags(fifo2));
label(write2,    ret, write(fifo2, buffer2, sizeof(buffer2)));

/* Check fifo contents */
label(read1,     ret, read(fifo1, fdcontents1, sizeof(fdcontents1)));
	if (strcmp(buffer1, fdcontents1) != 0) {
		log("FAIL", "original fifo contents don't match.");
		ret = EXIT_FAILURE;
		goto out;
	}
label(read2,     ret, read(fifo2, fdcontents2, sizeof(fdcontents2)));
	if (strcmp(buffer2, fdcontents2) != 0) {
		log("FAIL", "new fifo contents don't match.");
		ret = EXIT_FAILURE;
		goto out;
	}
	ret = EXIT_SUCCESS;
out:
	if (ret != EXIT_SUCCESS)
		perror("ERROR");
	if (fifo1 > -1)
		close(fifo1);
	if (fifo2 > -1)
		close(fifo2);
	unlink(pathname);
	fclose(logfp);
	exit(ret);
}
Esempio n. 18
0
int
main(int argc, char *argv[])
{
	extern int optind;
	extern char *optarg;
	enum S command, state;
	DB *dbp;
	DBT data, key, keydata;
	size_t len;
	int ch, oflags, sflag;
	char *fname, *infoarg, *p, *t, buf[8 * 1024];

	infoarg = NULL;
	fname = NULL;
	oflags = O_CREAT | O_RDWR;
	sflag = 0;
	while ((ch = getopt(argc, argv, "f:i:lo:s")) != -1)
		switch (ch) {
		case 'f':
			fname = optarg;
			break;
		case 'i':
			infoarg = optarg;
			break;
		case 'l':
			oflags |= DB_LOCK;
			break;
		case 'o':
			if ((ofd = open(optarg,
			    O_WRONLY|O_CREAT|O_TRUNC, 0666)) < 0)
				err("%s: %s", optarg, strerror(errno));
			break;
		case 's':
			sflag = 1;
			break;
		case '?':
		default:
			usage();
		}
	argc -= optind;
	argv += optind;

	if (argc != 2)
		usage();

	/* Set the type. */
	type = dbtype(*argv++);

	/* Open the descriptor file. */
        if (strcmp(*argv, "-") && freopen(*argv, "r", stdin) == NULL)
	    err("%s: %s", *argv, strerror(errno));

	/* Set up the db structure as necessary. */
	if (infoarg == NULL)
		infop = NULL;
	else
		for (p = strtok(infoarg, ",\t "); p != NULL;
		    p = strtok(0, ",\t "))
			if (*p != '\0')
				infop = setinfo(type, p);

	/*
	 * Open the DB.  Delete any preexisting copy, you almost never
	 * want it around, and it often screws up tests.
	 */
	if (fname == NULL) {
		p = getenv("TMPDIR");
		if (p == NULL)
			p = "/var/tmp";
		snprintf(buf, sizeof(buf), "%s/__dbtest", p);
		fname = buf;
		unlink(buf);
	} else  if (!sflag)
		unlink(fname);

	if ((dbp = dbopen(fname,
	    oflags, S_IRUSR | S_IWUSR, type, infop)) == NULL)
		err("dbopen: %s", strerror(errno));
	XXdbp = dbp;

	state = COMMAND;
	for (lineno = 1;
	    (p = fgets(buf, sizeof(buf), stdin)) != NULL; ++lineno) {
		/* Delete the newline, displaying the key/data is easier. */
		if (ofd == STDOUT_FILENO && (t = strchr(p, '\n')) != NULL)
			*t = '\0';
		if ((len = strlen(buf)) == 0 || isspace(*p) || *p == '#')
			continue;

		/* Convenient gdb break point. */
		if (XXlineno == lineno)
			XXlineno = 1;
		switch (*p) {
		case 'c':			/* compare */
			if (state != COMMAND)
				err("line %lu: not expecting command", lineno);
			state = KEY;
			command = COMPARE;
			break;
		case 'e':			/* echo */
			if (state != COMMAND)
				err("line %lu: not expecting command", lineno);
			/* Don't display the newline, if CR at EOL. */
			if (p[len - 2] == '\r')
				--len;
			if (write(ofd, p + 1, len - 1) != len - 1 ||
			    write(ofd, "\n", 1) != 1)
				err("write: %s", strerror(errno));
			break;
		case 'g':			/* get */
			if (state != COMMAND)
				err("line %lu: not expecting command", lineno);
			state = KEY;
			command = GET;
			break;
		case 'p':			/* put */
			if (state != COMMAND)
				err("line %lu: not expecting command", lineno);
			state = KEY;
			command = PUT;
			break;
		case 'r':			/* remove */
			if (state != COMMAND)
				err("line %lu: not expecting command", lineno);
                        if (flags == R_CURSOR) {
				rem(dbp, &key);
				state = COMMAND;
                        } else {
				state = KEY;
				command = REMOVE;
			}
			break;
		case 'S':			/* sync */
			if (state != COMMAND)
				err("line %lu: not expecting command", lineno);
			synk(dbp);
			state = COMMAND;
			break;
		case 's':			/* seq */
			if (state != COMMAND)
				err("line %lu: not expecting command", lineno);
			if (flags == R_CURSOR) {
				state = KEY;
				command = SEQ;
			} else
				seq(dbp, &key);
			break;
		case 'f':
			flags = setflags(p + 1);
			break;
		case 'D':			/* data file */
			if (state != DATA)
				err("line %lu: not expecting data", lineno);
			data.data = rfile(p + 1, &data.size);
			goto ldata;
		case 'd':			/* data */
			if (state != DATA)
				err("line %lu: not expecting data", lineno);
			data.data = xmalloc(p + 1, len - 1);
			data.size = len - 1;
ldata:			switch (command) {
			case COMPARE:
				compare(&keydata, &data);
				break;
			case PUT:
				put(dbp, &key, &data);
				break;
			default:
				err("line %lu: command doesn't take data",
				    lineno);
			}
			if (type != DB_RECNO)
				free(key.data);
			free(data.data);
			state = COMMAND;
			break;
		case 'K':			/* key file */
			if (state != KEY)
				err("line %lu: not expecting a key", lineno);
			if (type == DB_RECNO)
				err("line %lu: 'K' not available for recno",
				    lineno);
			key.data = rfile(p + 1, &key.size);
			goto lkey;
		case 'k':			/* key */
			if (state != KEY)
				err("line %lu: not expecting a key", lineno);
			if (type == DB_RECNO) {
				static recno_t recno;
				recno = atoi(p + 1);
				key.data = &recno;
				key.size = sizeof(recno);
			} else {
				key.data = xmalloc(p + 1, len - 1);
				key.size = len - 1;
			}
lkey:			switch (command) {
			case COMPARE:
				getdata(dbp, &key, &keydata);
				state = DATA;
				break;
			case GET:
				get(dbp, &key);
				if (type != DB_RECNO)
					free(key.data);
				state = COMMAND;
				break;
			case PUT:
				state = DATA;
				break;
			case REMOVE:
				rem(dbp, &key);
				if ((type != DB_RECNO) && (flags != R_CURSOR))
					free(key.data);
				state = COMMAND;
				break;
			case SEQ:
				seq(dbp, &key);
				if ((type != DB_RECNO) && (flags != R_CURSOR))
					free(key.data);
				state = COMMAND;
				break;
			default:
				err("line %lu: command doesn't take a key",
				    lineno);
			}
			break;
		case 'o':
			dump(dbp, p[1] == 'r');
			break;
		default:
			err("line %lu: %s: unknown command character",
			    lineno, p);
		}
	}
#ifdef STATISTICS
	/*
	 * -l must be used (DB_LOCK must be set) for this to be
	 * used, otherwise a page will be locked and it will fail.
	 */
	if (type == DB_BTREE && oflags & DB_LOCK)
		__bt_stat(dbp);
#endif
	if (dbp->close(dbp))
		err("db->close: %s", strerror(errno));
	close(ofd);
	exit(0);
}
Esempio n. 19
0
int spcmd_splitadd(void *source, int cargc, char **cargv) {
  nick *np = (nick*)source;
  unsigned long long num;
  char *end;
  flag_t servertype = 0;
  char *servername;
  size_t servernamelen;
  time_t splittime;
  server fake;

  if (cargc < 1) {
      controlreply(np, "Usage: splitadd <servername> [+flags] [split time as unix timestamp]");
      return CMD_ERROR;
  }

  servername = cargv[0];
  servernamelen = strlen(servername);

  if (findserver(servername) != -1) {
    controlreply(np, "Server %s is linked right now, refusing to add split.",
        servername);
    return CMD_ERROR;
  }

  if (doessplitalreadyexist(servername)) {
    controlreply(np, "There is a split for %s already.", servername);
    return CMD_ERROR;
  }

  if (servernamelen > SERVERLEN) {
    controlreply(np, "Server name %s is too long (max: %d characters)",
        servername, SERVERLEN);
    return CMD_ERROR;
  }

  /* Handle flags */
  if (cargc > 1) {
    if (setflags(&servertype, (flag_t)-1, cargv[1], servertypeflags,
          REJECT_UNKNOWN) != REJECT_NONE) {
      controlreply(np, "Flag string %s contained invalid flags.", cargv[1]);
      return CMD_ERROR;
    }
  } else {
    /* Set up a fake server for getservertype. */
    memset(&fake, 0, sizeof(fake));

    fake.name = getsstring(servername, servernamelen);
    servertype = getservertype(&fake);
    freesstring(fake.name);
  }

  /* Handle timestamp */
  if (cargc < 3) {
    splittime = getnettime();
  } else {
    errno = 0;
    num = strtoull(cargv[2], &end, 10);
    if (errno == ERANGE) {
      controlreply(np, "%s is out of range for a timestamp.", cargv[2]);
      return CMD_ERROR;
    }

    /* Truncation may happen here. 
     * However, there's no way to get the max time_t value, so we'll just try to
     * find out after the fact.
     */
    splittime = (time_t)num;

    if ((unsigned long long)splittime < num) {
      controlreply(np, "Tried to use %llu as split time value, but it's too "
          "large for the system to handle", num);
      return CMD_ERROR;
    }
  }

  sp_addsplit(servername, splittime, servertype);
  controlreply(np, "Added split for %s (%s ago) with flags %s.",
      servername, longtoduration(getnettime() - splittime, 1),
      printflags(servertype, servertypeflags));

  return CMD_OK;
}