Пример #1
0
void
rcv_account_read (struct htlc_conn *htlc)
{
   struct hl_access_bits acc;
   u_int8_t login[32], name[32];
   u_int16_t llen, nlen;
   int err;

   dh_start(htlc)
      if (dh_type != HTLC_DATA_LOGIN)
         continue;
      llen = dh_len > 31 ? 31 : dh_len;
      memcpy(login, dh_data, llen);
      login[llen] = 0;
      if ((err = account_read(login, 0, name, &acc))) {
         snd_strerror(htlc, err);
         continue;
      }
      
      hl_encode(login, login, llen);
      nlen = strlen(name);
      hlwrite(htlc, HTLS_HDR_TASK, 0, 4,
         HTLS_DATA_NAME, nlen, name,
         HTLS_DATA_LOGIN, llen, login,
         HTLS_DATA_PASSWORD, 1, "\0",
         HTLS_DATA_ACCESS, 8, &acc);
   dh_end()
}
Пример #2
0
int main(int argc, char *argv[])
{
    int cardno;
    struct account *account;
    struct consume_record *b, *e;

    if (argc < 2)
        return 1;

    cardno = atoi(argv[argc - 1]);
    if (account_read(cardno, &account) == E_OK) {
        account_query_by_date(account, "20130621", &b, &e);
        print_nrecords(b, e);
        SEP;
        account_query_by_date(account, "20131221", &b, &e);
        print_nrecords(b, e);
        printf("date");
        SEP;

        account_query_by_date_range(account, "20130621", "20130731", &b, &e);
        print_nrecords(b, e);
        SEP;
        account_query_by_date_range(account, "20130621", "20131231", &b, &e);
        print_nrecords(b, e);
        printf("date range");
        SEP;

        account_query_by_sum(account, 15.00, &b, &e);
        print_nrecords(b, e);
        SEP;
        account_query_by_sum(account, 150.00, &b, &e);
        print_nrecords(b, e);
        SEP;
        account_query_by_sum(account, 1.00, &b, &e);
        print_nrecords(b, e);
        printf("sum");
        SEP;

        account_destory(account);
    }

    return 0;
}
Пример #3
0
void
create_account (struct htlc_conn *htlc, int create)
{
   struct htlc_conn *htlcp;
   struct hl_access_bits acc;
   u_int8_t name[32], login[32], password[32];
   u_int16_t nlen = 0, llen = 0, plen = 0, alen = 0;
   int err;

   name[0] = password[0] = 0;
   memset(&acc, 0, sizeof(struct hl_access_bits));

   dh_start(htlc)
      switch (dh_type) {
         case HTLC_DATA_NAME:
            nlen = dh_len > 31 ? 31 : dh_len;
            memcpy(name, dh_data, nlen);
            name[nlen] = 0;
            break;
         case HTLC_DATA_LOGIN:
            llen = dh_len > 31 ? 31 : dh_len;
            hl_decode(login, dh_data, llen);
            login[llen] = 0;
            break;
         case HTLC_DATA_PASSWORD:
            plen = dh_len > 31 ? 31 : dh_len;
            hl_decode(password, dh_data, plen);
            password[plen] = 0;
            break;
         case HTLC_DATA_ACCESS:
            alen = dh_len;
            if (alen >= sizeof(struct hl_access_bits))
               memcpy(&acc, dh_data, sizeof(struct hl_access_bits));
            break;
      }
   dh_end()

   /* issue an error if the client didn't provide a login name */
   if (!llen) {
      send_taskerror(htlc, "huh?!?");
      return;
   }

   hxd_log("%s:%s:%u - create/modify account %s",
      htlc->name, htlc->login, htlc->uid, login);

   if ((plen == 1 && password[0] == 255))
      account_read(login, password, 0, 0);
   if (!nlen)
      account_read(login, 0, name, 0);
   if (!alen)
      account_read(login, 0, 0, &acc);
   if ((err = account_write(login, password, name, &acc))) {
      snd_strerror(htlc, err);
      return;
   }
   
   memset(password, 0, sizeof(password));

   /* confirm that account was created/modified successfully */
   hlwrite(htlc, HTLS_HDR_TASK, 0, 0);

   /* update the users using this account with new priveleges */
   for (htlcp = htlc_list->next; htlcp; htlcp = htlcp->next) {

      /* check if user is logged in with the account */
      if (!strcmp(login, htlcp->login)) {

         /* update name of the account (might have changed) */
         strcpy(htlcp->defaults.name, name);

         /* support for rfc2 on 256 indexed color, only update the user's
          * color if they are using index 0 or 1 color, standard protocol */
         if (htlcp->color == 0 || htlcp->color == 2)
            htlcp->color = acc.disconnect_users ? 2 : 0;
         else if (htlcp->color == 1 || htlcp->color == 3)
            htlcp->color = acc.disconnect_users ? 3 : 1;

         /* send the updated access priveleges to the user */
         memcpy(&htlcp->access, &acc, sizeof(struct hl_access_bits));
         update_access(htlcp);

         /* send the updated user information to the clients */
         update_user(htlcp);

      }

   } /* for */

   if (create && strlen(hxd_cfg.paths.nuser)) {
      /* execute a script after adding the account */
      switch (fork()) {
         case -1:
            hxd_log("create_account: fork: %s", strerror(errno));
            break;
         case 0:
            {
               char *envp[3], acctdir[MAXPATHLEN + 16], account[32];
               char rlpath[MAXPATHLEN], expath[MAXPATHLEN];

#ifdef HAVE_CORESERVICES
               resolve_alias_path(hxd_cfg.paths.nuser, expath);
               resolve_alias_path(hxd_cfg.paths.accounts, rlpath);
#else
               realpath(hxd_cfg.paths.nuser, expath);
               realpath(hxd_cfg.paths.accounts, rlpath);
#endif
               snprintf(acctdir, sizeof(acctdir), "ACCOUNTDIR=%s", rlpath);
               snprintf(account, sizeof(htlc->login), "ACCOUNT=%s", login);
               envp[0] = acctdir;
               envp[1] = account;
               envp[2] = 0;
               execle(expath, expath, 0, envp);
               exit(0);
            }
      }
   }
}