]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
passdb: Use getline(3) to read our old machine sid
authorVolker Lendecke <vl@samba.org>
Wed, 10 Apr 2024 12:45:56 +0000 (14:45 +0200)
committerJeremy Allison <jra@samba.org>
Tue, 30 Apr 2024 22:44:32 +0000 (22:44 +0000)
Don't read the whole file.

Signed-off-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
source3/passdb/machine_sid.c

index 16ef6ce266cff1c5ca5f0afafca561f9003e77c4..c6b8ed403eaf8bcc622c88c7b105e43d4c889e53 100644 (file)
@@ -21,7 +21,6 @@
 */
 
 #include "includes.h"
-#include "lib/util/util_file.h"
 #include "passdb/machine_sid.h"
 #include "secrets.h"
 #include "dbwrap/dbwrap.h"
@@ -42,19 +41,24 @@ static struct dom_sid *global_sam_sid=NULL;
 
 static bool read_sid_from_file(const char *fname, struct dom_sid *sid)
 {
-       char **lines;
-       int numlines;
-       bool ret;
-
-       lines = file_lines_load(fname, &numlines,0, NULL);
+       char *line = NULL;
+       size_t n;
+       ssize_t len;
+       bool ret = false;
+       FILE *f = NULL;
+
+       f = fopen(fname, "r");
+       if (f == NULL) {
+               return false;
+       }
 
-       if (!lines || numlines < 1) {
-               TALLOC_FREE(lines);
-               return False;
+       len = getline(&line, &n, f);
+       if (len >= 0) {
+               ret = string_to_sid(sid, line);
+               SAFE_FREE(line);
        }
 
-       ret = string_to_sid(sid, lines[0]);
-       TALLOC_FREE(lines);
+       fclose(f);
        return ret;
 }