Logged user mapping errors (which occur before mounting)
parent
c79b3777ca
commit
d76c7f6172
|
@ -43,6 +43,9 @@
|
|||
#ifdef HAVE_FCNTL_H
|
||||
#include <fcntl.h>
|
||||
#endif
|
||||
#ifdef HAVE_SYSLOG_H
|
||||
#include <syslog.h>
|
||||
#endif
|
||||
#include <unistd.h>
|
||||
#include <pwd.h>
|
||||
#include <grp.h>
|
||||
|
@ -3935,6 +3938,33 @@ static SID *encodesid(const char *sidstr)
|
|||
return (sid);
|
||||
}
|
||||
|
||||
/*
|
||||
* Early logging before the logs are redirected
|
||||
*
|
||||
* (not quite satisfactory : this appears before the ntfs-g banner,
|
||||
* and with a different pid)
|
||||
*/
|
||||
|
||||
static void log_early_error(const char *format, ...)
|
||||
__attribute__((format(printf, 1, 2)));
|
||||
|
||||
static void log_early_error(const char *format, ...)
|
||||
{
|
||||
va_list args;
|
||||
|
||||
va_start(args, format);
|
||||
#ifdef HAVE_SYSLOG_H
|
||||
openlog("ntfs-3g", LOG_PID, LOG_USER);
|
||||
ntfs_log_handler_syslog(NULL, NULL, 0,
|
||||
NTFS_LOG_LEVEL_ERROR, NULL,
|
||||
format, args);
|
||||
#else
|
||||
vfprintf(stderr,format,args);
|
||||
#endif
|
||||
va_end(args);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Get a single mapping item from buffer
|
||||
*
|
||||
|
@ -3950,6 +3980,8 @@ static struct MAPLIST *getmappingitem(FILEREADER reader, void *fileid,
|
|||
int dst;
|
||||
char *p;
|
||||
char *q;
|
||||
char *pu;
|
||||
char *pg;
|
||||
int gotend;
|
||||
struct MAPLIST *item;
|
||||
|
||||
|
@ -3978,22 +4010,25 @@ static struct MAPLIST *getmappingitem(FILEREADER reader, void *fileid,
|
|||
}
|
||||
} while (*psize && ((item->maptext[0] == '#') || !gotend));
|
||||
if (gotend) {
|
||||
pu = pg = (char*)NULL;
|
||||
/* decompose into uid, gid and sid */
|
||||
p = item->maptext;
|
||||
item->uidstr = item->maptext;
|
||||
item->gidstr = strchr(item->uidstr, ':');
|
||||
if (item->gidstr) {
|
||||
*item->gidstr++ = '\0';
|
||||
pu = item->gidstr++;
|
||||
item->sidstr = strchr(item->gidstr, ':');
|
||||
if (item->sidstr) {
|
||||
*item->sidstr++ = 0;
|
||||
pg = item->sidstr++;
|
||||
q = strchr(item->sidstr, ':');
|
||||
if (q) *q = 0;
|
||||
} else
|
||||
p = (char*)NULL;
|
||||
} else
|
||||
p = (char*)NULL; /* bad line, stop */
|
||||
if (!p) {
|
||||
}
|
||||
}
|
||||
if (pu && pg)
|
||||
*pu = *pg = '\0';
|
||||
else {
|
||||
log_early_error("Bad mapping item \"%s\"\n",
|
||||
item->maptext);
|
||||
free(item);
|
||||
item = (struct MAPLIST*)NULL;
|
||||
}
|
||||
|
@ -4118,7 +4153,11 @@ struct MAPPING *ntfs_do_user_mapping(struct MAPLIST *firstitem)
|
|||
uid = 0;
|
||||
if (item->uidstr[0]) {
|
||||
pwd = getpwnam(item->uidstr);
|
||||
if (pwd) uid = pwd->pw_uid;
|
||||
if (pwd)
|
||||
uid = pwd->pw_uid;
|
||||
else
|
||||
log_early_error("Invalid user \"%s\"\n",
|
||||
item->uidstr);
|
||||
}
|
||||
}
|
||||
/*
|
||||
|
@ -4194,7 +4233,11 @@ struct MAPPING *ntfs_do_group_mapping(struct MAPLIST *firstitem)
|
|||
gid = 0;
|
||||
if (item->gidstr[0]) {
|
||||
grp = getgrnam(item->gidstr);
|
||||
if (grp) gid = grp->gr_gid;
|
||||
if (grp)
|
||||
gid = grp->gr_gid;
|
||||
else
|
||||
log_early_error("Invalid group \"%s\"\n",
|
||||
item->gidstr);
|
||||
}
|
||||
}
|
||||
/*
|
||||
|
|
Loading…
Reference in New Issue