int fio_net_send_cmd(int fd, uint16_t opcode, const void *buf, off_t size, uint64_t *tagptr, struct flist_head *list) { struct fio_net_cmd *cmd = NULL; size_t this_len, cur_len = 0; uint64_t tag; int ret; if (list) { assert(tagptr); tag = *tagptr = alloc_reply(*tagptr, opcode); } else tag = tagptr ? *tagptr : 0; do { this_len = size; if (this_len > FIO_SERVER_MAX_FRAGMENT_PDU) this_len = FIO_SERVER_MAX_FRAGMENT_PDU; if (!cmd || cur_len < sizeof(*cmd) + this_len) { if (cmd) free(cmd); cur_len = sizeof(*cmd) + this_len; cmd = malloc(cur_len); } fio_init_net_cmd(cmd, opcode, buf, this_len, tag); if (this_len < size) cmd->flags = __cpu_to_le32(FIO_NET_CMD_F_MORE); fio_net_cmd_crc(cmd); ret = fio_send_data(fd, cmd, sizeof(*cmd) + this_len); size -= this_len; buf += this_len; } while (!ret && size); if (list) { if (ret) free_reply(tag); else add_reply(tag, list); } if (cmd) free(cmd); return ret; }
/* * If 'list' is non-NULL, then allocate and store the sent command for * later verification. */ int fio_net_send_simple_cmd(int sk, uint16_t opcode, uint64_t tag, struct flist_head *list) { int ret; if (list) tag = alloc_reply(tag, opcode); ret = fio_net_send_simple_stack_cmd(sk, opcode, tag); if (ret) { if (list) free_reply(tag); return ret; } if (list) add_reply(tag, list); return 0; }
static int pamtest_simple_conv(int num_msg, const struct pam_message **msgm, struct pam_response **response, void *appdata_ptr) { int i, ri = 0; int ret; struct pam_response *reply = NULL; const char *prompt; struct pamtest_conv_ctx *cctx = \ (struct pamtest_conv_ctx *) appdata_ptr; if (cctx == NULL) { return PAM_CONV_ERR; } if (response) { reply = (struct pam_response *) calloc(num_msg, sizeof(struct pam_response)); if (reply == NULL) { return PAM_CONV_ERR; } } for (i=0; i < num_msg; i++) { switch (msgm[i]->msg_style) { case PAM_PROMPT_ECHO_OFF: prompt = (const char *) \ cctx->data->in_echo_off[cctx->echo_off_idx]; if (reply != NULL) { if (prompt != NULL) { ret = add_to_reply(&reply[ri], prompt); if (ret != PAM_SUCCESS) { free_reply(reply, num_msg); return ret; } } else { reply[ri].resp = NULL; } ri++; } cctx->echo_off_idx++; break; case PAM_PROMPT_ECHO_ON: prompt = (const char *) \ cctx->data->in_echo_on[cctx->echo_on_idx]; if (prompt == NULL) { free_reply(reply, num_msg); return PAM_CONV_ERR; } if (reply != NULL) { if (prompt != NULL) { ret = add_to_reply(&reply[ri], prompt); if (ret != PAM_SUCCESS) { free_reply(reply, num_msg); return ret; } } ri++; } cctx->echo_on_idx++; break; case PAM_ERROR_MSG: if (cctx->data->out_err != NULL) { memcpy(cctx->data->out_err[cctx->err_idx], msgm[i]->msg, MIN(strlen(msgm[i]->msg), PAM_MAX_MSG_SIZE)); cctx->err_idx++; } break; case PAM_TEXT_INFO: if (cctx->data->out_info != NULL) { memcpy(cctx->data->out_info[cctx->info_idx], msgm[i]->msg, MIN(strlen(msgm[i]->msg), PAM_MAX_MSG_SIZE)); cctx->info_idx++; } break; default: continue; } } if (response && ri > 0) { *response = reply; } else { free(reply); } return PAM_SUCCESS; }