audit_logging: Remove incorrect check for NT_STATUS_OBJECT_NAME_NOT_FOUND
[nivanova/samba-autobuild/.git] / lib / audit_logging / audit_logging.c
1 /*
2    common routines for audit logging
3
4    Copyright (C) Andrew Bartlett <abartlet@samba.org> 2018
5
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.
10
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.
15
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/>.
18 */
19
20 /*
21  * Error handling:
22  *
23  * The json_object structure contains a boolean 'error'.  This is set whenever
24  * an error is detected. All the library functions check this flag and return
25  * immediately if it is set.
26  *
27  *      if (object->error) {
28  *              return;
29  *      }
30  *
31  * This allows the operations to be sequenced naturally with out the clutter
32  * of error status checks.
33  *
34  *      audit = json_new_object();
35  *      json_add_version(&audit, OPERATION_MAJOR, OPERATION_MINOR);
36  *      json_add_int(&audit, "statusCode", ret);
37  *      json_add_string(&audit, "status", ldb_strerror(ret));
38  *      json_add_string(&audit, "operation", operation);
39  *      json_add_address(&audit, "remoteAddress", remote);
40  *      json_add_sid(&audit, "userSid", sid);
41  *      json_add_string(&audit, "dn", dn);
42  *      json_add_guid(&audit, "transactionId", &ac->transaction_guid);
43  *      json_add_guid(&audit, "sessionId", unique_session_token);
44  *
45  * The assumptions are that errors will be rare, and that the audit logging
46  * code should not cause failures. So errors are logged but processing
47  * continues on a best effort basis.
48  */
49
50 #include "includes.h"
51
52 #include "librpc/ndr/libndr.h"
53 #include "lib/tsocket/tsocket.h"
54 #include "libcli/security/dom_sid.h"
55 #include "lib/messaging/messaging.h"
56 #include "auth/common_auth.h"
57 #include "audit_logging.h"
58
59 /*
60  * @brief Get a human readable timestamp.
61  *
62  * Returns the current time formatted as
63  *  "Tue, 14 Mar 2017 08:38:42.209028 NZDT"
64  *
65  * The returned string is allocated by talloc in the supplied context.
66  * It is the callers responsibility to free it.
67  *
68  * @param mem_ctx talloc memory context that owns the returned string.
69  *
70  * @return a human readable time stamp.
71  *
72  */
73 char* audit_get_timestamp(TALLOC_CTX *frame)
74 {
75         char buffer[40];        /* formatted time less usec and timezone */
76         char tz[10];            /* formatted time zone                   */
77         struct tm* tm_info;     /* current local time                    */
78         struct timeval tv;      /* current system time                   */
79         int r;                  /* response code from gettimeofday       */
80         char * ts;              /* formatted time stamp                  */
81
82         r = gettimeofday(&tv, NULL);
83         if (r) {
84                 DBG_ERR("Unable to get time of day: (%d) %s\n",
85                         errno,
86                         strerror(errno));
87                 return NULL;
88         }
89
90         tm_info = localtime(&tv.tv_sec);
91         if (tm_info == NULL) {
92                 DBG_ERR("Unable to determine local time\n");
93                 return NULL;
94         }
95
96         strftime(buffer, sizeof(buffer)-1, "%a, %d %b %Y %H:%M:%S", tm_info);
97         strftime(tz, sizeof(tz)-1, "%Z", tm_info);
98         ts = talloc_asprintf(frame, "%s.%06ld %s", buffer, tv.tv_usec, tz);
99         if (ts == NULL) {
100                 DBG_ERR("Out of memory formatting time stamp\n");
101         }
102         return ts;
103 }
104
105 /*
106  * @brief write an audit message to the audit logs.
107  *
108  * Write a human readable text audit message to the samba logs.
109  *
110  * @param prefix Text to be printed at the start of the log line
111  * @param message The content of the log line.
112  * @param debub_class The debug class to log the message with.
113  * @param debug_level The debug level to log the message with.
114  */
115 void audit_log_human_text(const char* prefix,
116                           const char* message,
117                           int debug_class,
118                           int debug_level)
119 {
120         DEBUGC(debug_class, debug_level, ("%s %s\n", prefix, message));
121 }
122
123 #ifdef HAVE_JANSSON
124 /*
125  * @brief write a json object to the samba audit logs.
126  *
127  * Write the json object to the audit logs as a formatted string
128  *
129  * @param prefix Text to be printed at the start of the log line
130  * @param message The content of the log line.
131  * @param debub_class The debug class to log the message with.
132  * @param debug_level The debug level to log the message with.
133  */
134 void audit_log_json(const char* prefix,
135                     struct json_object* message,
136                     int debug_class,
137                     int debug_level)
138 {
139         TALLOC_CTX *ctx = talloc_new(NULL);
140         char *s = json_to_string(ctx, message);
141         DEBUGC(debug_class, debug_level, ("JSON %s: %s\n", prefix, s));
142         TALLOC_FREE(ctx);
143 }
144
145 /*
146  * @brief get a connection to the messaging event server.
147  *
148  * Get a connection to the messaging event server registered by server_name.
149  *
150  * @param msg_ctx a valid imessaging_context.
151  * @param server_name name of messaging event server to connect to.
152  * @param server_id The event server details to populate
153  *
154  * @return NTSTATUS
155  */
156 static NTSTATUS get_event_server(
157         struct imessaging_context *msg_ctx,
158         const char *server_name,
159         struct server_id *event_server)
160 {
161         NTSTATUS status;
162         TALLOC_CTX *frame = talloc_stackframe();
163         unsigned num_servers, i;
164         struct server_id *servers;
165
166         status = irpc_servers_byname(
167                 msg_ctx,
168                 frame,
169                 server_name,
170                 &num_servers,
171                 &servers);
172
173         if (!NT_STATUS_IS_OK(status)) {
174                 DBG_NOTICE(
175                         "Failed to find '%s' registered on the message bus to "
176                         "send JSON audit events to: %s\n",
177                         server_name,
178                         nt_errstr(status));
179                 TALLOC_FREE(frame);
180                 return status;
181         }
182
183         /*
184          * Select the first server that is listening, because we get
185          * connection refused as NT_STATUS_OBJECT_NAME_NOT_FOUND
186          * without waiting
187          */
188         for (i = 0; i < num_servers; i++) {
189                 status = imessaging_send(
190                         msg_ctx,
191                         servers[i],
192                         MSG_PING,
193                         &data_blob_null);
194                 if (NT_STATUS_IS_OK(status)) {
195                         *event_server = servers[i];
196                         TALLOC_FREE(frame);
197                         return NT_STATUS_OK;
198                 }
199         }
200         DBG_NOTICE(
201                 "Failed to find '%s' registered on the message bus to "
202                 "send JSON audit events to: %s\n",
203                 server_name,
204                 nt_errstr(status));
205         TALLOC_FREE(frame);
206         return NT_STATUS_OBJECT_NAME_NOT_FOUND;
207 }
208
209 /*
210  * @brief send an audit message to a messaging event server.
211  *
212  * Send the message to a registered and listening event server.
213  * Note: Any errors are logged, and the message is not sent.  This is to ensure
214  *       that a poorly behaved event server does not impact Samba.
215  *
216  *       As it is possible to lose messages, especially during server
217  *       shut down, currently this function is primarily intended for use
218  *       in integration tests.
219  *
220  * @param msg_ctx an imessaging_context, can be NULL in which case no message
221  *                will be sent.
222  * @param server_name the naname of the event server to send the message to.
223  * @param messag_type A message type defined in librpc/idl/messaging.idl
224  * @param message The message to send.
225  *
226  */
227 void audit_message_send(
228         struct imessaging_context *msg_ctx,
229         const char *server_name,
230         uint32_t message_type,
231         struct json_object *message)
232 {
233         struct server_id event_server;
234         NTSTATUS status;
235
236         const char *message_string = NULL;
237         DATA_BLOB message_blob = data_blob_null;
238         TALLOC_CTX *ctx = talloc_new(NULL);
239
240         if (msg_ctx == NULL) {
241                 DBG_DEBUG("No messaging context\n");
242                 TALLOC_FREE(ctx);
243                 return;
244         }
245
246         /* Need to refetch the address each time as the destination server may
247          * have disconnected and reconnected in the interim, in which case
248          * messages may get lost
249          */
250         status = get_event_server(msg_ctx, server_name, &event_server);
251         if (!NT_STATUS_IS_OK(status)) {
252                 DBG_ERR("get_event_server for %s returned (%s)\n",
253                         server_name,
254                         nt_errstr(status));
255                 TALLOC_FREE(ctx);
256                 return;
257         }
258
259         message_string = json_to_string(ctx, message);
260         message_blob = data_blob_string_const(message_string);
261         status = imessaging_send(
262                 msg_ctx,
263                 event_server,
264                 message_type,
265                 &message_blob);
266
267         /*
268          * If the server crashed, try to find it again
269          */
270         if (NT_STATUS_EQUAL(status, NT_STATUS_OBJECT_NAME_NOT_FOUND)) {
271                 status = get_event_server(msg_ctx, server_name, &event_server);
272                 if (!NT_STATUS_IS_OK(status)) {
273                         DBG_ERR("get_event_server for %s returned (%s)\n",
274                                 server_name,
275                                 nt_errstr(status));
276                         TALLOC_FREE(ctx);
277                         return;
278                 }
279                 imessaging_send(
280                         msg_ctx,
281                         event_server,
282                         message_type,
283                         &message_blob);
284         }
285         TALLOC_FREE(ctx);
286 }
287
288 /*
289  * @brief Create a new struct json_object, wrapping a JSON Object.
290  *
291  * Create a new json object, the json_object wraps the underlying json
292  * implementations JSON Object representation.
293  *
294  * Free with a call to json_free_object, note that the jansson inplementation
295  * allocates memory with malloc and not talloc.
296  *
297  * @return a struct json_object, error will be set to true if the object
298  *         could not be created.
299  *
300  */
301 struct json_object json_new_object(void) {
302
303         struct json_object object;
304         object.error = false;
305
306         object.root = json_object();
307         if (object.root == NULL) {
308                 object.error = true;
309                 DBG_ERR("Unable to create json_object\n");
310         }
311         return object;
312 }
313
314 /*
315  * @brief Create a new struct json_object wrapping a JSON Array.
316  *
317  * Create a new json object, the json_object wraps the underlying json
318  * implementations JSON Array representation.
319  *
320  * Free with a call to json_free_object, note that the jansson inplementation
321  * allocates memory with malloc and not talloc.
322  *
323  * @return a struct json_object, error will be set to true if the array
324  *         could not be created.
325  *
326  */
327 struct json_object json_new_array(void) {
328
329         struct json_object array;
330         array.error = false;
331
332         array.root = json_array();
333         if (array.root == NULL) {
334                 array.error = true;
335                 DBG_ERR("Unable to create json_array\n");
336         }
337         return array;
338 }
339
340
341 /*
342  * @brief free and invalidate a previously created JSON object.
343  *
344  * Release any resources owned by a json_object, and then mark the structure
345  * as invalid.  It is safe to call this multiple times on an object.
346  *
347  */
348 void json_free(struct json_object *object)
349 {
350         if (object->root != NULL) {
351                 json_decref(object->root);
352         }
353         object->root = NULL;
354         object->error = true;
355 }
356
357 /*
358  * @brief is the current JSON object invalid?
359  *
360  * Check the state of the object to determine if it is invalid.
361  *
362  * @return is the object valid?
363  *
364  */
365 bool json_is_invalid(struct json_object *object)
366 {
367         return object->error;
368 }
369
370 /*
371  * @brief Add an integer value to a JSON object.
372  *
373  * Add an integer value named 'name' to the json object.
374  * In the event of an error object will be invalidated.
375  *
376  * @param object the JSON object to be updated.
377  * @param name the name of the value.
378  * @param value the value.
379  *
380  */
381 void json_add_int(struct json_object *object,
382                   const char* name,
383                   const int value)
384 {
385         int rc = 0;
386
387         if (object->error) {
388                 return;
389         }
390
391         rc = json_object_set_new(object->root, name, json_integer(value));
392         if (rc) {
393                 DBG_ERR("Unable to set name [%s] value [%d]\n", name, value);
394                 object->error = true;
395         }
396 }
397
398 /*
399  * @brief Add a boolean value to a JSON object.
400  *
401  * Add a boolean value named 'name' to the json object.
402  * In the event of an error object will be invalidated.
403  *
404  * @param object the JSON object to be updated.
405  * @param name the name.
406  * @param value the value.
407  *
408  */
409 void json_add_bool(struct json_object *object,
410                    const char* name,
411                    const bool value)
412 {
413         int rc = 0;
414
415         if (object->error) {
416                 return;
417         }
418
419         rc = json_object_set_new(object->root, name, json_boolean(value));
420         if (rc) {
421                 DBG_ERR("Unable to set name [%s] value [%d]\n", name, value);
422                 object->error = true;
423         }
424
425 }
426
427 /*
428  * @brief Add a string value to a JSON object.
429  *
430  * Add a string value named 'name' to the json object.
431  * In the event of an error object will be invalidated.
432  *
433  * @param object the JSON object to be updated.
434  * @param name the name.
435  * @param value the value.
436  *
437  */
438 void json_add_string(struct json_object *object,
439                      const char* name,
440                      const char* value)
441 {
442         int rc = 0;
443
444         if (object->error) {
445                 return;
446         }
447
448         if (value) {
449                 rc = json_object_set_new(
450                         object->root,
451                         name,
452                         json_string(value));
453         } else {
454                 rc = json_object_set_new(object->root, name, json_null());
455         }
456         if (rc) {
457                 DBG_ERR("Unable to set name [%s] value [%s]\n", name, value);
458                 object->error = true;
459         }
460 }
461
462 /*
463  * @brief Assert that the current JSON object is an array.
464  *
465  * Check that the current object is a JSON array, and if not
466  * invalidate the object. We also log an error message as this indicates
467  * bug in the calling code.
468  *
469  * @param object the JSON object to be validated.
470  */
471 void json_assert_is_array(struct json_object *array) {
472
473         if (array->error) {
474                 return;
475         }
476
477         if (json_is_array(array->root) == false) {
478                 DBG_ERR("JSON object is not an array\n");
479                 array->error = true;
480                 return;
481         }
482 }
483
484 /*
485  * @brief Add a JSON object to a JSON object.
486  *
487  * Add a JSON object named 'name' to the json object.
488  * In the event of an error object will be invalidated.
489  *
490  * @param object the JSON object to be updated.
491  * @param name the name.
492  * @param value the value.
493  *
494  */
495 void json_add_object(struct json_object *object,
496                      const char* name,
497                      struct json_object *value)
498 {
499         int rc = 0;
500         json_t *jv = NULL;
501
502         if (object->error) {
503                 return;
504         }
505
506         if (value != NULL && value->error) {
507                 object->error = true;
508                 return;
509         }
510
511         jv = value == NULL ? json_null() : value->root;
512
513         if (json_is_array(object->root)) {
514                 rc = json_array_append_new(object->root, jv);
515         } else if (json_is_object(object->root)) {
516                 rc = json_object_set_new(object->root, name,  jv);
517         } else {
518                 DBG_ERR("Invalid JSON object type\n");
519                 object->error = true;
520         }
521         if (rc) {
522                 DBG_ERR("Unable to add object [%s]\n", name);
523                 object->error = true;
524         }
525 }
526
527 /*
528  * @brief Add a string to a JSON object, truncating if necessary.
529  *
530  *
531  * Add a string value named 'name' to the json object, the string will be
532  * truncated if it is more than len characters long. If len is 0 the value
533  * is encoded as a JSON null.
534  *
535  * In the event of an error object will be invalidated.
536  *
537  * @param object the JSON object to be updated.
538  * @param name the name.
539  * @param value the value.
540  * @param len the maximum number of characters to be copied.
541  *
542  */
543 void json_add_stringn(struct json_object *object,
544                       const char *name,
545                       const char *value,
546                       const size_t len)
547 {
548
549         int rc = 0;
550         if (object->error) {
551                 return;
552         }
553
554         if (value != NULL && len > 0) {
555                 char buffer[len+1];
556                 strncpy(buffer, value, len);
557                 buffer[len] = '\0';
558                 rc = json_object_set_new(object->root,
559                                          name,
560                                          json_string(buffer));
561         } else {
562                 rc = json_object_set_new(object->root, name, json_null());
563         }
564         if (rc) {
565                 DBG_ERR("Unable to set name [%s] value [%s]\n", name, value);
566                 object->error = true;
567         }
568 }
569
570 /*
571  * @brief Add a version object to a JSON object
572  *
573  * Add a version object to the JSON object
574  *      "version":{"major":1, "minor":0}
575  *
576  * The version tag is intended to aid the processing of the JSON messages
577  * The major version number should change when an attribute is:
578  *  - renamed
579  *  - removed
580  *  - its meaning changes
581  *  - its contents change format
582  * The minor version should change whenever a new attribute is added and for
583  * minor bug fixes to an attributes content.
584  *
585  * In the event of an error object will be invalidated.
586  *
587  * @param object the JSON object to be updated.
588  * @param major the major version number
589  * @param minor the minor version number
590  */
591 void json_add_version(struct json_object *object, int major, int minor)
592 {
593         struct json_object version = json_new_object();
594         json_add_int(&version, "major", major);
595         json_add_int(&version, "minor", minor);
596         json_add_object(object, "version", &version);
597 }
598
599 /*
600  * @brief add an ISO 8601 timestamp to the object.
601  *
602  * Add the current date and time as a timestamp in ISO 8601 format
603  * to a JSON object
604  *
605  * "timestamp":"2017-03-06T17:18:04.455081+1300"
606  *
607  * In the event of an error object will be invalidated.
608  *
609  * @param object the JSON object to be updated.
610  */
611 void json_add_timestamp(struct json_object *object)
612 {
613         char buffer[40];        /* formatted time less usec and timezone */
614         char timestamp[65];     /* the formatted ISO 8601 time stamp     */
615         char tz[10];            /* formatted time zone                   */
616         struct tm* tm_info;     /* current local time                    */
617         struct timeval tv;      /* current system time                   */
618         int r;                  /* response code from gettimeofday       */
619
620         if (object->error) {
621                 return;
622         }
623
624         r = gettimeofday(&tv, NULL);
625         if (r) {
626                 DBG_ERR("Unable to get time of day: (%d) %s\n",
627                         errno,
628                         strerror(errno));
629                 object->error = true;
630                 return;
631         }
632
633         tm_info = localtime(&tv.tv_sec);
634         if (tm_info == NULL) {
635                 DBG_ERR("Unable to determine local time\n");
636                 object->error = true;
637                 return;
638         }
639
640         strftime(buffer, sizeof(buffer)-1, "%Y-%m-%dT%T", tm_info);
641         strftime(tz, sizeof(tz)-1, "%z", tm_info);
642         snprintf(
643                 timestamp,
644                 sizeof(timestamp),
645                 "%s.%06ld%s",
646                 buffer,
647                 tv.tv_usec,
648                 tz);
649         json_add_string(object, "timestamp", timestamp);
650 }
651
652
653 /*
654  *@brief Add a tsocket_address to a JSON object
655  *
656  * Add the string representation of a Samba tsocket_address to the object.
657  *
658  * "localAddress":"ipv6::::0"
659  *
660  * In the event of an error object will be invalidated.
661  *
662  * @param object the JSON object to be updated.
663  * @param name the name.
664  * @param address the tsocket_address.
665  *
666  */
667 void json_add_address(struct json_object *object,
668                       const char *name,
669                       const struct tsocket_address *address)
670 {
671
672         if (object->error) {
673                 return;
674         }
675         if (address == NULL) {
676                 int rc = json_object_set_new(object->root, name, json_null());
677                 if (rc) {
678                         DBG_ERR("Unable to set address [%s] to null\n", name);
679                         object->error = true;
680                 }
681         } else {
682                 TALLOC_CTX *ctx = talloc_new(NULL);
683                 char *s = NULL;
684
685                 s = tsocket_address_string(address, ctx);
686                 json_add_string(object, name, s);
687                 TALLOC_FREE(ctx);
688         }
689 }
690
691 /*
692  * @brief Add a formatted string representation of a sid to a json object.
693  *
694  * Add the string representation of a Samba sid to the object.
695  *
696  * "sid":"S-1-5-18"
697  *
698  * In the event of an error object will be invalidated.
699  *
700  * @param object the JSON object to be updated.
701  * @param name the name.
702  * @param sid the sid
703  *
704  */
705 void json_add_sid(struct json_object *object,
706                   const char *name,
707                   const struct dom_sid *sid)
708 {
709
710         if (object->error) {
711                 return;
712         }
713         if (sid == NULL) {
714                 int rc = json_object_set_new(object->root, name, json_null());
715                 if (rc) {
716                         DBG_ERR("Unable to set SID [%s] to null\n", name);
717                         object->error = true;
718                 }
719         } else {
720                 char sid_buf[DOM_SID_STR_BUFLEN];
721
722                 dom_sid_string_buf(sid, sid_buf, sizeof(sid_buf));
723                 json_add_string(object, name, sid_buf);
724         }
725 }
726
727 /*
728  * @brief Add a formatted string representation of a guid to a json object.
729  *
730  * Add the string representation of a Samba GUID to the object.
731  *
732  * "guid":"1fb9f2ee-2a4d-4bf8-af8b-cb9d4529a9ab"
733  *
734  * In the event of an error object will be invalidated.
735  *
736  * @param object the JSON object to be updated.
737  * @param name the name.
738  * @param guid the guid.
739  *
740  *
741  */
742 void json_add_guid(struct json_object *object,
743                    const char *name,
744                    const struct GUID *guid)
745 {
746
747
748         if (object->error) {
749                 return;
750         }
751         if (guid == NULL) {
752                 int rc = json_object_set_new(object->root, name, json_null());
753                 if (rc) {
754                         DBG_ERR("Unable to set GUID [%s] to null\n", name);
755                         object->error = true;
756                 }
757         } else {
758                 char *guid_str;
759                 struct GUID_txt_buf guid_buff;
760
761                 guid_str = GUID_buf_string(guid, &guid_buff);
762                 json_add_string(object, name, guid_str);
763         }
764 }
765
766
767 /*
768  * @brief Convert a JSON object into a string
769  *
770  * Convert the jsom object into a string suitable for printing on a log line,
771  * i.e. with no embedded line breaks.
772  *
773  * If the object is invalid it returns NULL.
774  *
775  * @param mem_ctx the talloc memory context owning the returned string
776  * @param object the json object.
777  *
778  * @return A string representation of the object or NULL if the object
779  *         is invalid.
780  */
781 char *json_to_string(TALLOC_CTX *mem_ctx,
782                      struct json_object *object)
783 {
784         char *json = NULL;
785         char *json_string = NULL;
786
787         if (object->error) {
788                 return NULL;
789         }
790
791         /*
792          * json_dumps uses malloc, so need to call free(json) to release
793          * the memory
794          */
795         json = json_dumps(object->root, 0);
796         if (json == NULL) {
797                 DBG_ERR("Unable to convert JSON object to string\n");
798                 return NULL;
799         }
800
801         json_string = talloc_strdup(mem_ctx, json);
802         if (json_string == NULL) {
803                 free(json);
804                 DBG_ERR("Unable to copy JSON object string to talloc string\n");
805                 return NULL;
806         }
807         free(json);
808
809         return json_string;
810 }
811
812 /*
813  * @brief get a json array named "name" from the json object.
814  *
815  * Get the array attribute named name, creating it if it does not exist.
816  *
817  * @param object the json object.
818  * @param name the name of the array attribute
819  *
820  * @return The array object, will be created if it did not exist.
821  */
822 struct json_object json_get_array(struct json_object *object,
823                                   const char* name)
824 {
825
826         struct json_object array = json_new_array();
827         json_t *a = NULL;
828
829         if (object->error) {
830                 array.error = true;
831                 return array;
832         }
833
834         a = json_object_get(object->root, name);
835         if (a == NULL) {
836                 return array;
837         }
838         json_array_extend(array.root, a);
839
840         return array;
841 }
842
843 /*
844  * @brief get a json object named "name" from the json object.
845  *
846  * Get the object attribute named name, creating it if it does not exist.
847  *
848  * @param object the json object.
849  * @param name the name of the object attribute
850  *
851  * @return The object, will be created if it did not exist.
852  */
853 struct json_object json_get_object(struct json_object *object,
854                                    const char* name)
855 {
856
857         struct json_object o = json_new_object();
858         json_t *v = NULL;
859
860         if (object->error) {
861                 o.error = true;
862                 return o;
863         }
864
865         v = json_object_get(object->root, name);
866         if (v == NULL) {
867                 return o;
868         }
869         json_object_update(o.root, v);
870
871         return o;
872 }
873 #endif