Skip to content

Commit 5493f41

Browse files
committed
Users: fix crashing on Windows; rename tty to more common name sessionName
1 parent 4e75fa9 commit 5493f41

File tree

4 files changed

+11
-10
lines changed

4 files changed

+11
-10
lines changed

src/detection/users/users.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ typedef struct FFUserResult
1010
FFstrbuf name;
1111
FFstrbuf hostName;
1212
FFstrbuf clientIp;
13-
FFstrbuf tty;
13+
FFstrbuf sessionName;
1414
uint64_t loginTime; // ms
1515
} FFUserResult;
1616

src/detection/users/users_linux.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ const char* ffDetectUsers(FFlist* users)
3131
FFUserResult* user = (FFUserResult*) ffListAdd(users);
3232
ffStrbufInitS(&user->name, n->ut_user);
3333
ffStrbufInitS(&user->hostName, n->ut_host);
34-
ffStrbufInitS(&user->tty, n->ut_line);
34+
ffStrbufInitS(&user->sessionName, n->ut_line);
3535
#ifdef __linux__
3636
if(n->ut_addr_v6[0] || n->ut_addr_v6[1] || n->ut_addr_v6[2] || n->ut_addr_v6[3])
3737
ffStrbufInitF(&user->clientIp, "%u.%u.%u.%u", n->ut_addr_v6[0], n->ut_addr_v6[1], n->ut_addr_v6[2], n->ut_addr_v6[3]);

src/detection/users/users_windows.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@ const char* ffDetectUsers(FFlist* users)
2828
FFUserResult* user = (FFUserResult*) ffListAdd(users);
2929
ffStrbufInitWS(&user->name, session->pUserName);
3030
ffStrbufInitWS(&user->hostName, session->pHostName);
31-
ffStrbufInitS(&user->clientIp, "0.0.0.0");
31+
ffStrbufInitWS(&user->sessionName, session->pSessionName);
32+
ffStrbufInit(&user->clientIp);
3233
user->loginTime = 0;
3334

3435
DWORD bytes = 0;

src/modules/users/users.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ void ffPrintUsers(FFUsersOptions* options)
7575
ffPrintFormat(FF_USERS_MODULE_NAME, users.length == 1 ? 0 : (uint8_t) (i + 1), &options->moduleArgs, FF_USERS_NUM_FORMAT_ARGS, (FFformatarg[]){
7676
{FF_FORMAT_ARG_TYPE_STRBUF, &user->name},
7777
{FF_FORMAT_ARG_TYPE_STRBUF, &user->hostName},
78-
{FF_FORMAT_ARG_TYPE_STRBUF, &user->tty},
78+
{FF_FORMAT_ARG_TYPE_STRBUF, &user->sessionName},
7979
{FF_FORMAT_ARG_TYPE_STRBUF, &user->clientIp},
8080
{FF_FORMAT_ARG_TYPE_UINT64, &user->loginTime},
8181
});
@@ -86,7 +86,7 @@ void ffPrintUsers(FFUsersOptions* options)
8686
{
8787
ffStrbufDestroy(&user->clientIp);
8888
ffStrbufDestroy(&user->hostName);
89-
ffStrbufDestroy(&user->tty);
89+
ffStrbufDestroy(&user->sessionName);
9090
ffStrbufDestroy(&user->name);
9191
}
9292
}
@@ -159,19 +159,19 @@ void ffGenerateUsersJson(FF_MAYBE_UNUSED FFUsersOptions* options, yyjson_mut_doc
159159
FF_LIST_FOR_EACH(FFUserResult, user, results)
160160
{
161161
yyjson_mut_val* obj = yyjson_mut_arr_add_obj(doc, arr);
162-
yyjson_mut_obj_add_strbuf(doc, obj, "clientIp", &user->clientIp);
162+
yyjson_mut_obj_add_strbuf(doc, obj, "name", &user->name);
163163
yyjson_mut_obj_add_strbuf(doc, obj, "hostName", &user->hostName);
164+
yyjson_mut_obj_add_strbuf(doc, obj, "sessionName", &user->sessionName);
165+
yyjson_mut_obj_add_strbuf(doc, obj, "clientIp", &user->clientIp);
164166
yyjson_mut_obj_add_uint(doc, obj, "loginTime", user->loginTime);
165-
yyjson_mut_obj_add_strbuf(doc, obj, "name", &user->name);
166-
yyjson_mut_obj_add_strbuf(doc, obj, "tty", &user->tty);
167167
}
168168

169169
exit:
170170
FF_LIST_FOR_EACH(FFUserResult, user, results)
171171
{
172172
ffStrbufDestroy(&user->clientIp);
173173
ffStrbufDestroy(&user->hostName);
174-
ffStrbufDestroy(&user->tty);
174+
ffStrbufDestroy(&user->sessionName);
175175
ffStrbufDestroy(&user->name);
176176
}
177177
}
@@ -181,7 +181,7 @@ void ffPrintUsersHelpFormat(void)
181181
ffPrintModuleFormatHelp(FF_USERS_MODULE_NAME, "{1}@{2} - login time {5}", FF_USERS_NUM_FORMAT_ARGS, (const char* []) {
182182
"User name",
183183
"Host name",
184-
"TTY name",
184+
"Session name",
185185
"Client IP",
186186
"Login Time"
187187
});

0 commit comments

Comments
 (0)