Changeset 8840

Show
Ignore:
Timestamp:
05/19/11 17:30:51 (2 years ago)
Author:
sampson
Message:

Windows certificate support

Location:
branches/windows-client/src/client/windows/client-service
Files:
5 modified

Legend:

Unmodified
Added
Removed
  • branches/windows-client/src/client/windows/client-service/cert.c

    r8839 r8840  
    228228} 
    229229 
    230 /* get user profile directory */ 
    231 static unsigned int get_profile_dir(char *userid,  
    232                                     char *profile_dir) 
    233 { 
    234     LPUSER_INFO_4 user_info; 
     230/* get user home directory */ 
     231static unsigned int get_home_dir(char *userid,  
     232                                 char *home_dir) 
     233{ 
     234    LPUSER_INFO_11 user_info; 
    235235    LPWSTR wuserid; 
    236236    int ret; 
     
    243243 
    244244    /* get user information */ 
    245     ret = NetUserGetInfo(NULL, wuserid, 4, (LPBYTE *) &user_info); 
     245    ret = NetUserGetInfo(NULL, wuserid, 11, (LPBYTE *) &user_info); 
    246246 
    247247    if (ret == 0) 
    248248    { 
    249         mbstr = convert_wstring(user_info->usri4_profile); 
     249        mbstr = convert_wstring(user_info->usri11_home_dir); 
    250250        if (mbstr == NULL)  
    251251        { 
     
    254254        } 
    255255         
    256         strncpy(profile_dir, mbstr, MAX_PATH); 
    257  
    258         free(mbstr); 
     256        strncpy(home_dir, mbstr, MAX_PATH); 
     257 
     258        if (mbstr != NULL) 
     259            free(mbstr); 
    259260 
    260261        NetApiBufferFree(user_info); 
     
    294295 
    295296    /* locate the certificates and CA */ 
    296     if (goptions->cert_dir_prefix != NULL) 
     297    if (strlen(goptions->cert_dir_prefix) > 0) 
    297298    { 
    298299        if ((strlen(goptions->cert_dir_prefix) + strlen(userid) + 8) > MAX_PATH) 
     
    309310    { 
    310311        /* get profile directory */ 
    311         ret = get_profile_dir(userid, cert_dir); 
     312        ret = get_home_dir(userid, cert_dir); 
    312313        if (ret != 0) 
    313314        { 
     
    328329 
    329330    strcpy(cert_pattern, cert_dir); 
    330     strcat(cert_pattern, "cert.*"); 
     331    strcat(cert_pattern, "\\cert.*"); 
    331332    h_find = FindFirstFile(cert_pattern, &find_data); 
    332333    if (h_find == INVALID_HANDLE_VALUE) 
  • branches/windows-client/src/client/windows/client-service/config.c

    r8839 r8840  
    1414extern struct qhash_table user_cache; 
    1515 
    16 FILE *open_config_file() 
     16static FILE *open_config_file(char *error_msg,  
     17                              unsigned int error_msg_len) 
    1718{ 
    1819    FILE *f = NULL; 
    19     char *file_name, exe_path[MAX_PATH], *p; 
     20    char *file_name = NULL, exe_path[MAX_PATH], *p; 
    2021    DWORD ret = 0, malloc_flag = FALSE; 
    2122 
     
    4142        { 
    4243            ret = GetLastError(); 
    43             fprintf(stderr, "GetModuleFileName failed: %u\n", ret); 
     44            _snprintf(error_msg, error_msg_len, "GetModuleFileName failed: %u\n", ret); 
    4445        } 
    4546    } 
     
    5051 
    5152    if (f == NULL) 
    52         fprintf(stderr, "Fatal: could not open file %s\n",  
     53        _snprintf(error_msg, error_msg_len, "Fatal: could not open configuration file %s\n",  
    5354            file_name == NULL ? "(null)" : file_name); 
    5455 
     
    5960} 
    6061 
    61 void close_config_file(FILE *f) 
     62static void close_config_file(FILE *f) 
    6263{ 
    6364    fclose(f); 
     
    145146} 
    146147 
    147 int get_config(PORANGEFS_OPTIONS options) 
     148int get_config(PORANGEFS_OPTIONS options, 
     149               char *error_msg, 
     150               unsigned int error_msg_len) 
    148151{ 
    149152    FILE *config_file; 
    150153    char line[256], copy[256], *token; 
    151  
    152     config_file = open_config_file(); 
     154    int ret = 0; 
     155 
     156    config_file = open_config_file(error_msg, error_msg_len); 
    153157    if (config_file == NULL) 
    154158        /* config file is required */ 
     
    204208                if (token == NULL) 
    205209                { 
    206                     fprintf(stderr, "user-mode option must be list, certificate, or ldap\n"); 
    207                     close_config_file(config_file); 
    208                     return 1; 
     210                    _snprintf(error_msg, error_msg_len, "user-mode option must be list, certificate, or ldap\n");                     
     211                    ret = 1; 
     212                    goto get_config_exit; 
    209213                } 
    210214                if (!stricmp(token, "list")) 
     
    222226                else 
    223227                { 
    224                     fprintf(stderr, "user-mode option must be list, certificate, or ldap\n"); 
    225                     close_config_file(config_file); 
    226                     return 1; 
     228                    _snprintf(error_msg, error_msg_len, "user-mode option must be list, certificate, or ldap\n"); 
     229                    ret = 1; 
     230                    goto get_config_exit; 
    227231                } 
    228232            } 
     
    231235                if (options->user_mode == USER_MODE_NONE) 
    232236                { 
    233                     fprintf(stderr, "user option: specify 'user-mode list' above user option\n"); 
    234                     close_config_file(config_file); 
    235                     return 1; 
     237                    _snprintf(error_msg, error_msg_len, "user option: specify 'user-mode list' above user option\n"); 
     238                    ret = 1; 
     239                    goto get_config_exit; 
    236240                } 
    237241                else if (options->user_mode != USER_MODE_LIST) 
    238242                { 
    239                     fprintf(stderr, "user option: not legal with current user mode\n"); 
    240                     close_config_file(config_file); 
    241                     return 1; 
     243                    _snprintf(error_msg, error_msg_len, "user option: not legal with current user mode\n"); 
     244                    ret = 1; 
     245                    goto get_config_exit; 
    242246                } 
    243247 
    244248                if (parse_user() != 0) 
    245249                { 
    246                     fprintf(stderr, "user option: parse error\n"); 
    247                     close_config_file(config_file); 
    248                     return 1; 
     250                    _snprintf(error_msg, error_msg_len, "user option: parse error\n"); 
     251                    ret = 1; 
     252                    goto get_config_exit; 
    249253                } 
    250254            }             
     
    260264                else 
    261265                { 
    262                     fprintf(stderr, "cert-dir-prefix option: parse error\n"); 
     266                    _snprintf(error_msg, error_msg_len, "cert-dir-prefix option: parse error\n"); 
     267                    ret = 1; 
     268                    goto get_config_exit; 
    263269                } 
    264270            } 
     
    272278                else 
    273279                { 
    274                     fprintf(stderr, "ca-path option: parse error\n"); 
     280                    _snprintf(error_msg, error_msg_len, "ca-path option: parse error\n"); 
     281                    ret = 1; 
     282                    goto get_config_exit; 
    275283                } 
    276284            } 
     
    280288            }             
    281289            else 
    282                 fprintf(stderr, "Unknown option %s\n", token); 
    283         } 
    284     } 
     290                _snprintf(error_msg, error_msg_len, "Unknown option %s\n", token); 
     291        } 
     292    } 
     293 
     294    if (options->user_mode == USER_MODE_NONE) 
     295    { 
     296        _snprintf(error_msg, error_msg_len, "Must specify user-mode (list, certificate or ldap)\n"); 
     297        ret = 1; 
     298        goto get_config_exit; 
     299    } 
     300 
     301    if (options->user_mode == USER_MODE_CERT && 
     302        strlen(options->ca_path) == 0) 
     303    { 
     304        _snprintf(error_msg, error_msg_len, "Must specify ca-path with certificate mode\n"); 
     305        ret = 1; 
     306    } 
     307 
     308get_config_exit: 
    285309 
    286310    close_config_file(config_file); 
    287311 
    288     if (options->user_mode == USER_MODE_NONE) 
    289     { 
    290         fprintf(stderr, "Must specify user-mode (list, certificate or ldap)\n"); 
    291         return 1; 
    292     } 
    293  
    294     return 0; 
     312    return ret; 
    295313} 
  • branches/windows-client/src/client/windows/client-service/config.h

    r8718 r8840  
    77#include "client-service.h" 
    88 
    9 int get_config(PORANGEFS_OPTIONS options); 
     9int get_config(PORANGEFS_OPTIONS options, 
     10               char *error_msg, 
     11               unsigned int error_msg_len); 
    1012 
    1113#endif 
  • branches/windows-client/src/client/windows/client-service/service-main.c

    r8839 r8840  
    301301    PORANGEFS_OPTIONS options; 
    302302    int ret; 
     303    char error_msg[512];     
    303304 
    304305    /* allocate options */ 
     
    314315 
    315316    /* read from config file */ 
    316     ret = get_config(options); 
     317    ret = get_config(options, error_msg, 512); 
    317318 
    318319    /* point global options */ 
     
    329330    if (ret != 0) 
    330331    { 
    331         service_debug("Could not parse config file: check user options\n"); 
     332        service_debug(error_msg); 
     333        service_debug("Could not parse config file: exiting\n"); 
    332334        close_service_log(); 
    333335        return; 
     
    543545  DWORD err = 0; 
    544546  char mount_point[256]; 
     547  char error_msg[512]; 
    545548 
    546549  SERVICE_TABLE_ENTRY dispatch_table[2] =  
     
    602605 
    603606      /* get options from config file */ 
    604       if (get_config(options) != 0) 
    605           return 1; 
     607      if (get_config(options, error_msg, 512) != 0) 
     608      { 
     609          fprintf(stderr, error_msg); 
     610          err = 1; 
     611          goto main_exit; 
     612      } 
    606613 
    607614      /* point goptions */ 
     
    623630      { 
    624631          fprintf(stderr, "Drive already in use\n"); 
    625           return -1; 
     632          err = 1; 
     633          goto main_exit; 
    626634      } 
    627635 
     
    631639      { 
    632640          fprintf(stderr, "User cache thread did not start: %u\n", err); 
    633           free(options); 
    634           return err; 
     641          goto main_exit; 
    635642      } 
    636643 
     
    646653      cache_thread_stop(); 
    647654 
     655main_exit: 
     656 
    648657      qhash_destroy_and_finalize(user_cache, struct user_entry, hash_link, free); 
    649658 
  • branches/windows-client/src/client/windows/client-service/user-cache.c

    r8839 r8840  
    135135        { 
    136136            head = qhash_search_at_index(user_cache, i); 
    137             qhash_for_each_safe(link, temp, head) 
    138             { 
    139                 entry = qhash_entry(link, struct user_entry, hash_link); 
    140                 if (entry->expires != 0 && entry->expires < now) 
    141                 {    
    142                     DbgPrint("user_cache_thread: removing %s\n", entry->user_name); 
    143                     qhash_del(link); 
    144                     free(entry); 
     137            if (head != NULL) 
     138            {     
     139                qhash_for_each_safe(link, temp, head) 
     140                { 
     141                    entry = qhash_entry(link, struct user_entry, hash_link); 
     142                    if (entry->expires != 0 && entry->expires < now) 
     143                    {    
     144                        DbgPrint("user_cache_thread: removing %s\n", entry->user_name); 
     145                        qhash_del(link); 
     146                        free(entry); 
     147                    } 
    145148                } 
    146149            }