/*
- * Copyright (C) 2013 Intel Corporation.
+ * Copyright (C) 2013-2014 Intel Corporation.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
+#include <sys/types.h>
+#include <pwd.h>
#include <tzplatform_config.h>
-s --space separate with spaces instead of new-lines\n\
-q --query silently check that given variables are existing\n\
-c --continue continue to process if error\n\
+-u --user id set the user using its 'id' (name or numeric)\n\
\n\
";
int main(int argc, char **argv)
{
- char *progname = *argv++;
+ char *progname = *argv++, *user = 0;
int all = 0, not = 0, query = 0, export = 0, space = 0, list = 0, cont = 0;
int i, n, *sel, p;
enum tzplatform_variable id;
+ struct passwd pwd, *spw;
+ char buf[1024];
/* parse args */
while(*argv && **argv=='-') {
case 'l': x = "list"; break;
case 'c': x = "continue"; break;
case 'h': x = "help"; break;
+ case 'u': x = "user"; break;
}
if (!x || strcmp(x,opt))
c = 0;
case 's': space = 1; break;
case 'l': list = 1; break;
case 'c': cont = 1; break;
+ case 'u': user = *argv; if (user) argv++; break;
case 'h':
fprintf( stdout, help, basename(progname));
return 0;
if (query)
return 0;
+ /* set the user */
+ if (user) {
+ for (i=0 ; '0' <= user[i] && user[i] <= '9' ; i++);
+ if (user[i])
+ getpwnam_r(user, &pwd, buf, sizeof(buf), &spw);
+ else
+ getpwuid_r((uid_t)atoi(user), &pwd, buf, sizeof(buf), &spw);
+ if (!spw) {
+ fprintf( stderr, "error! %s isn't standing for a valid user.\n", user);
+ if (!cont)
+ return 1;
+ } else {
+ i = tzplatform_set_user(spw->pw_uid);
+ if (i) {
+ fprintf( stderr, "error! can't set the valid user %s.\n", user);
+ if (!cont)
+ return 1;
+ }
+ }
+ }
+
/* emits the result */
for (p = i = 0 ; i < n ; i++) {
if (sel[i] != not) {