CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
rapid7

Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.

GitHub Repository: rapid7/metasploit-framework
Path: blob/master/external/source/ipwn/misc.c
Views: 11766
1
/*
2
* Copyright (c) 2004-2005 vlad902 <vlad902 [at] gmail.com>
3
* Copyright (c) 2007 H D Moore <hdm [at] metasploit.com>
4
* This file is part of the Metasploit Framework.
5
* $Revision$
6
*/
7
8
#include <stdio.h>
9
#include <time.h>
10
#include <pwd.h>
11
#include <grp.h>
12
#include <string.h>
13
14
#include "cmd.h"
15
16
17
char * get_uid_str(int uid)
18
{
19
struct passwd * pwd;
20
static char id[20];
21
22
snprintf(id, sizeof(id), "%i", uid);
23
if((pwd = getpwuid(uid)) != NULL)
24
strncpy(id, pwd->pw_name, sizeof(id));
25
id[sizeof(id) - 1] = '\0';
26
27
return id;
28
}
29
30
char * get_gid_str(int gid)
31
{
32
struct group * grp;
33
static char id[10];
34
35
snprintf(id, sizeof(id), "%i", gid);
36
if((grp = getgrgid(gid)) != NULL)
37
strncpy(id, grp->gr_name, sizeof(id));
38
id[sizeof(id) - 1] = '\0';
39
40
return id;
41
}
42
43
char * get_time_str(char * format)
44
{
45
static char time_stamp[128];
46
time_t time_int;
47
48
time(&time_int);
49
strftime(time_stamp, sizeof(time_stamp), format, localtime(&time_int));
50
return time_stamp;
51
}
52
53