From: Kay Sievers <kay.sievers@vrfy.org>
To: linux-hotplug@vger.kernel.org
Subject: Re: udev - TODO update
Date: Sun, 29 Feb 2004 04:01:47 +0000 [thread overview]
Message-ID: <20040229040147.GA1887@vrfy.org> (raw)
In-Reply-To: <20040212234538.GC21117@vrfy.org>
[-- Attachment #1: Type: text/plain, Size: 474 bytes --]
On Sat, Feb 28, 2004 at 05:37:10PM -0500, Robert Love wrote:
> On Sat, 2004-02-28 at 17:19, Kay Sievers wrote:
>
> > I did it :)
> > Please have a look. If this is what you want, I will solve the klibc
> > beast.
>
> You are incredible, Kay. This is exactly what I was planning.
And this is exactly what I want to hear :)
> Adding utmp parsing to klibc cannot be fun, though.. ;)
Oh, it's only list of a static record in a file. So here is the first try.
thanks,
Kay
[-- Attachment #2: 04-localuser.patch --]
[-- Type: text/plain, Size: 4282 bytes --]
===== klibc_fixups.c 1.5 vs edited =====
--- 1.5/klibc_fixups.c Mon Feb 23 20:02:03 2004
+++ edited/klibc_fixups.c Sun Feb 29 04:51:47 2004
@@ -25,6 +25,7 @@
#include <stdio.h>
#include <string.h>
#include <ctype.h>
+#include <fcntl.h>
#include <sys/types.h>
#include "klibc_fixups.h"
@@ -32,6 +33,8 @@
#define PW_FILE "/etc/passwd"
#define GR_FILE "/etc/group"
+#define UTMP_FILE "/var/run/utmp"
+
/* return the id of a passwd style line, selected by the users name */
static unsigned long get_id_by_name(const char *uname, const char *dbfile)
@@ -105,6 +108,40 @@
return NULL;
else
return &gr;
+}
+
+
+int ufd = -1;
+
+void setutent()
+{
+ if (ufd < 0)
+ ufd = open(UTMP_FILE, O_RDONLY);
+ fcntl(ufd, F_SETFD, FD_CLOEXEC);
+ lseek(ufd, 0, SEEK_SET);
+}
+
+void endutent() {
+ if (ufd < 0)
+ return;
+ close(ufd);
+ ufd = -1;
+}
+
+struct utmp *getutent(void)
+{
+ static struct utmp utmp;
+ int retval;
+
+ if (ufd < 0) {
+ setutent();
+ if (ufd < 0)
+ return NULL;
+ }
+ retval = read(ufd, &utmp, sizeof(struct utmp));
+ if (retval < 1)
+ return NULL;
+ return &utmp;
}
#endif
===== klibc_fixups.h 1.5 vs edited =====
--- 1.5/klibc_fixups.h Mon Feb 23 20:03:20 2004
+++ edited/klibc_fixups.h Sun Feb 29 04:51:47 2004
@@ -1,7 +1,7 @@
#ifdef __KLIBC__
#ifndef KLIBC_FIXUPS_H
-#define KLIBC_FIXUPS_H
+#define KLIBC_FIXUPS_H
struct passwd {
char *pw_name; /* user name */
@@ -23,6 +23,49 @@
struct passwd *getpwnam(const char *name);
struct group *getgrnam(const char *name);
-#endif
+#define UT_LINESIZE 32
+#define UT_NAMESIZE 32
+#define UT_HOSTSIZE 256
+#define USER_PROCESS 7 /* normal process */
+#define ut_time ut_tv.tv_sec
+
+
+extern int ufd;
+
+struct exit_status {
+ short int e_termination; /* process termination status */
+ short int e_exit; /* process exit status */
+};
+
+struct utmp
+{
+ short int ut_type; /* type of login */
+ pid_t ut_pid; /* pid of login process */
+ char ut_line[UT_LINESIZE]; /* devicename */
+ char ut_id[4]; /* Inittab id */
+ char ut_user[UT_NAMESIZE]; /* username */
+ char ut_host[UT_HOSTSIZE]; /* hostname for remote login */
+ struct exit_status ut_exit; /* exit status of a process marked as DEAD_PROCESS */
+ /* The ut_session and ut_tv fields must be the same size for 32 and 64-bit */
+#if __WORDSIZE == 64 && defined __WORDSIZE_COMPAT32
+ int32_t ut_session; /* sid used for windowing */
+ struct {
+ int32_t tv_sec; /* seconds */
+ int32_t tv_usec; /* microseconds */
+ } ut_tv;
+#else
+ long int ut_session;
+ struct timeval ut_tv;
#endif
+ int32_t ut_addr_v6[4]; /* internet address of remote host */
+ char __unused[20]; /* reserved for future use */
+};
+
+struct utmp *getutent(void);
+void setutent(void);
+void endutent(void);
+
+
+#endif /* KLIBC_FIXUPS_H */
+#endif /* __KLIBC__ */
===== udev-add.c 1.53 vs edited =====
--- 1.53/udev-add.c Sat Feb 28 03:41:27 2004
+++ edited/udev-add.c Sun Feb 29 04:53:11 2004
@@ -32,6 +32,7 @@
#include <grp.h>
#ifndef __KLIBC__
#include <pwd.h>
+#include <utmp.h>
#endif
#include "libsysfs/sysfs/libsysfs.h"
@@ -44,6 +45,8 @@
#include "udevdb.h"
#include "klibc_fixups.h"
+#define LOCAL_USER "$local"
+
/*
* Right now the major/minor of a device is stored in a file called
* "dev" in sysfs.
@@ -132,6 +135,37 @@
return 0;
}
+/* get the local logged in user */
+static void set_to_local_user(char *user)
+{
+ struct utmp *u;
+ time_t recent = 0;
+
+ strnfieldcpy(user, default_owner_str, OWNER_SIZE);
+ setutent();
+ while (1) {
+ u = getutent();
+ if (u == NULL)
+ break;
+
+ /* is this a user login ? */
+ if (u->ut_type != USER_PROCESS)
+ continue;
+
+ /* is this a local login ? */
+ if (strcmp(u->ut_host, ""))
+ continue;
+
+ if (u->ut_time > recent) {
+ recent = u->ut_time;
+ strfieldcpy(user, u->ut_user);
+ dbg("local user is '%s'", user);
+ break;
+ }
+ }
+ endutent();
+}
+
static int create_node(struct udevice *dev, int fake)
{
struct stat stats;
@@ -175,6 +209,9 @@
if (endptr[0] == '\0')
uid = (uid_t) id;
else {
+ if (strncmp(dev->owner, LOCAL_USER, sizeof(LOCAL_USER)) == 0)
+ set_to_local_user(dev->owner);
+
struct passwd *pw = getpwnam(dev->owner);
if (pw == NULL)
dbg("specified user unknown '%s'", dev->owner);
next prev parent reply other threads:[~2004-02-29 4:01 UTC|newest]
Thread overview: 41+ messages / expand[flat|nested] mbox.gz Atom feed top
2004-02-12 23:45 udev - TODO update Kay Sievers
2004-02-13 1:26 ` Greg KH
2004-02-13 1:59 ` Kay Sievers
2004-02-13 6:16 ` Daniel Drake
2004-02-13 8:31 ` Olaf Hering
2004-02-13 17:52 ` Mike Frysinger
2004-02-13 19:34 ` Daniel Stekloff
2004-02-13 22:53 ` Greg KH
2004-02-17 1:41 ` Greg KH
2004-02-17 1:48 ` Mike Frysinger
2004-02-27 0:41 ` Kay Sievers
2004-02-27 0:49 ` Robert Love
2004-02-27 1:00 ` Greg KH
2004-02-27 1:13 ` Mike Frysinger
2004-02-27 1:23 ` Mike Waychison
2004-02-27 1:27 ` Robert Love
2004-02-27 1:36 ` Robert Love
2004-02-27 2:24 ` Bill Nottingham
2004-02-27 11:03 ` Robert McMeekin
2004-02-27 15:45 ` Kay Sievers
2004-02-27 17:35 ` Greg KH
2004-02-27 17:37 ` Greg KH
2004-02-27 18:08 ` Mike Waychison
2004-02-27 19:10 ` Bill Nottingham
2004-02-27 19:19 ` Robert Love
2004-02-27 19:20 ` Robert Love
2004-02-28 0:55 ` Greg KH
2004-02-28 13:07 ` Erik van Konijnenburg
2004-02-28 16:47 ` Robert Love
2004-02-28 22:19 ` Kay Sievers
2004-02-28 22:37 ` Robert Love
2004-02-29 4:01 ` Kay Sievers [this message]
2004-03-01 22:44 ` Greg KH
2004-03-01 23:05 ` Robert Love
2004-03-01 23:16 ` Greg KH
2004-03-02 0:04 ` Kay Sievers
2004-03-02 0:09 ` Greg KH
2004-03-02 7:24 ` [linux-hotplug-devel] " Wout Mertens
2004-03-02 7:32 ` Wout Mertens
2004-03-02 20:15 ` Greg KH
2004-03-02 20:55 ` Wout Mertens
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20040229040147.GA1887@vrfy.org \
--to=kay.sievers@vrfy.org \
--cc=linux-hotplug@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.