| 1 |
/* SPDX-License-Identifier: BSD-2-Clause |
| 2 |
|
| 3 |
Copyright (c) 2023, Thorsten Kukuk <[email protected]> |
| 4 |
|
| 5 |
Redistribution and use in source and binary forms, with or without |
| 6 |
modification, are permitted provided that the following conditions are met: |
| 7 |
|
| 8 |
1. Redistributions of source code must retain the above copyright notice, |
| 9 |
this list of conditions and the following disclaimer. |
| 10 |
|
| 11 |
2. Redistributions in binary form must reproduce the above copyright |
| 12 |
notice, this list of conditions and the following disclaimer in the |
| 13 |
documentation and/or other materials provided with the distribution. |
| 14 |
|
| 15 |
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
| 16 |
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| 17 |
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
| 18 |
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE |
| 19 |
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
| 20 |
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
| 21 |
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
| 22 |
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
| 23 |
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
| 24 |
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
| 25 |
POSSIBILITY OF SUCH DAMAGE. |
| 26 |
*/ |
| 27 |
|
| 28 |
/* Test case: |
| 29 |
Create login entry, add logout time via logwtmpdb() |
| 30 |
*/ |
| 31 |
|
| 32 |
#include <time.h> |
| 33 |
#include <stdio.h> |
| 34 |
#include <stdlib.h> |
| 35 |
#include <string.h> |
| 36 |
|
| 37 |
#include "wtmpdb.h" |
| 38 |
|
| 39 |
int |
| 40 |
main(void) |
| 41 |
{ |
| 42 |
const char *db_path = "tst-logwtmpdb.db"; |
| 43 |
char *error = NULL; |
| 44 |
|
| 45 |
/* make sure there is no old stuff flying around */ |
| 46 |
remove (db_path); |
| 47 |
|
| 48 |
if (logwtmpdb (db_path, "pts/99", "user", NULL, "test", &error) < 0) |
| 49 |
{ |
| 50 |
if (error) |
| 51 |
{ |
| 52 |
fprintf (stderr, "%s\n", error); |
| 53 |
free (error); |
| 54 |
} |
| 55 |
else |
| 56 |
fprintf (stderr, "logwtmpdb (login) failed\n"); |
| 57 |
return 1; |
| 58 |
} |
| 59 |
|
| 60 |
if (logwtmpdb (db_path, "pts/99", NULL, NULL, NULL, &error) != 0) |
| 61 |
{ |
| 62 |
if (error) |
| 63 |
{ |
| 64 |
fprintf (stderr, "%s\n", error); |
| 65 |
free (error); |
| 66 |
} |
| 67 |
else |
| 68 |
fprintf (stderr, "logwtmpdb (logout) failed\n"); |
| 69 |
return 1; |
| 70 |
} |
| 71 |
|
| 72 |
return 0; |
| 73 |
} |