Ignore:
Timestamp:
Nov 24, 2016, 1:14:11 PM (9 years ago)
Author:
Silvan Scherrer
Message:

Samba Server: update vendor to version 4.4.3

File:
1 edited

Legend:

Unmodified
Added
Removed
  • vendor/current/source4/ntvfs/cifs/vfs_cifs.c

    r740 r988  
    3535#include "param/param.h"
    3636#include "libcli/resolve/resolve.h"
     37#include "../libcli/smb/smbXcli_base.h"
    3738
    3839struct cvfs_file {
     
    6465};
    6566
     67NTSTATUS ntvfs_cifs_init(void);
     68
    6669#define CHECK_UPSTREAM_OPEN do { \
    67         if (! p->transport->socket->sock) { \
     70        if (!smbXcli_conn_is_connected(p->transport->conn)) { \
    6871                req->async_states->state|=NTVFS_ASYNC_STATE_CLOSE; \
    6972                return NT_STATUS_CONNECTION_DISCONNECTED; \
     
    98101#define CIFS_SHARE              "cifs:share"
    99102#define CIFS_USE_MACHINE_ACCT   "cifs:use-machine-account"
     103#define CIFS_USE_S4U2PROXY      "cifs:use-s4u2proxy"
    100104#define CIFS_MAP_GENERIC        "cifs:map-generic"
    101105#define CIFS_MAP_TRANS2         "cifs:map-trans2"
    102106
    103107#define CIFS_USE_MACHINE_ACCT_DEFAULT   false
     108#define CIFS_USE_S4U2PROXY_DEFAULT      false
    104109#define CIFS_MAP_GENERIC_DEFAULT        false
    105110#define CIFS_MAP_TRANS2_DEFAULT         true
     
    149154        struct cli_credentials *credentials;
    150155        bool machine_account;
     156        bool s4u2proxy;
    151157        const char* sharename;
     158        TALLOC_CTX *tmp_ctx;
     159
     160        tmp_ctx = talloc_new(req);
     161        if (tmp_ctx == NULL) {
     162                return NT_STATUS_NO_MEMORY;
     163        }
    152164
    153165        switch (tcon->generic.level) {
     
    162174                break;
    163175        default:
    164                 return NT_STATUS_INVALID_LEVEL;
     176                status = NT_STATUS_INVALID_LEVEL;
     177                goto out;
    165178        }
    166179
     
    174187        /* Here we need to determine which server to connect to.
    175188         * For now we use parametric options, type cifs.
    176          * Later we will use security=server and auth_server.c.
    177189         */
    178         host = share_string_option(scfg, CIFS_SERVER, NULL);
    179         user = share_string_option(scfg, CIFS_USER, NULL);
    180         pass = share_string_option(scfg, CIFS_PASSWORD, NULL);
    181         domain = share_string_option(scfg, CIFS_DOMAIN, NULL);
    182         remote_share = share_string_option(scfg, CIFS_SHARE, NULL);
     190        host = share_string_option(tmp_ctx, scfg, CIFS_SERVER, NULL);
     191        user = share_string_option(tmp_ctx, scfg, CIFS_USER, NULL);
     192        pass = share_string_option(tmp_ctx, scfg, CIFS_PASSWORD, NULL);
     193        domain = share_string_option(tmp_ctx, scfg, CIFS_DOMAIN, NULL);
     194        remote_share = share_string_option(tmp_ctx, scfg, CIFS_SHARE, NULL);
    183195        if (!remote_share) {
    184196                remote_share = sharename;
     
    186198
    187199        machine_account = share_bool_option(scfg, CIFS_USE_MACHINE_ACCT, CIFS_USE_MACHINE_ACCT_DEFAULT);
     200        s4u2proxy = share_bool_option(scfg, CIFS_USE_S4U2PROXY, CIFS_USE_S4U2PROXY_DEFAULT);
    188201
    189202        p = talloc_zero(ntvfs, struct cvfs_private);
    190203        if (!p) {
    191                 return NT_STATUS_NO_MEMORY;
     204                status = NT_STATUS_NO_MEMORY;
     205                goto out;
    192206        }
    193207
     
    196210        if (!host) {
    197211                DEBUG(1,("CIFS backend: You must supply server\n"));
    198                 return NT_STATUS_INVALID_PARAMETER;
     212                status = NT_STATUS_INVALID_PARAMETER;
     213                goto out;
    199214        }
    200215       
     
    203218                credentials = cli_credentials_init(p);
    204219                if (!credentials) {
    205                         return NT_STATUS_NO_MEMORY;
     220                        status = NT_STATUS_NO_MEMORY;
     221                        goto out;
    206222                }
    207223                cli_credentials_set_conf(credentials, ntvfs->ctx->lp_ctx);
     
    220236                status = cli_credentials_set_machine_account(credentials, ntvfs->ctx->lp_ctx);
    221237                if (!NT_STATUS_IS_OK(status)) {
    222                         return status;
     238                        goto out;
    223239                }
    224240        } else if (req->session_info->credentials) {
    225241                DEBUG(5, ("CIFS backend: Using delegated credentials\n"));
    226242                credentials = req->session_info->credentials;
     243        } else if (s4u2proxy) {
     244                struct ccache_container *ccc = NULL;
     245                const char *err_str = NULL;
     246                int ret;
     247                char *impersonate_principal;
     248                char *self_service;
     249                char *target_service;
     250
     251                impersonate_principal = talloc_asprintf(req, "%s@%s",
     252                                                req->session_info->info->account_name,
     253                                                req->session_info->info->domain_name);
     254
     255                self_service = talloc_asprintf(req, "cifs/%s",
     256                                               lpcfg_netbios_name(ntvfs->ctx->lp_ctx));
     257
     258                target_service = talloc_asprintf(req, "cifs/%s", host);
     259
     260                DEBUG(5, ("CIFS backend: Using S4U2Proxy credentials\n"));
     261
     262                credentials = cli_credentials_init(p);
     263                cli_credentials_set_conf(credentials, ntvfs->ctx->lp_ctx);
     264                if (domain) {
     265                        cli_credentials_set_domain(credentials, domain, CRED_SPECIFIED);
     266                }
     267                status = cli_credentials_set_machine_account(credentials, ntvfs->ctx->lp_ctx);
     268                if (!NT_STATUS_IS_OK(status)) {
     269                        goto out;
     270                }
     271                cli_credentials_invalidate_ccache(credentials, CRED_SPECIFIED);
     272                cli_credentials_set_impersonate_principal(credentials,
     273                                                          impersonate_principal,
     274                                                          self_service);
     275                cli_credentials_set_target_service(credentials, target_service);
     276                ret = cli_credentials_get_ccache(credentials,
     277                                                 ntvfs->ctx->event_ctx,
     278                                                 ntvfs->ctx->lp_ctx,
     279                                                 &ccc,
     280                                                 &err_str);
     281                if (ret != 0) {
     282                        status = NT_STATUS_CROSSREALM_DELEGATION_FAILURE;
     283                        DEBUG(1,("S4U2Proxy: cli_credentials_get_ccache() gave: ret[%d] str[%s] - %s\n",
     284                                ret, err_str, nt_errstr(status)));
     285                        goto out;
     286                }
     287
    227288        } else {
    228289                DEBUG(1,("CIFS backend: NO delegated credentials found: You must supply server, user and password or the client must supply delegated credentials\n"));
    229                 return NT_STATUS_INVALID_PARAMETER;
     290                status = NT_STATUS_INTERNAL_ERROR;
     291                goto out;
    230292        }
    231293
     
    252314                                          ntvfs->ctx->event_ctx);
    253315        status = smb_composite_connect_recv(creq, p);
    254         NT_STATUS_NOT_OK_RETURN(status);
     316        if (!NT_STATUS_IS_OK(status)) {
     317                goto out;
     318        }
    255319
    256320        p->tree = io.out.tree;
     
    261325
    262326        ntvfs->ctx->fs_type = talloc_strdup(ntvfs->ctx, "NTFS");
    263         NT_STATUS_HAVE_NO_MEMORY(ntvfs->ctx->fs_type);
     327        if (ntvfs->ctx->fs_type == NULL) {
     328                status = NT_STATUS_NO_MEMORY;
     329                goto out;
     330        }
    264331        ntvfs->ctx->dev_type = talloc_strdup(ntvfs->ctx, "A:");
    265         NT_STATUS_HAVE_NO_MEMORY(ntvfs->ctx->dev_type);
     332        if (ntvfs->ctx->dev_type == NULL) {
     333                status = NT_STATUS_NO_MEMORY;
     334                goto out;
     335        }
    266336
    267337        if (tcon->generic.level == RAW_TCON_TCONX) {
     
    277347        p->map_trans2 = share_bool_option(scfg, CIFS_MAP_TRANS2, CIFS_MAP_TRANS2_DEFAULT);
    278348
    279         return NT_STATUS_OK;
     349        status = NT_STATUS_OK;
     350
     351out:
     352        TALLOC_FREE(tmp_ctx);
     353        return status;
    280354}
    281355
     
    11411215       
    11421216        /* fill in all the operations */
    1143         ops.connect = cvfs_connect;
    1144         ops.disconnect = cvfs_disconnect;
    1145         ops.unlink = cvfs_unlink;
    1146         ops.chkpath = cvfs_chkpath;
    1147         ops.qpathinfo = cvfs_qpathinfo;
    1148         ops.setpathinfo = cvfs_setpathinfo;
    1149         ops.open = cvfs_open;
    1150         ops.mkdir = cvfs_mkdir;
    1151         ops.rmdir = cvfs_rmdir;
    1152         ops.rename = cvfs_rename;
    1153         ops.copy = cvfs_copy;
    1154         ops.ioctl = cvfs_ioctl;
    1155         ops.read = cvfs_read;
    1156         ops.write = cvfs_write;
    1157         ops.seek = cvfs_seek;
    1158         ops.flush = cvfs_flush;
    1159         ops.close = cvfs_close;
    1160         ops.exit = cvfs_exit;
    1161         ops.lock = cvfs_lock;
    1162         ops.setfileinfo = cvfs_setfileinfo;
    1163         ops.qfileinfo = cvfs_qfileinfo;
    1164         ops.fsinfo = cvfs_fsinfo;
    1165         ops.lpq = cvfs_lpq;
    1166         ops.search_first = cvfs_search_first;
    1167         ops.search_next = cvfs_search_next;
    1168         ops.search_close = cvfs_search_close;
    1169         ops.trans = cvfs_trans;
    1170         ops.logoff = cvfs_logoff;
    1171         ops.async_setup = cvfs_async_setup;
    1172         ops.cancel = cvfs_cancel;
    1173         ops.notify = cvfs_notify;
    1174         ops.trans2 = cvfs_trans2;
     1217        ops.connect_fn = cvfs_connect;
     1218        ops.disconnect_fn = cvfs_disconnect;
     1219        ops.unlink_fn = cvfs_unlink;
     1220        ops.chkpath_fn = cvfs_chkpath;
     1221        ops.qpathinfo_fn = cvfs_qpathinfo;
     1222        ops.setpathinfo_fn = cvfs_setpathinfo;
     1223        ops.open_fn = cvfs_open;
     1224        ops.mkdir_fn = cvfs_mkdir;
     1225        ops.rmdir_fn = cvfs_rmdir;
     1226        ops.rename_fn = cvfs_rename;
     1227        ops.copy_fn = cvfs_copy;
     1228        ops.ioctl_fn = cvfs_ioctl;
     1229        ops.read_fn = cvfs_read;
     1230        ops.write_fn = cvfs_write;
     1231        ops.seek_fn = cvfs_seek;
     1232        ops.flush_fn = cvfs_flush;
     1233        ops.close_fn = cvfs_close;
     1234        ops.exit_fn = cvfs_exit;
     1235        ops.lock_fn = cvfs_lock;
     1236        ops.setfileinfo_fn = cvfs_setfileinfo;
     1237        ops.qfileinfo_fn = cvfs_qfileinfo;
     1238        ops.fsinfo_fn = cvfs_fsinfo;
     1239        ops.lpq_fn = cvfs_lpq;
     1240        ops.search_first_fn = cvfs_search_first;
     1241        ops.search_next_fn = cvfs_search_next;
     1242        ops.search_close_fn = cvfs_search_close;
     1243        ops.trans_fn = cvfs_trans;
     1244        ops.logoff_fn = cvfs_logoff;
     1245        ops.async_setup_fn = cvfs_async_setup;
     1246        ops.cancel_fn = cvfs_cancel;
     1247        ops.notify_fn = cvfs_notify;
     1248        ops.trans2_fn = cvfs_trans2;
    11751249
    11761250        /* register ourselves with the NTVFS subsystem. We register
Note: See TracChangeset for help on using the changeset viewer.