2 Unix SMB/CIFS implementation.
3 Samba utility functions
4 Copyright (C) Andrew Bartlett 2011
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 3 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program. If not, see <http://www.gnu.org/licenses/>.
21 #include "librpc/gen_ndr/server_id.h"
23 bool server_id_equal(const struct server_id
*p1
, const struct server_id
*p2
)
25 if (p1
->pid
!= p2
->pid
) {
29 if (p1
->task_id
!= p2
->task_id
) {
33 if (p1
->vnn
!= p2
->vnn
) {
37 if (p1
->unique_id
!= p2
->unique_id
) {
44 char *server_id_str(TALLOC_CTX
*mem_ctx
, const struct server_id
*id
)
46 if (id
->vnn
== NONCLUSTER_VNN
&& id
->task_id
== 0) {
47 return talloc_asprintf(mem_ctx
,
49 (unsigned long long)id
->pid
);
50 } else if (id
->vnn
== NONCLUSTER_VNN
) {
51 return talloc_asprintf(mem_ctx
,
53 (unsigned long long)id
->pid
,
54 (unsigned)id
->task_id
);
55 } else if (id
->task_id
== 0) {
56 return talloc_asprintf(mem_ctx
,
59 (unsigned long long)id
->pid
);
61 return talloc_asprintf(mem_ctx
,
64 (unsigned long long)id
->pid
,
65 (unsigned)id
->task_id
);
69 struct server_id
server_id_from_string(uint32_t local_vnn
,
70 const char *pid_string
)
72 struct server_id result
;
73 unsigned long long pid
;
74 unsigned int vnn
, task_id
= 0;
79 * We accept various forms with 1, 2 or 3 component forms
80 * because the server_id_str() can print different forms, and
81 * we want backwards compatibility for scripts that may call
84 if (sscanf(pid_string
, "%u:%llu.%u", &vnn
, &pid
, &task_id
) == 3) {
87 result
.task_id
= task_id
;
88 } else if (sscanf(pid_string
, "%u:%llu", &vnn
, &pid
) == 2) {
91 } else if (sscanf(pid_string
, "%llu.%u", &pid
, &task_id
) == 2) {
92 result
.vnn
= local_vnn
;
94 result
.task_id
= task_id
;
95 } else if (sscanf(pid_string
, "%llu", &pid
) == 1) {
96 result
.vnn
= local_vnn
;
99 result
.vnn
= NONCLUSTER_VNN
;
100 result
.pid
= UINT64_MAX
;