diff options
author | Stefan Metzmacher <metze@samba.org> | 2012-08-17 12:47:57 +0200 |
---|---|---|
committer | Stefan Metzmacher <metze@samba.org> | 2012-08-17 20:07:07 +0200 |
commit | d4a0aeb49a3e7536b34d101cf7b70b48cfa5f4ba (patch) | |
tree | 916cbf50922289819c16ef5b3e2e9234c8a741f7 | |
parent | 6a58c5fc648088c7c8930a0e653c2f1b01a90b13 (diff) | |
download | samba-d4a0aeb49a3e7536b34d101cf7b70b48cfa5f4ba.tar.gz samba-d4a0aeb49a3e7536b34d101cf7b70b48cfa5f4ba.tar.bz2 samba-d4a0aeb49a3e7536b34d101cf7b70b48cfa5f4ba.zip |
lib/util: add server_id_from_string()
metze
-rw-r--r-- | lib/util/samba_util.h | 2 | ||||
-rw-r--r-- | lib/util/server_id.c | 36 |
2 files changed, 38 insertions, 0 deletions
diff --git a/lib/util/samba_util.h b/lib/util/samba_util.h index 26a5c6872b..e69aa7c40c 100644 --- a/lib/util/samba_util.h +++ b/lib/util/samba_util.h @@ -901,5 +901,7 @@ const char *shlib_ext(void); struct server_id; bool server_id_equal(const struct server_id *p1, const struct server_id *p2); char *server_id_str(TALLOC_CTX *mem_ctx, const struct server_id *id); +struct server_id server_id_from_string(uint32_t local_vnn, + const char *pid_string); #endif /* _SAMBA_UTIL_H_ */ diff --git a/lib/util/server_id.c b/lib/util/server_id.c index 7370ad9335..d41fb0b287 100644 --- a/lib/util/server_id.c +++ b/lib/util/server_id.c @@ -60,3 +60,39 @@ char *server_id_str(TALLOC_CTX *mem_ctx, const struct server_id *id) (unsigned)id->task_id); } } + +struct server_id server_id_from_string(uint32_t local_vnn, + const char *pid_string) +{ + struct server_id result; + unsigned long long pid; + unsigned int vnn, task_id = 0; + + ZERO_STRUCT(result); + + /* + * We accept various forms with 1, 2 or 3 component forms + * because the server_id_str() can print different forms, and + * we want backwards compatibility for scripts that may call + * smbclient. + */ + if (sscanf(pid_string, "%u:%llu.%u", &vnn, &pid, &task_id) == 3) { + result.vnn = vnn; + result.pid = pid; + result.task_id = task_id; + } else if (sscanf(pid_string, "%u:%llu", &vnn, &pid) == 2) { + result.vnn = vnn; + result.pid = pid; + } else if (sscanf(pid_string, "%llu.%u", &pid, &task_id) == 2) { + result.vnn = local_vnn; + result.pid = pid; + result.task_id = task_id; + } else if (sscanf(pid_string, "%llu", &pid) == 1) { + result.vnn = local_vnn; + result.pid = pid; + } else { + result.vnn = NONCLUSTER_VNN; + result.pid = UINT64_MAX; + } + return result; +} |