VirtualBox

source: vbox/trunk/src/VBox/Runtime/r3/localipc.cpp@ 64287

Last change on this file since 64287 was 64287, checked in by vboxsync, 8 years ago

build fix for r111300

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 3.2 KB
Line 
1/** @file
2* IPRT - defines the function to create ipc pipe name.
3*/
4
5/*
6* Copyright (C) 2010-2016 Oracle Corporation
7*
8* This file is part of VirtualBox Open Source Edition (OSE), as
9* available from http://www.virtualbox.org. This file is free software;
10* you can redistribute it and/or modify it under the terms of the GNU
11* General Public License (GPL) as published by the Free Software
12* Foundation, in version 2 as it comes in the "COPYING" file of the
13* VirtualBox OSE distribution. VirtualBox OSE is distributed in the
14* hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
15*
16* The contents of this file may alternatively be used under the terms
17* of the Common Development and Distribution License Version 1.0
18* (CDDL) only, as it comes in the "COPYING.CDDL" file of the
19* VirtualBox OSE distribution, in which case the provisions of the
20* CDDL are applicable instead of those of the GPL.
21*
22* You may elect to license modified versions of this file under the
23* terms and conditions of either the GPL or the CDDL or both.
24*/
25
26/*********************************************************************************************************************************
27* Header Files *
28*********************************************************************************************************************************/
29#include <iprt/localipc.h>
30
31#include <iprt/err.h>
32#include <iprt/string.h>
33#include <iprt/crc.h>
34
35/**
36* Make the IPC pipe name unique for user
37* in a form like 'VBoxTrayIPC-6a4500cb7c726949'
38*
39* @returns IPRT status code.
40* @retval VINF_SUCCESS and *pcbDest if pipe name created successfully.
41* @retval VERR_INVALID_PARAMETER in case of invalid parameter value.
42* @retval VERR_BUFFER_OVERFLOW if the pszDest is too small.
43*
44* @param pszPrefix Pipe name prefix, for example 'VBoxTrayIPC-'
45* @param pszUserName User name
46* @param pszDest Destination buffer to store created pipe name
47* @param pcbDest IN - size of destination buffer in bytes,
48* OUT - length of created pipe name in bytes without trailing zero
49*/
50RTDECL(int) RTLocalIpcMakeNameUniqueUser(const char* pszPrefix, const char* pszUserName, char* pszDest, size_t* pcbDest)
51{
52 AssertPtrReturn(pszPrefix, VERR_INVALID_PARAMETER);
53 AssertPtrReturn(pszUserName, VERR_INVALID_PARAMETER);
54 AssertPtrReturn(pcbDest, VERR_INVALID_PARAMETER);
55 AssertReturn(*pcbDest, VERR_INVALID_PARAMETER);
56 AssertPtrReturn(pszDest, VERR_INVALID_PARAMETER);
57
58 const size_t cbPrefixSize = RTStrNLen(pszPrefix, RTSTR_MAX);
59 AssertReturn(*pcbDest > cbPrefixSize + 17, VERR_BUFFER_OVERFLOW);
60
61 const size_t cbSourceSize = RTStrNLen(pszUserName, RTSTR_MAX);
62 AssertReturn(cbSourceSize, VERR_INVALID_PARAMETER);
63
64 /* Use the crc of user name instead of user name to avoid localized pipe problem */
65 uint64_t uiCrc = RTCrc64(pszUserName, cbSourceSize);
66 AssertReturn(uiCrc > 0, VERR_INVALID_PARAMETER);
67
68 RT_BZERO(pszDest, *pcbDest);
69 size_t cbRes = RTStrPrintf(pszDest, *pcbDest, "%s%016RX64", pszPrefix, uiCrc);
70 AssertReturn(cbRes, VERR_BUFFER_OVERFLOW);
71
72 *pcbDest = cbRes;
73 return VINF_SUCCESS;
74}
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette