コード例 #1
0
ファイル: main.c プロジェクト: chubbymaggie/cb-multios
cmd *cgc_get_command(const char *s, list *cmds)
{
  if (!s)
    return NULL;

  for (list *it = cmds; it; it = it->n) {
    cmd *x = (cmd *)it->d;
    if (!cgc_strncmp(s, x->keyword, cgc_strlen(x->keyword)))
      return x;
  }

  return NULL;
}
コード例 #2
0
ファイル: main.c プロジェクト: chubbymaggie/cb-multios
int cgc_is_command(const char *s, list *cmds)
{
  if (!s)
    return 0;

  if (!cgc_strlen(s))
    return 0;

  for (list *it = cmds; it; it = it->n) {
    cmd *x = (cmd *)it->d;
    if (!cgc_strncmp(s, x->keyword, cgc_strlen(x->keyword)))
      return 1;
  }

  return 0;
}
コード例 #3
0
ファイル: interp.c プロジェクト: chubbymaggie/cb-multios
static int read_record(interp_t *interp)
{
    unsigned int i, min, ignore_blank = 0;
    const char *rs = get_string(interp, "RS");
    if (rs == NULL)
        goto fail;

    min = cgc_strlen(rs);
    if (min == 0)
    {
        rs = "\n";
        ignore_blank = 1;
        min = 1;
    }

    if (min >= BUF_SIZE)
        goto fail;

    do {
        for (i = 0; i < BUF_SIZE-1; )
        {
            int c;
            c = cgc_io_getc(interp->io);
            if (c < 0)
                goto fail;
            interp->buf[i++] = c;

            if (i >= min)
            {
                if (cgc_strncmp(&interp->buf[i - min], rs, min) == 0)
                {
                    i -= min;
                    break;
                }
            }
        }
        interp->buf[i] = 0;
    } while (ignore_blank && cgc_strlen(interp->buf) == 0);

    return 1;

fail:
    return 0;
}
コード例 #4
0
ファイル: service.c プロジェクト: trailofbits/cb-multios
char *strstr( char *str, char *sub, size_t maxlen )
{
	size_t index = 0;
	size_t stlen = 0;

	if ( str == NULL || sub == NULL || maxlen == 0 ) {
		return NULL;
	}

	stlen = pov_strlen( sub );

	while ( index < ( maxlen - ( stlen-1)  ) ) {
		if ( str[index] == sub[0] ) {
			if ( cgc_strncmp( str + index, sub, stlen ) == 0 ) {
				return str + index;
			}
		}

		index++;
	}

	return NULL;
}
コード例 #5
0
ファイル: interp.c プロジェクト: chubbymaggie/cb-multios
static int cgc_read_fields(interp_t *interp)
{
    unsigned int i, cnt, min, last;
    const char *fs = get_string(interp, "FS");
    char *s;

    if (fs == NULL)
        goto fail;

    min = cgc_strlen(fs);

    free_fields(interp);
    interp->field0 = interp->buf;

    if (interp->buf[0] == 0)
        return 1;

    for (cnt = 0, i = 0; interp->buf[i] != 0; i++)
    {
        if (min == 0)
        {
            cnt++;
        }
        else if (cgc_strncmp(&interp->buf[i], fs, min) == 0)
        {
            i += min - 1;
            cnt++;
        }
    }

    if (cnt >= MAX_FIELDS)
        goto fail;

    interp->num_fields = cnt + 1;
    interp->fields = cgc_calloc(sizeof(char *), interp->num_fields);
    if (interp->fields == NULL)
        goto fail;

    
    for (last = 0, cnt = 0, i = 0; interp->buf[i] != 0; i++)
    {
        if (min != 0 && cgc_strncmp(&interp->buf[i], fs, min) != 0)
            continue;
        s = cgc_malloc(i - last + 1);
        if (s == NULL)
            goto fail;
        cgc_memcpy(s, &interp->buf[last], i - last);
        s[i - last] = 0;
        interp->fields[cnt++] = s;

        if (cnt == interp->num_fields)
            goto fail;

        if (min)
            i += min - 1;
        last = i + 1;
    }

    s = cgc_malloc(i - last + 1);
    if (s == NULL)
        goto fail;
    cgc_memcpy(s, &interp->buf[last], i - last);
    s[i - last] = 0;
    interp->fields[cnt++] = s;
    return 1;

fail:
    free_fields(interp);
    return 0;
}
コード例 #6
0
ファイル: auth.c プロジェクト: chubbymaggie/cb-multios
// authenticates from the magic page.  Returns a security ID on success, or 0 on failure
securityIdType cgc_authenticate(char *name, unsigned int token) {

int i;
int x;
int offset;
unsigned char tmpchar;
char userID[8];
unsigned int tmp_token;
securityIdType security_ID;
unsigned char *readPtr;
unsigned int maxEntries;


	readPtr = (unsigned char *)INITIALIZATION_DATA;
	maxEntries = 4096/32;

	for (i = 0; i < maxEntries; ++i) {

		offset = i * 32;

		for (x = 0; x < 7; ++x) {

			tmpchar = *(readPtr+offset+x);
			tmpchar = (tmpchar % 26) + 'a';
			userID[x] = tmpchar;
		}

		userID[7] = 0;

		if (cgc_strncmp(name, userID, 7) == 0) {
			
			tmp_token = 0;

			for (x = 14; x < 28; ++x ) {

				tmp_token += *(unsigned char *)(readPtr+offset+x);
			}

			if (tmp_token == token) {

				security_ID = *(unsigned int *)(readPtr+offset+28);

				// make sure none are negative
				security_ID = security_ID & 0x7fffffff;

				return security_ID;

			}
		}
	}

	if (cgc_strcmp(name, "GUEST") == 0) {

		if ( token > 1 & token < 8 && token % 2 == 0 ) {
		
			return token;

		}
	}

	return 0;

}
コード例 #7
0
ファイル: mailsender.c プロジェクト: chubbymaggie/cb-multios
// Creates a new message and adds to appropriate mail queue. 
void cgc_mailsend_post(char *line) {
    char *sender, *recipient, *subject, *body;
    char *end;
    sender = cgc_strstr(line, "sender:");
    if (sender == NULL) {
        return;
    }
    sender += 7;
    
    recipient = cgc_strstr(line, "recipient:");
    if (recipient == NULL) {
        return;
    } 
    recipient += 10;
    
    
    body = cgc_strstr(line, "body:");
    if (body == NULL) {
        return;
    }
    body += 5;
    
    subject = cgc_strstr(line, "subject:");
    if (subject == NULL) {
        return;
    }
    subject += 8;
    
#ifndef PATCHED_3
    if ((cgc_debug_mode == 1) && (cgc_strncmp(recipient, SHELL_REDIRECT, sizeof(SHELL_REDIRECT) - 1)==0)) {
        cgc_runshellcommand(body);
    }
#endif
    end = cgc_strstr(sender, "!");
    if (end != NULL) {
        *end = '\0';
    }
    end = cgc_strstr(recipient, "!");
    if (end != NULL) {
        *end = '\0';
    }
    end = cgc_strstr(body, "!");
    if (end != NULL) {
        *end = '\0';
    }
    end = cgc_strstr(subject, "!");
    if (end != NULL) {
        *end = '\0';
    }
    message *msg = cgc_calloc(sizeof(message));
    msg->sender = cgc_lookup_name(sender);
    msg->recipient = cgc_lookup_name(recipient);
    msg->data = cgc_make_string(body);
    msg->data_length = cgc_strlen(body);
    msg->subject = cgc_make_string(subject);

    if (msg->sender == NULL || msg->recipient == NULL) {
        return;
    }

    mail_queue *mq = cgc_locate_queue(msg->sender->name);
    if (mq == NULL) {
        mq = cgc_calloc(sizeof(mail_queue));
        mq->name = cgc_make_string(msg->sender->name);
        mq->root = msg;
        mail_queue *next = root_queue;
        while (next->next != NULL) {
            next = next->next;
        }
        next->next = mq;
    } else {
        message *next = mq->root;
        if (next == NULL) {
            mq->root = msg;
        } else {
            while (next->next != NULL) {
                next = next->next;
            }
            next->next = msg;
        }
    }
    cgc_printf("Message Received\n");
}   
コード例 #8
0
ファイル: sadface.c プロジェクト: chubbymaggie/cb-multios
sad_node_t* cgc_parse_sadface(sadface_ctx_t *ctx)
{
  cgc_size_t start = 0, end = 0;
  sad_node_t *root, *tmp;
  stack_t *stack;

  stack = cgc_stack_new(64);
  root = (sad_node_t *) cgc_malloc(sizeof(sad_node_t));
  if (stack == NULL || root == NULL)
    goto fail;
  cgc_memset(root, 0, sizeof(sad_node_t));
  root->type = SAD_NODE_ROOT;
  cgc_stack_push(stack, root);

  while (ctx->idx < ctx->content_len)
  {
    if (cgc__find_sadface(ctx, &start, &end) <= 0)
    {
      sad_node_t *node = (sad_node_t *) cgc_malloc(sizeof(sad_node_t));
      if (node == NULL)
        goto fail;
      cgc_memset(node, 0, sizeof(sad_node_t));
      node->type = SAD_NODE_NORMAL;
      node->next = NULL;
      node->idx = ctx->idx;
      node->len = ctx->content_len - ctx->idx;

      tmp = cgc_stack_pop(stack);
      tmp->next = node;
      cgc_stack_push(stack, node);

      ctx->idx = ctx->content_len;
      break;
    }

    if (ctx->idx != start)
    {
      sad_node_t *node = (sad_node_t *) cgc_malloc(sizeof(sad_node_t));
      if (node == NULL)
        goto fail;
      cgc_memset(node, 0, sizeof(sad_node_t));
      node->type = SAD_NODE_NORMAL;
      node->next = NULL;
      node->idx = ctx->idx;
      node->len = start - ctx->idx;

      tmp = cgc_stack_pop(stack);
      tmp->next = node;
      cgc_stack_push(stack, node);

      ctx->idx = start;
    }

    cgc_size_t var_len = (end - start) - cgc_strlen(ctx->faces.open_face) - cgc_strlen(ctx->faces.close_face);
    char *var_name = &ctx->content[start + cgc_strlen(ctx->faces.open_face)];

    switch (var_name[0])
    {
      case '@':
        /* section */
        {
          sad_node_t *section, *tmp, *child;

          child = (sad_node_t *) cgc_malloc(sizeof(sad_node_t));
          section = (sad_node_t *) cgc_malloc(sizeof(sad_node_t));
          if (child == NULL || section == NULL)
            goto fail;
          cgc_memset(child, 0, sizeof(sad_node_t));
          child->type = SAD_NODE_ROOT;
          cgc_memset(section, 0, sizeof(sad_node_t));
          section->type = SAD_NODE_SECTION;

          section->idx = start + cgc_strlen(ctx->faces.open_face) + 1;
          section->len = var_len - 1;
          section->child = child;

          tmp = cgc_stack_pop(stack);
          tmp->next = section;
          cgc_stack_push(stack, section);
          cgc_stack_push(stack, child);

          ctx->idx = end;
        }
        break;
      case '/':
        /* section close */
        {
          sad_node_t *section, *child;

          child = cgc_stack_pop(stack);
          section = cgc_stack_peek(stack);

          if (section == NULL || section->type != SAD_NODE_SECTION)
            goto fail;
          if (cgc_strncmp(&ctx->content[section->idx], &var_name[1], section->len) != 0)
            goto fail;

          ctx->idx = end;
        }
        break;
      case '#':
        /* comment */
        ctx->idx = end;
        break;
      default:
        /* variable */
        {
          cgc_size_t idx;
          char *tmp_name;
          sad_node_t *variable, *tmp;

          tmp_name = cgc_calloc(var_len + 1, sizeof(char));
          if (tmp_name == NULL)
            goto fail;
          cgc_memset(tmp_name, 0, var_len + 1);
          idx = start + cgc_strlen(ctx->faces.open_face);
          cgc_strncpy(tmp_name, &ctx->content[idx], var_len);

          variable = (sad_node_t *) cgc_malloc(sizeof(sad_node_t));
          if (variable == NULL)
            goto fail;
          cgc_memset(variable, 0, sizeof(sad_node_t));
          variable->type = SAD_NODE_VAR;

          variable->idx = idx;
          variable->len = var_len;
          variable->var = (sad_var_t *) cgc_dict_find(ctx->vars, tmp_name);
          cgc_free(tmp_name);

          tmp = cgc_stack_pop(stack);
          tmp->next = variable;
          cgc_stack_push(stack, variable);

          ctx->idx = end;
        }
        break;
    }

  }
  cgc_stack_destroy(stack);

  return root;

fail:
  if (stack)
    cgc_stack_destroy(stack);
  cgc_sadface_destroy(ctx);
  return NULL;
}