int set_user(users **u,usersCtrl *ctrlU)
{
  int uid,flag = 1;
  do
  {
    printf("\n%s %s\n",SELEC, "un usuario");
    show_users(ctrlU);
    printf(">");
    scanf("%i",&uid);
    getchar();

    *u = find_user(uid,ctrlU->front);
    if(u != NULL)
      break;
    else
    {
      printf("%s\n",FIND_FAIL);
      if(cancel("creacion del proceso") == 1)
      {
        flag = FAIL;
        break;
      }
    }
  }while(1);

  return flag;
}
Exemple #2
0
delusergo()
{
 static char forward[200];
 static char forwardto[200];
 FILE *fs;
 int i;
 struct vqpasswd *pw;
     
  if ( AdminType!=DOMAIN_ADMIN ) {
    sprintf(StatusMessage,"%s", get_html_text("142"));
    vclose();
    exit(0);
  }

  vdeluser( ActionUser, Domain );

  /* Start create forward when delete - 
   * Code added by Eugene Teo 6 June 2000 
   */

  GetValue(TmpCGI,forward, "forward=", MAX_BUFF);

#ifdef DEBUG
  fprintf(actout, "Forward: %s\n<br>", forward);
#endif

  if (strcmp(forward, "on") == 0) {

    /* replace "." in name with ":" */    

    sprintf(TmpBuf2, ".qmail-%s", ActionUser);
    for(i=6;TmpBuf2[i]!=0;++i) if ( TmpBuf2[i] == '.' ) TmpBuf2[i] = ':';
    
    if ((fs=fopen(TmpBuf2,"w")) == NULL) ack("Failed to open passwd file",21);
    
    GetValue(TmpCGI, forwardto, "forwardto=", MAX_BUFF);
        
#ifdef DEBUG        
    fprintf(actout, "Forward to: %s\n<br>", forwardto);
#endif

    fprintf(fs, "&%s", forwardto);
    fclose(fs);
        
    /* End create forward when delete - 
     * Code added by Eugene Teo 6 June 2000 
     */
  }
    
  sprintf(StatusMessage, "%s %s", ActionUser, get_html_text("141"));
    
  call_hooks(HOOK_DELUSER);
  show_users(Username, Domain, Mytime);

}
Exemple #3
0
set_remote_catchall_now()
{
 FILE *fs;

  if ( (fs = fopen(".qmail-default", "w")) == NULL ) {
    fprintf(actout,"%s %s<br>\n", get_html_text("144"), ".qmail-default");
  } else {
    fprintf(fs,"| %s/bin/vdelivermail '' %s\n",VPOPMAILDIR,Newu);
    fclose(fs);
  }
  show_users(Username, Domain, Mytime);
  exit(0);
}
Exemple #4
0
void deleteall()
{
 FILE *fs;

  if ( (fs = fopen(".qmail-default", "w")) == NULL ) {
    fprintf(actout,"%s %s<br>\n", get_html_text("144"), ".qmail-default");
  } else {
    fprintf(fs,"| %s/bin/vdelivermail '' delete\n",VPOPMAILDIR);
    fclose(fs);
  }
  show_users(Username, Domain, Mytime);
  vclose();
  exit(0);
}
Exemple #5
0
int
ac(FILE	*fp)
{
	struct utmp_list *lp, *head = NULL;
	struct utmp usr;
	struct tm *ltm;
	time_t secs = 0, prev = 0;
	int day = -1;

	while (fread((char *)&usr, sizeof(usr), 1, fp) == 1) {
		if (!FirstTime)
			FirstTime = usr.ut_time;
		if (usr.ut_time < prev)
			continue;	/* broken record */
		prev = usr.ut_time;
		if (Flags & AC_D) {
			ltm = localtime(&usr.ut_time);
			if (day >= 0 && day != ltm->tm_yday) {
				day = ltm->tm_yday;
				/*
				 * print yesterday's total
				 */
				secs = usr.ut_time;
				secs -= ltm->tm_sec;
				secs -= 60 * ltm->tm_min;
				secs -= 3600 * ltm->tm_hour;
				show_today(Users, head, secs);
			} else
				day = ltm->tm_yday;
		}
		switch(*usr.ut_line) {
		case '|':
			secs = usr.ut_time;
			break;
		case '{':
			secs -= usr.ut_time;
			/*
			 * adjust time for those logged in
			 */
			for (lp = head; lp != NULL; lp = lp->next)
				lp->usr.ut_time -= secs;
			break;
		case '~':			/* reboot or shutdown */
			head = log_out(head, &usr);
			FirstTime = usr.ut_time; /* shouldn't be needed */
			break;
		default:
			/*
			 * if they came in on a pseudo-tty, then it is only
			 * a login session if the ut_host field is non-empty
			 */
			if (*usr.ut_name) {
				if (strncmp(usr.ut_line, "tty", 3) != 0 ||
				    strchr("pqrstuvwxyzPQRST", usr.ut_line[3]) != NULL ||
				    *usr.ut_host != '\0')
					head = log_in(head, &usr);
			} else
				head = log_out(head, &usr);
			break;
		}
	}
	(void)fclose(fp);
	if (!(Flags & AC_W))
		usr.ut_time = time(NULL);
	(void)strlcpy(usr.ut_line, "~", sizeof usr.ut_line);

	if (Flags & AC_D) {
		ltm = localtime(&usr.ut_time);
		if (day >= 0 && day != ltm->tm_yday) {
			/*
			 * print yesterday's total
			 */
			secs = usr.ut_time;
			secs -= ltm->tm_sec;
			secs -= 60 * ltm->tm_min;
			secs -= 3600 * ltm->tm_hour;
			show_today(Users, head, secs);
		}
	}
	/*
	 * anyone still logged in gets time up to now
	 */
	head = log_out(head, &usr);

	if (Flags & AC_D)
		show_today(Users, head, time(NULL));
	else {
		if (Flags & AC_P)
			show_users(Users);
		show("total", Total);
	}
	return 0;
}
Exemple #6
0
modusergo()
{
 char crypted[20]; 
 char *tmpstr;
 int i;
 int ret_code;
 int password_updated = 0;
 struct vqpasswd *vpw=NULL;
 static char box[50];
 static char NewBuf[156];
 int count;
 FILE *fs;
#ifdef SQWEBMAIL_PASS
 uid_t uid;
 gid_t gid;
#endif

  vpw = vauth_getpw(ActionUser, Domain); 

  if (!( AdminType==DOMAIN_ADMIN ||
         (AdminType==USER_ADMIN && strcmp(ActionUser,Username)==0))){
    sprintf(StatusMessage,"%s", get_html_text("142"));
    vclose();
    exit(0);
  }

  if (strlen(Password1)>0 && strlen(Password2)>0 ) {
    if ( strncmp( Password1, Password2, MAX_BUFF ) != 0 ) {
      sprintf(StatusMessage, "%s\n", get_html_text("200"));
      moduser();
      vclose();
      exit(0);
    }
    if (strlen(Password1) > MAX_PW_CLEAR_PASSWD) {
      sprintf(StatusMessage,"%s %s@%s %s", 
        get_html_text("139"), ActionUser, Domain, VA_PASSWD_TOO_LONG );
      moduser();
      vclose();
      exit(0);
    } else if (vpw->pw_gid & NO_PASSWD_CHNG) {
      sprintf(StatusMessage, "%s", get_html_text("140"));
      moduser();
      vclose();
      exit(0);
    } else {
        sprintf(StatusMessage,"%s %s@%s", 
            get_html_text("139"), ActionUser, Domain);
    }

    mkpasswd3(Password1,Crypted, MAX_BUFF);
    vpw->pw_passwd = Crypted;

#ifdef CLEAR_PASS
      vpw->pw_clear_passwd = Password1;
#endif
#ifdef SQWEBMAIL_PASS
      vget_assign(Domain, NULL, 0, &uid, &gid );
      vsqwebmail_pass( vpw->pw_dir, Crypted, uid, gid);
#endif

  }

  GetValue(TmpCGI,Gecos, "gecos=", MAX_BUFF);
  if ( strlen( Gecos ) != 0 ) {
    vpw->pw_gecos = Gecos;
  }
  vauth_setpw(vpw, Domain);

  /* get the value of the cforward radio button */
  GetValue(TmpCGI,box, "cforward=", MAX_BUFF);

  /* if they want to disable everything */
  if ( strcmp(box,"disable") == 0 ) {

    /* unlink the .qmail file */
    if ( vpw == NULL ) vpw = vauth_getpw(ActionUser, Domain); 
    snprintf(NewBuf,156,"%s/.qmail", vpw->pw_dir);
    unlink(NewBuf);

    /* delete any vacation directory */
    snprintf(NewBuf,156,"%s/vacation", vpw->pw_dir);
    vdelfiles(NewBuf);

  /* if they want to forward */
  } else if (strcmp(box,"forward") == 0 ) {

    /* get the value of the foward */
    GetValue(TmpCGI,box, "nforward=", MAX_BUFF);

    /* If nothing was entered, error */
    if ( box[0] == 0 ) {
      sprintf(StatusMessage, "%s\n", get_html_text("215"));
      moduser();
      vclose();
      exit(0);

    /* check it for a valid email address
    } else if ( check_email_addr( box ) == 1 )  {
      sprintf(StatusMessage, "%s\n", get_html_text("148"));
      moduser();
    */
    }

    /* everything looks good, open the file */
    if ( vpw == NULL ) {
      vpw = vauth_getpw(ActionUser, Domain); 
    }
    snprintf(NewBuf,156,"%s/.qmail", vpw->pw_dir);

    fs = fopen(NewBuf,"w+");
    tmpstr = strtok(box," ,;\n");

    count=0;
    while( tmpstr != NULL && count < 2) {
      fprintf(fs,"&%s\n", tmpstr);
      tmpstr = strtok(NULL," ,\n");
      ++count;
    }

    /* if they want to save a copy */
    GetValue(TmpCGI,box, "fsaved=", MAX_BUFF);
    if ( strcmp(box,"on") == 0 ) {
      fprintf(fs,"%s/Maildir/\n", vpw->pw_dir);
    } 
    fclose(fs);

  /* they want vacation */
  } else if (strcmp(box,"vacation") == 0 ) {

    /* get the subject */
    GetValue(TmpCGI,box, "vsubject=", MAX_BUFF);

    /* if no subject, error */
    if ( box[0] == 0 ) {
      sprintf(StatusMessage, "%s\n", get_html_text("216"));
      moduser();
      vclose();
      exit(0);
    }
 
    /* make the vacation directory */
    if ( vpw == NULL ) vpw = vauth_getpw(ActionUser, Domain); 
    snprintf(NewBuf,156,"%s/vacation", vpw->pw_dir);
    mkdir(NewBuf, 448);

    /* open the .qmail file */
    snprintf(NewBuf,156,"%s/.qmail", vpw->pw_dir);
    fs = fopen(NewBuf,"w+");
    fprintf(fs, "| %s/autorespond 86400 3 %s/vacation/message %s/vacation\n",
      AUTORESPOND_BIN, vpw->pw_dir, vpw->pw_dir );

    /* save a copy for the user */
    fprintf(fs,"%s/Maildir/\n", vpw->pw_dir);
    fclose(fs);

    /* set up the message file */
    snprintf(NewBuf,156,"%s/vacation/message", vpw->pw_dir);
    GetValue(TmpCGI,Message, "vmessage=",MAX_BIG_BUFF);

    if ( (fs = fopen(NewBuf, "w")) == NULL ) ack("123", 123);
    fprintf(fs, "From: %s@%s\n", ActionUser,Domain);
    fprintf(fs, "Subject: %s\n\n", box);
    fprintf(fs, "%s", Message);
    fclose(fs);

    /* save the forward for vacation too */
    GetValue(TmpCGI,box,"nforward=", MAX_BUFF);
    snprintf(NewBuf, 156, "%s/.qmail", vpw->pw_dir);
    fs = fopen(NewBuf, "a+");
    tmpstr = strtok(box, " ,;\n");
    count = 0;
    while( tmpstr != NULL && count < 2 ) {
      fprintf(fs, "&%s\n", tmpstr);
      tmpstr = strtok(NULL, " ,;\n");
      ++count;
    }
    fclose(fs);

  } else {
    printf("nothing\n");
  }

  call_hooks(HOOK_MODUSER);
  show_users(Username, Domain, Mytime);
}
Exemple #7
0
addusernow()
{
 char pw[50];
 int cnt=0, num;
 char *c_num;
 char **mailingListNames;
 char *tmp;
 char *email;
 char **arguments;
 int pid;
 int i;
 int error;
 struct vqpasswd *mypw;


  c_num = malloc(MAX_BUFF);
  email = malloc(128);
  tmp = malloc(MAX_BUFF);
  arguments = (char **)malloc(MAX_BUFF);

  count_users();
  load_limits();

  if ( AdminType!=DOMAIN_ADMIN ) {
    sprintf(StatusMessage,"%s", get_html_text("142"));
    vclose();
    exit(0);
  }

  if ( MaxPopAccounts != -1 && CurPopAccounts >= MaxPopAccounts ) {
    sprintf(StatusMessage, "%s %d\n", get_html_text("199"),
      MaxPopAccounts);
    show_menu();
    vclose();
    exit(0);
  }
 
  GetValue(TmpCGI,Newu, "newu=", MAX_BUFF);

  if ( fixup_local_name(Newu) ) {
    sprintf(StatusMessage, "%s %s\n", get_html_text("148"), Newu);
    adduser();
    vclose();
    exit(0);
  } 

  if ( check_local_user(Newu) ) {
    sprintf(StatusMessage, "%s %s\n", get_html_text("175"), Newu);
    adduser();
    vclose();
    exit(0);
  } 
  GetValue(TmpCGI,Password1, "password1=", MAX_BUFF);
  GetValue(TmpCGI,Password2, "password2=", MAX_BUFF);
  if ( strncmp( Password1, Password2, MAX_BUFF ) != 0 ) {
    sprintf(StatusMessage, "%s\n", get_html_text("200"));
    adduser();
    vclose();
    exit(0);
  }

  if ( strlen(Password1) <= 0 ) {
    sprintf(StatusMessage, "%s\n", get_html_text("234"));
    adduser();
    vclose();
    exit(0);
  }

  strcpy(email, "");
  strcat(email,Newu);
  strcat(email,"@");
  strcat(email,Domain);
    
  GetValue(TmpCGI,Gecos, "gecos=", MAX_BUFF);
  if ( strlen( Gecos ) == 0 ) {
    strcpy(Gecos, Newu);
  }

  GetValue(TmpCGI, c_num, "number_of_mailinglist=", MAX_BUFF);
  num = atoi(c_num);
  if(!(mailingListNames = malloc(sizeof(char *) * num))) {
    sprintf(StatusMessage, "%s\n", get_html_text("201"));
    vclose();
    exit(0);

  } else {
    for(cnt = 0; cnt < num; cnt++) {
      if(!(mailingListNames[cnt] = malloc(MAX_BUFF))) {
        sprintf(StatusMessage, "%s\n", get_html_text("201"));
        vclose();
        exit(0);
      }
    }

    for(cnt = 0; cnt < num; cnt++) {
      sprintf(tmp, "subscribe%d=", cnt);
      error = GetValue(TmpCGI, mailingListNames[cnt], tmp, MAX_BUFF);
      if( error != -1 ) {
        pid=fork();

        if (pid==0) {
          sprintf(TmpBuf1, "%s/ezmlm-sub", EZMLMDIR);
          sprintf(TmpBuf2, "%s/%s", RealDir, mailingListNames[cnt]);
          execl(TmpBuf1, "ezmlm-sub", TmpBuf2, email, NULL);
          exit(127);
        } else {
          wait(&pid);
        }
      } 
    }
  }

  /* add the user then get the vpopmail password structure */
  if ( vadduser( Newu, Domain, Password1, Gecos, USE_POP ) == 0 && 
#ifdef MYSQL_REPLICATION
    !sleep(2) &&
#endif
    (mypw = vauth_getpw( Newu, Domain )) != NULL ) {

    /* from the load_limits() function, set user flags */
    if( DisablePOP > 0 )     mypw->pw_gid |= NO_POP; 
    if( DisableIMAP > 0 )    mypw->pw_gid |= NO_IMAP; 
    if( DisableDialup > 0 )  mypw->pw_gid |= NO_DIALUP; 
    if( DisablePasswordChanging > 0 ) mypw->pw_gid |= NO_PASSWD_CHNG; 
    if( DisableWebmail > 0 ) mypw->pw_gid |= NO_WEBMAIL; 
    if( DisableRelay > 0 )  mypw->pw_gid |= NO_RELAY; 
    if( DefaultQuota[0]!= 0 ) mypw->pw_shell = DefaultQuota;

    /* update the user information */
    if ( vauth_setpw( mypw, Domain ) != VA_SUCCESS ) {

      /* report error */
      sprintf(StatusMessage, "%s %s@%s (%s) %s",
        get_html_text("002"), Newu, Domain, Gecos,
        get_html_text("120"));

    } else {

      /* report success */
      sprintf(StatusMessage, "%s %s@%s (%s) %s",
        get_html_text("002"), Newu, Domain, Gecos,
        get_html_text("119"));
      }

    /* otherwise, report error */
  } else {
    sprintf(StatusMessage, "<font color=\"red\">%s %s@%s (%s) %s</font>", 
      get_html_text("002"), Newu, Domain, Gecos, get_html_text("120"));
  }

  call_hooks( HOOK_ADDUSER );

  /* After we add the user, show the user page
   * people like to visually verify the results
   */
  show_users(Username, Domain, Mytime);

}
/*1_Eliminacion de usuario junto con sus procesos*/
int del_user(pcbCtrl *ctrl, pcbStates *states, usersCtrl *us)
{
  pcb *temp;
  int i;
  printf("<< Eliminación de usuario >>\n");

  if( us->front != NULL )
  {
    int eleccion; //Eleccion de grupo
    users *elm = NULL; //Grupo

    do
    {
      printf("Escoja el usuario a eliminar:\n");
      show_users(us);
      do
      {
        scanf("%i", &eleccion);
        getchar();
      }while(val_npos(eleccion, 0) == FAIL);
      elm = find_user(eleccion, us->front);
    }while( val_mem( (void *) elm) );

    printf("Procesando...\n");
    if(elm->pcbU->front != NULL)
    {
      printf("Calculando la cantidad de procesos relacionados...\n");
      int tam = list_lenghtU( elm->pcbU );
      i = 0;

      if(tam > 0)
      {
        temp = elm->pcbU->front;
        do
        {
          if(temp->state == 4)
          i++;
        }while( next_pcbU(&temp, elm->pcbU->front) != FAIL);
      }
      printf("Procesos relacionados:\nDormidos: %i Otros:%i\n", i, tam);

      if(i == tam)
      {
        printf("Eliminando procesos relacionados al usuario...\n");
        do //Ciclo para eliminar los procesos relacionados al usuario
        {
          if(elm->pcbU->front == elm->pcbU->rear)
          {
            del_pcss_reaper(ctrl, states, elm->pcbU->front);
            elm->pcbU->rear = elm->pcbU->front = NULL;
            break;
          }
          else
          {
            pcb *aux = elm->pcbU->front;
            elm->pcbU->front = elm->pcbU->front->userSense->next;
            elm->pcbU->front->userSense->prev = elm->pcbU->rear;
            elm->pcbU->rear->userSense->next = elm->pcbU->front;
            del_pcss_reaper(ctrl, states, aux);
          }
        }while(1);
        printf("Procesos eliminados.\n");

        printf("Eliminando usuario...\n");
        if(us->front == us->rear)
        us->front = us->rear = NULL;
        else
        if(elm == us->front)
        {
          us->front = us->front->sense->next;
          us->front->sense->prev = us->rear;
          us->rear->sense->next = us->front;
        }
        else
        if(elm == us->rear)
        {
          us->rear = us->rear->sense->prev;
          us->front->sense->prev = us->rear;
          us->rear->sense->next = us->front;
        }
        else
        {
          elm->sense->next->sense->prev = elm->sense->prev;
          elm->sense->prev->sense->next = elm->sense->next;
        }
        free( elm );
        printf("Usuario eliminado.\n");
      }
      else
      printf("No se puede eliminar el grupo, tiene procesos pendientes.\n");
    }
    else
    {
      if(us->front == us->rear)
      us->front = us->rear = NULL;
      else
      if(elm == us->front)
      {
        us->front = us->front->sense->next;
        us->front->sense->prev = us->rear;
        us->rear->sense->next = us->front;
      }
      else
      if(elm == us->rear)
      {
        us->rear = us->rear->sense->prev;
        us->front->sense->prev = us->rear;
        us->rear->sense->next = us->front;
      }
      else
      {
        elm->sense->next->sense->prev = elm->sense->prev;
        elm->sense->prev->sense->next = elm->sense->next;
      }
      free( elm );
    }

  }
  else
    printf("No existen usuarios.\n");

}
Exemple #9
0
int rtloginu ()
{
	CIRCUIT *c, *circuit;
	USER    *user;

// Is this user already logged in to RT somewhere else?

	if (user_find(CurProc->user))
	{
		tputs("*** Already connected at another node.\n");
		return cmd_exit;
	}

	if (log_rt) tlogp("RT Login");

// Create a circuit for this user.

	circuit = circuit_new(p_user, CurProc->output);
	if (!circuit) return cmd_exit;

// Create the user entry.

	user = user_join(circuit, CurProc->user, Node->calls, Node->aliass);
	circuit->u.user = user;
	tputs("RoundTable Server.\nType /h for command summary.\nBringing up links to other nodes.\n");
	tputs("This may take a minute or two.\nThe /p command shows what nodes are linked.\n");
	text_tellu(user, rtjoin, NULL, o_all);
	user_tell(user, id_join);
	show_users();
	makelinks();

// Run in circles, scream and shout.

	for (;;) if (getinp(circuit))
	{
		if (circuit->buf[0] is '/')
		{
			if (!rt_cmd(circuit))
			{
				tputs("Returned to node.\n");
				logout(circuit);
				return cmd_ok;
			}
		}
		else
		{
			text_tellu(user, circuit->buf, NULL, o_topic); // To local users.

// To remote users.

			for (c = circuit_hd; c; c = c->next)
			if ((c->flags & p_linked) && c->refcnt && ct_find(c, user->topic))
				nprintf(c->s, "%c%c%s %s %s\n",
				FORMAT, id_data, Node->calls, user->call, circuit->buf);
		}
	}
	else
	{
		logout(circuit);
		return cmd_exit;
	}
}
Exemple #10
0
static int rt_cmd(CIRCUIT *circuit)
{
	CIRCUIT *c;
	USER    *user, *su;
	char    *f1, *f2;

	user = circuit->u.user;

	switch(tolower(circuit->buf[1]))
	{
		case 'b' :                               return FALSE;
		case 'e' : user->flags flipbit u_echo;   return true;
		
		case 'h' :
			tputs("/U - Show Users.\n/N - Enter your Name.\n/Q - Enter your QTH.\n/T - Show Topics.\n");
			tputs("/T Name - Join Topic or Create new Topic.\n/P - Show Ports and Links.\n");
			tputs("/E - Toggle Echo.\n/S CALL Text - Send Text to that station only.\n");
			tputs("/F - Force all links to be made.\n/K - Show Known nodes.\n");
			tputs("/B - Leave RoundTable and return to node.\n");
			return true;
		
		case 'k' : show_nodes();                 return true;

		case 'n' :
			strnew(&user->name, circuit->buf + 3);
			saydone();
			upduser(user);
			user_tell(user, id_user);
			return true;

		case 'p' : show_circuits(); return true;

		case 'q' :
			strnew(&user->qth, circuit->buf + 3);
			saydone();
			upduser(user);
			user_tell(user, id_user);
			return true;

		case 's' :
			strcat(circuit->buf, "\n");
			f1 = strlop(circuit->buf, ' ');  // To.
			if (!f1) break;
			f2 = strlop(f1, ' ');            // Text to send.
			if (!f2) break;
			strupr(f1);
			su = user_find(f1);

			if (!su)
			{
				tputs("*** That user is not logged in.\n");
				return true;
			}

// Send to the desired user only.

			if (su->circuit->flags & p_user)
				text_tellu(user, f2, f1, o_one);
			else
				text_xmit(user, su, f2);

			return true;

		case 't' :
			f1 = strlop(circuit->buf, ' ');
			if (f1)
			{
				topic_chg(user, f1);

// Tell all link circuits about the change of topic.

				for (c = circuit_hd; c; c = c->next)
					if (c->flags & p_linked) topic_xmit(user, c);
			}
			else
			  show_topics();
			return true;

		case 'u' : show_users(); return true;

		default  : break;
	}

	saywhat();
	return true;
}