Ver Mensaje Individual
  #22 (permalink)  
Antiguo 29/11/2013, 09:27
xoceunder
 
Fecha de Ingreso: junio-2012
Ubicación: En el Mundo
Mensajes: 759
Antigüedad: 11 años, 10 meses
Puntos: 10
Respuesta: duda en buscar, editar y eliminar en archivo .user

continua el archivo

Código Java:
Ver original
  1. #ifdef CS_ANTICASC
  2. static void account_fixups_fn(void *var)
  3. {
  4.     struct s_auth *account = var;
  5.     if(account->ac_users < -1) { account->ac_users = DEFAULT_AC_USERS; }
  6.     if(account->ac_penalty < -1) { account->ac_penalty = DEFAULT_AC_PENALTY; }
  7. }
  8. #endif
  9.  
  10. #define OFS(X) offsetof(struct s_auth, X)
  11. #define SIZEOF(X) sizeof(((struct s_auth *)0)->X)
  12.  
  13. static const struct config_list account_opts[] =
  14. {
  15. #ifdef CS_ANTICASC
  16.     DEF_OPT_FIXUP_FUNC(account_fixups_fn),
  17. #endif
  18.     DEF_OPT_INT8("disabled"             , OFS(disabled),                0),
  19.     DEF_OPT_SSTR("user"                 , OFS(usr),                     "", SIZEOF(usr)),
  20.     DEF_OPT_STR("pwd"                   , OFS(pwd),                     NULL),
  21. #ifdef WEBIF
  22.     DEF_OPT_STR("description"           , OFS(description),             NULL),
  23. #endif
  24.     DEF_OPT_STR("hostname"              , OFS(dyndns),                  NULL),
  25.     DEF_OPT_FUNC("caid"                 , OFS(ctab),                    check_caidtab_fn),
  26.     DEF_OPT_INT8("uniq"                 , OFS(uniq),                    0),
  27.     DEF_OPT_UINT8("sleepsend"           , OFS(c35_sleepsend),           0),
  28.     DEF_OPT_INT32("failban"             , OFS(failban),                 0),
  29.     DEF_OPT_INT8("monlevel"             , OFS(monlvl),                  0),
  30.     DEF_OPT_FUNC("sleep"                , OFS(tosleep),                 account_tosleep_fn),
  31.     DEF_OPT_FUNC("suppresscmd08"        , OFS(c35_suppresscmd08),       account_c35_suppresscmd08_fn),
  32.     DEF_OPT_FUNC("umaxidle"                   , OFS(umaxidle),                          account_umaxidle_fn),
  33.     DEF_OPT_FUNC("keepalive"            , OFS(ncd_keepalive),           account_ncd_keepalive_fn),
  34.     DEF_OPT_FUNC("au"                   , 0,                            account_au_fn),
  35.     DEF_OPT_UINT8("emmreassembly"       , OFS(emm_reassembly),          2),
  36.     DEF_OPT_FUNC("expdate"              , 0,                            account_expdate_fn),
  37.     DEF_OPT_FUNC("allowedprotocols"     , 0,                            account_allowedprotocols_fn),
  38.     DEF_OPT_FUNC("allowedtimeframe"     , 0,                            account_allowedtimeframe_fn),
  39.     DEF_OPT_FUNC("betatunnel"           , OFS(ttab),                    account_tuntab_fn),
  40.     DEF_OPT_FUNC("group"                , OFS(grp),                     group_fn),
  41.     DEF_OPT_FUNC("services"             , OFS(sidtabs),                 services_fn),
  42.     DEF_OPT_FUNC_X("ident"              , OFS(ftab),                    ftab_fn, FTAB_ACCOUNT | FTAB_PROVID),
  43.     DEF_OPT_FUNC_X("chid"               , OFS(fchid),                   ftab_fn, FTAB_ACCOUNT | FTAB_CHID),
  44.     DEF_OPT_FUNC("class"                , OFS(cltab),                   class_fn),
  45. #ifdef CS_CACHEEX
  46.     DEF_OPT_INT8("cacheex"              , OFS(cacheex.mode),            0),
  47.     DEF_OPT_INT8("cacheex_maxhop"       , OFS(cacheex.maxhop),          0),
  48.     DEF_OPT_FUNC("cacheex_ecm_filter"   , OFS(cacheex.filter_caidtab),  cacheex_hitvaluetab_fn),
  49.     DEF_OPT_UINT8("cacheex_drop_csp"    , OFS(cacheex.drop_csp),        0),
  50.     DEF_OPT_UINT8("cacheex_allow_request"   , OFS(cacheex.allow_request),   1),
  51. #endif
  52. #ifdef MODULE_CCCAM
  53.     DEF_OPT_INT32("cccmaxhops"          , OFS(cccmaxhops),              DEFAULT_CC_MAXHOPS),
  54.     DEF_OPT_INT8("cccreshare"           , OFS(cccreshare),              DEFAULT_CC_RESHARE),
  55.     DEF_OPT_INT8("cccignorereshare"     , OFS(cccignorereshare),        DEFAULT_CC_IGNRSHR),
  56.     DEF_OPT_INT8("cccstealth"           , OFS(cccstealth),              DEFAULT_CC_STEALTH),
  57. #endif
  58. #ifdef CS_ANTICASC
  59.     DEF_OPT_INT32("fakedelay"           , OFS(ac_fakedelay),            -1),
  60.     DEF_OPT_INT32("numusers"            , OFS(ac_users),                DEFAULT_AC_USERS),
  61.     DEF_OPT_INT8("penalty"              , OFS(ac_penalty),              DEFAULT_AC_PENALTY),
  62. #endif
  63. #ifdef WITH_LB
  64.     DEF_OPT_INT32("lb_nbest_readers"    , OFS(lb_nbest_readers),        -1),
  65.     DEF_OPT_INT32("lb_nfb_readers"      , OFS(lb_nfb_readers),          -1),
  66.     DEF_OPT_FUNC("lb_nbest_percaid"     , OFS(lb_nbest_readers_tab),    caidvaluetab_fn),
  67. #endif
  68.     DEF_LAST_OPT
  69. };
  70.  
  71. void chk_account(const char *token, char *value, struct s_auth *account)
  72. {
  73.     if(config_list_parse(account_opts, token, value, account))
  74.         { return; }
  75.     else if(token[0] != '#')
  76.         { fprintf(stderr, "Warning: keyword '%s' in account section not recognized\n", token); }
  77. }
  78.  
  79. void account_set_defaults(struct s_auth *account)
  80. {
  81.     config_list_set_defaults(account_opts, account);
  82. }
  83.  
  84. struct s_auth *init_userdb(void)
  85. {
  86.     FILE *fp = open_config_file(cs_user);
  87.     if(!fp)
  88.         { return NULL; }
  89.  
  90.     struct s_auth *authptr = NULL;
  91.     int32_t tag = 0, nr = 0, expired = 0, disabled = 0;
  92.     char *token;
  93.     struct s_auth *account = NULL;
  94.     struct s_auth *probe = NULL;
  95.     if(!cs_malloc(&token, MAXLINESIZE))
  96.         { return NULL; }
  97.  
  98.     while(fgets(token, MAXLINESIZE, fp))
  99.     {
  100.         int32_t l;
  101.         void *ptr;
  102.  
  103.         if((l = strlen(trim(token))) < 3)
  104.             { continue; }
  105.         if(token[0] == '[' && token[l - 1] == ']')
  106.         {
  107.             token[l - 1] = 0;
  108.             tag = streq("account", strtolower(token + 1));
  109.             if(!cs_malloc(&ptr, sizeof(struct s_auth)))
  110.                 { break; }
  111.             if(account)
  112.                 { account->next = ptr; }
  113.             else
  114.                 { authptr = ptr; }
  115.  
  116.             account = ptr;
  117.             account_set_defaults(account);
  118.             nr++;
  119.  
  120.             continue;
  121.         }
  122.  
  123.         if(!tag)
  124.             { continue; }
  125.         char *value = strchr(token, '=');
  126.         if(!value)
  127.             { continue; }
  128.  
  129.         *value++ = '\0';
  130.  
  131.         // check for duplicate useraccounts and make the name unique
  132.         if(streq(trim(strtolower(token)), "user"))
  133.         {
  134.             for(probe = authptr; probe; probe = probe->next)
  135.             {
  136.                 if(!strcmp(probe->usr, trim(value)))
  137.                 {
  138.                     fprintf(stderr, "Warning: duplicate account '%s'\n", value);
  139.                     strncat(value, "_x", sizeof(probe->usr) - strlen(value) - 1);
  140.                 }
  141.             }
  142.         }
  143.         chk_account(trim(strtolower(token)), trim(value), account);
  144.     }
  145.     free(token);
  146.     fclose(fp);
  147.  
  148.     for(account = authptr; account; account = account->next)
  149.     {
  150.         if(account->expirationdate && account->expirationdate < time(NULL))
  151.             { ++expired; }
  152.         if(account->disabled)
  153.             { ++disabled; }
  154.     }
  155.     cs_log("userdb reloaded: %d accounts loaded, %d expired, %d disabled", nr, expired, disabled);
  156.     return authptr;
  157. }
  158. int32_t init_free_userdb(struct s_auth *ptr)
  159. {
  160.     int32_t nro;
  161.     for(nro = 0; ptr; nro++)
  162.     {
  163.         struct s_auth *ptr_next;
  164.         ptr_next = ptr->next;
  165.         ll_destroy(ptr->aureader_list);
  166.         ptr->next = NULL;
  167.         config_list_gc_values(account_opts, ptr);
  168.         add_garbage(ptr);
  169.         ptr = ptr_next;
  170.     }
  171.     cs_log("userdb %d accounts freed", nro);
  172.     return nro;
  173. }
  174.  
  175. int32_t write_userdb(void)
  176. {
  177.     struct s_auth *account;
  178.     FILE *f = create_config_file(cs_user);
  179.     if(!f)
  180.         { return 1; }
  181.     for(account = cfg.account; account; account = account->next)
  182.     {
  183.         fprintf(f, "[account]\n");
  184.         config_list_apply_fixups(account_opts, account);
  185.         config_list_save(f, account_opts, account, cfg.http_full_cfg);
  186.         fprintf(f, "\n");
  187.     }
  188.     return flush_config_file(f, cs_user);
  189. }
  190.  
  191. void cs_accounts_chk(void)
  192. {
  193.     struct s_auth *account1, *account2;
  194.     struct s_auth *new_accounts = init_userdb();
  195.     cs_writelock(&config_lock);
  196.     struct s_auth *old_accounts = cfg.account;
  197.     for(account1 = cfg.account; account1; account1 = account1->next)
  198.     {
  199.         for(account2 = new_accounts; account2; account2 = account2->next)
  200.         {
  201.             if(!strcmp(account1->usr, account2->usr))
  202.             {
  203.                 account2->cwfound    = account1->cwfound;
  204.                 account2->cwcache    = account1->cwcache;
  205.                 account2->cwnot      = account1->cwnot;
  206.                 account2->cwtun      = account1->cwtun;
  207.                 account2->cwignored  = account1->cwignored;
  208.                 account2->cwtout     = account1->cwtout;
  209.                 account2->emmok      = account1->emmok;
  210.                 account2->emmnok     = account1->emmnok;
  211.                 account2->firstlogin = account1->firstlogin;
  212.                 ac_copy_vars(account1, account2);
  213.             }
  214.         }
  215.     }
  216.     cs_reinit_clients(new_accounts);
  217.     cfg.account = new_accounts;
  218.     init_free_userdb(old_accounts);
  219.     ac_clear();
  220.     cs_writeunlock(&config_lock);
  221. }