Changeset 8877

Show
Ignore:
Timestamp:
06/09/11 17:31:53 (2 years ago)
Author:
sampson
Message:

Windows client: error reporting, symbolic links fixing

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

Legend:

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

    r8870 r8877  
    3838} 
    3939 
     40#define report_cert_error(msg)    _report_cert_error(msg, __func__) 
     41 
    4042/* certificate error reporting */ 
    41 static void report_cert_error(char *message) 
     43static void _report_cert_error(char *message, char *fn_name) 
    4244{ 
    4345    /* debug the message */ 
    44     DbgPrint("   %s\n", message); 
     46    DbgPrint("   %s: %s\n", fn_name, message); 
    4547 
    4648    /* write to Event Log */ 
     
    7274 
    7375 
    74 static int get_proxy_auth_ex_data_idx(void) 
     76static int get_proxy_auth_ex_data_cred() 
    7577{ 
    7678    static volatile int idx = -1; 
     
    8082        if (idx < 0) 
    8183        { 
    82             idx = X509_STORE_CTX_get_ex_new_index(0, 
    83                                                   "for verify callback", 
    84                                                   NULL,NULL,NULL); 
     84            idx = X509_STORE_CTX_get_ex_new_index(0, "credentials", NULL, NULL, 
     85                NULL); 
     86        } 
     87        CRYPTO_w_unlock(CRYPTO_LOCK_X509_STORE); 
     88    } 
     89 
     90    return idx; 
     91} 
     92 
     93static int get_proxy_auth_ex_data_userid() 
     94{ 
     95    static volatile int idx = -1; 
     96    if (idx < 0) 
     97    { 
     98        CRYPTO_w_lock(CRYPTO_LOCK_X509_STORE); 
     99        if (idx < 0) 
     100        { 
     101            idx = X509_STORE_CTX_get_ex_new_index(0, "userid", 
     102                NULL, NULL, NULL); 
    85103        } 
    86104        CRYPTO_w_unlock(CRYPTO_LOCK_X509_STORE); 
     
    144162static int verify_callback(int ok, X509_STORE_CTX *ctx) 
    145163{ 
     164    char *userid; 
    146165    X509 *xs; 
    147166    PROXY_CERT_INFO_EXTENSION *pci; 
    148167    char *credstr; 
    149168    PVFS_credentials *credentials; 
     169    char error_msg[256]; 
    150170    int ret; 
    151171 
     
    157177        if (xs->ex_flags & EXFLAG_PROXY) 
    158178        { 
     179            /* get userid for error logging */ 
     180            userid = (char *) X509_STORE_CTX_get_ex_data(ctx,  
     181                get_proxy_auth_ex_data_userid()); 
     182             
     183            /* get credentials in {UID}/{GID} form from cert policy */ 
    159184            pci = (PROXY_CERT_INFO_EXTENSION *)  
    160185                    X509_get_ext_d2i(xs, NID_proxyCertInfo, NULL, NULL); 
     
    164189                credstr = (char *) pci->proxyPolicy->policy->data; 
    165190                credentials = (PVFS_credentials *) X509_STORE_CTX_get_ex_data( 
    166                     ctx, get_proxy_auth_ex_data_idx()); 
     191                    ctx, get_proxy_auth_ex_data_cred()); 
    167192                ret = parse_credentials(credstr, &credentials->uid,  
    168193                                        &credentials->gid); 
    169194                if (ret != 0) 
    170195                { 
    171                     DbgPrint("   verify_callback: could not parse credential string: %s\n", credstr); 
     196                    _snprintf(error_msg, sizeof(error_msg), "User %s: proxy " 
     197                        "certificate contains invalid credential policy",  
     198                        userid); 
     199                    report_cert_error(error_msg); 
    172200                    ok = 0; 
    173201                } 
     
    175203            else 
    176204            { 
    177                 DbgPrint("   verify_callback: could not load policy\n"); 
     205                _snprintf(error_msg, sizeof(error_msg), "User %s: proxy " 
     206                          "certificate contains no credential policy",  
     207                          userid); 
     208                report_cert_error(error_msg); 
    178209                ok = 0; 
    179210            }             
     
    187218 
    188219/* verify certificate */ 
    189 static unsigned long verify_cert(X509 *cert,  
     220static unsigned long verify_cert(char *userid, 
     221                                 X509 *cert,  
    190222                                 X509 *ca_cert, 
    191223                                 STACK_OF(X509) *chain, 
     
    196228    int ret, verify_flag = 0; 
    197229    int (*save_verify_cb)(int ok, X509_STORE_CTX *ctx); 
     230    char error_msg[256]; 
    198231 
    199232    /* add CA cert to trusted store */ 
     
    230263    save_verify_cb = ctx->verify_cb; 
    231264    X509_STORE_CTX_set_verify_cb(ctx, verify_callback); 
    232     X509_STORE_CTX_set_ex_data(ctx, get_proxy_auth_ex_data_idx(), credentials); 
     265    X509_STORE_CTX_set_ex_data(ctx, get_proxy_auth_ex_data_cred(), credentials); 
     266    X509_STORE_CTX_set_ex_data(ctx, get_proxy_auth_ex_data_userid(), userid); 
    233267    X509_STORE_CTX_set_flags(ctx, X509_V_FLAG_ALLOW_PROXY_CERTS); 
    234268 
     
    245279    if (verify_flag && ret == OPENSSL_CERT_ERROR && ctx->error != 0) 
    246280    { 
    247         DbgPrint("   verify_cert: %s\n",  
     281        _snprintf(error_msg, sizeof(error_msg), "User %s: proxy certificate " 
     282            "verification error: %s", userid,  
    248283            X509_verify_cert_error_string(ctx->error)); 
     284        report_cert_error(error_msg); 
    249285    } 
    250286 
     
    288324    STACK_OF(X509) *chain = NULL; 
    289325    int ret; 
    290     unsigned long err; 
    291     char errstr[256]; 
     326    unsigned long err, err_flag = FALSE; 
     327    size_t err_size; 
     328    char error_msg[256], errstr[256]; 
    292329 
    293330    DbgPrint("   get_cert_credentials: enter\n"); 
     
    304341        if ((strlen(goptions->cert_dir_prefix) + strlen(userid) + 8) > MAX_PATH) 
    305342        { 
    306             DbgPrint("   get_cert_credentials: user %s: path to cert too long\n", userid); 
     343            _snprintf(error_msg, sizeof(error_msg), "User %s: path to certificate " 
     344                "too long", userid); 
     345            report_cert_error(error_msg); 
    307346            return -1; 
    308347        } 
     
    324363        else 
    325364        { 
    326             DbgPrint("   get_cert_credentials: user %s: could not locate profile dir: %d\n", userid, 
    327                 ret); 
     365            _snprintf(error_msg, sizeof(error_msg), "User %s: could not locate " 
     366                "profile directory: %d", userid, ret); 
     367            report_cert_error(error_msg); 
    328368            return ret; 
    329369        } 
     
    331371        if (strlen(cert_dir) + 7 > MAX_PATH) 
    332372        { 
    333             DbgPrint("   get_cert_credentials: user %s: profile dir too long\n", userid); 
     373            _snprintf(error_msg, sizeof(error_msg), "User %s: profile directory too " 
     374                "long", userid); 
     375            report_cert_error(error_msg); 
    334376            return -1; 
    335377        } 
     
    344386    if (h_find == INVALID_HANDLE_VALUE) 
    345387    { 
    346         DbgPrint("   get_cert_credentials: user %s: no certificates\n", userid); 
     388        _snprintf(error_msg, sizeof(error_msg), "User %s: no certificates in %s",  
     389            userid, cert_dir); 
     390        report_cert_error(error_msg); 
    347391        ret = -1; 
    348392        goto get_cert_credentials_exit; 
     
    367411        if (ret != 0) 
    368412        { 
    369             DbgPrint("   get_cert_credentials: error loading cert %s: %d\n",  
    370                 cert_path, ret); 
     413            _snprintf(error_msg, sizeof(error_msg), "Error loading cert %s. See " 
     414                "subsequent log messages for details", cert_path); 
     415            report_cert_error(error_msg); 
    371416        } 
    372417    } while (ret == 0 && FindNextFile(h_find, &find_data)); 
     
    377422    if (cert == NULL) 
    378423    { 
    379         DbgPrint("   get_cert_credentials: missing or invalid cert.0\n"); 
     424        _snprintf(error_msg, sizeof(error_msg), "Missing or invalid %scert.0. See " 
     425            "subsequent log messages for details", cert_dir); 
     426        report_cert_error(error_msg); 
    380427        ret = OPENSSL_CERT_ERROR; 
    381428    } 
     
    388435    if (ret != 0) 
    389436    { 
    390         DbgPrint("   get_cert_credentials: error loading CA cert %s: %d\n",  
    391             goptions->ca_path, ret); 
     437        _snprintf(error_msg, sizeof(error_msg), "User %s: error loading CA " 
     438            "certificate %s. See subsequent log messages for details",  
     439            userid, goptions->ca_path); 
     440        report_cert_error(error_msg); 
    392441        goto get_cert_credentials_exit; 
    393442    } 
    394443 
    395444    /* read and cache credentials from certificate */ 
    396     ret = verify_cert(cert, ca_cert, chain, credentials); 
     445    ret = verify_cert(userid, cert, ca_cert, chain, credentials); 
    397446 
    398447    if (ret == 0) 
     
    406455    if (ret == OPENSSL_CERT_ERROR) 
    407456    { 
    408         while ((err = ERR_get_error()) != 0) 
    409         { 
    410             ERR_error_string_n(err, errstr, 256); 
    411             DbgPrint("   get_cert_credentials: %s\n", errstr); 
    412         } 
     457        _snprintf(error_msg, sizeof(error_msg), "User %s: certificate " 
     458            "errors:\n", userid); 
     459        err_size = 255 - strlen(error_msg); 
     460        /* use err_size for remaining buffer size */ 
     461        while ((err = ERR_get_error()) != 0 && err_size > 0) 
     462        { 
     463            err_flag = TRUE; 
     464            ERR_error_string_n(err, errstr, 256);             
     465            strncat(error_msg, errstr, err_size); 
     466            err_size = 255 - strlen(error_msg); 
     467            strncat(error_msg, "\n", err_size); 
     468            err_size = 255 - strlen(error_msg); 
     469        } 
     470        if (err_flag) 
     471            report_cert_error(error_msg); 
    413472    } 
    414473 
  • branches/windows-client/src/client/windows/client-service/dokan-interface.c

    r8858 r8877  
    12001200} 
    12011201 
     1202/* free attribute buffers that are allocated with fs_getattr */ 
     1203#define FREE_ATTR_BUFS(attr)    do { \ 
     1204                                    if (attr.dist_name != NULL) \ 
     1205                                        free(attr.dist_name); \ 
     1206                                    if (attr.dist_params != NULL) \ 
     1207                                        free(attr.dist_params); \ 
     1208                                    if (attr.link_target != NULL) \ 
     1209                                        free(attr.link_target); \ 
     1210                                } while (0) 
     1211 
    12021212 
    12031213static int __stdcall 
     
    12291239 
    12301240    if (ret == 0) 
    1231     { 
     1241    {         
    12321242        strcpy(info, "   "); 
    12331243        /* convert to Windows attributes */ 
     
    12841294        HandleFileInformation->nFileSizeLow = (attr.size & 0xFFFFFFFFLL); 
    12851295 
     1296        FREE_ATTR_BUFS(attr); 
    12861297    }     
    12871298     
  • branches/windows-client/src/client/windows/client-service/fs.c

    r8870 r8877  
    158158{ 
    159159    struct PVFS_sys_mntent *mntent = fs_get_mntent(0); 
     160    char *real_path; 
    160161    PVFS_sysresp_lookup resp; 
    161     int ret; 
    162  
    163     ret = PVFS_sys_lookup(mntent->fs_id, fs_path, credentials, &resp, 
    164                           TRUE, NULL); 
     162    PVFS_sysresp_getattr resp_getattr; 
     163    PVFS_fs_id fs_id; 
     164    int ret, link_flag; 
     165 
     166    real_path = strdup(fs_path); 
     167    do  
     168    { 
     169        link_flag = FALSE; 
     170 
     171        /* lookup the given path on the FS */ 
     172        ret = PVFS_sys_lookup(mntent->fs_id, real_path, credentials, &resp, 
     173            FALSE, NULL); 
     174        if (ret != 0) 
     175            break; 
     176 
     177        /* check if it's a link */ 
     178        memset(&resp_getattr, 0, sizeof(resp_getattr)); 
     179        ret = PVFS_sys_getattr(resp.ref, PVFS_ATTR_SYS_LNK_TARGET, credentials, 
     180            &resp_getattr, NULL); 
     181        if (ret != 0) 
     182            break; 
     183 
     184        if (resp_getattr.attr.link_target != NULL) 
     185        { 
     186            link_flag = TRUE; 
     187            /* get file name */ 
     188            free(real_path); 
     189            real_path = (char *) malloc(PVFS_NAME_MAX); 
     190            ret = PVFS_util_resolve(resp_getattr.attr.link_target, &fs_id,  
     191                real_path, PVFS_NAME_MAX); 
     192            /* free attr buffer */ 
     193            free(resp_getattr.attr.link_target); 
     194        } 
     195    } while (link_flag); 
     196 
     197    free(real_path); 
     198 
    165199    if (ret == 0) 
    166200        *handle = resp.ref.handle; 
     
    358392{ 
    359393    struct PVFS_sys_mntent *mntent = fs_get_mntent(0); 
    360     int ret; 
     394    char *real_path; 
     395    int ret, link_flag; 
     396    PVFS_fs_id fs_id; 
    361397    PVFS_sysresp_lookup resp_lookup; 
    362398    PVFS_sysresp_getattr resp_getattr; 
     
    367403 
    368404    /* lookup file */ 
    369     ret = PVFS_sys_lookup(mntent->fs_id, fs_path, credentials, &resp_lookup, 
    370                           TRUE, NULL); 
    371     if (ret != 0) 
    372         goto fs_getattr_exit; 
    373  
    374     /* read all attributes */ 
    375     ret = PVFS_sys_getattr(resp_lookup.ref, PVFS_ATTR_SYS_ALL_NOHINT,  
     405    real_path = strdup(fs_path); 
     406    do { 
     407        link_flag = FALSE; 
     408 
     409        ret = PVFS_sys_lookup(mntent->fs_id, real_path, credentials, &resp_lookup, 
     410            FALSE, NULL); 
     411        if (ret != 0) 
     412            break; 
     413         
     414        /* read all attributes */ 
     415        memset(&resp_getattr, 0, sizeof(resp_getattr)); 
     416        ret = PVFS_sys_getattr(resp_lookup.ref, PVFS_ATTR_SYS_ALL_NOHINT,  
    376417                           credentials, &resp_getattr, NULL); 
     418        if (ret != 0) 
     419            break; 
     420 
     421        /* get attributes for link target */ 
     422        if (resp_getattr.attr.link_target != NULL) 
     423        { 
     424            link_flag = TRUE; 
     425            /* get file name */ 
     426            free(real_path); 
     427            real_path = (char *) malloc(PVFS_NAME_MAX); 
     428            ret = PVFS_util_resolve(resp_getattr.attr.link_target, &fs_id,  
     429                real_path, PVFS_NAME_MAX); 
     430            /* free attr buffers */ 
     431            free(resp_getattr.attr.link_target); 
     432            if (resp_getattr.attr.dist_name != NULL) 
     433                free(resp_getattr.attr.dist_name); 
     434            if (resp_getattr.attr.dist_params != NULL) 
     435                free(resp_getattr.attr.dist_params);             
     436        } 
     437    } while (link_flag); 
     438 
     439    free(real_path); 
     440 
    377441    if (ret != 0) 
    378442        goto fs_getattr_exit; 
  • branches/windows-client/src/client/windows/client-service/ldap-support.c

    r8856 r8877  
    1818extern PORANGEFS_OPTIONS goptions; 
    1919 
     20#define report_ldap_error(msg)    _report_ldap_error(msg, __func__) 
     21 
     22static void _report_ldap_error(char *message, char *fn_name) 
     23{ 
     24    /* debug the message */ 
     25    DbgPrint("   %s: %s\n", fn_name, message); 
     26 
     27    /* write to Event Log */ 
     28    report_error_event(message, FALSE); 
     29} 
     30 
    2031/* initialize LDAP SSL */ 
    2132int PVFS_ldap_init() 
     
    5970    int version, ret = -1, bind_ret = 0; 
    6071    char *bind_dn, *password, filter[384], 
    61          *attrs[3], *attr_name, **values; 
     72         *attrs[3], *attr_name, **values, 
     73         error_msg[256]; 
    6274    LDAPMessage *results, *entry; 
    6375    BerElement *ptr; 
     
    7183    if (ld == NULL) 
    7284    { 
    73         DbgPrint("   get_ldap_credentials: ldapssl_init failed\n"); 
     85        _snprintf(error_msg, sizeof(error_msg), "User %s: could not initialize " 
     86            "LDAP", userid); 
     87        report_ldap_error(error_msg); 
    7488        goto get_ldap_credentials_exit; 
    7589    } 
     
    94108    if (bind_ret != 0) 
    95109    { 
    96         DbgPrint("   get_ldap_credentials: bind failed: %s (%d)\n", 
    97                  ldap_err2string(bind_ret), bind_ret); 
     110        _snprintf(error_msg, sizeof(error_msg), "User %s: could not bind to " 
     111            "LDAP server: %s (%d)", userid, ldap_err2string(bind_ret), bind_ret); 
     112        report_ldap_error(error_msg); 
    98113        goto get_ldap_credentials_exit; 
    99114    } 
     
    150165                        else 
    151166                        { 
    152                             DbgPrint("   get_ldap_credentials: %s: not a number " 
    153                                 "(%s)\n", attr_name, values[0]); 
     167                            _snprintf(error_msg, sizeof(error_msg), "User %s: " 
     168                                "LDAP attribute %s: not a number (%s)", userid, 
     169                                attr_name, values[0]); 
     170                            report_ldap_error(error_msg); 
    154171                            ret = -1; 
    155172                        } 
     
    159176                    else 
    160177                    { 
    161                         DbgPrint("   get_ldap_credentials: %s: no values\n", attr_name); 
     178                        _snprintf(error_msg, sizeof(error_msg), "User %s: no " 
     179                            "values for LDAP attribute %s", userid, attr_name); 
     180                        report_ldap_error(error_msg); 
    162181                        ret = -1; 
    163182                    } 
     
    172191            { 
    173192                ldap_get_option(ld, LDAP_OPT_RESULT_CODE, &ret); 
    174                 DbgPrint("   get_ldap_credentials: no entries: %s (%d)\n", 
    175                     ldap_err2string(ret), ret); 
     193                _snprintf(error_msg, sizeof(error_msg), "User %s: no LDAP " 
     194                    "entries", userid); 
     195                report_ldap_error(error_msg); 
    176196                ret = -1; 
    177197            } 
     
    181201        else 
    182202        { 
    183             DbgPrint("   get_ldap_credentials: no results\n"); 
     203            _snprintf(error_msg, sizeof(error_msg), "User %s: no LDAP " 
     204                "results", userid); 
     205            report_ldap_error(error_msg); 
    184206            ret = -1; 
    185207        } 
     
    187209    else  
    188210    { 
    189         DbgPrint("   get_ldap_credentials: search: %s (%d)\n",  
    190             ldap_err2string(ret), ret); 
     211        _snprintf(error_msg, sizeof(error_msg), "User %s: LDAP search error: " 
     212            "%s (%d)", userid, ldap_err2string(ret), ret); 
     213        report_ldap_error(error_msg); 
    191214    } 
    192215 
     
    196219    if (ret == 0 && (credentials->uid == -1 || credentials->gid == -1)) 
    197220    { 
    198         DbgPrint("   ldap_get_credentials: credentials not found\n"); 
     221        _snprintf(error_msg, sizeof(error_msg), "User %s: LDAP credentials " 
     222            "not found", userid); 
     223        report_ldap_error(error_msg); 
    199224        ret = -1; 
    200225    }