コード例 #1
0
/*
 * Change the count associated with number of processes
 * a given user is using.
 */
int
chgproccnt(uid_t uid, int diff)
{
	struct uidinfo *uip;
	long proccnt;

	uip = uid_find(uid);
	proccnt = atomic_add_long_nv(&uip->ui_proccnt, diff);
	KASSERT(proccnt >= 0);
	return proccnt;
}
コード例 #2
0
ファイル: nullclient.c プロジェクト: kristopolous/taim
/*
   static void signed_on(PurpleConnection *gc, gpointer null)
   {
   taim_session *pses;
//GSList *bs;
//PurpleBuddy *btry;
PurpleAccount *account = purple_connection_get_account(gc);
purple_blist_add_account(account);
purple_blist_show();

// The hash is only added here
pses = uid_find_account(account);

if(pses)
{
pses->pses->account->hash_have = 1;

SHA1
(	
pses->pses->account->password_try, 
strlen(pses->pses->account->password_try), 
pses->pses->account->hash
);

memset(pses->pses->account->password_try, 0, 64);
}
}
*/
void drecurse(PurpleBlistNode *pnode, char*uid)
{	
  PurpleBuddy *pbuddy;
  PurplePresence *ppresence;

  taim_session *pses;
  gboolean gb;

  while(pnode) {
    if(pnode->child) {
      drecurse(pnode->child, uid);
    }

    switch(pnode->type) {
      case PURPLE_BLIST_GROUP_NODE:
        break;

      case PURPLE_BLIST_CONTACT_NODE:
        break;

      case PURPLE_BLIST_BUDDY_NODE:
        pbuddy = (PurpleBuddy*)pnode;
        ppresence = purple_buddy_get_presence(pbuddy);	
        gb = purple_presence_is_online(ppresence);

        if(gb)
        {
          pses = uid_find(uid);

          if(pses->pses->account->account && pbuddy->account)
          {
            if(strlen(pbuddy->account->username) == strlen(pses->pses->account->account->username))
            {
              if(!strcmp(pbuddy->account->username, pses->pses->account->account->username))
              {
                buddy_get(pses, pbuddy->name);
              }
            }
          }
        }
        break;

      case PURPLE_BLIST_CHAT_NODE:
        break;

      case PURPLE_BLIST_OTHER_NODE:
        break;
    }

    pnode = pnode->next;
  }
  return;
}
コード例 #3
0
void
uid_init(void)
{

	/*
	 * In case of MP system, SLIST_FOREACH would force a cache line
	 * write-back for every modified 'uidinfo', thus we try to keep the
	 * lists short.
	 */
	const u_int uihash_sz = (maxproc > 1 ? 1024 : 64);

	uihashtbl = hashinit(uihash_sz, HASH_SLIST, true, &uihash);

	/*
	 * Ensure that uid 0 is always in the user hash table, as
	 * sbreserve() expects it available from interrupt context.
	 */
	(void)uid_find(0);
}
コード例 #4
0
ファイル: nullclient.c プロジェクト: kristopolous/taim
void *client_chat(void*in) {	
  int ret = 0;

  taim_buddy *tbuddy = 0;

  taim_session *pses = 0;
  taim_pipe *ptofree = 0;

  char buffer[BUFFER_SIZE] = {0},
       ret_buffer[BUFFER_SIZE] = {0},
       *uid;

  client_struct*pin = ((client_struct*)in);

  // End declaration

  // Raise the lock count
  atomic_increment();
  g_client_inuse[pin->thread] = 1;

  ret = read(pin->client, buffer, BUFFER_SIZE);

  // No data found, return
  if(ret <= 0) {
    atomic_decrement();
    return 0;
  }

  d(buffer);
  // Get the uid from the input string
  ret = parse(buffer, ret_buffer, &uid);
  if(ret == RET_ERROR) {
    atomic_decrement();
    return 0;
  }

  // Find the uid structure
  pses = uid_find(uid);
  if(pses != NULL) {

    if(ret == RET_DATA) {
      // clear the outgoing buffers
      buddy_ret_clear(pses);

      // lock the pipe mutex and fill the pipe
      pthread_mutex_lock(&pses->pses->pipe_mutex);
      for(;;) {

        if(pses->pses->cpipe->next == 0) {
          break;
        }

        // if a buddy was talking, set it as active
        tbuddy = buddy_get(pses, pses->pses->cpipe->user);
        if(tbuddy != NULL) {
          buddy_set_active(pses, tbuddy);

          buddy_ret_add(
              pses,
              tbuddy,
              pses->pses->cpipe->data,
              strlen(pses->pses->cpipe->data));
        }

        // clear this member of the linked list and move on
        ptofree = pses->pses->cpipe;
        pses->pses->cpipe = pses->pses->cpipe->next;
        free(ptofree);
      }

      // generate the list of buddies to return
      buddy_get_list(pses);

      // fill the buffer with this list
      buddy_ret_print(pses, ret_buffer);

      // unlock the pipes
      pthread_mutex_unlock(&pses->pses->pipe_mutex);
    }	
  }

  ret = write(pin->client, ret_buffer, strlen(ret_buffer));

  // drop the connection
  close(pin->client);
  g_client_inuse[pin->thread] = 0;

  free(uid);
  atomic_decrement();

  return 0;
}	
コード例 #5
0
ファイル: nullclient.c プロジェクト: kristopolous/taim
int parse(char*toParse, char*ret_buffer, char**uid)
{
  char command = -1,
       *pCur,
       *pPrev;

  int ix,
      Bound = TK__LAST;

  taim_session *ses;

  pCur = toParse;

  for(ix = 0; ix < Bound; ix++)
  {
    if(!strncmp(pCur, g_commands[ix], strlen(g_commands[ix])))
    {
      command = ix;
      pCur += strlen(g_commands[ix]);
      break;
    }
  }

  switch(command) {
    case TK_UID:
      if(*pCur == ' ') {
        pCur++;
        pPrev = pCur;
        while(*pCur > 32) {
          pCur ++;
        }
        *uid = (char*) malloc(pCur - pPrev);
        memcpy(*uid, pPrev, pCur - pPrev);
        (*uid)[pCur - pPrev] = 0;
      } else {
        *uid = 0;

        do {
          if(*uid != 0)
          {
            free(*uid);
          }
          *uid = (char*) malloc(KEY_LENGTH + 1);
          memcpy(*uid, generate_uid(), KEY_LENGTH);
        } while(uid_addsession(*uid) == 0);
      }

      memcpy(ret_buffer, *uid, strlen(*uid));
      sprintf(ret_buffer + strlen(*uid) + 1, "\n");
      return RET_NODATA;
      break;

    case TK_USER:
      pCur++;

      pPrev = pCur;
      while(*pCur > 32 ) {
        pCur++;
      }
      *uid = (char*)malloc(pCur - pPrev + 1);
      memcpy(*uid, pPrev, pCur - pPrev);
      (*uid)[pCur - pPrev] = 0;
      ses = uid_find(*uid);
      pCur ++;

      {
        char *username = pCur;

        for(	ix = 0;
            username[ix] > ' ';
            ix++);

        username[ix] = 0;

        GList *iter = purple_plugins_get_protocols();
        PurplePlugin *plugin = iter->data;
        PurplePluginInfo *info = plugin->info;
        printf("<%x>", (unsigned int)ses);
        fflush(0);

        if(ses->pses->account == 0) {
          taim_new_account(ses);
        }
        d(username);
        ses->pses->account->account = purple_account_new(username, info->id);
      }
      return RET_NODATA;
      break;

    case TK_PASS:
      pCur++;

      pPrev = pCur;
      while(*pCur > 32 ) {
        pCur++;
      }
      *uid = (char*)malloc(pCur - pPrev + 1);
      memcpy(*uid, pPrev, pCur - pPrev);
      (*uid)[pCur - pPrev] = 0;
      pCur ++;
      ses = uid_find(*uid);

      {
        PurpleSavedStatus *status;

        char	*password = pCur,
              hash[20];

        for(ix = 0; password[ix] > ' '; ix++);

        password[ix] = 0;

        if(ses->pses->account->hash_have == 1) {
          // See if the hashes match
          if(!memcmp(SHA1(password, strlen(password), hash), ses->pses->account->hash, 20)) {
            // If so, then bond the stuff
          }
          else
            // Otherwise, try to auth anyway
          {
            strcpy(ses->pses->account->password_try, password);
          }
          purple_account_set_password(ses->pses->account->account, password);
          purple_account_set_enabled(ses->pses->account->account, UI_ID, TRUE);
          // Either way, this password is replaced with the new one
        } else {
          strcpy(ses->pses->account->password_try, password);
          purple_account_set_password(ses->pses->account->account, password);
          purple_account_set_enabled(ses->pses->account->account, UI_ID, TRUE);
        }

        // Now, to connect the account(s), create a status and activate it. 
        status = purple_savedstatus_new(NULL, PURPLE_STATUS_AVAILABLE);
        purple_savedstatus_activate(status);
        pthread_mutex_unlock(&g_mutex_init);
      }	
      return RET_NODATA;
      break;

    case TK_GET:
      pCur++;

      pPrev = pCur;
      while(*pCur > 32 ) {
        pCur++;
      }

      *uid = (char*)malloc(pCur - pPrev + 1);
      memcpy(*uid, pPrev, pCur - pPrev);
      (*uid)[pCur - pPrev] = 0;
      pCur ++;

      if((*uid)[0]) {
        d(*uid);
        drecurse(g_blist->root, *uid);
        return RET_DATA;
      } else {
        return RET_NODATA;
      }
      break;

    case TK_SEND:
      pCur++;

      pPrev = pCur;
      while(*pCur > 32 ) {
        pCur++;
      }

      *uid = (char*)malloc(pCur - pPrev + 1);
      memcpy(*uid, pPrev, pCur - pPrev);
      (*uid)[pCur - pPrev] = 0;
      pCur ++;

      pCur[strlen(pCur) - 1] = 0;
      taim_send(pCur, *uid, ret_buffer);
      return RET_NODATA;
      break;

    case TK_QUIT:
      do_exit();
      break;

    default:
      return RET_ERROR;
      // unknown command
      break;
  }
  return RET_ERROR;
}
コード例 #6
0
ファイル: nullclient.c プロジェクト: kristopolous/taim
void taim_send(char*ptosend,char*uid,char*buffer) {
  PurpleConversation *p_purpcon=0;

  taim_account *acct = 0;
  taim_session *pses = 0;

  char	*sn = ptosend,
        *msg = 0;

  int 	bound = strlen(ptosend),
        ix,
        userno;

  char	userchar;

  // First get the uid
  pses = uid_find(uid);

  if(pses->pses->account == NULL)
  {
    taim_new_account(pses);
    return;
  }

  acct = pses->pses->account;

  for(ix = 0;ix < bound;ix++) {
    if(sn[ix] == '.') {
      sn[ix] = 0;
      msg = sn + ix + 1;
      break;
    }
  }

  // Look for the conversation
  // '.' was replaced with '0' above!
  if(sn[1] == 0) {
    d("alias");
    sscanf(sn, "%c", &userchar);
    userchar |= 0x20;
    for(userno = 0;userno < MAX_USERS_TO_SHOW;userno++) {
      if(ALIAS_LOOKUP[userno] == userchar) {
        break;
      }
    }

    if(userno == MAX_USERS_TO_SHOW) {
      return;
    }

    sn = uid_get_user(uid, userno);
    if(sn == 0) {
      return;
    }
  }

  bound = acct->conversation_size_current;
  // Now find the conversation in the account
  for(ix = 0; ix < bound; ix++) {
    if(acct->conversation_list[ix]->name != 0) {
      if(!strcmp(acct->conversation_list[ix]->name, sn)) {
        p_purpcon = acct->conversation_list[ix]; 
        break;
      }
    } else {
      p_purpcon = 0;
      break;
    }
  }

  if(p_purpcon == 0) {
    // Make a new convo
    p_purpcon = purple_conversation_new(PURPLE_CONV_TYPE_IM, acct->account, sn);

    if(p_purpcon != NULL) {	
      taim_conv_add(sn, p_purpcon);
    } else {
      // BUG BUG
      snprintf(buffer + strlen(buffer), 
          BUFFER_SIZE-strlen(buffer),
          "User Authentication Failed\n");

      return;
    }
  }
  snprintf(buffer + strlen(buffer),
      BUFFER_SIZE-strlen(buffer),
      "[%s:%s]\n",
      sn,
      msg);

  purple_conv_im_send(
      p_purpcon->u.im,
      msg);

  return;
}