[winpr,utils] use sam file relative to config home

This commit is contained in:
Armin Novak 2024-10-02 12:26:06 +02:00 committed by akallabeth
parent 276e3d67e0
commit 934cf668a2
No known key found for this signature in database
GPG Key ID: A49454A3FC909FD5
2 changed files with 11 additions and 7 deletions

View File

@ -66,12 +66,13 @@ static int shadow_server_print_command_line_help(int argc, char** argv,
if ((argc < 1) || !largs || !argv)
return -1;
char* path = winpr_GetConfigFilePath(TRUE, "SAM");
printf("Usage: %s [options]\n", argv[0]);
printf("\n");
printf("Notes: By default NLA security is active.\n");
printf("\tIn this mode a SAM database is required.\n");
printf("\tProvide one with /sam-file:<file with path>\n");
printf("\telse the default path /etc/winpr/SAM is used.\n");
printf("\telse the default path %s is used.\n", path);
printf("\tIf there is no existing SAM file authentication for all users will fail.\n");
printf(
"\n\tIf authentication against PAM is desired, start with -sec-nla (requires compiled in "
@ -81,6 +82,8 @@ static int shadow_server_print_command_line_help(int argc, char** argv,
printf(" /option:<value> (specifies option with value)\n");
printf(" +toggle -toggle (enables or disables toggle, where '/' is a synonym of '+')\n");
printf("\n");
free(path);
arg = largs;
do

View File

@ -18,6 +18,7 @@
*/
#include <winpr/config.h>
#include <winpr/path.h>
#include <stdio.h>
#include <stdlib.h>
@ -35,11 +36,6 @@
#include <unistd.h>
#endif
#ifdef _WIN32
#define WINPR_SAM_FILE "C:\\SAM"
#else
#define WINPR_SAM_FILE "/etc/winpr/SAM"
#endif
#define TAG WINPR_TAG("utils")
struct winpr_sam
@ -95,9 +91,13 @@ WINPR_SAM* SamOpen(const char* filename, BOOL readOnly)
{
FILE* fp = NULL;
WINPR_SAM* sam = NULL;
char* allocatedFileName = NULL;
if (!filename)
filename = WINPR_SAM_FILE;
{
allocatedFileName = winpr_GetConfigFilePath(TRUE, "SAM");
filename = allocatedFileName;
}
if (readOnly)
fp = winpr_fopen(filename, "r");
@ -108,6 +108,7 @@ WINPR_SAM* SamOpen(const char* filename, BOOL readOnly)
if (!fp)
fp = winpr_fopen(filename, "w+");
}
free(allocatedFileName);
if (fp)
{