Ignore:
Timestamp:
Jul 2, 2009, 2:07:00 PM (16 years ago)
Author:
Silvan Scherrer
Message:

first drop, still some problems

Location:
branches/client-1.6/src
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/client-1.6/src/Makefile.kmk

    r293 r297  
    4545                $(SAMBA)/source/popt \
    4646                $(SAMBA)/source/lib/talloc \
    47                 $(SAMBA)/source/lib/pc \
     47                $(SAMBA)/source/librpc \
    4848                $(SAMBA)/source/lib/tdb/include \
    49         $(SAMBA)/source/lib/tdb/common \
    50         $(SAMBA)/source/lib/compression \
    51         $(SAMBA)/source/lib/ldb/include \
    52         $(SAMBA)/source/lib/ldb/ldb_tdb \
    53         $(SAMBA)/source/lib/ldb/modules \
    54         $(SAMBA)/source/lib/ldb/nssldb \
    55         $(SAMBA)/source/lib/ldb/tools \
    56         $(SAMBA)/source/lib/netapi \
    57         $(SAMBA)/source/lib/nss_wrapper \
    58         $(SAMBA)/source/lib/smbconf \
    59         $(SAMBA)/source/lib/socket_wrapper \
    6049                $(GCC_INC)
    6150
  • branches/client-1.6/src/smbwrp.c

    r189 r297  
    3333{
    3434        int i;
    35         WERROR result;
    36         ENUM_HND enum_hnd;
    37         uint32 info_level = 1;
    38         uint32 preferred_len = 0xffffffff;
    39         uint32 type;
    40         SRV_SHARE_INFO_CTR ctr;
     35        NTSTATUS status;
     36        WERROR werr;
     37        uint32_t resume_handle = 0;
     38        uint32_t total_entries = 0;
     39        struct srvsvc_NetShareInfoCtr info_ctr;
     40        struct srvsvc_NetShareCtr1 ctr1;
    4141        fstring name = "";
    4242        fstring comment = "";
    4343        void *mem_ctx;
    4444        struct rpc_pipe_client *pipe_hnd;
    45         NTSTATUS nt_status;
    4645
    4746        /* Open the server service pipe */
    48         pipe_hnd = cli_rpc_pipe_open_noauth(cli, PI_SRVSVC, &nt_status);
    49         if (!pipe_hnd) {
     47        status = cli_rpc_pipe_open_noauth(cli, &ndr_table_srvsvc.syntax_id, &pipe_hnd);
     48        if (!NT_STATUS_IS_OK(status)) {
    5049                DEBUG(1, ("net_share_enum_rpc pipe open fail!\n"));
    5150                return -1;
     
    5655        if (mem_ctx == NULL) {
    5756                DEBUG(0, ("out of memory for net_share_enum_rpc!\n"));
    58                 cli_rpc_pipe_close(pipe_hnd);
     57                TALLOC_FREE(pipe_hnd);
    5958                return -1;
    6059        }
    6160
    6261        /* Issue the NetShareEnum RPC call and retrieve the response */
    63         init_enum_hnd(&enum_hnd, 0);
    64         result = rpccli_srvsvc_net_share_enum(pipe_hnd,
    65                                               mem_ctx,
    66                                               info_level,
    67                                               &ctr,
    68                                               preferred_len,
    69                                               &enum_hnd);
     62        ZERO_STRUCT(info_ctr);
     63        ZERO_STRUCT(ctr1);
     64        info_ctr.level = 1;
     65        info_ctr.ctr.ctr1 = &ctr1;
     66        status = rpccli_srvsvc_NetShareEnumAll(pipe_hnd, mem_ctx,
     67                                              pipe_hnd->desthost,
     68                                              &info_ctr,
     69                                              0xffffffff,
     70                                              &total_entries,
     71                                              &resume_handle,
     72                                              &werr);
    7073
    7174        /* Was it successful? */
    72         if (!W_ERROR_IS_OK(result) || ctr.num_entries == 0) {
     75        if (!NT_STATUS_IS_OK(status) || !W_ERROR_IS_OK(werr) || info_ctr.ctr.ctr1->count == 0) {
    7376                /*  Nope.  Go clean up. */
    7477                goto done;
     
    7679
    7780        /* For each returned entry... */
    78         for (i = 0; i < ctr.num_entries; i++) {
    79 
    80                 /* pull out the share name */
    81                 rpcstr_pull_unistr2_fstring(
    82                         name, &ctr.share.info1[i].info_1_str.uni_netname);
    83 
    84                 /* pull out the share's comment */
    85                 rpcstr_pull_unistr2_fstring(
    86                         comment, &ctr.share.info1[i].info_1_str.uni_remark);
    87 
    88                 /* Get the type value */
    89                 type = ctr.share.info1[i].info_1.type;
     81        for (i = 0; i < info_ctr.ctr.ctr1->count; i++) {
     82                struct srvsvc_NetShareInfo1 info = info_ctr.ctr.ctr1->array[i];
    9083
    9184                /* Add this share to the list */
    92                 (*fn)(name, type, comment, state);
     85                (*fn)(info.name, info.type, info.comment, state);
    9386        }
    9487
    9588done:
    9689        /* Close the server service pipe */
    97         cli_rpc_pipe_close(pipe_hnd);
     90        TALLOC_FREE(pipe_hnd);
    9891
    9992        /* Free all memory which was allocated for this request */
     
    10194
    10295        /* Tell 'em if it worked */
    103         return W_ERROR_IS_OK(result) ? 0 : -1;
     96        return W_ERROR_IS_OK(status) ? 0 : -1;
    10497}
    10598
     
    129122        static int initialised = 0;
    130123        char *p;
    131         pstring line;
    132124
    133125        if (initialised)
     
    137129        initialised = 1;
    138130
     131        lp_set_in_client(true); /* Make sure that we tell lp_load we are client */
     132
    139133        load_case_tables();
    140134
    141         init_globals( True);
     135        if (!lp_load(get_dyn_CONFIGFILE(),true,false,false,true)) {
     136                debuglocal(0,("The initial smb.conf is missing, please reinstall the plugin!"));
     137        }
     138
    142139
    143140        load_interfaces();
     
    254251send a qpathinfo call with the SMB_QUERY_FILE_ALL_INFO info level
    255252****************************************************************************/
    256 BOOL cli_qpathinfo3(struct cli_state *cli, const char *fname,
     253bool cli_qpathinfo3(struct cli_state *cli, const char *fname,
    257254                    time_t *c_time, time_t *a_time, time_t *m_time,
    258255                    time_t *w_time, off_t *size, uint16 *mode,
     
    262259        unsigned int param_len = 0;
    263260        uint16 setup = TRANSACT2_QPATHINFO;
    264         pstring param;
     261        char *param;
     262        size_t nlen = 2*(strlen(fname)+1);
    265263        char *rparam=NULL, *rdata=NULL;
    266264        char *p;
     265       
     266        param = SMB_MALLOC_ARRAY(char, 6+nlen+2);
     267        if (!param) {
     268                return false;
     269        }
    267270
    268271        p = param;
    269         memset(p, 0, 6);
     272        memset(p, '\0', 6);
    270273        SSVAL(p, 0, SMB_QUERY_FILE_ALL_INFO);
    271274        p += 6;
    272         p += clistr_push(cli, p, fname, sizeof(pstring)-6, STR_TERMINATE);
     275        p += clistr_push(cli, p, fname, nlen, STR_TERMINATE);
    273276
    274277        param_len = PTR_DIFF(p, param);
     
    284287        }
    285288
     289        SAFE_FREE(param);
    286290        if (!cli_receive_trans(cli, SMBtrans2,
    287291                               &rparam, &param_len,
     
    324328send a qfileinfo call
    325329****************************************************************************/
    326 BOOL cli_qfileinfo3(struct cli_state *cli, int fnum,
     330bool cli_qfileinfo3(struct cli_state *cli, int fnum,
    327331                   uint16 *mode, off_t *size,
    328332                   time_t *c_time, time_t *a_time, time_t *m_time,
     
    332336        unsigned int param_len = 0;
    333337        uint16 setup = TRANSACT2_QFILEINFO;
    334         pstring param;
     338        char param[4];
    335339        char *rparam=NULL, *rdata=NULL;
    336340
     
    341345        param_len = 4;
    342346
    343         memset(param, 0, param_len);
    344347        SSVAL(param, 0, fnum);
    345348        SSVAL(param, 2, SMB_QUERY_FILE_ALL_INFO);
     
    404407        char *p, *server_n = server;
    405408        fstring group;
    406         struct in_addr ip;
     409        struct sockaddr_storage ss;
    407410        NTSTATUS rc;
    408411        struct cli_state * c;
     
    410413        int loginerror = 0;
    411414
    412         zero_ip(&ip);
     415        zero_sockaddr(&ss);
    413416
    414417        debuglocal(1,"Connecting to \\\\%s:*********@%s:%s\\%s. Master %s:%d\n", srv->username,  workgroup, server, share, srv->master, srv->ifmastergroup);
    415418
    416419        if (!*server) {
    417                 struct in_addr sip;
     420                struct sockaddr_storage sip;
    418421
    419422                if (*workgroup)
     
    422425                                return 1;
    423426                        }
    424                         fstrcpy(group, inet_ntoa(sip));
     427                        fstrcpy(group, inet_ntoa(sip.sin_addr));
    425428                        server_n = group;
    426429                } else
     
    432435                                        return 11;
    433436                                }
    434                                 strncpy(srv->master, inet_ntoa(sip), sizeof(srv->master) - 1);
     437                                strncpy(srv->master, inet_ntoa(sip.sin_addr), sizeof(srv->master) - 1);
    435438                                srv->ifmastergroup = 0;
    436439                        }
     
    447450
    448451 again:
    449         zero_ip(&ip);
     452        zero_sockaddr(&ss);
    450453
    451454        /* have to open a new connection */
     
    455458        }
    456459
    457         if (!NT_STATUS_IS_OK(cli_connect(c, server_n, &ip)))
     460        if (!NT_STATUS_IS_OK(cli_connect(c, server_n, &ss)))
    458461        {
    459462                return 3;
     
    666669        unsigned int param_len = 6;
    667670        uint16 setup = TRANSACT2_SETFILEINFO;
    668         pstring param;
     671        char param[6];
     672        unsigned char data[8];
    669673        char *rparam=NULL, *rdata=NULL;
    670674
    671         memset(param, 0, param_len);
    672675        SSVAL(param,0,fnum);
    673676        SSVAL(param,2,SMB_SET_FILE_END_OF_FILE_INFO);
     677        SSVAL(param,4,0);
     678
     679        SBVAL(data, 0, newsize);
    674680
    675681        if (!cli_send_trans(cli, SMBtrans2,
     
    678684                                                &setup, 1, 0,                   /* setup, length, max */
    679685                                                param, param_len, 2,            /* param, length, max */
    680                                                 (char *)&newsize,  sizeof(newsize), cli->max_xmit /* data, length, max */
     686                                                (char *)&data,  data_len,        /* data, length */
     687                                                cli->max_xmit /* max */
    681688                                                )) {
    682689                return False;
     
    10331040****************************************************************************/
    10341041// YD from libsmb\clilist.c
     1042// @todo def_finfo is not available anymore, probably the complete function needs more work
     1043// in the longrun we have to switch to file_info struct instead of our own smbwrp_fileinfo
     1044
    10351045static size_t _os2_interpret_long_filename(struct cli_state *cli,
    10361046                                   int level,char *p, smbwrp_fileinfo *finfo,
     
    11781188#endif
    11791189        int info_level;
    1180         char *p, *p2;
    1181         pstring mask;
     1190        char *p, *p2, *rdata_end;
     1191        char *mask=NULL;
    11821192        smbwrp_fileinfo finfo;
    11831193        int i;
     
    11851195        int dirlist_len = 0;
    11861196        int total_received = -1;
    1187         BOOL First = True;
     1197        bool First = True;
    11881198        int ff_searchcount=0;
    11891199        int ff_eos=0;
     
    11931203        unsigned int param_len, data_len;       
    11941204        uint16 setup;
    1195         pstring param;
     1205        char *param;
    11961206        const char *mnt;
    11971207        uint32 resume_key = 0;
    11981208        uint32 last_name_raw_len = 0;
    1199         DATA_BLOB last_name_raw = data_blob(NULL, 2*sizeof(pstring));
     1209        DATA_BLOB last_name_raw = data_blob(NULL, 0);
    12001210
    12011211        /* NT uses 260, OS/2 uses 2. Both accept 1. */
    12021212        info_level = (cli->capabilities&CAP_NT_SMBS)?260:2;
    1203 
    1204         debuglocal(4,"list_files level %d. mask <%s>\n", info_level, mask);
     1213       
     1214        debuglocal(4,"list_files level %d. mask <%s>\n", info_level, Mask);
    12051215
    12061216        /* when getting a directory listing from a 2k dfs root share,
    12071217           we have to include the full path (\server\share\mask) here */
    12081218           
    1209         if ( cli->dfsroot )
    1210                 pstr_sprintf( mask, "\\%s\\%s\\%s", cli->desthost, cli->share, Mask );
    1211         else
    1212                 pstrcpy(mask,Mask);
     1219        if ( cli->dfsroot ) {
     1220                mask = talloc_asprintf(mask, "\\%s\\%s\\%s", cli->desthost, cli->share, Mask );
     1221        } else {
     1222                mask = SMB_STRDUP(Mask);
     1223                if (!mask) {
     1224                      return -1;
     1225                }
     1226        }
    12131227
    12141228        while (ff_eos == 0) {
     
    12161230                if (loop_count > 200) {
    12171231                        debuglocal(0,"Error: Looping in FIND_NEXT??\n");
     1232                        break;
     1233                }
     1234
     1235                size_t nlen = 2*(strlen(mask)+1);
     1236                param = SMB_MALLOC_ARRAY(char, 12+nlen+last_name_raw.length+2);
     1237                if (!param) {
    12181238                        break;
    12191239                }
     
    12271247                        SIVAL(param,8,0);
    12281248                        p = param+12;
    1229                         p += clistr_push(cli, param+12, mask, sizeof(param)-12,
     1249                        p += clistr_push(cli, param+12, mask, nlen,
    12301250                                         STR_TERMINATE);
    12311251                } else {
     
    12411261                        SSVAL(param,10,(FLAG_TRANS2_FIND_REQUIRE_RESUME|FLAG_TRANS2_FIND_CLOSE_IF_END));        /* resume required + close on end */
    12421262                        p = param+12;
    1243                         if (last_name_raw_len && (last_name_raw_len < (sizeof(param)-12))) {
    1244                                 memcpy(p, last_name_raw.data, last_name_raw_len);
    1245                                 p += last_name_raw_len;
     1263                        if (last_name_raw.length) {
     1264                                memcpy(p, last_name_raw.data, last_name_raw.length);
     1265                                p += last_name_raw.length;
    12461266                        } else {
    1247                                 p += clistr_push(cli, param+12, mask, sizeof(param)-12, STR_TERMINATE);
     1267                                p += clistr_push(cli, param+12, mask, nlen, STR_TERMINATE);
    12481268                        }
    12491269                }
     
    12641284#endif
    12651285                                    )) {
     1286                        SAFE_FREE(param);
    12661287                        break;
    12671288                }
     1289
     1290                SAFE_FREE(param);
    12681291
    12691292                if (!cli_receive_trans(cli, SMBtrans2,
     
    13371360                /* point to the data bytes */
    13381361                p = rdata;
    1339 
    1340                 memset(&finfo, 0, sizeof(finfo));
     1362                rdata_end = rdata + data_len;
     1363
     1364                memset(&finfo, 0, sizeof(finfo));
    13411365                finfo.easize = -1;
    13421366                /* we might need the lastname for continuations */
    1343                 for (p2=p,i=0;i<ff_searchcount;i++) {
     1367                for (p2=p,i=0;i<ff_searchcount  && p2 < rdata_end;i++) {
    13441368                        if ((info_level == 260) && (i == ff_searchcount-1)) {
    13451369                                /* Last entry - fixup the last offset length. */
     
    13471371                        }
    13481372                        p2 += _os2_interpret_long_filename(cli,info_level,p2,&finfo,
    1349                                                         &resume_key,&last_name_raw,&last_name_raw_len);
     1373                                                        &resume_key,&last_name_raw,&last_name_raw.length);
     1374
     1375                        if (!finfo.fname) {
     1376                                debuglocal(0,("Error: unable to parse name from info level %d\n",
     1377                                        info_level));
     1378                                ff_eos = 1;
     1379                                break;
     1380                        }
    13501381
    13511382                        if (!First && *mask && strcsequal(finfo.fname, mask)) {
     
    13571388                }
    13581389
     1390                SAFE_FREE(mask);
    13591391                if (ff_searchcount > 0) {
    1360                         pstrcpy(mask, finfo.fname);
     1392                        mask = SMB_STRDUP(finfo.fname);
    13611393                } else {
    1362                         pstrcpy(mask,"");
     1394                        mask = SMB_STRDUP("");
     1395                }
     1396                if (!mask) {
     1397                        SAFE_FREE(rdata);
     1398                        SAFE_FREE(rparam);
     1399                        break;
    13631400                }
    13641401
     
    14071444        /* free up the dirlist buffer and last name raw blob */
    14081445        SAFE_FREE(dirlist);
     1446        SAFE_FREE(mask);
    14091447        data_blob_free(&last_name_raw);
    14101448        return(total_received);
     
    17211759        return 0;
    17221760}
    1723 
Note: See TracChangeset for help on using the changeset viewer.