Ignore:
Timestamp:
Nov 27, 2012, 4:43:17 PM (13 years ago)
Author:
Silvan Scherrer
Message:

Samba Server: updated trunk to 3.6.0

Location:
trunk/server
Files:
1 deleted
3 edited
1 copied

Legend:

Unmodified
Added
Removed
  • trunk/server

  • trunk/server/libcli/named_pipe_auth/npa_tstream.c

    r414 r745  
    2525#include "../librpc/gen_ndr/ndr_named_pipe_auth.h"
    2626#include "../libcli/named_pipe_auth/npa_tstream.h"
     27#if _SAMBA_BUILD_ == 4
    2728#include "libcli/raw/smb.h"
     29#endif
    2830
    2931static const struct tstream_context_ops tstream_npa_ops;
     
    4042        struct {
    4143                struct tevent_context *ev;
    42                 struct smb_iconv_convenience *smb_iconv_c;
    4344        } caller;
    4445
     
    5960
    6061struct tevent_req *tstream_npa_connect_send(TALLOC_CTX *mem_ctx,
    61                                         struct tevent_context *ev,
    62                                         struct smb_iconv_convenience *smb_iconv_c,
    63                                         const char *directory,
    64                                         const char *npipe,
    65                                         const struct tsocket_address *client,
    66                                         const char *client_name_in,
    67                                         const struct tsocket_address *server,
    68                                         const char *server_name,
    69                                         const struct netr_SamInfo3 *sam_info3,
    70                                         DATA_BLOB session_key,
    71                                         DATA_BLOB delegated_creds)
     62                                            struct tevent_context *ev,
     63                                            const char *directory,
     64                                            const char *npipe,
     65                                            const struct tsocket_address *client,
     66                                            const char *client_name_in,
     67                                            const struct tsocket_address *server,
     68                                            const char *server_name,
     69                                            const struct auth_session_info_transport *session_info)
    7270{
    7371        struct tevent_req *req;
     
    7674        int ret;
    7775        enum ndr_err_code ndr_err;
     76        char *lower_case_npipe;
     77        struct named_pipe_auth_req_info4 *info4;
    7878
    7979        req = tevent_req_create(mem_ctx, &state,
     
    8484
    8585        state->caller.ev = ev;
    86         state->caller.smb_iconv_c = smb_iconv_c;
     86
     87        lower_case_npipe = strlower_talloc(state, npipe);
     88        if (tevent_req_nomem(lower_case_npipe, req)) {
     89                goto post;
     90        }
    8791
    8892        state->unix_path = talloc_asprintf(state, "%s/%s",
    8993                                           directory,
    90                                            npipe);
     94                                           lower_case_npipe);
     95        talloc_free(lower_case_npipe);
    9196        if (tevent_req_nomem(state->unix_path, req)) {
    9297                goto post;
     
    110115
    111116        ZERO_STRUCT(state->auth_req);
    112         if (client) {
    113                 struct named_pipe_auth_req_info3 *info3;
    114 
    115                 if (!server) {
    116                         tevent_req_error(req, EINVAL);
    117                         goto post;
    118                 }
    119 
    120                 state->auth_req.level = 3;
    121                 info3 = &state->auth_req.info.info3;
    122 
    123                 info3->client_name = client_name_in;
    124                 info3->client_addr = tsocket_address_inet_addr_string(client, state);
    125                 if (!info3->client_addr) {
    126                         /* errno might be EINVAL */
    127                         tevent_req_error(req, errno);
    128                         goto post;
    129                 }
    130                 info3->client_port = tsocket_address_inet_port(client);
    131                 if (!info3->client_name) {
    132                         info3->client_name = info3->client_addr;
    133                 }
    134 
    135                 info3->server_addr = tsocket_address_inet_addr_string(server, state);
    136                 if (!info3->server_addr) {
    137                         /* errno might be EINVAL */
    138                         tevent_req_error(req, errno);
    139                         goto post;
    140                 }
    141                 info3->server_port = tsocket_address_inet_port(server);
    142                 if (!info3->server_name) {
    143                         info3->server_name = info3->server_addr;
    144                 }
    145 
    146                 info3->sam_info3 = discard_const_p(struct netr_SamInfo3, sam_info3);
    147                 info3->session_key_length = session_key.length;
    148                 info3->session_key = session_key.data;
    149                 info3->gssapi_delegated_creds_length = delegated_creds.length;
    150                 info3->gssapi_delegated_creds = delegated_creds.data;
    151 
    152         } else if (sam_info3) {
    153                 state->auth_req.level = 1;
    154                 state->auth_req.info.info1 = *sam_info3;
    155         } else {
    156                 state->auth_req.level = 0;
    157         }
     117
     118        if (!server) {
     119                tevent_req_error(req, EINVAL);
     120                goto post;
     121        }
     122
     123        state->auth_req.level = 4;
     124        info4 = &state->auth_req.info.info4;
     125
     126        info4->client_name = client_name_in;
     127        info4->client_addr = tsocket_address_inet_addr_string(client, state);
     128        if (!info4->client_addr) {
     129                /* errno might be EINVAL */
     130                tevent_req_error(req, errno);
     131                goto post;
     132        }
     133        info4->client_port = tsocket_address_inet_port(client);
     134        if (!info4->client_name) {
     135                info4->client_name = info4->client_addr;
     136        }
     137
     138        info4->server_addr = tsocket_address_inet_addr_string(server, state);
     139        if (!info4->server_addr) {
     140                /* errno might be EINVAL */
     141                tevent_req_error(req, errno);
     142                goto post;
     143        }
     144        info4->server_port = tsocket_address_inet_port(server);
     145        if (!info4->server_name) {
     146                info4->server_name = info4->server_addr;
     147        }
     148
     149        info4->session_info = discard_const_p(struct auth_session_info_transport, session_info);
    158150
    159151        if (DEBUGLVL(10)) {
     
    162154
    163155        ndr_err = ndr_push_struct_blob(&state->auth_req_blob,
    164                         state, smb_iconv_c, &state->auth_req,
     156                        state, &state->auth_req,
    165157                        (ndr_push_flags_fn_t)ndr_push_named_pipe_auth_req);
    166158        if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
     
    169161        }
    170162
    171         state->auth_req_iov.iov_base = state->auth_req_blob.data;
     163        state->auth_req_iov.iov_base = (char *) state->auth_req_blob.data;
    172164        state->auth_req_iov.iov_len = state->auth_req_blob.length;
    173165
     
    310302                return -1;
    311303        }
    312         vector[0].iov_base = state->auth_rep_blob.data + ofs;
     304        vector[0].iov_base = (char *) (state->auth_rep_blob.data + ofs);
    313305        vector[0].iov_len = state->auth_rep_blob.length - ofs;
    314306        count = 1;
     
    344336        ndr_err = ndr_pull_struct_blob(
    345337                &state->auth_rep_blob, state,
    346                 state->caller.smb_iconv_c, &state->auth_rep,
     338                &state->auth_rep,
    347339                (ndr_pull_flags_fn_t)ndr_pull_named_pipe_auth_rep);
    348340
     
    417409                                        location);
    418410        if (!stream) {
     411                *perrno = ENOMEM;
     412                tevent_req_received(req);
    419413                return -1;
    420414        }
     
    423417        npas->unix_stream = talloc_move(stream, &state->unix_stream);
    424418        switch (state->auth_rep.level) {
    425         case 0:
    426         case 1:
    427                 npas->file_type = FILE_TYPE_BYTE_MODE_PIPE;
    428                 device_state = 0x00ff;
    429                 allocation_size = 2048;
    430                 break;
    431         case 2:
    432                 npas->file_type = state->auth_rep.info.info2.file_type;
    433                 device_state = state->auth_rep.info.info2.device_state;
    434                 allocation_size = state->auth_rep.info.info2.allocation_size;
    435                 break;
    436         case 3:
    437                 npas->file_type = state->auth_rep.info.info3.file_type;
    438                 device_state = state->auth_rep.info.info3.device_state;
    439                 allocation_size = state->auth_rep.info.info3.allocation_size;
     419        case 4:
     420                npas->file_type = state->auth_rep.info.info4.file_type;
     421                device_state = state->auth_rep.info.info4.device_state;
     422                allocation_size = state->auth_rep.info.info4.allocation_size;
    440423                break;
    441424        }
     
    570553
    571554                                base += left;
    572                                 state->vector[0].iov_base = base;
     555                                state->vector[0].iov_base = (char *) base;
    573556                                state->vector[0].iov_len -= left;
    574557
     
    595578                if (left > 0) {
    596579                        memmove(pbase, pbase + ofs, left);
    597                         npas->pending.iov_base = pbase;
     580                        npas->pending.iov_base = (char *) pbase;
    598581                        npas->pending.iov_len = left;
    599582                        /*
     
    603586                        pbase = talloc_realloc(npas, pbase, uint8_t, left);
    604587                        if (pbase) {
    605                                 npas->pending.iov_base = pbase;
     588                                npas->pending.iov_base = (char *) pbase;
    606589                        }
    607590                        pbase = NULL;
     
    691674                }
    692675                ZERO_STRUCT(state->hdr);
    693                 vector[0].iov_base = state->hdr;
     676                vector[0].iov_base = (char *) state->hdr;
    694677                vector[0].iov_len = sizeof(state->hdr);
    695678
     
    727710                        uint8_t *base;
    728711                        base = (uint8_t *)state->vector[0].iov_base;
    729                         vector[count].iov_base = base;
     712                        vector[count].iov_base = (char *) base;
    730713                        vector[count].iov_len = left;
    731714                        count++;
    732715                        base += left;
    733                         state->vector[0].iov_base = base;
     716                        state->vector[0].iov_base = (char *) base;
    734717                        state->vector[0].iov_len -= left;
    735718                        break;
     
    744727        if (left > 0) {
    745728                /*
    746                  * if the message if longer than the buffers the caller
     729                 * if the message is longer than the buffers the caller
    747730                 * requested, we need to consume the rest of the message
    748731                 * into the pending buffer, where the next readv can
    749732                 * be served from.
    750733                 */
    751                 npas->pending.iov_base = talloc_array(npas, uint8_t, left);
     734                npas->pending.iov_base = talloc_array(npas, char, left);
    752735                if (!npas->pending.iov_base) {
    753736                        return -1;
     
    809792
    810793        /* the header for message mode */
     794        bool hdr_used;
    811795        uint8_t hdr[2];
    812796
     
    845829        switch (npas->file_type) {
    846830        case FILE_TYPE_BYTE_MODE_PIPE:
     831                state->hdr_used = false;
    847832                state->vector   = vector;
    848833                state->count    = count;
     
    858843                        goto post;
    859844                }
    860                 new_vector[0].iov_base = state->hdr;
     845                new_vector[0].iov_base = (char *) state->hdr;
    861846                new_vector[0].iov_len = sizeof(state->hdr);
    862847                memcpy(new_vector + 1, vector, sizeof(struct iovec)*count);
    863848
     849                state->hdr_used = true;
    864850                state->vector   = new_vector;
    865851                state->count    = count + 1;
     
    910896                tevent_req_error(req, sys_errno);
    911897                return;
     898        }
     899
     900        /*
     901         * in message mode we need to hide the length
     902         * of the hdr from the caller
     903         */
     904        if (state->hdr_used) {
     905                ret -= sizeof(state->hdr);
    912906        }
    913907
     
    10701064}
    10711065
     1066
     1067struct tstream_npa_accept_state {
     1068        struct tevent_context *ev;
     1069        struct tstream_context *plain;
     1070        uint16_t file_type;
     1071        uint16_t device_state;
     1072        uint64_t alloc_size;
     1073
     1074        DATA_BLOB npa_blob;
     1075        struct iovec out_iov;
     1076
     1077        /* results */
     1078        NTSTATUS accept_status;
     1079        struct tsocket_address *client;
     1080        char *client_name;
     1081        struct tsocket_address *server;
     1082        char *server_name;
     1083        struct auth_session_info_transport *session_info;
     1084};
     1085
     1086static int tstream_npa_accept_next_vector(struct tstream_context *unix_stream,
     1087                                          void *private_data,
     1088                                          TALLOC_CTX *mem_ctx,
     1089                                          struct iovec **_vector,
     1090                                          size_t *_count);
     1091static void tstream_npa_accept_existing_reply(struct tevent_req *subreq);
     1092static void tstream_npa_accept_existing_done(struct tevent_req *subreq);
     1093
     1094struct tevent_req *tstream_npa_accept_existing_send(TALLOC_CTX *mem_ctx,
     1095                                        struct tevent_context *ev,
     1096                                        struct tstream_context *plain,
     1097                                        uint16_t file_type,
     1098                                        uint16_t device_state,
     1099                                        uint64_t allocation_size)
     1100{
     1101        struct tstream_npa_accept_state *state;
     1102        struct tevent_req *req, *subreq;
     1103
     1104        req = tevent_req_create(mem_ctx, &state,
     1105                                struct tstream_npa_accept_state);
     1106        if (req == NULL) {
     1107                return NULL;
     1108        }
     1109
     1110        switch (file_type) {
     1111        case FILE_TYPE_BYTE_MODE_PIPE:
     1112                break;
     1113        case FILE_TYPE_MESSAGE_MODE_PIPE:
     1114                break;
     1115        default:
     1116                tevent_req_error(req, EINVAL);
     1117                goto post;
     1118        }
     1119
     1120        ZERO_STRUCTP(state);
     1121
     1122        state->ev = ev;
     1123        state->plain = plain;
     1124        state->file_type = file_type;
     1125        state->device_state = device_state;
     1126        state->alloc_size = allocation_size;
     1127
     1128        /*
     1129         * The named pipe pdu's have the length as 8 byte (initial_read_size),
     1130         * named_pipe_full_request provides the pdu length then.
     1131         */
     1132        subreq = tstream_readv_pdu_send(state, ev, plain,
     1133                                        tstream_npa_accept_next_vector,
     1134                                        state);
     1135        if (tevent_req_nomem(subreq, req)) {
     1136                goto post;
     1137        }
     1138
     1139        tevent_req_set_callback(subreq,
     1140                                tstream_npa_accept_existing_reply, req);
     1141
     1142        return req;
     1143
     1144post:
     1145        tevent_req_post(req, ev);
     1146        return req;
     1147}
     1148
     1149static int tstream_npa_accept_next_vector(struct tstream_context *unix_stream,
     1150                                          void *private_data,
     1151                                          TALLOC_CTX *mem_ctx,
     1152                                          struct iovec **_vector,
     1153                                          size_t *_count)
     1154{
     1155        struct tstream_npa_accept_state *state =
     1156                talloc_get_type_abort(private_data,
     1157                                        struct tstream_npa_accept_state);
     1158        struct iovec *vector;
     1159        size_t count;
     1160        off_t ofs = 0;
     1161
     1162        if (state->npa_blob.length == 0) {
     1163                state->npa_blob = data_blob_talloc(state, NULL, 4);
     1164                if (!state->npa_blob.data) {
     1165                        return -1;
     1166                }
     1167        } else if (state->npa_blob.length == 4) {
     1168                uint32_t msg_len;
     1169
     1170                ofs = 4;
     1171
     1172                msg_len = RIVAL(state->npa_blob.data, 0);
     1173
     1174                if (msg_len > 0x00FFFFFF) {
     1175                        errno = EMSGSIZE;
     1176                        return -1;
     1177                }
     1178
     1179                if (msg_len == 0) {
     1180                        errno = EMSGSIZE;
     1181                        return -1;
     1182                }
     1183
     1184                msg_len += ofs;
     1185
     1186                state->npa_blob.data = talloc_realloc(state,
     1187                                                      state->npa_blob.data,
     1188                                                      uint8_t, msg_len);
     1189                if (!state->npa_blob.data) {
     1190                        return -1;
     1191                }
     1192                state->npa_blob.length = msg_len;
     1193        } else {
     1194                if (memcmp(&state->npa_blob.data[4],
     1195                           NAMED_PIPE_AUTH_MAGIC, 4) != 0) {
     1196                        DEBUG(0, ("Wrong protocol\n"));
     1197#if defined(EPROTONOSUPPORT)
     1198                        errno = EPROTONOSUPPORT;
     1199#elif defined(EPROTO)
     1200                        errno = EPROTO;
     1201#else
     1202                        errno = EINVAL;
     1203#endif
     1204                        return -1;
     1205                }
     1206                *_vector = NULL;
     1207                *_count = 0;
     1208                return 0;
     1209        }
     1210
     1211        /* we need to get a message header */
     1212        vector = talloc_array(mem_ctx, struct iovec, 1);
     1213        if (!vector) {
     1214                return -1;
     1215        }
     1216        vector[0].iov_base = (char *) (state->npa_blob.data + ofs);
     1217        vector[0].iov_len = state->npa_blob.length - ofs;
     1218        count = 1;
     1219
     1220        *_vector = vector;
     1221        *_count = count;
     1222        return 0;
     1223}
     1224
     1225static void tstream_npa_accept_existing_reply(struct tevent_req *subreq)
     1226{
     1227        struct tevent_req *req =
     1228                        tevent_req_callback_data(subreq, struct tevent_req);
     1229        struct tstream_npa_accept_state *state =
     1230                        tevent_req_data(req, struct tstream_npa_accept_state);
     1231        struct named_pipe_auth_req *pipe_request;
     1232        struct named_pipe_auth_rep pipe_reply;
     1233        struct named_pipe_auth_req_info4 i4;
     1234        enum ndr_err_code ndr_err;
     1235        DATA_BLOB out;
     1236        int sys_errno;
     1237        int ret;
     1238
     1239        ret = tstream_readv_pdu_recv(subreq, &sys_errno);
     1240        TALLOC_FREE(subreq);
     1241        if (ret == -1) {
     1242                tevent_req_error(req, sys_errno);
     1243                return;
     1244        }
     1245
     1246        DEBUG(10, ("Received packet of length %lu\n",
     1247                   (long)state->npa_blob.length));
     1248        dump_data(11, state->npa_blob.data, state->npa_blob.length);
     1249
     1250        ZERO_STRUCT(pipe_reply);
     1251        pipe_reply.level = 0;
     1252        pipe_reply.status = NT_STATUS_INTERNAL_ERROR;
     1253        /*
     1254         * TODO: check it's a root (uid == 0) pipe
     1255         */
     1256
     1257        pipe_request = talloc(state, struct named_pipe_auth_req);
     1258        if (!pipe_request) {
     1259                DEBUG(0, ("Out of memory!\n"));
     1260                goto reply;
     1261        }
     1262
     1263        /* parse the passed credentials */
     1264        ndr_err = ndr_pull_struct_blob_all(
     1265                        &state->npa_blob, pipe_request, pipe_request,
     1266                        (ndr_pull_flags_fn_t)ndr_pull_named_pipe_auth_req);
     1267        if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
     1268                pipe_reply.status = ndr_map_error2ntstatus(ndr_err);
     1269                DEBUG(2, ("Could not unmarshall named_pipe_auth_req: %s\n",
     1270                          nt_errstr(pipe_reply.status)));
     1271                goto reply;
     1272        }
     1273
     1274        if (DEBUGLVL(10)) {
     1275                NDR_PRINT_DEBUG(named_pipe_auth_req, pipe_request);
     1276        }
     1277
     1278        ZERO_STRUCT(i4);
     1279
     1280        if (pipe_request->level != 4) {
     1281                DEBUG(0, ("Unknown level %u\n", pipe_request->level));
     1282                pipe_reply.level = 0;
     1283                pipe_reply.status = NT_STATUS_INVALID_LEVEL;
     1284                goto reply;
     1285        }
     1286
     1287        pipe_reply.level = 4;
     1288        pipe_reply.status = NT_STATUS_OK;
     1289        pipe_reply.info.info4.file_type = state->file_type;
     1290        pipe_reply.info.info4.device_state = state->device_state;
     1291        pipe_reply.info.info4.allocation_size = state->alloc_size;
     1292
     1293        i4 = pipe_request->info.info4;
     1294        if (i4.server_addr == NULL) {
     1295                pipe_reply.status = NT_STATUS_INVALID_ADDRESS;
     1296                DEBUG(2, ("Missing server address\n"));
     1297                goto reply;
     1298        }
     1299        if (i4.client_addr == NULL) {
     1300                pipe_reply.status = NT_STATUS_INVALID_ADDRESS;
     1301                DEBUG(2, ("Missing client address\n"));
     1302                goto reply;
     1303        }
     1304
     1305        state->server_name = discard_const_p(char,
     1306                                             talloc_move(state, &i4.server_name));
     1307        ret = tsocket_address_inet_from_strings(state, "ip",
     1308                                                i4.server_addr,
     1309                                                i4.server_port,
     1310                                                &state->server);
     1311        if (ret != 0) {
     1312                DEBUG(2, ("Invalid server address[%s:%u] - %s\n",
     1313                          i4.server_addr, i4.server_port,
     1314                          strerror(errno)));
     1315                pipe_reply.status = NT_STATUS_INVALID_ADDRESS;
     1316                goto reply;
     1317        }
     1318
     1319        state->client_name = discard_const_p(char,
     1320                                             talloc_move(state, &i4.client_name));
     1321        ret = tsocket_address_inet_from_strings(state, "ip",
     1322                                                i4.client_addr,
     1323                                                i4.client_port,
     1324                                                &state->client);
     1325        if (ret != 0) {
     1326                DEBUG(2, ("Invalid server address[%s:%u] - %s\n",
     1327                          i4.client_addr, i4.client_port,
     1328                          strerror(errno)));
     1329                pipe_reply.status = NT_STATUS_INVALID_ADDRESS;
     1330                goto reply;
     1331        }
     1332
     1333        state->session_info = talloc_move(state, &i4.session_info);
     1334reply:
     1335        /* create the output */
     1336        ndr_err = ndr_push_struct_blob(&out, state, &pipe_reply,
     1337                        (ndr_push_flags_fn_t)ndr_push_named_pipe_auth_rep);
     1338        if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
     1339                DEBUG(2, ("Error encoding structure: %s",
     1340                          ndr_map_error2string(ndr_err)));
     1341                tevent_req_error(req, EIO);
     1342                return;
     1343        }
     1344
     1345        DEBUG(10, ("named_pipe_auth reply[%u]\n", (unsigned)out.length));
     1346        dump_data(11, out.data, out.length);
     1347
     1348        if (DEBUGLVL(10)) {
     1349                NDR_PRINT_DEBUG(named_pipe_auth_rep, &pipe_reply);
     1350        }
     1351
     1352        state->accept_status = pipe_reply.status;
     1353
     1354        state->out_iov.iov_base = (char *) out.data;
     1355        state->out_iov.iov_len = out.length;
     1356
     1357        subreq = tstream_writev_send(state, state->ev,
     1358                                     state->plain,
     1359                                     &state->out_iov, 1);
     1360        if (tevent_req_nomem(subreq, req)) {
     1361                DEBUG(0, ("no memory for tstream_writev_send"));
     1362                return;
     1363        }
     1364
     1365        tevent_req_set_callback(subreq, tstream_npa_accept_existing_done, req);
     1366}
     1367
     1368static void tstream_npa_accept_existing_done(struct tevent_req *subreq)
     1369{
     1370        struct tevent_req *req =
     1371                        tevent_req_callback_data(subreq, struct tevent_req);
     1372        int sys_errno;
     1373        int ret;
     1374
     1375        ret = tstream_writev_recv(subreq, &sys_errno);
     1376        TALLOC_FREE(subreq);
     1377        if (ret == -1) {
     1378                tevent_req_error(req, sys_errno);
     1379                return;
     1380        }
     1381
     1382        tevent_req_done(req);
     1383}
     1384
     1385int _tstream_npa_accept_existing_recv(struct tevent_req *req,
     1386                                      int *perrno,
     1387                                      TALLOC_CTX *mem_ctx,
     1388                                      struct tstream_context **stream,
     1389                                      struct tsocket_address **client,
     1390                                      char **_client_name,
     1391                                      struct tsocket_address **server,
     1392                                      char **server_name,
     1393                                      struct auth_session_info_transport **session_info,
     1394                                      const char *location)
     1395{
     1396        struct tstream_npa_accept_state *state =
     1397                        tevent_req_data(req, struct tstream_npa_accept_state);
     1398        struct tstream_npa *npas;
     1399        int ret;
     1400
     1401        ret = tsocket_simple_int_recv(req, perrno);
     1402        if (ret != 0) {
     1403                DEBUG(2, ("Failed to accept named pipe conection: %s\n",
     1404                          strerror(*perrno)));
     1405                tevent_req_received(req);
     1406                return -1;
     1407        }
     1408
     1409        if (!NT_STATUS_IS_OK(state->accept_status)) {
     1410#if defined(EPROTONOSUPPORT)
     1411                *perrno = EPROTONOSUPPORT;
     1412#elif defined(EPROTO)
     1413                *perrno = EPROTO;
     1414#else
     1415                *perrno = EINVAL;
     1416#endif
     1417                DEBUG(2, ("Failed to accept named pipe conection: %s => %s\n",
     1418                          nt_errstr(state->accept_status),
     1419                          strerror(*perrno)));
     1420                tevent_req_received(req);
     1421                return -1;
     1422        }
     1423
     1424        *stream = tstream_context_create(mem_ctx,
     1425                                         &tstream_npa_ops,
     1426                                         &npas,
     1427                                         struct tstream_npa,
     1428                                         location);
     1429        if (!*stream) {
     1430                *perrno = ENOMEM;
     1431                tevent_req_received(req);
     1432                return -1;
     1433        }
     1434        ZERO_STRUCTP(npas);
     1435        npas->unix_stream = state->plain;
     1436        npas->file_type = state->file_type;
     1437
     1438        *client = talloc_move(mem_ctx, &state->client);
     1439        *_client_name = talloc_move(mem_ctx, &state->client_name);
     1440        *server = talloc_move(mem_ctx, &state->server);
     1441        *server_name = talloc_move(mem_ctx, &state->server_name);
     1442        *session_info = talloc_move(mem_ctx, &state->session_info);
     1443
     1444        tevent_req_received(req);
     1445        return 0;
     1446}
  • trunk/server/libcli/named_pipe_auth/npa_tstream.h

    r414 r745  
    2323struct tevent_req;
    2424struct tevent_context;
    25 struct netr_SamInfo3;
     25struct auth_session_info_transport;
     26struct tsocket_address;
    2627
    2728struct tevent_req *tstream_npa_connect_send(TALLOC_CTX *mem_ctx,
    28                                         struct tevent_context *ev,
    29                                         struct smb_iconv_convenience *smb_iconv_c,
    30                                         const char *directory,
    31                                         const char *npipe,
    32                                         const struct tsocket_address *client,
    33                                         const char *client_name_in,
    34                                         const struct tsocket_address *server,
    35                                         const char *server_name,
    36                                         const struct netr_SamInfo3 *info3,
    37                                         DATA_BLOB session_key,
    38                                         DATA_BLOB delegated_creds);
     29                                            struct tevent_context *ev,
     30                                            const char *directory,
     31                                            const char *npipe,
     32                                            const struct tsocket_address *client,
     33                                            const char *client_name_in,
     34                                            const struct tsocket_address *server,
     35                                            const char *server_name,
     36                                            const struct auth_session_info_transport *session_info);
    3937int _tstream_npa_connect_recv(struct tevent_req *req,
    4038                              int *perrno,
     
    5856                                     __location__)
    5957
     58
     59/**
     60 * @brief Accepts a connection for authenticated named pipes
     61 *
     62 * @param[in]  mem_ctx          The memory context for the operation
     63 * @param[in]  ev               The tevent_context for the operation
     64 * @param[in]  plain            The plain tstream_context of the bsd unix
     65 *                              domain socket.
     66 *                              This must be valid for the whole life of the
     67 *                              resulting npa tstream_context!
     68 * @param[in]  file_type        The file_type, message mode or byte mode
     69 * @param[in]  device_state     The reported device state
     70 * @param[in]  allocation_size  The reported allocation size
     71 *
     72 * @return the tevent_req handle
     73 */
     74struct tevent_req *tstream_npa_accept_existing_send(TALLOC_CTX *mem_ctx,
     75                                        struct tevent_context *ev,
     76                                        struct tstream_context *plain,
     77                                        uint16_t file_type,
     78                                        uint16_t device_state,
     79                                        uint64_t allocation_size);
     80
     81/**
     82 * @brief The receive end of the previous async function
     83 *
     84 * @param[in]  req              The tevent_req handle
     85 * @param[out] perrno           Pointer to store the errno in case of error
     86 * @param[in]  mem_ctx          The memory context for the results
     87 * @param[out] stream           The resulting stream
     88 * @param[out] client           The resulting client address
     89 * @param[out] client_name      The resulting client name
     90 * @param[out] server           The resulting server address
     91 * @param[out] server_name      The resulting server name
     92 * @param[out] info3            The info3 auth for the connecting user.
     93 * @param[out] session_key      The resulting session key
     94 * @param[out] delegated_creds  Delegated credentials
     95 *
     96 * @return  0 if successful, -1 on failure with *perror filled.
     97 */
     98int _tstream_npa_accept_existing_recv(struct tevent_req *req,
     99                                      int *perrno,
     100                                      TALLOC_CTX *mem_ctx,
     101                                      struct tstream_context **stream,
     102                                      struct tsocket_address **client,
     103                                      char **_client_name,
     104                                      struct tsocket_address **server,
     105                                      char **server_name,
     106                                      struct auth_session_info_transport **session_info,
     107                                      const char *location);
     108#define tstream_npa_accept_existing_recv(req, perrno, \
     109                                         mem_ctx, stream, \
     110                                         client, client_name, \
     111                                         server, server_name, \
     112                                         session_info) \
     113        _tstream_npa_accept_existing_recv(req, perrno, \
     114                                          mem_ctx, stream, \
     115                                          client, client_name, \
     116                                          server, server_name, \
     117                                          session_info, \
     118                                          __location__)
     119
    60120#endif /* NPA_TSTREAM_H */
Note: See TracChangeset for help on using the changeset viewer.