diff --git a/winpr/include/winpr/sam.h b/winpr/include/winpr/sam.h index a11967b12..6d932dfca 100644 --- a/winpr/include/winpr/sam.h +++ b/winpr/include/winpr/sam.h @@ -23,13 +23,6 @@ #include #include -struct winpr_sam -{ - FILE* fp; - char* line; - char* buffer; - BOOL readOnly; -}; typedef struct winpr_sam WINPR_SAM; struct winpr_sam_entry diff --git a/winpr/libwinpr/utils/sam.c b/winpr/libwinpr/utils/sam.c index b76302477..c2f979af1 100644 --- a/winpr/libwinpr/utils/sam.c +++ b/winpr/libwinpr/utils/sam.c @@ -43,6 +43,15 @@ #endif #define TAG WINPR_TAG("utils") +struct winpr_sam +{ + FILE* fp; + char* line; + char* buffer; + char* context; + BOOL readOnly; +}; + WINPR_SAM* SamOpen(const char* filename, BOOL readOnly) { FILE* fp = NULL; @@ -98,6 +107,7 @@ static BOOL SamLookupStart(WINPR_SAM* sam) if (fileSize < 1) return FALSE; + sam->context = NULL; sam->buffer = (char*)malloc(fileSize + 2); if (!sam->buffer) @@ -120,7 +130,7 @@ static BOOL SamLookupStart(WINPR_SAM* sam) sam->buffer[fileSize] = '\n'; sam->buffer[fileSize + 1] = '\0'; - sam->line = strtok(sam->buffer, "\n"); + sam->line = strtok_s(sam->buffer, "\n", &sam->context); return TRUE; } @@ -300,7 +310,7 @@ WINPR_SAM_ENTRY* SamLookupUserA(WINPR_SAM* sam, LPSTR User, UINT32 UserLength, L } SamResetEntry(entry); - sam->line = strtok(NULL, "\n"); + sam->line = strtok_s(NULL, "\n", sam->context); } out_fail: @@ -415,7 +425,7 @@ WINPR_SAM_ENTRY* SamLookupUserW(WINPR_SAM* sam, LPWSTR User, UINT32 UserLength, } SamResetEntry(entry); - sam->line = strtok(NULL, "\n"); + sam->line = strtok_s(NULL, "\n", sam->context); } out_fail: