Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update get device serial logic #280

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/build_conf.md
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ RETRY=false # Error Recovery disabled
Option to get device serial from system BIOS table:
GET_DEV_SERIAL=true # get device serial enabled
GET_DEV_SERIAL=false # get device serial disabled (default)
NOTE: linux-client required elevated privileges to get device serial from system BIOS table. Use 'sudo' to execute.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why is there a sudden need to use sudo?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

dmidecode -s system-serial-number is a linux command and it requires permissions to display system details.
Sudo is required to get a serial number from BIOS system. If sudo is not provided then it will take the default 'abcdef' serial number


Option to lock TPM for futher reads and writes:
LOCK_TPM=true # TPM Locked for futher reads and writes (default)
Expand Down
16 changes: 10 additions & 6 deletions lib/m-string.c
Original file line number Diff line number Diff line change
Expand Up @@ -93,13 +93,17 @@ static int read_fill_modelserial(void)
}

ch = temp_device_serial[0];
while (ch != '\0') {
if (!isalnum(ch)) {
flag = 1;
}
ch = temp_device_serial[++curr];
if (ch == '\n') {
if (ch == '\0') {
flag = 1;
} else {
while (ch != '\0') {
if (!isalnum(ch)) {
flag = 1;
}
ch = temp_device_serial[++curr];
if (ch == '\n') {
ch = temp_device_serial[++curr];
}
}
}

Expand Down
20 changes: 1 addition & 19 deletions storage/util.c
Original file line number Diff line number Diff line change
Expand Up @@ -337,9 +337,7 @@ int get_device_serial(char *serial_buff)
const char *cmd = "dmidecode -s system-serial-number";
int out_sz;
char out[MAX_DEV_SERIAL_SZ];
int results_sz = 0;
int ret = -1;
char *results = (char *)malloc(MAX_DEV_SERIAL_SZ * sizeof(char));

if (cmd != NULL) {
/* Open the command for reading. */
Expand All @@ -348,24 +346,12 @@ int get_device_serial(char *serial_buff)

/* Read the output a line at a time - output it. */
while (fgets(out, out_sz = sizeof(out), fp) != NULL) {
if (strcat_s(results, MAX_DEV_SERIAL_SZ, out) !=
if (strcat_s(serial_buff, MAX_DEV_SERIAL_SZ, out) !=
0) {
LOG(LOG_ERROR, "Strcat() failed!\n");
goto end;
}
}

results_sz = strnlen_s(results, MAX_DEV_SERIAL_SZ);
if (!results_sz) {
goto end;
}

if (memcpy_s(serial_buff, results_sz, results,
results_sz)) {
LOG(LOG_ERROR,
"Failed to copy device serial contents\n");
goto end;
}
} else {
goto end;
}
Expand All @@ -376,10 +362,6 @@ int get_device_serial(char *serial_buff)
if (fp) {
pclose(fp);
}
if (results) {
free(results);
results = NULL;
}
return ret;
}
#endif
Loading