📄 writetmp.c
字号:
/* writetmp.c -- Magic C++ write tmpx file process (Mostly) portable public-domain implementation -- Copyright(C) 2003 Magicunix Infomation Technology Limited This file is part of magicd. magicd is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. For details, see the Magic C++ World-Wide-Web page, `http://www.magicunix.com', or send a mail to the Magic C++ developers <support@magicunix.com>. */#include <stdio.h>#include <stdlib.h>#include <string.h>#ifdef HAVE_UNISTD_H#include <unistd.h>#endif#include <errno.h>#ifdef HAVE_UTMP_H#include <utmp.h>#endif#ifdef HAVE_UTMPX_H#include <utmpx.h>#endif#include "tools.h"#include "writetmp.h" /*#define WTMPX_FILE "/var/log/wtmp"*/extern char tty_name[];/*save tmpx infomation*/#ifdef HAVE_UTMPX_Hint pututmpx(){ char *clean_tty; struct utmpx utmpx; int pid = getpid(); clean_tty = (char *)clean_ttyname(tty_name); memset(&utmpx, 0, sizeof(utmpx)); strncpy(utmpx.ut_user, ".telnet", sizeof(utmpx.ut_user)); strncpy(utmpx.ut_line, clean_tty , 4);#ifdef HAVE_STRUCT_UTMP_UT_ID strncpy(utmpx.ut_id, make_id(clean_tty), sizeof(utmpx.ut_id));#endif utmpx.ut_pid = pid; utmpx.ut_type = LOGIN_PROCESS; gettimeofday (&utmpx.ut_tv, NULL); setutxent(); if (pututxline(&utmpx) == NULL) { util_err_log("pututxline() error!\n",__FILE__,__LINE__ ,errno ); } endutxent();}/*clear tmpx infomation*/int clearuputmpx(){ struct utmpx utmpx, *non_save_utxp; char *clean_tty = (char *)clean_ttyname(tty_name); /* * This updates the utmpx and utmp entries and make a wtmp/x entry */ setutxent(); memset(&utmpx, 0, sizeof(utmpx)); strncpy(utmpx.ut_line, clean_tty, sizeof(utmpx.ut_line)); utmpx.ut_type = LOGIN_PROCESS; non_save_utxp = getutxline(&utmpx); if (non_save_utxp) { struct utmpx *utxp; char user0; utxp = malloc(sizeof(struct utmpx)); *utxp = *non_save_utxp; user0 = utxp->ut_user[0]; utxp->ut_user[0] = '\0'; utxp->ut_type = DEAD_PROCESS; gettimeofday(&utxp->ut_tv, NULL); if( pututxline(utxp) == NULL ) { util_err_log("pututxline() error!\n",__FILE__,__LINE__ ,errno ); } free (utxp); } endutxent(); return 0;}#endif /*HAVE_UTMPX_H*//*get a device name without path*/static char *clean_ttyname (char *tty){ char *res = tty; char path[] = "/dev"; if (strncmp (res, path, strlen(path)) == 0) res += strlen(path) + 1; if (strncmp (res, "pty/", 4) == 0) res += 4; if (strncmp (res, "ptym/", 5) == 0) res += 5; return res;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -