Need help to write a function using Annotations(Microsoft SAL)

Hi everyone!

I have to implement some functions using SAL Annotation to simulate a student platform.

I just need to see how to create 1 function so i'll have a model for the rest.

I have never used SAL or any annotation source code language and I need your help.

The project is composed of 2 parts one solution that have the main.c file where the console is showed with all the commands i can use(i dont have to modify this file).

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
static void
PrintHelp()
{
    printf("Available commands:\n");
    printf("\t> register <username> <password>\n");
    printf("\t> login <username> <password>\n");
    printf("\t> logout\n");
    printf("\t> store <source file path> <submission name>\n");
    printf("\t> retrieve <submission name> <destination file path>\n");
    printf("\t> exit\n");
}

int main()
{
    char command[10];
    char arg1[MAX_PATH];
    char arg2[MAX_PATH];

    NTSTATUS status = GlobalDataInitialize();
    if (!NT_SUCCESS(status))
    {
        printf("GlobalDataInitialize failed with NTSTATUS = 0x%X\n", status);
        assert(FALSE);
        return -1;
    }

    PrintHelp();
    do
    {
        printf("Enter your command:\n");
        scanf("%s", command);

        if (memcmp(command, "register", sizeof("register")) == 0)
        {
            scanf("%s", arg1);    // username
            scanf("%s", arg2);    // password

            printf("register with username [%s] password [%s]\n", arg1, arg2);
            SafeStorageHandleRegister(arg1, (USHORT)strlen(arg1), arg2, (USHORT)strlen(arg2));
        }
        else if (memcmp(command, "login", sizeof("login")) == 0)
        {
            scanf("%s", arg1);    // username
            scanf("%s", arg2);    // password

            printf("login with username [%s] password [%s]\n", arg1, arg2);
            SafeStorageHandleLogin(arg1, (USHORT)strlen(arg1), arg2, (USHORT)strlen(arg2));
        }
        else if (memcmp(command, "logout", sizeof("logout")) == 0)
        {
            printf("logout\n");
            SafeStorageHandleLogout();
        }
        else if (memcmp(command, "store", sizeof("store")) == 0)
        {
            scanf("%s", arg1);    // source file path
            scanf("%s", arg2);    // submission name

            printf("store with source file path [%s] submission name [%s]\n", arg1, arg2);
            SafeStorageHandleStore(arg2, (USHORT)strlen(arg2), arg1, (USHORT)strlen(arg1));
        }
        else if (memcmp(command, "retrieve", sizeof("retrieve")) == 0)
        {
            scanf("%s", arg1);    // submission name 
            scanf("%s", arg2);    // destination file path

            printf("retrieve with submission name [%s] destination file path [%s]\n", arg1, arg2);
            SafeStorageHandleRetrieve(arg1, (USHORT)strlen(arg1), arg2, (USHORT)strlen(arg2));
        }
        else if (memcmp(command, "exit", sizeof("exit")) == 0)
        {
            printf("Bye Bye!\n");
            break;
        }
        else
        {
            printf("Unknown command. Try again!\n");
        }
    } while (TRUE);

    return 0;



The second solution is where i have to implement all the functionality of the functions. Basicly in this solution i have the headers folder and the source folder. My task is to implement the functions in the header files.
This is the function i need help with:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
// Handles the "register" command
// Creates the user with Username and Password specified
//      * Creates the user's subdirectory in the %APPDIR%\users directory
// Fails if the user is already registered
// This command is available only if no user is currently logged in (it must fail otherwise)
// It returns STATUS_SUCCESS if everything succeeded or a proper error status otherwise.

[code]_Must_inspect_result_
NTSTATUS
SafeStorageHandleRegister(
    _In_reads_bytes_opt_(UsernameLength) PCHAR Username,
    _In_ USHORT UsernameLength,
    _In_reads_bytes_opt_(PasswordLength) PCHAR Password, 
    _In_ USHORT PasswordLength);
[/code]

*****************************************
How can i implement this function?

Last edited on
Did you read this:

https://docs.microsoft.com/en-us/cpp/code-quality/understanding-sal?view=msvc-160

?

SAL is about parameter and result. So the content of the function is not affected.
Topic archived. No new replies allowed.