Ignore:
Timestamp:
Sep 27, 2013, 1:55:10 PM (12 years ago)
Author:
Silvan Scherrer
Message:

Samba Client 2.1: timestamp work and some backport from 2.2 client

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/client-2.1/src/smbwrp.c

    r816 r817  
    3939static int
    4040net_share_enum_rpc(struct cli_state *cli,
    41                    void (*fn)(const char *name,
    42                               uint32 type,
    43                               const char *comment,
    44                               void *state),
    45                    void *state)
    46 {
    47         int i;
     41                void (*fn)(const char *name,
     42                uint32 type,
     43                const char *comment,
     44                void *state),
     45                void *state)
     46{
     47        int i;
    4848        NTSTATUS status;
    49         WERROR werr;
     49        WERROR werr;
    5050        uint32_t resume_handle = 0;
    51         uint32_t total_entries = 0;
    52         struct srvsvc_NetShareInfoCtr info_ctr;
    53         struct srvsvc_NetShareCtr1 ctr1;
     51        uint32_t total_entries = 0;
     52        struct srvsvc_NetShareInfoCtr info_ctr;
     53        struct srvsvc_NetShareCtr1 ctr1;
    5454        fstring name = "";
    55         fstring comment = "";
    56         void *mem_ctx;
     55        fstring comment = "";
     56        void *mem_ctx;
    5757        struct rpc_pipe_client *pipe_hnd;
    5858
    59         /* Open the server service pipe */
    60         status = cli_rpc_pipe_open_noauth(cli, &ndr_table_srvsvc.syntax_id, &pipe_hnd);
    61         if (!NT_STATUS_IS_OK(status)) {
    62                 DEBUG(1, ("net_share_enum_rpc pipe open fail!\n"));
    63                 return -1;
    64         }
    65 
    66         /* Allocate a context for parsing and for the entries in "ctr" */
    67         mem_ctx = talloc_init("libsmbclient: net_share_enum_rpc");
    68         if (mem_ctx == NULL) {
    69                 DEBUG(0, ("out of memory for net_share_enum_rpc!\n"));
    70                 TALLOC_FREE(pipe_hnd);
    71                 return -1;
    72         }
    73 
    74         /* Issue the NetShareEnum RPC call and retrieve the response */
     59        /* Open the server service pipe */
     60        status = cli_rpc_pipe_open_noauth(cli, &ndr_table_srvsvc.syntax_id, &pipe_hnd);
     61        if (!NT_STATUS_IS_OK(status)) {
     62                DEBUG(1, ("net_share_enum_rpc pipe open fail!\n"));
     63                return -1;
     64        }
     65
     66        /* Allocate a context for parsing and for the entries in "ctr" */
     67        mem_ctx = talloc_init("libsmbclient: net_share_enum_rpc");
     68        if (mem_ctx == NULL) {
     69                DEBUG(0, ("out of memory for net_share_enum_rpc!\n"));
     70                TALLOC_FREE(pipe_hnd);
     71                return -1;
     72        }
     73
     74        /* Issue the NetShareEnum RPC call and retrieve the response */
    7575        ZERO_STRUCT(info_ctr);
    76         ZERO_STRUCT(ctr1);
    77         info_ctr.level = 1;
    78         info_ctr.ctr.ctr1 = &ctr1;
     76        ZERO_STRUCT(ctr1);
     77        info_ctr.level = 1;
     78        info_ctr.ctr.ctr1 = &ctr1;
    7979        status = rpccli_srvsvc_NetShareEnumAll(pipe_hnd, mem_ctx,
    80                                               pipe_hnd->desthost,
    81                                               &info_ctr,
    82                                               0xffffffff,
    83                                               &total_entries,
    84                                               &resume_handle,
    85                                               &werr);
    86 
    87         /* Was it successful? */
     80                                                pipe_hnd->desthost,
     81                                                &info_ctr,
     82                                                0xffffffff,
     83                                                &total_entries,
     84                                                &resume_handle,
     85                                                &werr);
     86
     87        /* Was it successful? */
    8888        if (!NT_STATUS_IS_OK(status) || !W_ERROR_IS_OK(werr) || info_ctr.ctr.ctr1->count == 0) {
    89                 /*  Nope.  Go clean up. */
     89                /*  Nope.  Go clean up. */
    9090                goto done;
    91         }
    92 
    93         /* For each returned entry... */
    94         for (i = 0; i < info_ctr.ctr.ctr1->count; i++) {
    95                 struct srvsvc_NetShareInfo1 info = info_ctr.ctr.ctr1->array[i];
    96 
    97                 /* Add this share to the list */
    98                 (*fn)(info.name, info.type, info.comment, state);
    99         }
     91        }
     92
     93        /* For each returned entry... */
     94        for (i = 0; i < info_ctr.ctr.ctr1->count; i++) {
     95                struct srvsvc_NetShareInfo1 info = info_ctr.ctr.ctr1->array[i];
     96
     97                /* Add this share to the list */
     98                (*fn)(info.name, info.type, info.comment, state);
     99        }
    100100
    101101done:
    102         /* Close the server service pipe */
    103         TALLOC_FREE(pipe_hnd);
    104 
    105         /* Free all memory which was allocated for this request */
    106         TALLOC_FREE(mem_ctx);
    107 
    108         /* Tell 'em if it worked */
    109         return W_ERROR_IS_OK(status) ? 0 : -1;
     102        /* Close the server service pipe */
     103        TALLOC_FREE(pipe_hnd);
     104
     105        /* Free all memory which was allocated for this request */
     106        TALLOC_FREE(mem_ctx);
     107
     108        /* Tell 'em if it worked */
     109        return W_ERROR_IS_OK(status) ? 0 : -1;
    110110}
    111111
     
    125125void smbwrp_Logging()
    126126{
    127         char slogfile[_MAX_PATH +1] = {0};
    128         char slogfilename[] = "log.smbc";
    129         char *env = getenv("LOGFILES");
    130                 if (env != NULL)
    131                 {
    132                    strncpy(slogfile, env, sizeof(slogfile) -1);
    133                    strncat(slogfile, "\\", sizeof(slogfile) - strlen(slogfile) -1);
    134                    strncat(slogfile, slogfilename, sizeof(slogfile) - strlen(slogfile) -1);
    135                 }
    136                 else
    137                 {
    138                    strncpy(slogfile, slogfilename, sizeof(slogfile) -1);
    139                 }
    140 
    141                 // init samba for debug messages
    142                 setup_logging(slogfile, false);
    143                 lp_set_logfile(slogfile);
    144                 debug_parse_levels("10");
     127        char slogfile[_MAX_PATH +1] = {0};
     128        char slogfilename[] = "log.smbc";
     129        char *env = getenv("LOGFILES");
     130        if (env != NULL)
     131        {
     132                strncpy(slogfile, env, sizeof(slogfile) -1);
     133                strncat(slogfile, "\\", sizeof(slogfile) - strlen(slogfile) -1);
     134                strncat(slogfile, slogfilename, sizeof(slogfile) - strlen(slogfile) -1);
     135        }
     136        else
     137        {
     138                strncpy(slogfile, slogfilename, sizeof(slogfile) -1);
     139        }
     140
     141        // init samba for debug messages
     142        setup_logging(slogfile, false);
     143        lp_set_logfile(slogfile);
     144        debug_parse_levels("10");
    145145
    146146}
    147147const char * smbwrp_getVersion()
    148148{
    149         return SAMBA_VERSION_STRING;
     149        return SAMBA_VERSION_STRING;
    150150}
    151151
     
    169169        initialised = 1;
    170170
    171         lp_set_in_client(true); /* Make sure that we tell lp_load we are client */
     171        lp_set_in_client(true); /* Make sure that we tell lp_load we are client */
    172172
    173173        load_case_tables();
     
    184184        }
    185185
    186         if (writeLog())
    187         {
    188                 smbwrp_Logging();
    189         }
     186        if (writeLog())
     187        {
     188                smbwrp_Logging();
     189        }
    190190
    191191/*
     
    200200void smbwrp_initthread(void)
    201201{
    202         /*
    203          * Block SIGPIPE (from lib/util_sock.c: write())
    204          * It is not needed and should not stop execution
    205          */
    206         BlockSignals(True, SIGPIPE);
     202        /*
     203        Block SIGPIPE (from lib/util_sock.c: write())
     204        It is not needed and should not stop execution
     205        */
     206        BlockSignals(True, SIGPIPE);
    207207}
    208208
     
    313313        uint16 setup = TRANSACT2_QPATHINFO;
    314314        char *param;
    315         size_t nlen = 2*(strlen(fname)+1);
     315        size_t nlen = 2*(strlen(fname)+1);
    316316        char *rparam=NULL, *rdata=NULL;
    317317        char *p;
    318        
    319         param = SMB_MALLOC_ARRAY(char, 6+nlen+2);
    320         if (!param) {
     318
     319        param = SMB_MALLOC_ARRAY(char, 6+nlen+2);
     320        if (!param) {
    321321                return false;
    322322        }
     
    331331
    332332        if (!cli_send_trans(cli, SMBtrans2,
    333                             NULL,                         /* name */
    334                             -1, 0,                        /* fid, flags */
    335                             &setup, 1, 0,                 /* setup, length, max */
    336                             param, param_len, 10,         /* param, length, max */
    337                             NULL, data_len, cli->max_xmit /* data, length, max */
    338                            )) {
     333                        NULL,                           /* name */
     334                        -1, 0,                          /* fid, flags */
     335                        &setup, 1, 0,                   /* setup, length, max */
     336                        param, param_len, 10,           /* param, length, max */
     337                        NULL, data_len, cli->max_xmit   /* data, length, max */
     338                        )) {
    339339                return False;
    340340        }
    341341
    342         SAFE_FREE(param);
     342        SAFE_FREE(param);
    343343        if (!cli_receive_trans(cli, SMBtrans2,
    344                                &rparam, &param_len,
    345                                &rdata, &data_len)) {
     344                        &rparam, &param_len,
     345                        &rdata, &data_len)) {
    346346                return False;
    347347        }
     
    402402
    403403        if (!cli_send_trans(cli, SMBtrans2,
    404                             NULL,                           /* name */
    405                             -1, 0,                          /* fid, flags */
    406                             &setup, 1, 0,                   /* setup, length, max */
    407                             param, param_len, 2,            /* param, length, max */
    408                             NULL, data_len, cli->max_xmit   /* data, length, max */
    409                            )) {
     404                        NULL,                           /* name */
     405                        -1, 0,                          /* fid, flags */
     406                        &setup, 1, 0,                   /* setup, length, max */
     407                        param, param_len, 2,            /* param, length, max */
     408                        NULL, data_len, cli->max_xmit   /* data, length, max */
     409                        )) {
    410410                return False;
    411411        }
    412412
    413413        if (!cli_receive_trans(cli, SMBtrans2,
    414                                &rparam, &param_len,
    415                                &rdata, &data_len)) {
     414                        &rparam, &param_len,
     415                        &rdata, &data_len)) {
    416416                return False;
    417417        }
     
    503503
    504504 again:
    505         zero_sockaddr(&ss);
     505        zero_sockaddr(&ss);
    506506
    507507        /* have to open a new connection */
     
    695695                debuglocal(4,"cli_close new mtime %lu\n", file->mtime);
    696696        }
    697 
    698         if (file->updatetime == 2 && !cli_setattrE(cli, file->fd, file->ctime, 0, file->mtime))
    699         {
    700                 debuglocal(4,"Set attrE on close failed %d\n", os2cli_errno(cli));
    701         }
    702697       
    703698        if (!cli_close(cli, file->fd))
     
    706701        }
    707702
    708         if (!rc && (file->openattr || file->mtime))
    709         {
    710                 debuglocal(4,"Set attr on close %s %08x %d %d\n", file->fname, file->openattr, file->mtime, file->mtime);
    711                 if (!cli_setatr(cli, file->fname, file->openattr, file->mtime))
    712                 {
    713                         debuglocal(4,"Set attr on close failed %d\n", os2cli_errno(cli));
     703        if (!rc && (file->openattr || file->mtime || file->ctime))
     704        {
     705                debuglocal(4,"Set pathinfo on close %s %08x %d %d\n", file->fname, file->openattr, file->mtime, file->ctime);
     706                if (!cli_setpathinfo(cli, file->fname, file->ctime, 0, file->mtime, 0, file->openattr))
     707                {
     708                        debuglocal(4,"Set pathinfo on close failed %d\n", os2cli_errno(cli));
    714709                        //rc = os2cli_errno(cli);
    715710                }
    716                
    717711        }
    718712
    719713        file->openattr = 0;
    720714        file->mtime = 0;
    721         file->updatetime = 0;           
     715        file->ctime = 0;
     716        file->updatetime = 0;
    722717        file->fd = -1;
    723718        file->offset = 0;
Note: See TracChangeset for help on using the changeset viewer.