~ubuntu-branches/ubuntu/vivid/gnupg2/vivid-proposed

« back to all changes in this revision

Viewing changes to common/sysutils.c

  • Committer: Package Import Robot
  • Author(s): Dmitrijs Ledkovs
  • Date: 2013-11-01 22:15:05 UTC
  • mfrom: (14.1.8 sid)
  • Revision ID: package-import@ubuntu.com-20131101221505-i1zpbl1qd1a3gsvx
Tags: 2.0.22-1ubuntu1
* Merge from Debian, remaining changes:
  - Drop sh prefix from openpgp test environment as it leads to exec
  invocations of sh /bin/bash leading to syntax errors from sh.  Fixes
  FTBFS detected in Ubuntu saucy archive rebuild.
  - Add udev rules to give gpg access to some smartcard readers;
    Debian #543217.
  - debian/gnupg2.udev: udev rules to set ACLs on SCM smartcard readers.
  - Add upstart user job for gpg-agent.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/* sysutils.c -  system helpers
2
2
 * Copyright (C) 1998, 1999, 2000, 2001, 2003, 2004,
3
3
 *               2007, 2008  Free Software Foundation, Inc.
 
4
 * Copyright (C) 2013 Werner Koch
4
5
 *
5
6
 * This file is part of GnuPG.
6
7
 *
495
496
               (unsigned long)pid, w32_strerror (-1));
496
497
#endif
497
498
}
 
499
 
 
500
 
 
501
#ifdef HAVE_W32_SYSTEM
 
502
/* Return the user's security identifier from the current process.  */
 
503
PSID
 
504
w32_get_user_sid (void)
 
505
{
 
506
  int okay = 0;
 
507
  HANDLE proc = NULL;
 
508
  HANDLE token = NULL;
 
509
  TOKEN_USER *user = NULL;
 
510
  PSID sid = NULL;
 
511
  DWORD tokenlen, sidlen;
 
512
 
 
513
  proc = OpenProcess (PROCESS_QUERY_INFORMATION, FALSE, GetCurrentProcessId());
 
514
  if (!proc)
 
515
    goto leave;
 
516
 
 
517
  if (!OpenProcessToken (proc, TOKEN_QUERY, &token))
 
518
    goto leave;
 
519
 
 
520
  if (!GetTokenInformation (token, TokenUser, NULL, 0, &tokenlen)
 
521
      && GetLastError() != ERROR_INSUFFICIENT_BUFFER)
 
522
    goto leave;
 
523
 
 
524
  user = xtrymalloc (tokenlen);
 
525
  if (!user)
 
526
    goto leave;
 
527
 
 
528
  if (!GetTokenInformation (token, TokenUser, user, tokenlen, &tokenlen))
 
529
    goto leave;
 
530
  if (!IsValidSid (user->User.Sid))
 
531
    goto leave;
 
532
  sidlen = GetLengthSid (user->User.Sid);
 
533
  sid = xtrymalloc (sidlen);
 
534
  if (!sid)
 
535
    goto leave;
 
536
  if (!CopySid (sidlen, sid, user->User.Sid))
 
537
    goto leave;
 
538
  okay = 1;
 
539
 
 
540
 leave:
 
541
  xfree (user);
 
542
  if (token)
 
543
    CloseHandle (token);
 
544
  if (proc)
 
545
    CloseHandle (proc);
 
546
 
 
547
  if (!okay)
 
548
    {
 
549
      xfree (sid);
 
550
      sid = NULL;
 
551
    }
 
552
  return sid;
 
553
}
 
554
#endif /*HAVE_W32_SYSTEM*/