?? tcl_connect.c
字號:
/* -*- Mode: C -*- * tcl_connect.c * * Description : ndmpc Tcl connect commands. * * Copyright (c) 1996,1997 PDC, Network Appliance. All Rights Reserved. * * $Id: tcl_connect.c,v 1.8 1998/02/09 06:50:19 tim Exp $ */#if !defined(lint) && !defined(SABER)static char rcsId[] __attribute__ ((unused)) = "@(#) $Id: tcl_connect.c,v 1.8 1998/02/09 06:50:19 tim Exp $";#endif#include <stdlib.h>#include <unistd.h>#include <string.h>#include <sys/types.h>#include <sys/stat.h>#include <fcntl.h>#include <tcl.h>#include "ndmp_common.h"#include "ndmpc.h"#include "md5.h"#define MD5_PASSWORD "ndmpsdk"/* * connectOpenCmd * Sends an ndmp_connect_open_request to the NDMP server. * usage: connect_open ?protocol_version? * * Parameters: * clientData (input) - connection handle. * interp (input) - Tcl interpreter. * argc (input) - argument count. * argv (input) - argument array. * * Returns: * Tcl error code. */intconnectOpenCmd(void* clientData, Tcl_Interp* interp, int argc, char* argv[]){ NdmpConnection connection = (NdmpConnection)clientData; ndmp_connect_open_request request; ndmp_connect_open_reply* reply = 0; int r; if (argc == 1) { request.protocol_version = 3; } else if (argc == 2) { request.protocol_version = strtoul(argv[1], 0, 0); } else { Tcl_SetResult(interp, "usage: connect_open ?protocol-version?", TCL_STATIC); return(TCL_ERROR); } r = ndmpSendRequest(connection, NDMP_CONNECT_OPEN, NDMP_NO_ERR, (void*)&request, (void*)&reply); if (ndmpcCheckNdmpSend(interp, r, reply ? reply->error : 0)) { ndmpFreeMessage(connection); return(r < 0 ? TCL_ERROR : TCL_OK); } ndmpFreeMessage(connection); ndmpSetVersion(connection, request.protocol_version); return(TCL_OK);}/* * connectClientAuthCmd * Sends an ndmp_connect_client_auth_request to the NDMP server to * authorize the connection. * usage: connect_client_auth "none" * connect_client_auth "text" user password * connect_auth "md5" user password * * Parameters: * clientData (input) - connection handle. * interp (input) - Tcl interpreter. * argc (input) - argument count. * argv (input) - argument array. * * Returns: * Tcl error code. */intconnectClientAuthCmd(void* clientData, Tcl_Interp* interp, int argc, char* argv[]){ NdmpConnection connection = (NdmpConnection)clientData; ndmp_connect_client_auth_request request; ndmp_connect_client_auth_reply* reply = 0; int r; /* * Currently, only none and clear text password authorization supported. */ if (argc < 2) { Tcl_SetResult(interp, "usage: connect_client_auth auth-type ?username password?", TCL_VOLATILE); return(TCL_ERROR); } if (strcmp(argv[1], "none") == 0) { request.auth_data.auth_type = NDMP_AUTH_NONE; request.auth_data.ndmp_auth_data_u.auth_text.auth_id = ""; request.auth_data.ndmp_auth_data_u.auth_text.auth_password = ""; } else if (strcmp(argv[1], "text") == 0) { if (argc != 4) { Tcl_SetResult(interp, "usage: connect_client_auth auth-type ?username password?", TCL_VOLATILE); return(TCL_ERROR); } request.auth_data.auth_type = NDMP_AUTH_TEXT; request.auth_data.ndmp_auth_data_u.auth_text.auth_id = argv[2]; request.auth_data.ndmp_auth_data_u.auth_text.auth_password = argv[3]; } else if (strcmp(argv[1], "md5") == 0) { ndmp_config_get_auth_attr_request challengeRequest; ndmp_config_get_auth_attr_reply* challengeReply = 0; if (argc != 4) { Tcl_SetResult(interp, "usage: connect_client_auth auth-type ?username password?", TCL_VOLATILE); return(TCL_ERROR); } challengeRequest.auth_type = NDMP_AUTH_MD5; r = ndmpSendRequest(connection, NDMP_CONFIG_GET_AUTH_ATTR, NDMP_NO_ERR, (void*)&challengeRequest, (void*)&challengeReply); if (ndmpcCheckNdmpSend(interp, r, challengeReply ? challengeReply->error : 0)) { ndmpFreeMessage(connection); return(r < 0 ? TCL_ERROR : TCL_OK); } if (challengeReply->server_attr.auth_type != NDMP_AUTH_MD5) { Tcl_SetResult(interp, "invalid auth_type returned for config_get_auth_attr request", TCL_STATIC); return(TCL_ERROR); } ndmpCreateMD5Digest(request.auth_data.ndmp_auth_data_u.auth_md5.auth_digest, argv[3], challengeReply->server_attr.ndmp_auth_attr_u.challenge); request.auth_data.auth_type = NDMP_AUTH_MD5; request.auth_data.ndmp_auth_data_u.auth_md5.auth_id = argv[2]; ndmpFreeMessage(connection); } else { Tcl_SetResult(interp, "usage: connect_client_auth auth-type ?username password?", TCL_VOLATILE); return(TCL_ERROR); } r = ndmpSendRequest(connection, NDMP_CONNECT_CLIENT_AUTH, NDMP_NO_ERR, &request, (void*)&reply); if (ndmpcCheckNdmpSend(interp, r, reply ? reply->error : 0)) { ndmpFreeMessage(connection); return(r < 0 ? TCL_ERROR : TCL_OK); } ndmpFreeMessage(connection); ndmpSetAuthorized(connection, TRUE); return(TCL_OK);}/* * connectServerAuthCmd * Sends an ndmp_connect_server_auth_request to the NDMP server to * authenticate the server. * usage: connect_server_auth none|text|md5 * * Parameters: * clientData (input) - connection handle. * interp (input) - Tcl interpreter. * argc (input) - argument count. * argv (input) - argument array. * * Returns: * Tcl error code. */intconnectServerAuthCmd(void* clientData, Tcl_Interp* interp, int argc, char* argv[]){ NdmpConnection connection = (NdmpConnection)clientData; ndmp_connect_server_auth_request request; ndmp_connect_server_auth_reply* reply = 0; int r; char md5Digest[16]; if (argc < 2) { Tcl_SetResult(interp, "usage: connect_server_auth auth-type", TCL_VOLATILE); return(TCL_ERROR); } if (strcmp(argv[1], "none") == 0) { request.client_attr.auth_type = NDMP_AUTH_NONE; } else if (strcmp(argv[1], "text") == 0) { request.client_attr.auth_type = NDMP_AUTH_TEXT; } else if (strcmp(argv[1], "md5") == 0) { int i; request.client_attr.auth_type = NDMP_AUTH_MD5; memset((void*)request.client_attr.ndmp_auth_attr_u.challenge, 0, 64); /* Dummy up a challenge. */ for (i = 0; i < 64; i++) request.client_attr.ndmp_auth_attr_u.challenge[i] = i; } else { Tcl_SetResult(interp, "usage: connect_auth auth-type", TCL_VOLATILE); return(TCL_ERROR); } r = ndmpSendRequest(connection, NDMP_CONNECT_SERVER_AUTH, NDMP_NO_ERR, &request, (void*)&reply); if (ndmpcCheckNdmpSend(interp, r, reply ? reply->error : 0)) { ndmpFreeMessage(connection); return(r < 0 ? TCL_ERROR : TCL_OK); } switch (reply->server_result.auth_type) { case NDMP_AUTH_NONE: ndmpcTclAddToResult(interp, "auth_type", "NONE"); break; case NDMP_AUTH_TEXT: ndmpcTclAddToResult(interp, "auth_type", "TEXT"); ndmpcTclAddToResult(interp, "auth_id", reply->server_result.ndmp_auth_data_u.auth_text.auth_id); ndmpcTclAddToResult(interp, "auth_password", reply->server_result.ndmp_auth_data_u.auth_text.auth_password); break; case NDMP_AUTH_MD5: { u_int i; char digestStr[64]; char* data = reply->server_result.ndmp_auth_data_u.auth_md5.auth_digest; sprintf(digestStr, "0x"); for (i = 0; i < 16; i++) sprintf(&digestStr[(i*2)+2], "%02x", data[i]); digestStr[34] = '\0'; ndmpcTclAddToResult(interp, "auth_type", "MD5"); ndmpcTclAddToResult(interp, "auth_id", reply->server_result.ndmp_auth_data_u.auth_md5.auth_id); ndmpcTclAddToResult(interp, "auth_digest", digestStr); /* * Build a digest with the expected password and verify * that the digest matches the digest received from * the server. */ ndmpCreateMD5Digest(md5Digest, MD5_PASSWORD, request.client_attr.ndmp_auth_attr_u.challenge); if (memcmp((void*)md5Digest, (void*)data, 16) == 0) ndmpcTclAddToResult(interp, "authentication", "passed"); else ndmpcTclAddToResult(interp, "authentication", "failed"); break; } } ndmpFreeMessage(connection); ndmpSetAuthorized(connection, TRUE); return(TCL_OK);}/* * connectCloseCmd * Sends an ndmp_connect_close_request to the NDMP server. * usage: connect_close * * Parameters: * clientData (input) - connection handle. * interp (input) - Tcl interpreter. * argc (input) - argument count. * argv (input) - argument array. * * Returns: * Tcl error code. */intconnectCloseCmd(void* clientData, Tcl_Interp* interp, int argc, char* argv[] __attribute__ ((unused))){ NdmpConnection connection = (NdmpConnection)clientData; int r; if (argc != 1) { Tcl_SetResult(interp, "usage: connect_close", TCL_VOLATILE); return(TCL_ERROR); } r = ndmpSendRequest(connection, NDMP_CONNECT_CLOSE, NDMP_NO_ERR, 0, 0); if (ndmpcCheckNdmpSend(interp, r, 0)) return(TCL_ERROR); return(TCL_OK);}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -