Ejemplo n.º 1
0
/**
 * The /ns list command.
 * @param u The user who issued the command
 * @param MOD_CONT to continue processing other modules, MOD_STOP to stop processing.
 **/
static int do_list(User * u)
{

/* SADMINS can search for nicks based on their NS_VERBOTEN and NS_NO_EXPIRE
 * status. The keywords FORBIDDEN and NOEXPIRE represent these two states
 * respectively. These keywords should be included after the search pattern.
 * Multiple keywords are accepted and should be separated by spaces. Only one
 * of the keywords needs to match a nick's state for the nick to be displayed.
 * Forbidden nicks can be identified by "[Forbidden]" appearing in the last
 * seen address field. Nicks with NOEXPIRE set are preceeded by a "!". Only
 * SADMINS will be shown forbidden nicks and the "!" indicator.
 * Syntax for sadmins: LIST pattern [FORBIDDEN] [NOEXPIRE]
 * -TheShadow
 *
 * UPDATE: SUSPENDED keyword is now accepted as well.
 */


    char *pattern = strtok(NULL, " ");
    char *keyword;
    NickAlias *na;
    NickCore *mync;
    int nnicks, i;
    char buf[BUFSIZE];
    int is_servadmin = is_services_admin(u);
    int16 matchflags = 0;
    NickRequest *nr = NULL;
    int nronly = 0;
    int susp_keyword = 0;
    char noexpire_char = ' ';
    int count = 0, from = 0, to = 0, tofree = 0;
    char *tmp = NULL;
    char *s = NULL;

    if (!(!NSListOpersOnly || (is_oper(u)))) {  /* reverse the help logic */
        notice_lang(s_NickServ, u, ACCESS_DENIED);
        return MOD_STOP;
    }

    if (!pattern) {
        syntax_error(s_NickServ, u, "LIST",
                     is_servadmin ? NICK_LIST_SERVADMIN_SYNTAX :
                     NICK_LIST_SYNTAX);
    } else {

        if (pattern) {
            if (pattern[0] == '#') {
                tmp = myStrGetOnlyToken((pattern + 1), '-', 0); /* Read FROM out */
                if (!tmp) {
                	notice_lang(s_ChanServ, u, LIST_INCORRECT_RANGE);
                    return MOD_CONT;
                }
                for (s = tmp; *s; s++) {
                    if (!isdigit(*s)) {
                        free(tmp);
	                	notice_lang(s_ChanServ, u, LIST_INCORRECT_RANGE);
                        return MOD_CONT;
                    }
                }
                from = atoi(tmp);
                free(tmp);
                tmp = myStrGetTokenRemainder(pattern, '-', 1);  /* Read TO out */
                if (!tmp) {
                	notice_lang(s_ChanServ, u, LIST_INCORRECT_RANGE);
                    return MOD_CONT;
                }
                for (s = tmp; *s; s++) {
                    if (!isdigit(*s)) {
                        free(tmp);
	                	notice_lang(s_ChanServ, u, LIST_INCORRECT_RANGE);
                        return MOD_CONT;
                    }
                }
                to = atoi(tmp);
                free(tmp);
                pattern = sstrdup("*");
                tofree = 1;
            }
        }

        nnicks = 0;

        while (is_servadmin && (keyword = strtok(NULL, " "))) {
            if (stricmp(keyword, "FORBIDDEN") == 0)
                matchflags |= NS_VERBOTEN;
            if (stricmp(keyword, "NOEXPIRE") == 0)
                matchflags |= NS_NO_EXPIRE;
            if (stricmp(keyword, "SUSPENDED") == 0)
                susp_keyword = 1;
            if (stricmp(keyword, "UNCONFIRMED") == 0)
                nronly = 1;
        }

        mync = (nick_identified(u) ? u->na->nc : NULL);

        notice_lang(s_NickServ, u, NICK_LIST_HEADER, pattern);
        if (nronly != 1) {
            for (i = 0; i < 1024; i++) {
                for (na = nalists[i]; na; na = na->next) {
                    /* Don't show private and forbidden nicks to non-services admins. */
                    if ((na->status & NS_VERBOTEN) && !is_servadmin)
                        continue;
                    if ((na->nc->flags & NI_PRIVATE) && !is_servadmin
                        && na->nc != mync)
                        continue;
                    if ((matchflags != 0) && !(na->status & matchflags) && (susp_keyword == 0))
                        continue;
		    else if ((susp_keyword == 1) && !(na->nc->flags & NI_SUSPENDED))
                        continue;

                    /* We no longer compare the pattern against the output buffer.
                     * Instead we build a nice nick!user@host buffer to compare.
                     * The output is then generated separately. -TheShadow */
                    snprintf(buf, sizeof(buf), "%s!%s", na->nick,
                             (na->last_usermask
                              && !(na->status & NS_VERBOTEN)) ? na->
                             last_usermask : "*@*");
                    if (stricmp(pattern, na->nick) == 0
                        || match_wild_nocase(pattern, buf)) {

                        if ((((count + 1 >= from) && (count + 1 <= to))
                             || ((from == 0) && (to == 0)))
                            && (++nnicks <= NSListMax)) {
                            if (is_servadmin
                                && (na->status & NS_NO_EXPIRE))
                                noexpire_char = '!';
                            else {
                                noexpire_char = ' ';
                            }
                            if ((na->nc->flags & NI_HIDE_MASK)
                                && !is_servadmin && na->nc != mync) {
                                snprintf(buf, sizeof(buf),
                                         "%-20s  [Hostname Hidden]",
                                         na->nick);
                            } else if (na->status & NS_VERBOTEN) {
                                snprintf(buf, sizeof(buf),
                                         "%-20s  [Forbidden]", na->nick);
                            } else if (na->nc->flags & NI_SUSPENDED) {
                                snprintf(buf, sizeof(buf),
                                         "%-20s  [Suspended]", na->nick);
                            } else {
                                snprintf(buf, sizeof(buf), "%-20s  %s",
                                         na->nick, na->last_usermask);
                            }
                            notice_user(s_NickServ, u, "   %c%s",
                                        noexpire_char, buf);
                        }
                        count++;
                    }
                }
            }
        }

        if (nronly == 1 || (is_servadmin && matchflags == 0 && susp_keyword == 0)) {
            noexpire_char = ' ';
            for (i = 0; i < 1024; i++) {
                for (nr = nrlists[i]; nr; nr = nr->next) {
                    snprintf(buf, sizeof(buf), "%s!*@*", nr->nick);
                    if (stricmp(pattern, nr->nick) == 0
                        || match_wild_nocase(pattern, buf)) {
                        if (++nnicks <= NSListMax) {
                            snprintf(buf, sizeof(buf),
                                     "%-20s  [UNCONFIRMED]", nr->nick);
                            notice_user(s_NickServ, u, "   %c%s",
                                        noexpire_char, buf);
                        }
                    }
                }
            }
        }
        notice_lang(s_NickServ, u, NICK_LIST_RESULTS,
                    nnicks > NSListMax ? NSListMax : nnicks, nnicks);
    }
    if (tofree)
        free(pattern);
    return MOD_CONT;
}
Ejemplo n.º 2
0
enum command_type
scan(char *buffer)
{
  while(!feof(get_byte_argument))
  { 
    char c = get_byte(get_byte_argument);
    char d = get_byte(get_byte_argument);
    if(d == '#' && !strchr("\n\t ", c))
      syntax_error();
    ungetc(d, get_byte_argument);
    switch(c)
    {
      case '#':
        d = get_byte(get_byte_argument);
      	while(d != '\n')
      	{
            if(d == EOF)
              return SIMPLE_COMMAND;
        	  d = get_byte(get_byte_argument);
      	}
        return scan(buffer);
      case '&':
        d = get_byte(get_byte_argument);
        if(d == '&')
        {
          eat_whitespace();
          return AND_COMMAND;
        }
        else if(d == EOF)
          syntax_error();
        else 
          ungetc(d, get_byte_argument);
        break;
      case '(':
      {
        eat_whitespace();
        return SUBSHELL_COMMAND;
      }
      case ')':
      {
        ungetc(c, get_byte_argument);
        return SIMPLE_COMMAND;
      }
      case '|':
        d = get_byte(get_byte_argument);
        if(d == '|')
        {
          eat_whitespace();
          return OR_COMMAND;
        }
        else if(isalnum(d) || strchr("!%+,-./:@^_\t\n ", d))
        {
          ungetc(d, get_byte_argument);
          eat_whitespace();
          return PIPE_COMMAND;
        }
        else if(d == EOF)
          syntax_error();
      case '\n': line_count++;
      case ';':
      case EOF:
        return SIMPLE_COMMAND;
    }
    buffer[strlen(buffer)] = c;
  }
  return SEQUENCE_COMMAND;
}
Ejemplo n.º 3
0
int do_addnick(User * u)
{
    NickAlias *na, *target;
    NickCore *nc;
    char *nick = strtok(NULL, " ");
    char *pass = strtok(NULL, " ");
    int i;
    char tsbuf[16];
    char modes[512];
    int len;

    if (NSEmailReg && (findrequestnick(u->nick))) {
        notice_lang(s_NickServ, u, NS_REQUESTED);
        return MOD_CONT;
    }

    if (readonly) {
        notice_lang(s_NickServ, u, NS_ADDNICK_DISABLED);
        return MOD_CONT;
    }
    if (checkDefCon(DEFCON_NO_NEW_NICKS)) {
        notice_lang(s_NickServ, u, OPER_DEFCON_DENIED);
        return MOD_CONT;
    }

    if (RestrictOperNicks) {
        for (i = 0; i < RootNumber; i++) {
            if (stristr(u->nick, ServicesRoots[i]) && !is_oper(u)) {
                notice_lang(s_NickServ, u, NICK_CANNOT_BE_REGISTERED,
                            u->nick);
                return MOD_CONT;
            }
        }
        for (i = 0; i < servadmins.count && (nc = servadmins.list[i]); i++) {
            if (stristr(u->nick, nc->display) && !is_oper(u)) {
                notice_lang(s_NickServ, u, NICK_CANNOT_BE_REGISTERED,
                            u->nick);
                return MOD_CONT;
            }
        }
        for (i = 0; i < servopers.count && (nc = servopers.list[i]); i++) {
            if (stristr(u->nick, nc->display) && !is_oper(u)) {
                notice_lang(s_NickServ, u, NICK_CANNOT_BE_REGISTERED,
                            u->nick);
                return MOD_CONT;
            }
        }
    }

    if (!nick || !pass) {
        syntax_error(s_NickServ, u, "ADDNICK", NS_ADDNICK_SYNTAX);
    } else if (!(target = findnick(nick))) {
        notice_lang(s_NickServ, u, NICK_X_NOT_REGISTERED, nick);
    } else if (time(NULL) < u->lastnickreg + NSRegDelay) {
        notice_lang(s_NickServ, u, NS_ADDNICK_PLEASE_WAIT, NSRegDelay);
    } else if (u->na && (u->na->status & NS_VERBOTEN)) {
        alog("%s: %s@%s tried to use ADDNICK from forbidden nick %s.",
             s_NickServ, u->username, u->host, u->nick);
        notice_lang(s_NickServ, u, NICK_X_FORBIDDEN, u->nick);
    } else if (u->na && (u->na->nc->flags & NI_SUSPENDED)) {
        alog("%s: %s!%s@%s tried to use ADDNICK from suspended nick %s.",
             s_NickServ, u->nick, u->username, u->host, target->nick);
        notice_lang(s_NickServ, u, NICK_X_SUSPENDED, u->nick);
    } else if (u->na && NSNoGroupChange) {
        notice_lang(s_NickServ, u, NS_ADDNICK_CHANGE_DISABLED, s_NickServ);
    } else if (u->na && !nick_identified(u)) {
        notice_lang(s_NickServ, u, NICK_IDENTIFY_REQUIRED, s_NickServ);
    } else if (target && (target->nc->flags & NI_SUSPENDED)) {
        alog("%s: %s!%s@%s tried to use GROUP from SUSPENDED nick %s",
             s_NickServ, u->nick, u->username, u->host, target->nick);
        notice_lang(s_NickServ, u, NICK_X_SUSPENDED, target->nick);
    } else if (target->status & NS_VERBOTEN) {
        notice_lang(s_NickServ, u, NICK_X_FORBIDDEN, nick);
    } else if (u->na && target->nc == u->na->nc) {
        notice_lang(s_NickServ, u, NS_ADDNICK_SAME, target->nick);
    } else if (NSMaxAliases && (target->nc->aliases.count >= NSMaxAliases)
               && !nick_is_services_admin(target->nc)) {
        notice_lang(s_NickServ, u, NS_ADDNICK_TOO_MANY, target->nick,
                    s_NickServ, s_NickServ);
    } else if (enc_check_password(pass, target->nc->pass) != 1) {
        alog("%s: Failed ADDNICK for %s!%s@%s (invalid password).",
             s_NickServ, u->nick, u->username, u->host);
        notice_lang(s_NickServ, u, PASSWORD_INCORRECT);
        bad_password(u);
    } else {
        /* If the nick is already registered, drop it.
         * If not, check that it is valid.
         */
        if (u->na) {
            delnick(u->na);
        } else {
            int prefixlen = strlen(NSGuestNickPrefix);
            int nicklen = strlen(u->nick);

            if (nicklen <= prefixlen + 7 && nicklen >= prefixlen + 1
                && stristr(u->nick, NSGuestNickPrefix) == u->nick
                && strspn(u->nick + prefixlen,
                          "1234567890") == nicklen - prefixlen) {
                notice_lang(s_NickServ, u, NICK_CANNOT_BE_REGISTERED,
                            u->nick);
                return MOD_CONT;
            }
        }
        na = makealias(u->nick, target->nc);

        if (na) {
            na->last_usermask =
                scalloc(strlen(common_get_vident(u)) +
                        strlen(common_get_vhost(u)) + 2, 1);
            sprintf(na->last_usermask, "%s@%s", common_get_vident(u),
                    common_get_vhost(u));
            na->last_realname = sstrdup(u->realname);
            na->time_registered = na->last_seen = time(NULL);
            na->status = (int16) (NS_IDENTIFIED | NS_RECOGNIZED);

            if (!(na->nc->flags & NI_SERVICES_ROOT)) {
                for (i = 0; i < RootNumber; i++) {
                    if (!stricmp(ServicesRoots[i], u->nick)) {
                        na->nc->flags |= NI_SERVICES_ROOT;
                        break;
                    }
                }
            }

            u->na = na;
            na->u = u;

#ifdef USE_RDB
            /* Is this really needed? Since this is a new alias it will get
             * its unique id on the next update, since it was previously
             * deleted by delnick. Must observe...
             */
            if (rdb_open()) {
                rdb_save_ns_alias(na);
                rdb_close();
            }
#endif
            send_event(EVENT_GROUP, 1, u->nick);
            alog("%s: %s!%s@%s makes %s join group of %s (%s) (e-mail: %s)", s_NickServ, u->nick, u->username, u->host, u->nick, target->nick, target->nc->display, (target->nc->email ? target->nc->email : "none"));
            notice_lang(s_NickServ, u, NS_ADDNICK_SUCCESS, target->nick);

            u->lastnickreg = time(NULL);
            snprintf(tsbuf, sizeof(tsbuf), "%lu",
                     (unsigned long int) u->timestamp);
            if (ircd->modeonreg) {
                len = strlen(ircd->modeonreg);
                strncpy(modes,ircd->modeonreg,512);
	       if(ircd->rootmodeonid && is_services_root(u)) { 
                    strncat(modes,ircd->rootmodeonid,512-len);
	        } else if(ircd->adminmodeonid && is_services_admin(u)) {
                    strncat(modes,ircd->adminmodeonid,512-len);
	        } else if(ircd->opermodeonid && is_services_oper(u)) {
                    strncat(modes,ircd->opermodeonid,512-len);
                }
                if (ircd->tsonmode) {
                    common_svsmode(u, modes, tsbuf);
                } else {
                    common_svsmode(u, modes, NULL);
                }
            }

            check_memos(u);
        } else {
            alog("%s: makealias(%s) failed", s_NickServ, u->nick);
            notice_lang(s_NickServ, u, NS_ADDNICK_FAILED);
        }
    }
    return MOD_CONT;
}
Ejemplo n.º 4
0
Term Yap_syntax_error(TokEntry *errtok, int sno) {
  return syntax_error(errtok, sno, CurrentModule);
}
Ejemplo n.º 5
0
/**
 * The /hs set command.
 * @param u The user who issued the command
 * @param MOD_CONT to continue processing other modules, MOD_STOP to stop processing.
 **/
static int myDoSet(User * u)
{
    char *nick = strtok(NULL, " ");
    char *rawhostmask = strtok(NULL, " ");
    char *hostmask = smalloc(HOSTMAX);

    NickAlias *na;
    int32 tmp_time;
    char *s;

    char *vIdent = NULL;

    if (!nick || !rawhostmask) {
        syntax_error(s_HostServ, u, "SET", HOST_SET_SYNTAX);
        free(hostmask);
        return MOD_CONT;
    }

    vIdent = myStrGetOnlyToken(rawhostmask, '@', 0);    /* Get the first substring, @ as delimiter */
    if (vIdent) {
        rawhostmask = myStrGetTokenRemainder(rawhostmask, '@', 1);      /* get the remaining string */
        if (!rawhostmask) {
            syntax_error(s_HostServ, u, "SET", HOST_SET_SYNTAX);
            free(vIdent);
            free(hostmask);
            return MOD_CONT;
        }
        if (strlen(vIdent) > USERMAX - 1) {
            notice_lang(s_HostServ, u, HOST_SET_IDENTTOOLONG, USERMAX);
            free(vIdent);
            free(rawhostmask);
            free(hostmask);
            return MOD_CONT;
        } else {
            for (s = vIdent; *s; s++) {
                if (!isvalidchar(*s)) {
                    notice_lang(s_HostServ, u, HOST_SET_IDENT_ERROR);
                    free(vIdent);
                    free(rawhostmask);
                    free(hostmask);
                    return MOD_CONT;
                }
            }
        }
        if (!ircd->vident) {
            notice_lang(s_HostServ, u, HOST_NO_VIDENT);
            free(vIdent);
            free(rawhostmask);
            free(hostmask);
            return MOD_CONT;
        }
    }
    if (strlen(rawhostmask) < HOSTMAX)
        snprintf(hostmask, HOSTMAX, "%s", rawhostmask);
    else {
        notice_lang(s_HostServ, u, HOST_SET_TOOLONG, HOSTMAX);
        if (vIdent) {
            free(vIdent);
            free(rawhostmask);
        }
        free(hostmask);
        return MOD_CONT;
    }

    if (!isValidHost(hostmask, 3)) {
        notice_lang(s_HostServ, u, HOST_SET_ERROR);
        if (vIdent) {
            free(vIdent);
            free(rawhostmask);
        }
        free(hostmask);
        return MOD_CONT;
    }


    tmp_time = time(NULL);

    if ((na = findnick(nick))) {
        if (na->status & NS_VERBOTEN) {
            notice_lang(s_HostServ, u, NICK_X_FORBIDDEN, nick);
            if (vIdent) {
                free(vIdent);
                free(rawhostmask);
            }
            free(hostmask);
            return MOD_CONT;
        }
        if (vIdent && ircd->vident) {
            alog("vHost for user \002%s\002 set to \002%s@%s\002 by oper \002%s\002", nick, vIdent, hostmask, u->nick);
        } else {
            alog("vHost for user \002%s\002 set to \002%s\002 by oper \002%s\002", nick, hostmask, u->nick);
        }
        addHostCore(nick, vIdent, hostmask, u->nick, tmp_time);
        if (vIdent) {
            notice_lang(s_HostServ, u, HOST_IDENT_SET, nick, vIdent,
                        hostmask);
        } else {
            notice_lang(s_HostServ, u, HOST_SET, nick, hostmask);
        }
    } else {
        notice_lang(s_HostServ, u, HOST_NOREG, nick);
    }
    free(hostmask);
    if (vIdent) {
        free(vIdent);
        free(rawhostmask);
    }
    return MOD_CONT;
}
Ejemplo n.º 6
0
int
validate (token_t *token_array)
{
  int i = 0;
  int res = 1;
  int in_subshell = 0;
  int token_array_len = 0;
  while (!(token_array[i]->line_num == -1)) {
    token_array_len++;
    i++;
  }

  i = 0;
  while (i < token_array_len && !(token_array[i]->line_num == -1)) 
  {
    char *operand = token_array[i]->word;

    // if (!is_char_validated(operand)) syntax_error(token_array[i]->line_num);
    if (!is_valid_operator(operand) && !is_valid_word(operand)) syntax_error(token_array[i]->line_num);

    if (operand[0] == '(') 
    {
      in_subshell = 1;
      if (i + 1 >= token_array_len) {
        res = 0;
        syntax_error(token_array_len);
      } 
      else 
      {
        if (token_array[i + 1]->word[0] != ')') 
        {
          token_t *sub_token_array = checked_malloc(sizeof (token_t) * 128);
          tokenize (token_array[i+1]->word, sub_token_array, token_array[i+1]->line_num);

          // int j = 0;
          // printf("subshell\n" );
          // while (sub_token_array[j]->line_num != -1) {
          //   printf ("token %d\n  word:'%s' line_number:%d\n", j, sub_token_array[j]->word, sub_token_array[j]->line_num);
          //   j++;
          // }

          if (validate (sub_token_array))
          {
            i++;
          }
        }
      }
      i++;
      continue;
    } 

    if (operand[0] == ')')
    {
      if (i - 1 < 0) {
        res = 0;
        syntax_error(0);
      } 
      else 
      {
        if (!in_subshell) 
        {
          res = 0;
          // error_number = (i - 1 >= 0) ? token_array[i - 1]->line_num: token_array[i]->line_num;
          syntax_error(token_array[i]->line_num);
        }
        else
        {
          in_subshell = 0;
        }
      }
      i++;
      continue;
    }

    if (!strcmp(operand, ";") || !strcmp(operand, "||") || !strcmp(operand, "|") || !strcmp(operand, "&&")) 
    {
      if (i - 1 < 0) 
      {
        res = 0;
        syntax_error(token_array[i]->line_num);
      }
      // else 
      // {
      //  if 
      // }
      if (!strcmp(operand, ";")) {
        if (i < token_array_len - 1 && (!strcmp(token_array[i + 1]->word, "&&") 
          || !strcmp(token_array[i + 1]->word, "||") || !strcmp(token_array[i + 1]->word, "|") 
          || token_array[i + 1]->word[0] == '>' || token_array[i + 1]->word[0] == '<' || 
          !strcmp(token_array[i+1]->word, ";")))
        {
          res = 0;
          syntax_error(token_array[i]->line_num);
        }

        if (i >= token_array_len - 1) 
        {
          res = 0;
          syntax_error(token_array[i]->line_num);
        }

        if (i - 1 >= 0)
        {
          char *tmp = token_array[i - 1]->word;
          int j = strlen(tmp) - 1;
          while (j >= 0)
          {
            if (tmp[j] == ' ' || tmp[j] == '\t') {j--; continue;}
            if (tmp[j] == '>' || tmp[j] == '<')
            {
              res = 0;
              syntax_error(token_array[i - 1]->line_num);
            }
            j--;
          }
        }
      }
      else 
      {
        if (i < token_array_len - 1 && (!strcmp(token_array[i + 1]->word, "&&") 
          || !strcmp(token_array[i + 1]->word, "||") || !strcmp(token_array[i + 1]->word, "|") 
          ))
        {
          res = 0;
          syntax_error(token_array[i]->line_num);
        } 
        if (i >= token_array_len - 1) 
        {
          res = 0;
          syntax_error(token_array[i]->line_num);
        }
      }
      
    }

    if (!strcmp(operand, "<") || !strcmp(operand, ">"))
    {
      if (i == token_array_len - 1 || i == 0) 
      {
        res = 0;
        syntax_error(token_array[i]->line_num);
      } 
      else 
      {
        if (!strcmp(token_array[i+1]->word, ">") || !strcmp(token_array[i+1]->word, "<"))
        {
          res = 0;
          syntax_error(token_array[i]->line_num);
        }
      }
    }
    

    i++;  
  }

  return res;
}
Ejemplo n.º 7
0
static int	syntax_error_and_return(int line_nb)
{
      syntax_error(line_nb);
      return (1);
}
Ejemplo n.º 8
0
int eat_int(tokenizer_t t){
  token tok = cur_tok(t);
  if(tok.kind != tok_int) syntax_error(t);
  next_tok(t);
  return tok.ival;
}
Ejemplo n.º 9
0
void eat_plus(tokenizer_t t){
  token tok = cur_tok(t);
  if (tok.kind != tok_plus) syntax_error(t);
  next_tok(t);
}
Ejemplo n.º 10
0
/**
 * ChanKill - Akill an entire channel (got botnet?)
 *
 * /msg OperServ ChanKill +expire #channel reason
 * @param u The user who issued the command
 * @param MOD_CONT to continue processing other modules, MOD_STOP to stop processing. 
 *
 **/
int do_chankill(User * u)
{
    char *expiry, *channel, *reason;
    time_t expires;
    char breason[BUFSIZE];
    char mask[USERMAX + HOSTMAX + 2];
    struct c_userlist *cu, *next;
    Channel *c;

    channel = strtok(NULL, " ");
    if (channel && *channel == '+') {
        expiry = channel;
        channel = strtok(NULL, " ");
    } else {
        expiry = NULL;
    }

    expires = expiry ? dotime(expiry) : ChankillExpiry;
    if (expiry && isdigit(expiry[strlen(expiry) - 1]))
        expires *= 86400;
    if (expires != 0 && expires < 60) {
        notice_lang(s_OperServ, u, BAD_EXPIRY_TIME);
        return MOD_CONT;
    } else if (expires > 0) {
        expires += time(NULL);
    }

    if (channel && (reason = strtok(NULL, ""))) {

        if (AddAkiller) {
            snprintf(breason, sizeof(breason), "[%s] %s", u->nick, reason);
            reason = sstrdup(breason);
        }

        if ((c = findchan(channel))) {
            for (cu = c->users; cu; cu = next) {
                next = cu->next;
                if (is_oper(cu->user)) {
                    continue;
                }
                (void) strncpy(mask, "*@", 3); /* Use *@" for the akill's, */
                strncat(mask, cu->user->host, HOSTMAX);
                add_akill(NULL, mask, s_OperServ, expires, reason);
                check_akill(cu->user->nick, cu->user->username,
                            cu->user->host, NULL, NULL);
            }
            if (WallOSAkill) {
                xanadu_cmd_global(s_OperServ, "%s used CHANKILL on %s (%s)",
                                 u->nick, channel, reason);
            }
        } else {
            notice_lang(s_OperServ, u, CHAN_X_NOT_IN_USE, channel);
        }
        if (AddAkiller) {
            free(reason);
        }
    } else {
        syntax_error(s_OperServ, u, "CHANKILL", OPER_CHANKILL_SYNTAX);
    }
    return MOD_CONT;
}
Ejemplo n.º 11
0
	std::vector<command> parse_line()
	{
		line = "";
		std::vector<command> pipes;
		std::vector<std::string> argvs;
		std::string argv, file1, file2;
		int file_num = 0, pipe_num = 1;
		int user_out = 0, user_in = 0;
		
		while(true)
		{
			char c = std::cin.get();
			if(!std::cin.good() || std::cin.eof())
				exit(0);	
			
			if(c != '\n' && c != '\r') 
				line.push_back(c);
			
			//if(c == '"')
			//{
			//	std::getline(std::cin, argv, '"');
			//	line += argv;
			//}	
			//else if(c == '\'')
			//{
			//	std::getline(std::cin, argv, '\'');
			//	line += argv;
			//}
			
			if(c == ' ' || c == '|' || c == '\n')
			{
				if(argv.size() != 0)
				{
					argv.erase(std::remove(argv.begin(), argv.end(), '\r'), argv.end());
					argvs.push_back(argv);
					argv = "";
				}
			}
			if(c == ' ' || c == '\r') 
			{}
			else if(c == '/')
			{
				syntax_error(c);
				argv = ""; file1 = ""; file2 = ""; user_out = 0; user_in = 0;
				argvs.resize(0); pipes.resize(0);
				file_num=0; pipe_num=1;
			}
			else if(c == '|')
			{
				while(true)
				{
					char nc = std::cin.peek();
					if(nc >= 48 && nc <= 57)// is 0~9
						argv.push_back(std::cin.get());
					else
						break;
				}
				pipe_num = std::atoi(argv.c_str());
				if(pipe_num == 0)
					pipe_num = 1;
				pipes.push_back({pipe_num, 0, false, argvs, file1, file2, user_out, user_in});
				line += argv;
				argv = ""; file1 = ""; file2 = ""; user_out = 0; user_in = 0;
				argvs.resize(0);				
				pipe_num = 1;
			}
			else if(c == '>')
			{
				int file_num = 1;
				// ls >f, ls > f
				if(argv.size() != 0)
				{ // ls 2> f, ls 2>f
					int num = std::atoi(argv.c_str());
					if(num == 0) // ls>f
						argvs.push_back(argv);
					else
						file_num = num;
				}
				line += argv;
				argv = "";
				int tag = parse_next_word(argv);
				if( tag == 0)
				{
					syntax_error(std::cin.peek());
					pipes.resize(0); argvs.resize(0);
				}
				int to_user = atoi(argv.c_str());
				if(tag == 1 || to_user == 0) // file
				{
					if(file_num == 1)
						file1 = argv;
					else
						file2 = argv;
				}
				else
				{
					user_out = to_user;
				}
				argv = "";
			}
			else if(c == '<')
			{
				int file_num = 1;
				// ls >f, ls > f
				if(argv.size() != 0)
				{ // ls 2> f, ls 2>f
					int num = std::atoi(argv.c_str());
					if(num == 0) // ls>f
						argvs.push_back(argv);
					else
						file_num = num;
				}
				line += argv;
				argv = "";
				int tag = parse_next_word(argv);
				if( tag == 0)
				{
					syntax_error(std::cin.peek());
					pipes.resize(0); argvs.resize(0);
				}
				int to_user = atoi(argv.c_str());
				if(tag == 1 || to_user == 0) // file
				{}
				else
				{
					user_in = to_user;
				}
				argv = "";
			}
			else if(c == '\n')
			{
				if(argvs.size() > 0)
					pipes.push_back({pipe_num, 0, true, argvs, file1, file2, user_out, user_in});
				break;
			}
			else
				argv.push_back(c);
		}
		return pipes;
	}
Ejemplo n.º 12
0
void
zzsyn(char *        text,
      int           tok, 
      char *        egroup,
      SetWordType * eset,
      int           etok,
      int           k,
      char *        bad_text)
{
   static char    msg [MAX_ERROR];
   int            len;

#ifndef ALLOW_WARNINGS
   text = NULL;                         /* avoid "unused parameter" warning */
#endif

   /* Initial message: give location of error */

   msg[0] = (char) 0;           /* make sure string is empty to start! */
   if (tok == zzEOF_TOKEN)
      strcat (msg, "at end of input");
   else
      sprintf (msg, "found \"%s\"", bad_text);

   len = strlen (msg);

   
   /* Caller supplied neither a single token nor set of tokens expected... */

   if (!etok && !eset)
   {
      syntax_error (msg);
      return;
   }
   else
   {
      strcat (msg, ", ");
      len += 2;
   }

   
   /* I'm not quite sure what this is all about, or where k would be != 1... */
   
   if (k != 1)
   {
      sprintf (msg+len, "; \"%s\" not", bad_text);
      if (zzset_deg (eset) > 1) strcat (msg, " in");
      len = strlen (msg);
   }


   /* This is the code that usually gets run */
   
   if (zzset_deg (eset) > 0) 
   {
      if (zzset_deg (eset) == 1)
         strcat (msg, "expected ");
      else
         strcat (msg, "expected one of: ");

      append_token_set (msg, eset);
   }
   else
   {
      sprintf (msg+len, "expected %s", zztokens[etok]);
      if (etok == ENTRY_CLOSE)
      {
         strcat (msg, " (skipping to next \"@\")");
         initialize_lexer_state ();
      }
   }

   len = strlen (msg);
   if (egroup && strlen (egroup) > 0) 
      sprintf (msg+len, " in %s", egroup);

   syntax_error (msg);

}
Ejemplo n.º 13
0
/**
 * The /ns saset command.
 * @param u The user who issued the command
 * @param MOD_CONT to continue processing other modules, MOD_STOP to stop processing.
 **/
static int do_saset(User * u)
{
    char *nick = strtok(NULL, " ");
    char *cmd = strtok(NULL, " ");
    char *param = strtok(NULL, " ");

    NickAlias *na;

    if (readonly) {
        notice_lang(s_NickServ, u, NICK_SASET_DISABLED);
        return MOD_CONT;
    }
	if (!nick) {
		syntax_error(s_NickServ, u, "SASET", NICK_SASET_SYNTAX);
		return MOD_CONT;
	}
    if (!(na = findnick(nick))) {
        notice_lang(s_NickServ, u, NICK_SASET_BAD_NICK, nick);
        return MOD_CONT;
    }

    if (!param
        && (!cmd
            || (stricmp(cmd, "URL") != 0 && stricmp(cmd, "EMAIL") != 0
                && stricmp(cmd, "GREET") != 0
                && stricmp(cmd, "ICQ") != 0))) {
        syntax_error(s_NickServ, u, "SASET", NICK_SASET_SYNTAX);
    } else if (!na) {
        notice_lang(s_NickServ, u, NICK_NOT_REGISTERED, nick);
    } else if (na->status & NS_VERBOTEN) {
        notice_lang(s_NickServ, u, NICK_X_FORBIDDEN, na->nick);
    } else if (na->nc->flags & NI_SUSPENDED) {
        notice_lang(s_NickServ, u, NICK_X_SUSPENDED, na->nick);
    } else if (stricmp(cmd, "DISPLAY") == 0) {
        do_saset_display(u, na->nc, param);
    } else if (stricmp(cmd, "PASSWORD") == 0) {
        do_saset_password(u, na->nc, param);
    } else if (stricmp(cmd, "URL") == 0) {
        do_saset_url(u, na->nc, param);
    } else if (stricmp(cmd, "EMAIL") == 0) {
        do_saset_email(u, na->nc, param);
    } else if (stricmp(cmd, "ICQ") == 0) {
        do_saset_icq(u, na->nc, param);
    } else if (stricmp(cmd, "GREET") == 0) {
        do_saset_greet(u, na->nc, param);
    } else if (stricmp(cmd, "KILL") == 0) {
        do_saset_kill(u, na->nc, param);
    } else if (stricmp(cmd, "SECURE") == 0) {
        do_saset_secure(u, na->nc, param);
    } else if (stricmp(cmd, "PRIVATE") == 0) {
        do_saset_private(u, na->nc, param);
    } else if (stricmp(cmd, "MSG") == 0) {
        do_saset_msg(u, na->nc, param);
    } else if (stricmp(cmd, "HIDE") == 0) {
        do_saset_hide(u, na->nc, param);
    } else if (stricmp(cmd, "NOEXPIRE") == 0) {
        do_saset_noexpire(u, na, param);
    } else if (stricmp(cmd, "AUTOOP") == 0) {
        do_saset_autoop(u, na->nc, param); 
    } else if (stricmp(cmd, "LANGUAGE") == 0) {
        do_saset_language(u, na->nc, param);
    } else {
        notice_lang(s_NickServ, u, NICK_SASET_UNKNOWN_OPTION, cmd);
    }
    return MOD_CONT;
}
Ejemplo n.º 14
0
static foreign_t
turtle_read_string(term_t C0, term_t Stream, term_t C, term_t Value)
{ int c;
  charbuf b;
  IOSTREAM *in;
  int endlen = 1;

  if ( !PL_get_integer(C0, &c) )
    return type_error(C0, "code");
  if ( c != '"' )
    return FALSE;

  if ( !PL_get_stream_handle(Stream, &in) )
    return FALSE;

  init_charbuf(&b);

  c = Sgetcode(in);
  if ( c == '"' )
  { c = Sgetcode(in);
    if ( c == '"' )			/* """...""" */
    { endlen = 3;
      c = Sgetcode(in);
    } else
    { PL_release_stream(in);
      return (PL_unify_integer(C, c) &&
	      PL_unify_atom(Value, ATOM_));
    }
  }

  for(;;c = Sgetcode(in))
  { if ( c == -1 )
    { free_charbuf(&b);
      PL_release_stream(in);
      return syntax_error("eof_in_string", in);
    } else if ( c == '"' )
    { int count = 1;

      for(count=1; count<endlen; )
      { if ( (c=Sgetcode(in)) == '"' )
	  count++;
	else
	  break;
      }

      if ( count == endlen )
      { int rc;

	c = Sgetcode(in);
	rc = (PL_unify_integer(C, c) &&
	      PL_unify_wchars(Value, PL_ATOM, b.here-b.base, b.base));
	free_charbuf(&b);
	PL_release_stream(in);
	return rc;
      }

      while(count-- > 0)
	add_charbuf(&b, '"');
      add_charbuf(&b, c);
    } else if ( c == '\\' )
    { int esc;

      c = Sgetcode(in);
      if ( !string_escape(in, c, &esc) )
      { free_charbuf(&b);
	PL_release_stream(in);
	return FALSE;
      }
      add_charbuf(&b, esc);
    } else
    { add_charbuf(&b, c);
    }
  }
}
Ejemplo n.º 15
0
static int do_akill(User * u)
{
    char *cmd = strtok(NULL, " ");
    char breason[BUFSIZE];

    if (!cmd)
        cmd = "";

    if (!stricmp(cmd, "ADD")) {
        int deleted = 0;
        char *expiry, *mask, *reason;
        time_t expires, now = time(NULL);

        mask = strtok(NULL, " ");
        if (mask && *mask == '+') {
            expiry = mask;
            mask = strtok(NULL, " ");
        } else {
            expiry = NULL;
        }

        expires = expiry ? dotime(expiry) : AutokillExpiry;
        /* If the expiry given does not contain a final letter, it's in days,
         * said the doc. Ah well.
         */
        if (expiry && isdigit(expiry[strlen(expiry) - 1]))
            expires *= 86400;
        /* Do not allow less than a minute expiry time */
        if (expires != 0 && expires < 60) {
            notice_lang(s_OperServ, u, BAD_EXPIRY_TIME);
            return MOD_CONT;
        } else if (expires > 0) {
            expires += time(NULL);
        }

        if (mask && (reason = strtok(NULL, ""))) {
            /* We first do some sanity check on the proposed mask. */
            if (strchr(mask, '!')) {
                notice_lang(s_OperServ, u, OPER_AKILL_NO_NICK);
                return MOD_CONT;
            }

            if (!strchr(mask, '@')) {
                notice_lang(s_OperServ, u, BAD_USERHOST_MASK);
                return MOD_CONT;
            }

            if (mask && strspn(mask, "~@.*?") == strlen(mask)) {
                notice_lang(s_OperServ, u, USERHOST_MASK_TOO_WIDE, mask);
                return MOD_CONT;
            }

            /**
             * Changed sprintf() to snprintf()and increased the size of
             * breason to match bufsize
             * -Rob
             **/
            if (AddAkiller) {
                snprintf(breason, sizeof(breason), "[%s] %s", u->nick,
                         reason);
                reason = sstrdup(breason);
            }

            deleted = add_akill(u, mask, u->nick, expires, reason);
            if (deleted < 0) {
                if (AddAkiller) {
                    free(reason);
                }
                return MOD_CONT;
            } else if (deleted) {
                notice_lang(s_OperServ, u, OPER_AKILL_DELETED_SEVERAL,
                            deleted);
            }
            notice_lang(s_OperServ, u, OPER_AKILL_ADDED, mask);

            if (WallOSAkill) {
                char buf[128];

                if (!expires) {
                    strcpy(buf, "does not expire");
                } else {
                    int wall_expiry = expires - now;
                    char *s = NULL;

                    if (wall_expiry >= 86400) {
                        wall_expiry /= 86400;
                        s = "day";
                    } else if (wall_expiry >= 3600) {
                        wall_expiry /= 3600;
                        s = "hour";
                    } else if (wall_expiry >= 60) {
                        wall_expiry /= 60;
                        s = "minute";
                    }

                    snprintf(buf, sizeof(buf), "expires in %d %s%s",
                             wall_expiry, s,
                             (wall_expiry == 1) ? "" : "s");
                }

                anope_cmd_global(s_OperServ,
                                 "%s added an AKILL for %s (%s) (%s)",
                                 u->nick, mask, reason, buf);
            }

            if (readonly) {
                notice_lang(s_OperServ, u, READ_ONLY_MODE);
            }
            if (AddAkiller) {
                free(reason);
            }
        } else {
            syntax_error(s_OperServ, u, "AKILL", OPER_AKILL_SYNTAX);
        }

    } else if (!stricmp(cmd, "DEL")) {

        char *mask;
        int res = 0;

        mask = strtok(NULL, " ");

        if (!mask) {
            syntax_error(s_OperServ, u, "AKILL", OPER_AKILL_SYNTAX);
            return MOD_CONT;
        }

        if (akills.count == 0) {
            notice_lang(s_OperServ, u, OPER_AKILL_LIST_EMPTY);
            return MOD_CONT;
        }

        if (isdigit(*mask) && strspn(mask, "1234567890,-") == strlen(mask)) {
            /* Deleting a range */
            res = slist_delete_range(&akills, mask, NULL);
            if (res == 0) {
                notice_lang(s_OperServ, u, OPER_AKILL_NO_MATCH);
                return MOD_CONT;
            } else if (res == 1) {
                notice_lang(s_OperServ, u, OPER_AKILL_DELETED_ONE);
            } else {
                notice_lang(s_OperServ, u, OPER_AKILL_DELETED_SEVERAL,
                            res);
            }
        } else {
            if ((res = slist_indexof(&akills, mask)) == -1) {
                notice_lang(s_OperServ, u, OPER_AKILL_NOT_FOUND, mask);
                return MOD_CONT;
            }

            slist_delete(&akills, res);
            notice_lang(s_OperServ, u, OPER_AKILL_DELETED, mask);
        }

        if (readonly)
            notice_lang(s_OperServ, u, READ_ONLY_MODE);

    } else if (!stricmp(cmd, "LIST")) {
        char *mask;
        int res, sent_header = 0;

        if (akills.count == 0) {
            notice_lang(s_OperServ, u, OPER_AKILL_LIST_EMPTY);
            return MOD_CONT;
        }

        mask = strtok(NULL, " ");

        if (!mask || (isdigit(*mask)
                      && strspn(mask, "1234567890,-") == strlen(mask))) {
            res =
                slist_enum(&akills, mask, &akill_list_callback, u,
                           &sent_header);
            if (res == 0) {
                notice_lang(s_OperServ, u, OPER_AKILL_NO_MATCH);
                return MOD_CONT;
            } else {
                notice_lang(s_OperServ, u, END_OF_ANY_LIST, "Akill");
            }
        } else {
            int i;
            char amask[BUFSIZE];

            for (i = 0; i < akills.count; i++) {
                snprintf(amask, sizeof(amask), "%s@%s",
                         ((Akill *) akills.list[i])->user,
                         ((Akill *) akills.list[i])->host);
                if (!stricmp(mask, amask)
                    || match_wild_nocase(mask, amask))
                    akill_list(i + 1, akills.list[i], u, &sent_header);
            }

            if (!sent_header)
                notice_lang(s_OperServ, u, OPER_AKILL_NO_MATCH);
            else {
                notice_lang(s_OperServ, u, END_OF_ANY_LIST, "Akill");
            }
        }
    } else if (!stricmp(cmd, "VIEW")) {
        char *mask;
        int res, sent_header = 0;

        if (akills.count == 0) {
            notice_lang(s_OperServ, u, OPER_AKILL_LIST_EMPTY);
            return MOD_CONT;
        }

        mask = strtok(NULL, " ");

        if (!mask || (isdigit(*mask)
                      && strspn(mask, "1234567890,-") == strlen(mask))) {
            res =
                slist_enum(&akills, mask, &akill_view_callback, u,
                           &sent_header);
            if (res == 0) {
                notice_lang(s_OperServ, u, OPER_AKILL_NO_MATCH);
                return MOD_CONT;
            }
        } else {
            int i;
            char amask[BUFSIZE];

            for (i = 0; i < akills.count; i++) {
                snprintf(amask, sizeof(amask), "%s@%s",
                         ((Akill *) akills.list[i])->user,
                         ((Akill *) akills.list[i])->host);
                if (!stricmp(mask, amask)
                    || match_wild_nocase(mask, amask))
                    akill_view(i + 1, akills.list[i], u, &sent_header);
            }

            if (!sent_header)
                notice_lang(s_OperServ, u, OPER_AKILL_NO_MATCH);
        }
    } else if (!stricmp(cmd, "CLEAR")) {
        slist_clear(&akills, 1);
        notice_lang(s_OperServ, u, OPER_AKILL_CLEAR);
    } else {
        syntax_error(s_OperServ, u, "AKILL", OPER_AKILL_SYNTAX);
    }
    return MOD_CONT;
}
Ejemplo n.º 16
0
tokenizer_t tokenize(tokenizer_t t){
  int i = 0, c = t->c;
  char a[10];
  FILE *fp = t->fp;
  if (t->num > 50) syntax_error(t);
  while (c == ' '){//スペース飛ばす
    t->error[t->num] = c;
    t->num++;
    c = fgetc(fp);
  }
  if (!isdigit(c)){//数字じゃない時
    t->error[t->num] = c;
    t->num++;
    switch (c){
      case  '+':
        t->tok.kind = TOK_PLUS;
        break;
      case '(':
        t->tok.kind = TOK_LPAREN;
        break;
      case ')':
        t->tok.kind = TOK_RPAREN;
        break;
      case '{':
        t->tok.kind = TOK_LBRACE;
        break;
      case '}':
        t->tok.kind = TOK_RBRACE;
        break;
      case '*':
        t->tok.kind = TOK_MUL;
        break;
      case '-':
        t->tok.kind = TOK_MINUS;
        break;
      case '/':
        t->tok.kind = TOK_DIV;
        break;
      case '%':
        t->tok.kind = TOK_REM;
        break;
      case '!':
        t->tok.kind = TOK_BANG;
        break;
      case '<':
        t->tok.kind = TOK_LT;
        break;
      case '>':
        t->tok.kind = TOK_GT;
        break;
      case '=':
        t->tok.kind = TOK_EQ;
        break;
      case ';':
        t->tok.kind = TOK_SEMICOLON;
        break;
      case ',':
        t->tok.kind = TOK_COMMA;
        break;
      case '\n':
        t->tok.kind = tok_nl;
        t->line++;
        memset(t->error, 0, 50);
        break;
      case EOF:
        t->tok.kind = tok_eof;
        break;
      default:
        t->tok.kind = tok_other;
        break;
    }
    t->c = fgetc(fp);
    t->fp = fp;
    return t;
  }
  while(isdigit(c)){
    t->error[t->num] = c;
    t->num++;
    if (i== 9) syntax_error(t);
    a[i++] = (char)c;
    c = fgetc(fp);
  }
  t->c = c;
  t->fp = fp;
  t->tok.kind = tok_int;
  a[i] = 0;
  t->tok.ival = atoi(a);
  return t;
}
Ejemplo n.º 17
0
int main(int argc, const char **argv)
{
	if (argc < 3)
		return syntax_error(argv, 5);
	int csize = atoi(argv[1]), climit0 = atoi(argv[2]);
	if (csize < 1 || csize > 4)
		return syntax_error(argv, 6);
	if (climit0 < 0)
		return syntax_error(argv, 7);
	int exit_code = 0;
	size_t count = 0;
	size_t cmax = csize == 4 ? 0xffffffff :
				   0xffffffff & ((1 << (csize * 8)) - 1);
	size_t climit = climit0 ? S_MIN((size_t)climit0, cmax) : cmax;
#ifdef COUNTER_USE_BITSET
	#define COUNTER_SET(val) sb_set(&bs, val)
	#define COUNTER_POPCOUNT sb_popcount(bs)
	sb_t *bs = sb_alloc(0);
	sb_eval(&bs, cmax);
#else
	#define COUNTER_SET(val) sm_uu32_insert(&m, val, 1)
	#define COUNTER_POPCOUNT sm_size(m)
	sm_t *m = sm_alloc(SM_U32U32, 0);
#endif
	unsigned char buf[3 * 4 * 128];
	int i;
	ssize_t l;
	for (;;) {
		l = read(0, buf, sizeof(buf));
		l = (l / csize) * csize;
		if (l <= 0)
			break;
		#define CNTLOOP(inc, val)			\
			for (i = 0; i < l; i += inc) {		\
				COUNTER_SET(val);		\
				count++;			\
				if (COUNTER_POPCOUNT >= climit)	\
					goto done;		\
			}
		switch (csize) {
		case 1:	CNTLOOP(1, buf[i]);
			break;
		case 2:	CNTLOOP(2, (size_t)(buf[i] << 8 | buf[i + 1]));
			break;
		case 3:	CNTLOOP(3, (size_t)(buf[i] << 16 | buf[i + 1] << 8 | buf[i + 2]));
			break;
		case 4:	CNTLOOP(4, (size_t)buf[i] << 24 |
				   (size_t)buf[i + 1] << 16 |
				   (size_t)buf[i + 2] << 8 |
				   (size_t)buf[i + 3]);
			break;
		default:
			goto done;
		}
		#undef CNTLOOP
	}
done:
	printf(FMT_ZU ", " FMT_ZU, count, COUNTER_POPCOUNT);
#ifdef COUNTER_USE_BITSET
	sb_free(&bs);
#else
	sm_free(&m);
#endif
	return exit_code;
}
Ejemplo n.º 18
0
static void do_clearmodes(User * u)
{
	int i, all;
	int count;		/* For saving ban info */
	char *s;
	char *argv[3];
	char *chan;
	Channel *c;
	Ban **bans;		/* For saving ban info */
	struct c_userlist *cu, *next;

	chan = strtok(NULL, " ");
	all = 0;

	if (!chan) {
		syntax_error(s_OperServ, u, "CLEARMODES",
		    OPER_CLEARMODES_SYNTAX);
	} else if (!(c = findchan(chan))) {
		notice_lang(s_OperServ, u, CHAN_X_NOT_IN_USE, chan);
	} else if (c->bouncy_modes) {
		notice_lang(s_OperServ, u, OPER_BOUNCY_MODES_U_LINE);
		return;
	} else {
		s = strtok(NULL, " ");

		if (s) {
			if (stricmp(s, "ALL") == 0) {
				all = 1;
			} else {
				syntax_error(s_OperServ, u, "CLEARMODES",
				    OPER_CLEARMODES_SYNTAX);
				return;
			}
		}

		if (WallOSClearmodes) {
			wallops(s_OperServ, "%s used CLEARMODES%s on %s",
			    u->nick, all ? " ALL" : "", chan);
		}

		if (all) {
			/* Clear mode +o */
			for (cu = c->chanops; cu; cu = next) {
				next = cu->next;
				argv[0] = sstrdup(chan);
				argv[1] = sstrdup("-o");
				argv[2] = sstrdup(cu->user->nick);
				send_cmd(MODE_SENDER(s_ChanServ),
				    "MODE %s %s :%s", argv[0], argv[1],
				    argv[2]);
				do_cmode(s_ChanServ, 3, argv);
				free(argv[2]);
				free(argv[1]);
				free(argv[0]);
			}

			/* Clear mode +v */
			for (cu = c->voices; cu; cu = next) {
				next = cu->next;
				argv[0] = sstrdup(chan);
				argv[1] = sstrdup("-v");
				argv[2] = sstrdup(cu->user->nick);
				send_cmd(MODE_SENDER(s_ChanServ),
				    "MODE %s %s :%s", argv[0], argv[1],
				    argv[2]);
				do_cmode(s_ChanServ, 3, argv);
				free(argv[2]);
				free(argv[1]);
				free(argv[0]);
			}
		}

		/* Clear modes */
		send_cmd(MODE_SENDER(s_OperServ),
		    "MODE %s -ciklmMnOpsRt :%s", chan,
		    c->key ? c->key : "");
		argv[0] = sstrdup(chan);
		argv[1] = sstrdup("-ciklmMnOpsRt");
		argv[2] = c->key ? c->key : sstrdup("");
		do_cmode(s_OperServ, 2, argv);
		free(argv[0]);
		free(argv[1]);
		free(argv[2]);
		c->key = NULL;
		c->limit = 0;

		/* Clear bans */
		count = c->bancount;
		bans = smalloc(sizeof(Ban *) * count);

		for (i = 0; i < count; i++) {
			bans[i] = smalloc(sizeof(Ban));
			bans[i]->mask = sstrdup(c->newbans[i]->mask);
		}
		for (i = 0; i < count; i++) {
			argv[0] = sstrdup(chan);
			argv[1] = sstrdup("-b");
			argv[2] = bans[i]->mask;
			send_cmd(MODE_SENDER(s_OperServ), "MODE %s %s :%s",
			    argv[0], argv[1], argv[2]);
			do_cmode(s_OperServ, 3, argv);
			free(argv[2]);
			free(argv[1]);
			free(argv[0]);
			free(bans[i]);
		}
		free(bans);

		if (all) {
			notice_lang(s_OperServ, u, OPER_CLEARMODES_ALL_DONE,
			    chan);
		} else {
			notice_lang(s_OperServ, u, OPER_CLEARMODES_DONE,
			    chan);
		}
	}
}
Ejemplo n.º 19
0
void block(char *name, int level) {
	LIST *S = (LIST*)malloc(sizeof(LIST));
    SYMBOL *tmp = NULL;
	/* initial block call */
	if(is_program_block == 1) {
		is_program_block = 0;

		if(token == TK_LBRAC) {
			debug(level,"BLOCK");
			push_scope(name);
			new_function(name, PROG);
			debug_lex(level+1);
			declerations(level+1);
			subprograms(level+1);
			
         	tmp = lookup(name);
         	tmp->func.genquad = qlabel;
			main_start_quad = qlabel;         
			
			genquad("begin_block", program_name, "_", "_");
			sequence(S, level+1);

			if(token == TK_RBRAC) {
				
				
				pop_scope();
				debug_lex();
			} else {
				/* syntax error lpar expected */
				syntax_error("a '}' expected");
			}
		} else {
			/* syntax error rpar expected */
			syntax_error("'{' expected");
		}
		backpatch(S->next, int2string(nextquad()));
		
		genquad("halt", "_", "_", "_");
		genquad("end_block", program_name, "_", "_");
		
		
	} else {

		if(token == TK_LBRAC) {
			debug(level,"BLOCK");
			
			debug_lex(level+1);

			declerations(level+1);
			subprograms(level+1);
            
            tmp = lookup(name);
            tmp->func.genquad = qlabel;

			genquad("begin_block", name, "_", "_");

            fprintf(stderr, "quad quad %s %d\n", tmp->name, tmp->func.genquad);
			
            sequence(S, level+1);
			
			if(token == TK_RBRAC) {
				
				if (!strcmp(assembly, "x86")) {
					generate_final_x86( program_name);
				} else {
					generate_final( program_name);
				}
				
				pop_scope();
				debug_lex();
			} else {
				/* syntax error lpar expected */
				syntax_error("a '}' expected");
			}
			
		} else {
			/* syntax error rpar expected */
			syntax_error("'{' expected");
		}
		backpatch(S->next, int2string(nextquad()));
		genquad("end_block", name,"_", "_");
	}
}
Ejemplo n.º 20
0
static void do_oper(User * u)
{
	MYSQL_ROW row;
	unsigned int nick_id, fields, rows, err;
	MYSQL_RES *result;
	char *cmd, *nick;

	cmd = strtok(NULL, " ");
	
	if (!cmd)
		cmd = "";

	if (stricmp(cmd, "ADD") == 0) {
		if (!is_services_admin(u)) {
			notice_lang(s_OperServ, u, PERMISSION_DENIED);
			return;
		}
		
		nick = strtok(NULL, " ");
		
		if (nick) {
			if (!(nick_id = mysql_findnick(nick))) {
				notice_lang(s_OperServ, u,
				    NICK_X_NOT_REGISTERED, nick);
				return;
			} else if (num_serv_opers() >= MAX_SERVOPERS) {
				notice_lang(s_OperServ, u,
				    OPER_OPER_TOO_MANY, MAX_SERVOPERS);
				return;
			}

			nick_id = mysql_getlink(nick_id);

			result = mysql_simple_query(mysqlconn, &err,
			    "INSERT INTO oper (nick_id) VALUES (%u)",
			    nick_id);

			switch (err) {
			case 0:
				mysql_free_result(result);
				notice_lang(s_OperServ, u, OPER_OPER_ADDED,
				    nick);
				break;
			case ER_DUP_ENTRY:
				notice_lang(s_OperServ, u,
				    OPER_OPER_EXISTS, nick);
				break;
			default:
				handle_mysql_error(mysqlconn,
				    "insert_oper");
				break;	/* never reached */
			}
		} else {
			syntax_error(s_OperServ, u, "OPER",
			    OPER_OPER_ADD_SYNTAX);
		}

	} else if (stricmp(cmd, "DEL") == 0) {
		if (!is_services_admin(u)) {
			notice_lang(s_OperServ, u, PERMISSION_DENIED);
			return;
		}
		nick = strtok(NULL, " ");
		if (nick) {
			if (!(nick_id = mysql_findnick(nick))) {
				notice_lang(s_OperServ, u,
				    NICK_X_NOT_REGISTERED, nick);
				return;
			}

			nick_id = mysql_getlink(nick_id);

			result = smysql_bulk_query(mysqlconn, &fields,
			    &rows, "DELETE FROM oper WHERE nick_id=%u",
			    nick_id);

			if (rows) {
				notice_lang(s_OperServ, u,
				    OPER_OPER_REMOVED, nick);
			} else {
				notice_lang(s_OperServ, u,
				    OPER_OPER_NOT_FOUND, nick);
			}

			mysql_free_result(result);
		} else {
			syntax_error(s_OperServ, u, "OPER",
			    OPER_OPER_DEL_SYNTAX);
		}

	} else if (stricmp(cmd, "LIST") == 0) {
		notice_lang(s_OperServ, u, OPER_OPER_LIST_HEADER);

		result = smysql_bulk_query(mysqlconn, &fields, &rows,
		    "SELECT nick.nick FROM nick, oper "
		    "WHERE nick.nick_id=oper.nick_id ORDER BY nick.nick");

		while ((row = smysql_fetch_row(mysqlconn, result)))
			notice(s_OperServ, u->nick, "%s", row[0]);

	} else {
		syntax_error(s_OperServ, u, "OPER", OPER_OPER_SYNTAX);
	}
}
Ejemplo n.º 21
0
/* This does the dirty work.  gc_currently_forbidden is 1 when this is called.
 */
int
button_item_to_widget_value(Lisp_Object gui_object_instance,
			    Lisp_Object gui_item, widget_value * wv,
			    int allow_text_field_p, int no_keys_p,
			    int menu_entry_p, int accel_p)
{
	/* This function cannot GC because gc_currently_forbidden is set when
	   it's called */
	Lisp_Gui_Item *pgui = 0;

	/* degenerate case */
	if (STRINGP(gui_item)) {
		wv->type = TEXT_TYPE;
		if (accel_p)
			wv->name = add_accel_and_to_external(gui_item);
		else
			LISP_STRING_TO_EXTERNAL_MALLOC(gui_item, wv->name,
						       Qlwlib_encoding);
		return 1;
	} else if (!GUI_ITEMP(gui_item))
		syntax_error("need a string or a gui_item here", gui_item);

	pgui = XGUI_ITEM(gui_item);

	if (!NILP(pgui->filter))
		syntax_error(":filter keyword not permitted on leaf nodes",
			     gui_item);

#ifdef HAVE_MENUBARS
	if (menu_entry_p
	    && !gui_item_included_p(gui_item, Vmenubar_configuration)) {
		/* the include specification says to ignore this item. */
		return 0;
	}
#endif				/* HAVE_MENUBARS */

	if (!STRINGP(pgui->name))
		pgui->name = Feval(pgui->name);

	CHECK_STRING(pgui->name);
	if (accel_p) {
		Lisp_Object tmp = gui_item_accelerator(gui_item);
		wv->name = add_accel_and_to_external(pgui->name);
		wv->accel = LISP_TO_VOID(tmp);
	} else {
		LISP_STRING_TO_EXTERNAL_MALLOC(pgui->name, wv->name,
					       Qlwlib_encoding);
		wv->accel = LISP_TO_VOID(Qnil);
	}

	if (!NILP(pgui->suffix)) {
		Lisp_Object suffix2;

		/* Shortcut to avoid evaluating suffix each time */
		if (STRINGP(pgui->suffix))
			suffix2 = pgui->suffix;
		else {
			suffix2 = Feval(pgui->suffix);
			CHECK_STRING(suffix2);
		}

		LISP_STRING_TO_EXTERNAL_MALLOC(suffix2, wv->value,
					       Qlwlib_encoding);
	}

	wv_set_evalable_slot(wv->enabled, pgui->active);
	wv_set_evalable_slot(wv->selected, pgui->selected);

	if (!NILP(pgui->callback) || !NILP(pgui->callback_ex)) {
		Lisp_Object tmp = cons3(gui_object_instance,
					pgui->callback, pgui->callback_ex);
		wv->call_data = LISP_TO_VOID(tmp);
	}

	if (no_keys_p
#ifdef HAVE_MENUBARS
	    || (menu_entry_p && !menubar_show_keybindings)
#endif
		) {
		wv->key = 0;
	} else if (!NILP(pgui->keys)) {
		/* Use this string to generate key bindings */
		CHECK_STRING(pgui->keys);
		pgui->keys = Fsubstitute_command_keys(pgui->keys);
		if (XSTRING_LENGTH(pgui->keys) > 0)
			LISP_STRING_TO_EXTERNAL_MALLOC(pgui->keys, wv->key,
						       Qlwlib_encoding);
		else
			wv->key = 0;
	} else if (SYMBOLP(pgui->callback)) {	/* Show the binding of this command. */
		char buf[1024];	/* #### */
		/* #### Warning, dependency here on current_buffer and point */
		where_is_to_char(pgui->callback, buf);
		if (buf[0])
			C_STRING_TO_EXTERNAL_MALLOC(buf, wv->key,
						    Qlwlib_encoding);
		else
			wv->key = 0;
	}

	CHECK_SYMBOL(pgui->style);
	if (NILP(pgui->style)) {
		Bufbyte *intname = NULL;
		Bytecount intlen;
		/* If the callback is nil, treat this item like unselectable text.
		   This way, dashes will show up as a separator. */
		if (!wv->enabled)
			wv->type = BUTTON_TYPE;
		TO_INTERNAL_FORMAT(C_STRING, wv->name,
				   ALLOCA, (intname, intlen), Qlwlib_encoding);
		if (intname != NULL && separator_string_p(intname)) {
			wv->type = SEPARATOR_TYPE;
			wv->value =
			    menu_separator_style_and_to_external(intname);
		} else {
#if 0
			/* #### - this is generally desirable for menubars, but it breaks
			   a package that uses dialog boxes and next_command_event magic
			   to use the callback slot in dialog buttons for data instead of
			   a real callback.

			   Code is data, right?  The beauty of LISP abuse.   --Stig */
			if (NILP(callback))
				wv->type = TEXT_TYPE;
			else
#endif
				wv->type = BUTTON_TYPE;
		}
	} else if (EQ(pgui->style, Qbutton))
		wv->type = BUTTON_TYPE;
	else if (EQ(pgui->style, Qtoggle))
		wv->type = TOGGLE_TYPE;
	else if (EQ(pgui->style, Qradio))
		wv->type = RADIO_TYPE;
	else if (EQ(pgui->style, Qtext)) {
		wv->type = TEXT_TYPE;
#if 0
		wv->value = wv->name;
		wv->name = "value";
#endif
	} else
		syntax_error_2("Unknown style", pgui->style, gui_item);

	if (!allow_text_field_p && (wv->type == TEXT_TYPE))
		syntax_error("Text field not allowed in this context",
			     gui_item);

	if (!NILP(pgui->selected) && EQ(pgui->style, Qtext))
		syntax_error
		    (":selected only makes sense with :style toggle, radio or button",
		     gui_item);
	return 1;
}
Ejemplo n.º 22
0
/* Parser entry point.  Opens and parses the test sets in the given file.
 */
struct TestFile *parse_test_file(const char *path)
{
    struct TestFile *tf = NEW0(struct TestFile);

    tf->fd = open(path, O_RDONLY);
    if (tf->fd == -1) {
        fprintf(stderr, "Opening file %s: %s\n", path, strerror(errno));
        return NULL;
    }
    tf->path = path;

    if (fstat(tf->fd, &tf->statbuf)) {
        fprintf(stderr, "Stat file %s: %s\n", path, strerror(errno));
        goto close_it;
    }
    if (tf->statbuf.st_size < 1) {
        fprintf(stderr, "File %s is empty!\n", path);
        goto close_it;
    }

    tf->file_buf =
        (char *)mmap(NULL, tf->statbuf.st_size, PROT_READ, MAP_SHARED, tf->fd, 0);
    if (!tf->file_buf) {
        fprintf(stderr, "Mapping file %s: %s\n", path, strerror(errno));
        goto close_it;
    }
    tf->file_end = tf->file_buf + tf->statbuf.st_size;

    if (!next_line(tf)) {
        syntax_error(tf);
        goto close_it;
    }

    for (;;) {
        size_t toklen;
        char *token = next_token(tf, &toklen);
        if (same_token("set", 3, token, toklen)) {
            struct TestSet *set = parse_set(tf);
            if (!set) // parse failure already reported
                goto close_it;
            set->next = tf->sets;
            tf->sets = set;
        } else if (token == END_OF_LINE) {
            if (!next_line(tf)) { // EOF
                if (!tf->sets) {
                    goto no_sets;
                }
                goto done;
            }
            // else swallow blank line
        } else {
no_sets:
            fail(tf, tf->read_pos, "expected a test set");
            goto close_it;
        }
    }

 close_it:
    if (tf->sets) {
        free_sets(tf->sets);
        tf->sets = NULL;
    }
    close_testfile(tf);
 done:
    return tf;
}
Ejemplo n.º 23
0
/**
 * The /cs clear command.
 * @param u The user who issued the command
 * @param MOD_CONT to continue processing other modules, MOD_STOP to stop processing.
 **/
int do_clear(User * u)
{
    char *chan = strtok(NULL, " ");
    char *what = strtok(NULL, " ");
    char tmp[BUFSIZE];
    Channel *c;
    ChannelInfo *ci;

    if (!what) {
        syntax_error(s_ChanServ, u, "CLEAR", CHAN_CLEAR_SYNTAX);
    } else if (!(c = findchan(chan))) {
        notice_lang(s_ChanServ, u, CHAN_X_NOT_IN_USE, chan);
    } else if (!(ci = c->ci)) {
        notice_lang(s_ChanServ, u, CHAN_X_NOT_REGISTERED, chan);
    } else if (ci->flags & CI_VERBOTEN) {
        notice_lang(s_ChanServ, u, CHAN_X_FORBIDDEN, chan);
    } else if (!u || !check_access(u, ci, CA_CLEAR)) {
        notice_lang(s_ChanServ, u, PERMISSION_DENIED);
    } else if (stricmp(what, "bans") == 0) {
        char *av[2];
        int i;

        /* Save original ban info */
        int count = c->bancount;
        char **bans = scalloc(sizeof(char *) * count, 1);
        for (i = 0; i < count; i++)
            bans[i] = sstrdup(c->bans[i]);

        for (i = 0; i < count; i++) {
            av[0] = sstrdup("-b");
            av[1] = bans[i];
            anope_cmd_mode(whosends(ci), chan, "%s %s", av[0], av[1]);
            chan_set_modes(whosends(ci), c, 2, av, 0);
            free(av[1]);
            free(av[0]);
        }
        notice_lang(s_ChanServ, u, CHAN_CLEARED_BANS, chan);
        free(bans);
    } else if (ircd->except && stricmp(what, "excepts") == 0) {
        char *av[2];
        int i;

        /* Save original except info */
        int count = c->exceptcount;
        char **excepts = scalloc(sizeof(char *) * count, 1);
        for (i = 0; i < count; i++)
            excepts[i] = sstrdup(c->excepts[i]);

        for (i = 0; i < count; i++) {
            av[0] = sstrdup("-e");
            av[1] = excepts[i];
            anope_cmd_mode(whosends(ci), chan, "%s %s", av[0], av[1]);
            chan_set_modes(whosends(ci), c, 2, av, 0);
            free(av[1]);
            free(av[0]);
        }
        notice_lang(s_ChanServ, u, CHAN_CLEARED_EXCEPTS, chan);
        free(excepts);

    } else if (ircd->invitemode && stricmp(what, "invites") == 0) {
        char *av[2];
        int i;

        /* Save original except info */
        int count = c->invitecount;
        char **invites = scalloc(sizeof(char *) * count, 1);
        for (i = 0; i < count; i++)
            invites[i] = sstrdup(c->invite[i]);

        for (i = 0; i < count; i++) {
            av[0] = sstrdup("-I");
            av[1] = invites[i];
            anope_cmd_mode(whosends(ci), chan, "%s %s", av[0], av[1]);
            chan_set_modes(whosends(ci), c, 2, av, 0);
            free(av[1]);
            free(av[0]);
        }
        notice_lang(s_ChanServ, u, CHAN_CLEARED_INVITES, chan);
        free(invites);

    } else if (stricmp(what, "modes") == 0) {
        char buf[BUFSIZE], *end = buf;
        char *argv[2];

        if (c->mode) {
            /* Clear modes the bulk of the modes */
            anope_cmd_mode(whosends(ci), c->name, "%s",
                           ircd->modestoremove);
            argv[0] = sstrdup(ircd->modestoremove);
            chan_set_modes(whosends(ci), c, 1, argv, 0);
            free(argv[0]);

            /* to prevent the internals from complaining send -k, -L, -f by themselves if we need
               to send them - TSL */
            if (c->key) {
                anope_cmd_mode(whosends(ci), c->name, "-k %s", c->key);
                argv[0] = sstrdup("-k");
                argv[1] = c->key;
                chan_set_modes(whosends(ci), c, 2, argv, 0);
                free(argv[0]);
            }
            if (ircd->Lmode && c->redirect) {
                anope_cmd_mode(whosends(ci), c->name, "-L %s",
                               c->redirect);
                argv[0] = sstrdup("-L");
                argv[1] = c->redirect;
                chan_set_modes(whosends(ci), c, 2, argv, 0);
                free(argv[0]);
            }
            if (ircd->fmode && c->flood) {
                if (flood_mode_char_remove) {
                    anope_cmd_mode(whosends(ci), c->name, "%s %s",
                                   flood_mode_char_remove, c->flood);
                    argv[0] = sstrdup(flood_mode_char_remove);
                    argv[1] = c->flood;
                    chan_set_modes(whosends(ci), c, 2, argv, 0);
                    free(argv[0]);
                } else {
                    if (debug) {
                        alog("debug: flood_mode_char_remove was not set unable to remove flood/throttle modes");
                    }
                }
            }
            check_modes(c);
        }



        /* TODO: decide if the above implementation is better than this one. */

        if (0) {
            CBModeInfo *cbmi = cbmodeinfos;
            CBMode *cbm;

            do {
                if (c->mode & cbmi->flag)
                    *end++ = cbmi->mode;
            } while ((++cbmi)->flag != 0);

            cbmi = cbmodeinfos;

            do {
                if (cbmi->getvalue && (c->mode & cbmi->flag)
                    && !(cbmi->flags & CBM_MINUS_NO_ARG)) {
                    char *value = cbmi->getvalue(c);

                    if (value) {
                        *end++ = ' ';
                        while (*value)
                            *end++ = *value++;

                        /* Free the value */
                        cbm = &cbmodes[(int) cbmi->mode];
                        cbm->setvalue(c, NULL);
                    }
                }
            } while ((++cbmi)->flag != 0);

            *end = 0;

            anope_cmd_mode(whosends(ci), c->name, "-%s", buf);
            c->mode = 0;
            check_modes(c);
        }
        notice_lang(s_ChanServ, u, CHAN_CLEARED_MODES, chan);
    } else if (stricmp(what, "ops") == 0) {
        char *av[3];
        struct c_userlist *cu, *next;

        if (ircd->svsmode_ucmode) {
            av[0] = sstrdup(chan);
            anope_cmd_svsmode_chan(av[0], "-o", NULL);
            if (ircd->owner) {
                anope_cmd_svsmode_chan(av[0], ircd->ownerunset, NULL);
            }
            if (ircd->protect || ircd->admin) {
                anope_cmd_svsmode_chan(av[0], ircd->adminunset, NULL);
            }
            for (cu = c->users; cu; cu = next) {
                next = cu->next;
                av[0] = sstrdup(chan);
                if (!chan_has_user_status(c, cu->user, CUS_OP)) {
                    if (!chan_has_user_status(c, cu->user, CUS_PROTECT)) {
                        if (!chan_has_user_status(c, cu->user, CUS_OWNER)) {
                            continue;
                        } else {
                            snprintf(tmp, BUFSIZE, "%so",
                                     ircd->ownerunset);
                            av[1] = sstrdup(tmp);

                        }
                    } else {
                        snprintf(tmp, BUFSIZE, "%so", ircd->adminunset);
                        av[1] = sstrdup(tmp);
                    }
                } else {
                    av[1] = sstrdup("-o");
                }
                av[2] = sstrdup(cu->user->nick);
                do_cmode(s_ChanServ, 3, av);
                free(av[2]);
                free(av[1]);
                free(av[0]);
            }
        } else {
            for (cu = c->users; cu; cu = next) {
                next = cu->next;
                av[0] = sstrdup(chan);
                if (!chan_has_user_status(c, cu->user, CUS_OP)) {
                    if (!chan_has_user_status(c, cu->user, CUS_PROTECT)) {
                        if (!chan_has_user_status(c, cu->user, CUS_OWNER)) {
                            continue;
                        } else {
                            snprintf(tmp, BUFSIZE, "%so",
                                     ircd->ownerunset);
                            av[1] = sstrdup(tmp);
                        }
                    } else {
                        snprintf(tmp, BUFSIZE, "%so", ircd->adminunset);
                        av[1] = sstrdup(tmp);
                    }
                } else {
                    av[1] = sstrdup("-o");
                }
                av[2] = sstrdup(cu->user->nick);
                anope_cmd_mode(whosends(ci), av[0], "%s :%s", av[1],
                               av[2]);
                do_cmode(s_ChanServ, 3, av);
                free(av[2]);
                free(av[1]);
                free(av[0]);
            }
        }
        notice_lang(s_ChanServ, u, CHAN_CLEARED_OPS, chan);
    } else if (ircd->halfop && stricmp(what, "hops") == 0) {
        char *av[3];
        struct c_userlist *cu, *next;

        for (cu = c->users; cu; cu = next) {
            next = cu->next;
            if (!chan_has_user_status(c, cu->user, CUS_HALFOP))
                continue;
            av[0] = sstrdup(chan);
            av[1] = sstrdup("-h");
            av[2] = sstrdup(cu->user->nick);
            if (ircd->svsmode_ucmode) {
                anope_cmd_svsmode_chan(av[0], av[1], NULL);
                do_cmode(s_ChanServ, 3, av);
                break;
            } else {
                anope_cmd_mode(whosends(ci), av[0], "%s :%s", av[1],
                               av[2]);
            }
            do_cmode(s_ChanServ, 3, av);
            free(av[2]);
            free(av[1]);
            free(av[0]);
        }
        notice_lang(s_ChanServ, u, CHAN_CLEARED_HOPS, chan);
    } else if (stricmp(what, "voices") == 0) {
        char *av[3];
        struct c_userlist *cu, *next;

        for (cu = c->users; cu; cu = next) {
            next = cu->next;
            if (!chan_has_user_status(c, cu->user, CUS_VOICE))
                continue;
            av[0] = sstrdup(chan);
            av[1] = sstrdup("-v");
            av[2] = sstrdup(cu->user->nick);
            if (ircd->svsmode_ucmode) {
                anope_cmd_svsmode_chan(av[0], av[1], NULL);
                do_cmode(s_ChanServ, 3, av);
                break;
            } else {
                anope_cmd_mode(whosends(ci), av[0], "%s :%s", av[1],
                               av[2]);
            }
            do_cmode(s_ChanServ, 3, av);
            free(av[2]);
            free(av[1]);
            free(av[0]);
        }
        notice_lang(s_ChanServ, u, CHAN_CLEARED_VOICES, chan);
    } else if (stricmp(what, "users") == 0) {
        char *av[3];
        struct c_userlist *cu = NULL, *next = NULL;
        char buf[256];

        snprintf(buf, sizeof(buf), "CLEAR USERS command from %s", u->nick);

        for (cu = c->users; cu; cu = next) {
	
            next = cu->next;
	    
	    if ((cu->user->mode & UMODE_q))
	    {
	        continue;
            }

            av[0] = sstrdup(chan);
            av[1] = sstrdup(cu->user->nick);
            av[2] = sstrdup(buf);
            anope_cmd_kick(whosends(ci), av[0], av[1], av[2]);
            do_kick(s_ChanServ, 3, av);
            free(av[2]);
            free(av[1]);
            free(av[0]);
        }
        notice_lang(s_ChanServ, u, CHAN_CLEARED_USERS, chan);
    } else {
        syntax_error(s_ChanServ, u, "CLEAR", CHAN_CLEAR_SYNTAX);
    }
    return MOD_CONT;
}
Ejemplo n.º 24
0
static struct TestSet *parse_set(struct TestFile *tf)
{
    struct TestSet *set = NEW0(struct TestSet);
    char *tok;
    size_t len;

    assert(tf->next_pos);
    assert(tf->next_pos > tf->read_pos);

    set->name = expect_name(tf, &set->name_len, "set");
    if (!set->name)
        goto err;

    if (expect_eol(tf))
        goto err;

    // set contents: dep, tolerance, setup, teardown, test case, fortran
    set->tolerance = 0.0; // XXX magic number == BAD
    for (;;) {
        tok = next_token(tf, &len);
        if (tok == END_OF_LINE) {
            if (!next_line(tf)) {
                syntax_error(tf);
                goto err; // EOF
            }
        } else if (tok) {
            if (same_token("dep", 3, tok, len)) {
                struct TestDependency *dep = parse_dependency(tf);
                if (!dep)
                    goto err;
                dep->next = set->deps;
                set->deps = dep;
                set->n_deps++;
            } else if (same_token("use", 3, tok, len)) {
                struct TestModule *mod = parse_module(tf);
                if (!mod)
                    goto err;

                mod->next = set->mods;
                set->mods = mod;
                set->n_mods++;
            } else if (same_token("tolerance", 9, tok, len)) {
                char *tolend;
                tok = next_token(tf, &len);
                if (!tok || tok == END_OF_LINE) {
                    fail(tf, tf->read_pos, "expected tolerance value");
                    goto err;
                }
                set->tolerance = strtod(tf->read_pos, &tolend);
                if (tolend == tf->read_pos || tolend != tf->next_pos) {
                    fail(tf, tf->read_pos, "not a floating point value");
                    goto err;
                }
                tf->next_pos = tolend;
            } else if (same_token("setup", 5, tok, len)) {
                if (set->setup) {
                    fail(tf, tf->next_pos,
                         "more than one setup case specified");
                    goto err;
                }
                set->setup = parse_support(tf, "setup");
                if (!set->setup)
                    goto err;
            } else if (same_token("teardown", 8, tok, len)) {
                if (set->teardown) {
                    fail(tf, tf->next_pos,
                         "more than one teardown case specified");
                    goto err;
                }
                set->teardown = parse_support(tf, "teardown");
                if (!set->teardown)
                    goto err;
            } else if (same_token("test", 4, tok, len)) {
                struct TestCase *test = parse_test_case(tf);
                if (!test)
                    goto err;
                test->next = set->tests;
                set->tests = test;
                set->n_tests++;
            } else if (same_token("end", 3, tok, len)) {
                tf->next_pos = tf->read_pos;
                break; // end of test set
            } else { // fortran code
                struct Code *code;
                tf->next_pos = tf->read_pos = tf->line_pos;
                code = parse_fortran(tf, NULL);
                // XXX check for parse fail?
                code->next = set->code;
                set->code = code;
            }
        } else { // EOF
            fail(tf, tf->read_pos, "expected end set");
            goto err;
        }
    }

    // end set name
    if (parse_end_sequence(tf, "set", set->name, set->name_len))
        goto err;

    return set;
 err:
    free_sets(set);
    return NULL;
}
Ejemplo n.º 25
0
command_t
make_simple_command(char *buffer)
{
  if(!strlen(buffer))
    syntax_error();
  command_t command = checked_malloc(sizeof(struct command));
  command->type = SIMPLE_COMMAND; command->status = -1;
  command->input = NULL; command->output = NULL;
  command->u.word = checked_malloc(8*sizeof(char*)); size_t word_size = 8;
  size_t input_size = 8;size_t output_size = 8;      
  size_t cur_word_size; size_t index = 0; bool in_word = false;
  bool in_input = false; bool in_output = false;
  bool input = false; bool output = false; int i;
  for(i = 0; buffer[i]; i++)
  {
    if(buffer[i] == '<')
    {
      if(i == 0 || input || output 
        || in_input || in_output)
        syntax_error();
      command->input = checked_malloc(8*sizeof(char));
      in_input = true;
    }
    else if(buffer[i] == '>')
    {
      if(i == 0 || output || in_output)
        syntax_error();
      command->output = checked_malloc(8*sizeof(char)); 
      in_input = false;
      in_output = true;
    }
    else if(isalnum(buffer[i]) || strchr("!%+,-./:@^_", buffer[i]))
    {
      if(in_input)
      {
        input = true;
        char* string = command->input;
        if(strlen(string) >= input_size)
          checked_grow_alloc(string, &input_size);
        string[strlen(string)] = buffer[i];
      }
      else if(in_output)
      {
        output = true;
        char* string = command->output;
        if(strlen(string) >= output_size)
          checked_grow_alloc(string, &output_size);
        string[strlen(string)] = buffer[i];
      }
      else if(!in_word)
      {
        if((input || output) && !in_input && !in_output)
          syntax_error();
        if(index >= word_size)
          checked_grow_alloc(command->u.word, &word_size);
        command->u.word[index] = checked_malloc(8*sizeof(char));
        cur_word_size = 8;
        command->u.word[index][0] = buffer[i];
        in_word = true;
      }
      else if(in_word)
      {
        char *string = command->u.word[index];
        if(strlen(string) >= cur_word_size)
          checked_grow_alloc(string, &cur_word_size);
        string[strlen(string)] = buffer[i];
      }
    }
    else if(strchr("\t ", buffer[i]))
    {
      if(in_word)
      {
        in_word = false;
        index++;
      }
      else if(input && in_input)
        in_input = false;
      else if(output && in_output)
        in_output = false; 
    }
    else if(buffer[i] == EOF)
    {
      if(index >= word_size)
        checked_grow_alloc(command->u.word, &word_size);
      return command;
    }
    else
      syntax_error();
  }
  memset((void *) buffer, '\0', 1024);
  if(index >= word_size)
        checked_grow_alloc(command->u.word, &word_size);
  return command;
}
Ejemplo n.º 26
0
/* check for end of line, issue error, if not */
void eol(char *s)
{
  s = skip(s);
  if (*s!='\0' && *s!=commentchar)
    syntax_error(6);
}
Ejemplo n.º 27
0
/* statements -> lstatement [statements] */
void parse_statements(ast_node* block) {
  if (parse_lstatement(block))
    while (parse_lstatement(block));
  else
    syntax_error("'ID', 'skip', 'if', 'while' or 'await'");
}
Ejemplo n.º 28
0
int
main (int argc, char **argv)
{
	MsOle *ole;
	int lp, exit = 0, interact = 0;
	char *buffer = g_new (char, 1024) ;

	if (argc<2)
		syntax_error(0);

	if (!g_strcasecmp (argv [1], "regression")) {
		do_regression_tests ();
		return 0;
	}

	printf ("Ole file '%s'\n", argv[1]);
	if (ms_ole_open_vfs (&ole, argv[1], TRUE, NULL)
	    != MS_OLE_ERR_OK) {
		printf ("Creating new file '%s'\n", argv[1]);
		if (ms_ole_create_vfs (&ole, argv[1], TRUE, NULL)
		    != MS_OLE_ERR_OK)
			syntax_error ("Can't open file or create new one");
	}

	if (argc<=2)
		syntax_error ("Need command or -i");

	if (argc>2 && argv[argc-1][0]=='-'
	    && argv[argc-1][1]=='i') 
		interact=1;
	else {
		char *str=g_strdup(argv[2]) ;
		for (lp=3;lp<argc;lp++)
			str = g_strconcat(str," ",argv[lp],NULL); /* FIXME Mega leak :-) */
		buffer = str; /* and again */
	}

	cur_dir = g_strdup ("/");

	do
	{
		char *ptr;

		if (interact) {
			fprintf (stdout,"> ");
			fflush (stdout);
			fgets (buffer, 1023, stdin);
		}

		arg_data = g_strsplit (g_strchomp (buffer), delim, -1);
		arg_cur  = 0;
		if (!arg_data && interact) continue;
		if (!interact)
			printf ("Command : '%s'\n", arg_data[0]);
		ptr = arg_data[arg_cur++];
		if (!ptr)
			continue;

		if (g_strcasecmp (ptr, "ls") == 0)
			list_files (ole);
		else if (g_strcasecmp (ptr, "cd") == 0)
			enter_dir (ole);
		else if (g_strcasecmp (ptr, "dump") == 0)
			do_dump (ole);
		else if (g_strcasecmp (ptr, "biff") == 0)
			do_biff (ole);
		else if (g_strcasecmp (ptr, "biffraw") == 0)
			do_biff_raw (ole);
		else if (g_strcasecmp (ptr, "get") == 0)
			do_get (ole);
		else if (g_strcasecmp (ptr, "put") == 0)
			do_put (ole);
		else if (g_strcasecmp (ptr, "copyin") == 0)
			do_copyin (ole);
		else if (g_strcasecmp (ptr, "copyout") == 0)
			do_copyout (ole);
		else if (g_strcasecmp (ptr, "summary") == 0)
			do_summary (ole);
		else if (g_strcasecmp (ptr, "docsummary") == 0)
			do_docsummary (ole);
		else if (g_strcasecmp (ptr, "debug") == 0)
			ms_ole_debug (ole, 1);
		else if (g_strcasecmp (ptr, "tree") == 0)
			ms_ole_debug (ole, 2);
		else if (g_strcasecmp (ptr, "vba") == 0)
			dump_vba (ole);
		else if (g_strcasecmp (ptr, "help") == 0 ||
			 g_strcasecmp (ptr, "?") == 0 ||
			 g_strcasecmp (ptr, "info") == 0 ||
			 g_strcasecmp (ptr, "man") == 0)
			list_commands ();
		else if (g_strcasecmp (ptr, "exit") == 0 ||
			 g_strcasecmp (ptr, "quit") == 0 ||
			 g_strcasecmp (ptr, "q") == 0 ||
			 g_strcasecmp (ptr, "bye") == 0)
			exit = 1;
	}
	while (!exit && interact);

	ms_ole_destroy (&ole);
	return 0;
}
Ejemplo n.º 29
0
/*
 * Tokenize an 'if' statement condition.
 */
static struct condition * tokenize_if( const char * pnt )
{
    struct condition * list;
    struct condition * last;
    struct condition * prev;

    /* eat the open bracket */
    while ( *pnt == ' ' || *pnt == '\t' )
	pnt++;
    if ( *pnt != '[' )
	syntax_error( "bad 'if' condition" );
    pnt++;

    list = last = NULL;
    for ( ; ; )
    {
	struct condition * cond;

	/* advance to the next token */
	while ( *pnt == ' ' || *pnt == '\t' )
	    pnt++;
	if ( *pnt == '\0' )
	    syntax_error( "unterminated 'if' condition" );
	if ( *pnt == ']' )
	    return list;

	/* allocate a new token */
	cond = malloc( sizeof(*cond) );
	memset( cond, 0, sizeof(*cond) );
	if ( last == NULL )
	    { list = last = cond; prev = NULL; }
	else
	    { prev = last; last->next = cond; last = cond; }

	/* determine the token value */
	if ( *pnt == '-' && pnt[1] == 'a' )
	{
	    if ( ! prev || ( prev->op != op_variable && prev->op != op_constant ) )
		syntax_error( "incorrect argument" );
	    cond->op = op_and;  pnt += 2; continue;
	}

	if ( *pnt == '-' && pnt[1] == 'o' )
	{
	    if ( ! prev || ( prev->op != op_variable && prev->op != op_constant ) )
		syntax_error( "incorrect argument" );
	    cond->op = op_or;   pnt += 2; continue;
	}

	if ( *pnt == '!' && pnt[1] == '=' )
	{
	    if ( ! prev || ( prev->op != op_variable && prev->op != op_constant ) )
		syntax_error( "incorrect argument" );
	    cond->op = op_neq;  pnt += 2; continue;
	}

	if ( *pnt == '=' )
	{
	    if ( ! prev || ( prev->op != op_variable && prev->op != op_constant ) )
		syntax_error( "incorrect argument" );
	    cond->op = op_eq;   pnt += 1; continue;
	}

	if ( *pnt == '!' )
	{
	    if ( prev && ( prev->op != op_and && prev->op != op_or
		      && prev->op != op_bang ) )
		syntax_error( "incorrect argument" );
	    cond->op = op_bang; pnt += 1; continue;
	}

	if ( *pnt == '"' )
	{
	    const char * word;

	    if ( prev && ( prev->op == op_variable || prev->op == op_constant ) )
		syntax_error( "incorrect argument" );
	    /* advance to the word */
	    pnt++;
	    if ( *pnt == '$' )
		{ cond->op = op_variable; pnt++; }
	    else
		{ cond->op = op_constant; }

	    /* find the end of the word */
	    word = pnt;
	    for ( ; ; )
	    {
		if ( *pnt == '\0' )
		    syntax_error( "unterminated double quote" );
		if ( *pnt == '"' )
		    break;
		pnt++;
	    }

	    /* store a copy of this word */
	    {
		char * str = malloc( pnt - word + 1 );
		memcpy( str, word, pnt - word );
		str [pnt - word] = '\0';
		if ( cond->op == op_variable )
		{
		    cond->nameindex = get_varnum( str );
		    free( str );
		}
		else /* op_constant */
		{
		    cond->str = str;
		}
	    }

	    pnt++;
	    continue;
	}

	/* unknown token */
	syntax_error( "bad if condition" );
    }
}
Ejemplo n.º 30
0
Archivo: syntax.c Proyecto: ezrec/vasm
/* Very simple, very incomplete. */
void parse(void)
{
  char *s,*line,*inst,*ext[MAX_QUALIFIERS?MAX_QUALIFIERS:1],*op[MAX_OPERANDS];
  int inst_len,ext_len[MAX_QUALIFIERS?MAX_QUALIFIERS:1],op_len[MAX_OPERANDS];
  int i,ext_cnt,op_cnt,par_cnt;
  instruction *ip;
  while(line=read_next_line()){
    s=line;

    if(isalnum((unsigned char)*s)){
      /* Handle labels at beginning of line */
      char *labname,*equ;
      symbol *label;
      while(*s&&!isspace((unsigned char)*s)&&*s!=':')
        s++;
      labname=cnvstr(line,s-line);
      s=skip(s+1);
      if(!strncmp(s,"equ",3)&&isspace((unsigned char)s[3])){
        s=skip(s+3);
        label=new_abs(labname,parse_expr(&s));
      }else{
        label=new_labsym(0,labname);
        add_atom(0,new_label_atom(label));
      }
      free(labname);
    }

    s=parse_cpu_special(s);

    if(handle_directive(s))
      continue;

    /* skip spaces */
    s=skip(s);
    if(!*s)
      continue;

    /* read mnemonic name */
    inst=s;
    if(!ISIDSTART(*s)){
      syntax_error(10);
      continue;
    }
#if MAX_QUALIFIERS==0
    while(*s&&!isspace((unsigned char)*s))
      s++;
#else
    while(*s&&*s!='.'&&!isspace((unsigned char)*s))
      s++;
#endif
    inst_len=s-inst;

    /* read qualifiers */
    ext_cnt=0;
    while(*s=='.'&&ext_cnt<MAX_QUALIFIERS){
      s++;
      ext[ext_cnt]=s;
      while(*s&&*s!='.'&&!isspace((unsigned char)*s))
        s++;
      ext_len[ext_cnt]=s-ext[ext_cnt];
      if(ext_len[ext_cnt]<=0)
        syntax_error(1);
      else
        ext_cnt++;
    }

    if(!isspace((unsigned char)*s)) syntax_error(2);
    
    /* read operands, terminated by comma (unless in parentheses)  */
    s=skip(s);
    op_cnt=0;
    while(*s&&op_cnt<MAX_OPERANDS){
      op[op_cnt]=s;
      s=skip_operand(s);
      op_len[op_cnt]=s-op[op_cnt];
      if(op_len[op_cnt]<=0)
        syntax_error(5);
      else
        op_cnt++;
      s=skip(s);
      if(*s!=','){
        break;
      }else{
        s=skip(s+1);
      }
    }      
    s=skip(s);
    if(*s!=0) syntax_error(6);
    ip=new_inst(inst,inst_len,op_cnt,op,op_len);
#if MAX_QUALIFIERS>0
    if(ip){
      for(i=0;i<ext_cnt;i++)
        ip->qualifiers[i]=cnvstr(ext[i],ext_len[i]);
      for(;i<MAX_QUALIFIERS;i++)
        ip->qualifiers[i]=0;
    }
#endif
    if(ip){
      add_atom(0,new_inst_atom(ip));
    }else
      ;
  }
}