config.c
来自「网络数据管理协议的开发」· C语言 代码 · 共 618 行 · 第 1/2 页
C
618 行
/* -*- Mode: C -*- * config.c * * Description : NDMP configuration request handler functions. * * Copyright (c) 1996,1997 PDC, Network Appliance. All Rights Reserved. * * $Id: config.c,v 1.10 1998/05/26 03:52:14 tim Exp $ */#if !defined(lint) && !defined(SABER)static char rcsId[] __attribute__ ((unused)) = "@(#) $Id: config.c,v 1.10 1998/05/26 03:52:14 tim Exp $";#endif#include <stdio.h>#include <stdlib.h>#include <errno.h>#include <sys/utsname.h>#include <unistd.h>#include <string.h>#include <sys/systeminfo.h>#include <sys/mnttab.h>#include <sys/statvfs.h>#include "ndmp_common.h"#include "ndmpd.h"#include "module.h"#include "simple.h"/* * ndmpdConfigGetHostInfo * * This handler handles the ndmp_config_get_host_info request. * Host specific information is returned. * * Parameters: * connection (input) - connection handle. * body (input) - request message body. * * Returns: * void */voidndmpdConfigGetHostInfo(NdmpConnection connection, void* body __attribute__ ((unused))){ ndmp_config_get_host_info_reply reply; struct utsname uts; char hostidstr[16]; u_long hostid; Debug(DBG_CAT_CONFIG|DBG_FOC_FLOW, "ndmpdConfigGetHostInfo: \n"); memset((void*)&reply, 0, sizeof(reply)); if (uname(&uts) < 0) { Error(LOG_ERR, "ndmpdConfigGetHostInfo: uname error: %s.\n", strerror(errno)); reply.error = NDMP_UNDEFINED_ERR; if (ndmpSendReply(connection, NDMP_NO_ERR, (void *)&reply) < 0) Error(LOG_ERR, "ndmpdConfigGetHostInfo: error sending ndmp_config_get_host_info reply.\n"); return; } if (sysinfo(SI_HW_SERIAL, hostidstr, sizeof(hostidstr)) < 0) { Error(LOG_ERR, "ndmpdConfigGetHostInfo: sysinfo error: %s.\n", strerror(errno)); reply.error = NDMP_UNDEFINED_ERR; if (ndmpSendReply(connection, NDMP_NO_ERR, (void *)&reply) < 0) Error(LOG_ERR, "ndmpdConfigGetHostInfo: error sending ndmp_config_get_host_info reply.\n"); return; } /* * Convert the hostid to hex. The returned string must match * the string returned by hostid(1). */ hostid = strtoul(hostidstr, 0, 0); sprintf(hostidstr, "%lx", hostid); reply.error = NDMP_NO_ERR; reply.hostname = uts.nodename; reply.os_type = uts.sysname; reply.os_vers = uts.release; reply.hostid = hostidstr; if (ndmpSendReply(connection, NDMP_NO_ERR, (void *)&reply) < 0) Error(LOG_ERR, "ndmpdConfigGetHostInfo: error sending ndmp_config_get_host_info reply.\n");}/* * ndmpdConfigGetConnectionType * * This handler handles the ndmp_config_get_connection_type_request. * A list of supported data connection types is returned. * * Parameters: * connection (input) - connection handle. * body (input) - request message body. * * Returns: * void */voidndmpdConfigGetConnectionType(NdmpConnection connection, void* body __attribute__ ((unused))){ ndmp_config_get_connection_type_reply reply; ndmp_addr_type addrTypes[2]; Debug(DBG_CAT_CONFIG|DBG_FOC_FLOW, "ndmpdConfigGetConnectionType: \n"); memset((void*)&reply, 0, sizeof(reply)); reply.error = NDMP_NO_ERR; addrTypes[0] = NDMP_ADDR_LOCAL; addrTypes[1] = NDMP_ADDR_TCP; reply.addr_types.addr_types_len = 2; reply.addr_types.addr_types_val = addrTypes; if (ndmpSendReply(connection, NDMP_NO_ERR, (void *)&reply) < 0) Error(LOG_ERR, "ndmpdConfigGetConnectionType: error sending ndmp_config_get_connection_type_reply.\n");}/* * ndmpdConfigGetAuthAttr * * This handler handles the ndmp_config_get_auth_attr_request. * Authorization type specific information is returned. * * Parameters: * connection (input) - connection handle. * body (input) - request message body. * * Returns: * void */voidndmpdConfigGetAuthAttr(NdmpConnection connection, void* body){ ndmp_config_get_auth_attr_request* request = (ndmp_config_get_auth_attr_request *)body; ndmp_config_get_auth_attr_reply reply; NdmpdSession* session = ndmpGetClientData(connection); Debug(DBG_CAT_CONFIG|DBG_FOC_FLOW, "ndmpdConfigGetAuthAttr: \n"); memset((void*)&reply, 0, sizeof(reply)); reply.error = NDMP_NO_ERR; reply.server_attr.auth_type = request->auth_type; switch (request->auth_type) { case NDMP_AUTH_NONE: break; case NDMP_AUTH_TEXT: break; case NDMP_AUTH_MD5: ndmpdCreateMD5Challenge(session, reply.server_attr.ndmp_auth_attr_u.challenge); break; default: Error(LOG_ERR, "ndmpdConfigGetAuthAttr: invalid auth type: %d.\n", request->auth_type); reply.error = NDMP_ILLEGAL_ARGS_ERR; break; } if (ndmpSendReply(connection, NDMP_NO_ERR, (void *)&reply) < 0) Error(LOG_ERR, "ndmpdConfigGetAuthAttr: error sending ndmp_config_get_auth_attr reply.\n");}/* * ndmpdConfigGetButypeInfo * * This handler handles the ndmp_config_get_butype_info_request. * Information about all supported backup types are returned. * * Parameters: * connection (input) - connection handle. * body (input) - request message body. * * Returns: * void */voidndmpdConfigGetButypeInfo(NdmpConnection connection, void* body __attribute__ ((unused))){ ndmp_config_get_butype_info_reply reply; ndmp_butype_info info; ndmp_pval pval; Debug(DBG_CAT_CONFIG|DBG_FOC_FLOW, "ndmpdConfigGetButypeInfo: \n"); memset((void*)&reply, 0, sizeof(reply)); pval.name = "HIST"; pval.value = "F"; (void)simpleGetAttrs(&info.attrs); info.butype_name = "dump"; info.default_env.default_env_len = 1; info.default_env.default_env_val = &pval; reply.error = NDMP_NO_ERR; reply.butype_info.butype_info_len = 1; reply.butype_info.butype_info_val = &info; if (ndmpSendReply(connection, NDMP_NO_ERR, (void *)&reply) < 0) Error(LOG_ERR, "ndmpdConfigGetButypeInfo: error sending ndmp_config_get_butype_info_reply.\n");}/* * ndmpdConfigGetFsInfo * * This handler handles the ndmp_config_get_fs_info_request. * Information about all mounted file systems is returned. * * Parameters: * connection (input) - connection handle. * body (input) - request message body. * * Returns: * void */voidndmpdConfigGetFsInfo(NdmpConnection connection, void* body __attribute__ ((unused))){ ndmp_config_get_fs_info_reply reply; ndmp_fs_info* fsInfo; FILE* fp; u_long nMounts; u_long i; struct mnttab mt; struct statvfs statBuf; int err; Debug(DBG_CAT_CONFIG|DBG_FOC_FLOW, "ndmpdConfigGetFsInfo: \n"); memset((void*)&reply, 0, sizeof(reply)); if ((fp = fopen("/etc/mnttab", "r")) == 0) { Error(LOG_ERR, "ndmpdConfigGetFsInfo: error opening /etc/mnttab: %s.\n", strerror(errno)); reply.error = NDMP_UNDEFINED_ERR; if (ndmpSendReply(connection, NDMP_NO_ERR, (void *)&reply) < 0) Error(LOG_ERR, "ndmpdConfigGetFsInfo: error sending ndmp_config_get_fs_info_reply.\n"); return; } /* * Count the number of mount points. */ for (nMounts = 0; ; nMounts++) { err = getmntent(fp, &mt); /* Check for EOF */ if (err < 0) break; if (err > 0) { Error(LOG_ERR, "ndmpdConfigGetFsInfo: getmntent error.\n"); reply.error = NDMP_UNDEFINED_ERR; if (ndmpSendReply(connection, NDMP_NO_ERR, (void *)&reply) < 0) Error(LOG_ERR, "ndmpdConfigGetFsInfo: error sending ndmp_config_get_fs_info_reply.\n"); fclose(fp); return; } } if ((fsInfo = (ndmp_fs_info*)malloc(nMounts*sizeof(ndmp_fs_info))) == 0) { Error(LOG_ERR, "ndmpdConfigGetFsInfo: malloc error.\n"); reply.error = NDMP_NO_MEM_ERR;
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?