Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Is there a way to give different users unique system date/times in Ubuntu?

For example, if I wanted the date to always be June 22nd for user Bob (because that's his birthday) but still have the correct date/time display for every other user, is there a way, straightforward or not, to do so?

share|improve this question
    
Break the clock display for bob. Ubuntu is open source so pretty much everything is possible if you are willing to put in the time to find out how to do it. –  soandos May 31 '11 at 19:20
1  
Not without hacking into the kernelspace. Of course, if you are just trying to fake date(1) then you can just add an if statement with the getuid() function. –  bubu May 31 '11 at 19:28
    
Tell me more about this if statement –  tel May 31 '11 at 19:37
1  
Bob has the same birthday as me. Neat. –  Zoredache May 31 '11 at 20:57

1 Answer 1

No need to hack the kernel. That would be relatively easy with an interposition library assuming the ways Bob uses to know what the time is are bounded.

For example, many commands like date(1) are using clock_gettime(2) to get the current date and time. An interposing library would patch on the fly the date part and set it June 22.

This won't work statically linked binaries like busybox, but these binaries could be easily patched the same way.

Here is a sample code demonstrating the feasibility:

#define _GNU_SOURCE
#include <stdio.h>
#include <stdint.h>
#include <time.h>
#include <dlfcn.h>
#include <unistd.h>
#include <sys/types.h>

int clock_gettime(clockid_t clk_id, struct timespec *tp)
{
    static int (*cgt)(clockid_t, struct timespec*) = NULL;
    if (!cgt)
        cgt = dlsym(RTLD_NEXT, "clock_gettime");

    int rv = cgt(clk_id, tp);
    if(getuid()==1000) // Assuming 1000 is bob's uid.
    {
        struct tm * tm=localtime(&tp->tv_sec);
        tm->tm_mday=22;
        tm->tm_mon=5;
        time_t tt=mktime(tm);
        tp->tv_sec=tt;
    }
    return rv;
}

And what it provides:

$ date
Wed Jun  2 23:44:51 CEST 2011
$ export LD_PRELOAD=$PWD/a.so
$ date
Wed Jun 22 23:44:51 CEST 2011
$ id -u
1000
share|improve this answer
1  
OK, so... how do you actually do it? –  Nitrodist May 31 '11 at 20:56
    
Hints added in my reply. –  jlliagre Jun 1 '11 at 9:24
    
and full code now. –  jlliagre Jun 2 '11 at 23:03

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.